GNUnet 0.24.1-16-gbc519cf4b
testing_cmd_transport_connect_peers.c File Reference
Include dependency graph for testing_cmd_transport_connect_peers.c:

Go to the source code of this file.

Macros

#define LOG(kind, ...)   GNUNET_log (kind, __VA_ARGS__)
 Generic logging shortcut. More...
 

Functions

static void connect_peers_run (void *cls, struct GNUNET_TESTING_Interpreter *is)
 The run method of this cmd will connect to peers. More...
 
static void connect_peers_cleanup (void *cls)
 The cleanup function of this cmd frees resources the cmd allocated. More...
 
enum GNUNET_GenericReturnValue connect_peers_traits (void *cls, const void **ret, const char *trait, unsigned int index)
 This function prepares an array with traits. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_transport_connect_peers (const char *label, const char *start_peer_label, const char *create_label, uint32_t num, struct GNUNET_TESTING_NetjailTopology *topology, unsigned int additional_connects, unsigned int wait_for_connect, struct GNUNET_MQ_MessageHandler *handlers)
 

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log (kind, __VA_ARGS__)

Generic logging shortcut.

Definition at line 38 of file testing_cmd_transport_connect_peers.c.

Function Documentation

◆ connect_peers_run()

static void connect_peers_run ( void *  cls,
struct GNUNET_TESTING_Interpreter is 
)
static

The run method of this cmd will connect to peers.

Definition at line 46 of file testing_cmd_transport_connect_peers.c.

48{
49 struct GNUNET_TESTING_ConnectPeersState *cps = cls;
50 const struct GNUNET_TESTING_StartPeerState *sps;
51 const struct GNUNET_TESTING_Command *system_cmd;
52 struct GNUNET_TESTBED_System *tl_system;
53 const struct GNUNET_TESTING_Command *peer1_cmd;
54 struct GNUNET_PeerIdentity *peer;
55 enum GNUNET_NetworkType nt = 0;
56 struct GNUNET_TESTING_NodeConnection *pos_connection;
57 struct GNUNET_TESTING_AddressPrefix *pos_prefix;
58 const enum GNUNET_GenericReturnValue *broadcast;
59 unsigned int con_num = 0;
60 uint32_t num;
61 char *addr;
62 char *addr_and_port;
63 char *emsg = NULL;
64
65 cps->is = is;
67 cps->start_peer_label);
69 &broadcast);
71 &sps);
72
74 cps->create_label);
76 &tl_system);
77
78 cps->tl_system = tl_system;
79
81 "cps->num: %u \n",
82 cps->num);
83
84
86 if (NULL == cps->ah)
87 {
89 "Failed to initialize the TRANSPORT application suggestion client handle for peer `%s': `%s'\n",
90 sps->cfgname,
91 emsg);
92 GNUNET_free (emsg);
94 return;
95 }
96
98 cps->topology);
99
100 for (pos_connection = cps->node_connections_head; NULL != pos_connection;
101 pos_connection = pos_connection->next)
102 {
103 con_num++;
104 num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology);
105 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
106 pos_prefix =
107 pos_prefix->next)
108 {
109 addr = GNUNET_TESTING_get_address (pos_connection,
110 pos_prefix->address_prefix);
111 if (NULL != addr)
112 {
113 char *natted_p = strstr (pos_prefix->address_prefix, "_");
114
116 "0 validating peer number %s %s %s\n",
117 natted_p,
118 pos_prefix->address_prefix,
119 addr);
120 if (0 == GNUNET_memcmp (pos_prefix->address_prefix, "udp"))
122 "validating memcmp\n");
123 if (GNUNET_YES == *broadcast)
125 "validating broadcast\n");
126 if ((0 == GNUNET_memcmp (pos_prefix->address_prefix, "udp")) &&
127 (GNUNET_YES == *broadcast) )
128 GNUNET_asprintf (&addr_and_port,
129 "%s:2086",
130 addr);
131 else if (NULL == natted_p)
132 GNUNET_asprintf (&addr_and_port,
133 "%s:60002",
134 addr);
135 else if (NULL != natted_p)
136 {
137 char *prefix;
138 char *rest;
139 char *address;
140
141 prefix = strtok (addr, "_");
142 rest = strtok (NULL, "_");
143 strtok (rest, "-");
144 address = strtok (NULL, "-");
145
146 GNUNET_asprintf (&addr_and_port,
147 "%s-%s:0",
148 prefix,
149 address);
150
151 }
152 peer = GNUNET_TESTING_get_peer (num, tl_system);
154 "validating peer number %u with identity %s and address %s %u %s and handle %p\n",
155 num,
156 GNUNET_i2s (peer),
157 addr_and_port,
158 *broadcast,
159 pos_prefix->address_prefix,
160 cps->ah);
163 *) cps->ah,
164 peer,
165 nt,
166 addr_and_port);
167 GNUNET_free (peer);
168 GNUNET_free (addr);
169 GNUNET_free (addr_and_port);
170 }
171 }
172 }
173 cps->con_num = con_num;
174}
static struct GNUNET_TESTING_Interpreter * is
static int prefix
If printing the value of PREFIX has been requested.
Definition: gnunet-config.c:65
static char * address
GNS address for this phone.
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
void GNUNET_TESTING_interpreter_fail(struct GNUNET_TESTING_Interpreter *is)
Current command failed, clean up and fail the test case.
enum GNUNET_GenericReturnValue GNUNET_TESTING_TESTBED_get_trait_test_system(const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTBED_System **ret)
enum GNUNET_GenericReturnValue GNUNET_TRANSPORT_TESTING_get_trait_broadcast(const struct GNUNET_TESTING_Command *cmd, const enum GNUNET_GenericReturnValue **ret)
struct GNUNET_PeerIdentity * GNUNET_TESTING_get_peer(unsigned int num, const struct GNUNET_TESTING_System *tl_system)
Retrieve peer identity from the test system with the unique node id.
enum GNUNET_GenericReturnValue GNUNET_TRANSPORT_TESTING_get_trait_state(const struct GNUNET_TESTING_Command *cmd, const struct GNUNET_TESTING_StartPeerState **ret)
void GNUNET_TRANSPORT_application_validate(struct GNUNET_TRANSPORT_ApplicationHandle *ch, const struct GNUNET_PeerIdentity *peer, enum GNUNET_NetworkType nt, const char *addr)
An application (or a communicator) has received a HELLO (or other address data of another peer) and w...
struct GNUNET_TRANSPORT_ApplicationHandle * GNUNET_TRANSPORT_application_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the TRANSPORT application client handle.
#define GNUNET_log(kind,...)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_YES
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:44
The identity of the host (wraps the signing key of the peer).
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testbed.c:54
Protocol address prefix für a connection between nodes.
struct GNUNET_TESTING_AddressPrefix * next
Pointer to the next prefix in the DLL.
char * address_prefix
The address prefix.
A command to be run by the interpreter.
API for cmds working with core sub system provided by libgnunetcoretesting.
uint32_t num
Number globally identifying the node.
const struct GNUNET_TESTBED_System * tl_system
The testing system of this node.
struct GNUNET_TESTING_Interpreter * is
unsigned int con_num
Number of connections.
const char * start_peer_label
Label of the cmd to start a peer.
struct GNUNET_TRANSPORT_ApplicationHandle * ah
Handle for transport.
struct GNUNET_TESTING_NodeConnection * node_connections_head
Connections to other peers.
struct GNUNET_TESTING_NetjailTopology * topology
The topology of the test setup.
Connection to another node.
struct GNUNET_TESTING_NodeConnection * next
Pointer to the next connection in the DLL.
struct GNUNET_TESTING_AddressPrefix * address_prefixes_head
Head of the DLL with the address prefixes for the protocols this node is reachable.
Handle for a peer controlled via ARM.
struct GNUNET_CONFIGURATION_Handle * cfg
Peer's configuration.
char * cfgname
GNUnet configuration file used to start a peer.
Handle to the TRANSPORT subsystem for application management.
struct GNUNET_TESTING_NodeConnection * GNUNET_TESTING_get_connections(unsigned int num, const struct GNUNET_TESTING_NetjailTopology *topology)
Get the connections to other nodes for a specific node.
unsigned int GNUNET_TESTING_calculate_num(struct GNUNET_TESTING_NodeConnection *node_connection, struct GNUNET_TESTING_NetjailTopology *topology)
Calculate the unique id identifying a node from a given connection.
char * GNUNET_TESTING_get_address(struct GNUNET_TESTING_NodeConnection *connection, const char *prefix)
Get the address for a specific communicator from a connection.
#define LOG(kind,...)
Generic logging shortcut.

References address, GNUNET_TESTING_AddressPrefix::address_prefix, GNUNET_TESTING_NodeConnection::address_prefixes_head, GNUNET_TESTING_ConnectPeersState::ah, GNUNET_TESTING_StartPeerState::cfg, GNUNET_TESTING_StartPeerState::cfgname, GNUNET_TESTING_ConnectPeersState::con_num, GNUNET_TESTING_ConnectPeersState::create_label, GNUNET_asprintf(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_memcmp, GNUNET_TESTING_calculate_num(), GNUNET_TESTING_get_address(), GNUNET_TESTING_get_connections(), GNUNET_TESTING_get_peer(), GNUNET_TESTING_interpreter_fail(), GNUNET_TESTING_interpreter_lookup_command(), GNUNET_TESTING_TESTBED_get_trait_test_system(), GNUNET_TRANSPORT_application_init(), GNUNET_TRANSPORT_application_validate(), GNUNET_TRANSPORT_TESTING_get_trait_broadcast(), GNUNET_TRANSPORT_TESTING_get_trait_state(), GNUNET_YES, GNUNET_TESTING_ConnectPeersState::is, is, LOG, GNUNET_TESTING_AddressPrefix::next, GNUNET_TESTING_NodeConnection::next, GNUNET_TESTING_ConnectPeersState::node_connections_head, nt, GNUNET_TESTING_ConnectPeersState::num, prefix, GNUNET_TESTING_ConnectPeersState::start_peer_label, GNUNET_TESTING_ConnectPeersState::tl_system, and GNUNET_TESTING_ConnectPeersState::topology.

Referenced by GNUNET_TESTING_cmd_transport_connect_peers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ connect_peers_cleanup()

static void connect_peers_cleanup ( void *  cls)
static

The cleanup function of this cmd frees resources the cmd allocated.

Definition at line 182 of file testing_cmd_transport_connect_peers.c.

183{
184 struct GNUNET_TESTING_ConnectPeersState *cps = cls;
185
187 GNUNET_free (cps);
188}
struct GNUNET_CONTAINER_MultiShortmap * connected_peers_map
A map with struct GNUNET_MQ_Handle values for each peer this peer is connected to.

References GNUNET_TESTING_ConnectPeersState::connected_peers_map, and GNUNET_free.

Referenced by GNUNET_TESTING_cmd_transport_connect_peers().

Here is the caller graph for this function:

◆ connect_peers_traits()

enum GNUNET_GenericReturnValue connect_peers_traits ( void *  cls,
const void **  ret,
const char *  trait,
unsigned int  index 
)

This function prepares an array with traits.

Definition at line 196 of file testing_cmd_transport_connect_peers.c.

200{
201 struct GNUNET_TESTING_ConnectPeersState *cps = cls;
202 struct GNUNET_TESTING_Trait traits[] = {
203 GNUNET_TRANSPORT_TESTING_make_trait_connect_peer_state ((const void *) cps),
205 };
207 ret,
208 trait,
209 index);
210}
static int ret
Final status code.
Definition: gnunet-arm.c:93
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" of traits array.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait(const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
Obtain value of a trait from a command.
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
unsigned int index
Index number associated with the trait.
static enum GNUNET_GenericReturnValue traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.

References GNUNET_TESTING_get_trait(), GNUNET_TESTING_trait_end(), GNUNET_TESTING_Trait::index, ret, and traits().

Referenced by GNUNET_TESTING_cmd_transport_connect_peers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_cmd_transport_connect_peers()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_transport_connect_peers ( const char *  label,
const char *  start_peer_label,
const char *  create_label,
uint32_t  num,
struct GNUNET_TESTING_NetjailTopology topology,
unsigned int  additional_connects,
unsigned int  wait_for_connect,
struct GNUNET_MQ_MessageHandler handlers 
)

Definition at line 214 of file testing_cmd_transport_connect_peers.c.

223{
225 //unsigned int node_additional_connects;
226 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
228 unsigned int i;
229
230 //node_additional_connects = GNUNET_TESTING_get_additional_connects (num,
231 // topology);
232
234 "global: %u\n",
235 additional_connects);
236 // node_additional_connects);
237
238 //if (0 != node_additional_connects)
239 // additional_connects = node_additional_connects;
240
242 cps->start_peer_label = start_peer_label;
243 cps->num = num;
244 cps->create_label = create_label;
245 cps->topology = topology;
246 cps->additional_connects = additional_connects;
247 cps->wait_for_connect = wait_for_connect;
248 cps->connected_peers_map = connected_peers_map;
249
250 if (NULL != handlers)
251 {
252 for (i = 0; NULL != handlers[i].cb; i++)
253 cps->handlers = GNUNET_new_array (i + 1,
256 handlers,
257 i * sizeof(struct GNUNET_MQ_MessageHandler));
258 }
259 // FIXME: wrap with cmd_make_unblocking!
260 if (GNUNET_YES == wait_for_connect)
262 label,
266 &cps->ac);
267 else
268 return GNUNET_TESTING_command_new (cps,
269 label,
273}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new_ac(void *cls, const char *label, GNUNET_TESTING_CommandRunRoutine run, GNUNET_TESTING_CommandCleanupRoutine cleanup, GNUNET_TESTING_CommandGetTraits traits, struct GNUNET_TESTING_AsyncContext *ac)
Create a new command that may be asynchronous.
#define GNUNET_TESTING_command_new(cls, label, run, cleanup, traits)
Create a new command.
struct GNUNET_CONTAINER_MultiShortmap * GNUNET_CONTAINER_multishortmap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_NO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
Internal representation of the hash map.
Message handler for a specific message type.
unsigned int additional_connects
Number of additional connects this cmd will wait for not triggered by this cmd.
unsigned int wait_for_connect
Flag indicating, whether the command is waiting for peers to connect that are configured to connect.
struct GNUNET_MQ_MessageHandler * handlers
Receive callback.
struct GNUNET_TESTING_AsyncContext ac
Context for our asynchronous completion.
static void connect_peers_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
The run method of this cmd will connect to peers.
static void connect_peers_cleanup(void *cls)
The cleanup function of this cmd frees resources the cmd allocated.
enum GNUNET_GenericReturnValue connect_peers_traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.

References GNUNET_TESTING_ConnectPeersState::ac, GNUNET_TESTING_ConnectPeersState::additional_connects, connect_peers_cleanup(), connect_peers_run(), connect_peers_traits(), GNUNET_TESTING_ConnectPeersState::connected_peers_map, GNUNET_TESTING_ConnectPeersState::create_label, GNUNET_CONTAINER_multishortmap_create(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_memcpy, GNUNET_new, GNUNET_new_array, GNUNET_NO, GNUNET_TESTING_command_new, GNUNET_TESTING_command_new_ac(), GNUNET_YES, handlers, GNUNET_TESTING_ConnectPeersState::handlers, LOG, GNUNET_TESTING_ConnectPeersState::num, GNUNET_TESTING_ConnectPeersState::start_peer_label, GNUNET_TESTING_ConnectPeersState::topology, and GNUNET_TESTING_ConnectPeersState::wait_for_connect.

Here is the call graph for this function: