GNUnet 0.22.2
transport_api_cmd_connecting_peers.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_lib.h"
#include "gnunet_testbed_lib.h"
#include "gnunet_transport_testing_ng_lib.h"
#include "transport-testing-cmds.h"
#include "gnunet_transport_application_service.h"
Include dependency graph for transport_api_cmd_connecting_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 * notify_connect (struct GNUNET_TESTING_Interpreter *is, const struct GNUNET_PeerIdentity *peer)
 Callback from start peer cmd for signaling a peer got connected. 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_TRANSPORT_cmd_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)
 Create command. More...
 

Macro Definition Documentation

◆ LOG

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

Generic logging shortcut.

Definition at line 37 of file transport_api_cmd_connecting_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 44 of file transport_api_cmd_connecting_peers.c.

46{
47 struct ConnectPeersState *cps = cls;
48 const struct GNUNET_TESTING_Command *system_cmd;
49 const struct GNUNET_TESTBED_System *tl_system;
50
51
52 const struct GNUNET_TESTING_Command *peer1_cmd;
54 struct GNUNET_PeerIdentity *peer;
55 char *addr;
56 char *addr_and_port;
57 enum GNUNET_NetworkType nt = 0;
58 uint32_t num;
59 struct GNUNET_TESTING_NodeConnection *pos_connection;
60 struct GNUNET_TESTING_AddressPrefix *pos_prefix;
61 unsigned int con_num = 0;
62 const enum GNUNET_GenericReturnValue *broadcast;
63
64 cps->is = is;
66 cps->start_peer_label);
67 if (GNUNET_YES == cps->wait_for_connect)
68 {
70 "Wait for connect.\n");
72 &ah);
73 }
74 else
75 {
77 "Not waiting for connect.\n");
79 &ah);
80 }
81
83 &broadcast);
84
86 cps->create_label);
87 GNUNET_TESTBED_get_trait_test_system (system_cmd,
88 &tl_system);
89
90 cps->tl_system = tl_system;
91
93 "cps->num: %u \n",
94 cps->num);
95
97 cps->topology);
98
99 for (pos_connection = cps->node_connections_head; NULL != pos_connection;
100 pos_connection = pos_connection->next)
101 {
102 con_num++;
103 num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology);
104 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
105 pos_prefix =
106 pos_prefix->next)
107 {
108 addr = GNUNET_TESTING_get_address (pos_connection,
109 pos_prefix->address_prefix);
110 if (NULL != addr)
111 {
112 char *natted_p = strstr (pos_prefix->address_prefix, "_");
113
115 "0 validating peer number %s %s %s\n",
116 natted_p,
117 pos_prefix->address_prefix,
118 addr);
119 if (0 == GNUNET_memcmp (pos_prefix->address_prefix, "udp"))
121 "validating memcmp\n");
122 if (GNUNET_YES == *broadcast)
124 "validating broadcast\n");
125 if ((0 == GNUNET_memcmp (pos_prefix->address_prefix, "udp")) &&
126 (GNUNET_YES == *broadcast) )
127 GNUNET_asprintf (&addr_and_port,
128 "%s:2086",
129 addr);
130 else if (NULL == natted_p)
131 GNUNET_asprintf (&addr_and_port,
132 "%s:60002",
133 addr);
134 else if (NULL != natted_p)
135 {
136 char *prefix;
137 char *rest;
138 char *address;
139
140 prefix = strtok (addr, "_");
141 rest = strtok (NULL, "_");
142 strtok (rest, "-");
143 address = strtok (NULL, "-");
144
145 GNUNET_asprintf (&addr_and_port,
146 "%s-%s:0",
147 prefix,
148 address);
149
150 }
151 peer = GNUNET_TESTING_get_peer (num, tl_system);
153 "validating peer number %u with identity %s and address %s %u %s and handle %p\n",
154 num,
155 GNUNET_i2s (peer),
156 addr_and_port,
157 *broadcast,
158 pos_prefix->address_prefix,
159 ah);
162 *) ah,
163 peer,
164 nt,
165 addr_and_port);
166 GNUNET_free (peer);
167 GNUNET_free (addr);
168 GNUNET_free (addr_and_port);
169 }
170 }
171 }
172 cps->con_num = con_num;
173}
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_AutoHandle * ah
Handle to ongoing autoconfiguration.
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.
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_application_handle(const struct GNUNET_TESTING_Command *cmd, const struct GNUNET_TRANSPORT_ApplicationHandle **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...
#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_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
Struct to store information needed in callbacks.
unsigned int con_num
Number of connections.
uint32_t num
Number globally identifying the node.
struct GNUNET_TESTING_Interpreter * is
struct GNUNET_TESTING_NodeConnection * node_connections_head
Connections to other peers.
struct GNUNET_TESTING_NetjailTopology * topology
The topology of the test setup.
unsigned int wait_for_connect
Flag indicating, whether the command is waiting for peers to connect that are configured to connect.
const struct GNUNET_TESTBED_System * tl_system
The testing system of this node.
const char * start_peer_label
Label of the cmd to start a peer.
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.
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 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)
Deallocate memory of the struct GNUNET_TESTING_NetjailTopology.
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, ah, ConnectPeersState::con_num, ConnectPeersState::create_label, GNUNET_asprintf(), GNUNET_ERROR_TYPE_DEBUG, 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_lookup_command(), GNUNET_TRANSPORT_application_validate(), GNUNET_TRANSPORT_TESTING_get_trait_application_handle(), GNUNET_TRANSPORT_TESTING_get_trait_broadcast(), GNUNET_YES, is, ConnectPeersState::is, LOG, GNUNET_TESTING_AddressPrefix::next, GNUNET_TESTING_NodeConnection::next, ConnectPeersState::node_connections_head, nt, ConnectPeersState::num, prefix, ConnectPeersState::start_peer_label, ConnectPeersState::tl_system, ConnectPeersState::topology, and ConnectPeersState::wait_for_connect.

Referenced by GNUNET_TRANSPORT_cmd_connect_peers().

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

◆ notify_connect()

static void * notify_connect ( struct GNUNET_TESTING_Interpreter is,
const struct GNUNET_PeerIdentity peer 
)
static

Callback from start peer cmd for signaling a peer got connected.

Definition at line 181 of file transport_api_cmd_connecting_peers.c.

183{
184 const struct GNUNET_TESTING_Command *cmd;
185 struct ConnectPeersState *cps;
186 struct GNUNET_PeerIdentity *peer_connection;
187 unsigned int num;
188 unsigned int con_num;
189 void *ret = NULL;
190
191 cmd = GNUNET_TESTING_interpreter_lookup_command_all (is,
192 "connect-peers");
193 cps = cmd->cls; // WTF? Never go directly into cls of another command! FIXME!
194 con_num = cps->con_num_notified;
195 for (struct GNUNET_TESTING_NodeConnection *pos_connection =
197 NULL != pos_connection;
198 pos_connection = pos_connection->next)
199 {
200 num = GNUNET_TESTING_calculate_num (pos_connection,
201 cps->topology);
202 peer_connection = GNUNET_TESTING_get_peer (num,
203 cps->tl_system);
204 if (0 == GNUNET_memcmp (peer,
205 peer_connection))
206 cps->con_num_notified++;
207 GNUNET_free (peer_connection);
208 }
209 if (cps->con_num_notified == con_num)
211
213 "con_num: %u add: %u num_notified: %u add_notified: %u peer: %s\n",
214 cps->con_num,
216 cps->con_num_notified,
218 GNUNET_i2s (peer));
219 if ((cps->con_num == cps->con_num_notified) &&
221 {
223 }
224 return ret;
225}
static int ret
Final status code.
Definition: gnunet-arm.c:93
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
struct GNUNET_TESTING_AsyncContext ac
Context for our asynchronous completion.
unsigned int additional_connects_notified
Number of additional connects this cmd will wait for not triggered by this cmd we already have a noti...
unsigned int con_num_notified
Number of connections we already have a notification for.
unsigned int additional_connects
Number of additional connects this cmd will wait for not triggered by this cmd.
void * cls
Closure for all commands with command-specific context information.

References ConnectPeersState::ac, ConnectPeersState::additional_connects, ConnectPeersState::additional_connects_notified, GNUNET_TESTING_Command::cls, ConnectPeersState::con_num, ConnectPeersState::con_num_notified, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_memcmp, GNUNET_TESTING_async_finish(), GNUNET_TESTING_calculate_num(), GNUNET_TESTING_get_peer(), is, GNUNET_TESTING_NodeConnection::next, ConnectPeersState::node_connections_head, ret, ConnectPeersState::tl_system, and ConnectPeersState::topology.

Referenced by GNUNET_TRANSPORT_cmd_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 233 of file transport_api_cmd_connecting_peers.c.

234{
235 struct ConnectPeersState *cps = cls;
236
237 GNUNET_free (cps);
238}

References GNUNET_free.

Referenced by GNUNET_TRANSPORT_cmd_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 246 of file transport_api_cmd_connecting_peers.c.

250{
251 struct ConnectPeersState *cps = cls;
252 struct GNUNET_TESTING_Trait traits[] = {
253 GNUNET_TRANSPORT_TESTING_make_trait_connect_peer_state ((const void *) cps),
255 };
257 ret,
258 trait,
259 index);
260}
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_TRANSPORT_cmd_connect_peers().

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

◆ GNUNET_TRANSPORT_cmd_connect_peers()

struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_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 
)

Create command.

Parameters
labelname for command
start_peer_labelLabel of the cmd to start a peer.
create_labelLabel of the cmd which started the test system.
numNumber globally identifying the node.
topologyThe topology for the test setup.
additional_connectsNumber of additional connects this cmd will wait for not triggered by this cmd.
Returns
command.

Definition at line 264 of file transport_api_cmd_connecting_peers.c.

272{
273 struct ConnectPeersState *cps;
274 unsigned int node_additional_connects;
275
276 node_additional_connects = GNUNET_TESTING_get_additional_connects (num,
277 topology);
278
280 "global: %u and local: %u additional_connects\n",
282 node_additional_connects);
283
284 if (0 != node_additional_connects)
285 additional_connects = node_additional_connects;
286
287 cps = GNUNET_new (struct ConnectPeersState);
289 cps->num = num;
291 cps->topology = topology;
295
296 // FIXME: wrap with cmd_make_unblocking!
299 label,
303 &cps->ac);
304 else
305 return GNUNET_TESTING_command_new (cps,
306 label,
310}
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.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
GNUNET_TESTING_notify_connect_cb notify_connect
unsigned int GNUNET_TESTING_get_additional_connects(unsigned int num, struct GNUNET_TESTING_NetjailTopology *topology)
Get the number of unintentional additional connections the node waits for.
static void connect_peers_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
The run method of this cmd will connect to peers.
static void * notify_connect(struct GNUNET_TESTING_Interpreter *is, const struct GNUNET_PeerIdentity *peer)
Callback from start peer cmd for signaling a peer got connected.
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 ConnectPeersState::ac, ConnectPeersState::additional_connects, connect_peers_cleanup(), connect_peers_run(), connect_peers_traits(), ConnectPeersState::create_label, GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, GNUNET_TESTING_command_new, GNUNET_TESTING_command_new_ac(), GNUNET_TESTING_get_additional_connects(), GNUNET_YES, LOG, ConnectPeersState::notify_connect, notify_connect(), ConnectPeersState::num, ConnectPeersState::start_peer_label, ConnectPeersState::topology, and ConnectPeersState::wait_for_connect.

Here is the call graph for this function: