GNUnet  0.17.6
Macros | Functions
transport_api_cmd_connecting_peers.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
#include "gnunet_testing_netjail_lib.h"
#include "gnunet_transport_application_service.h"
#include "gnunet_hello_lib.h"
#include "gnunet_transport_service.h"
#include "transport-testing-cmds.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)
 Create command. More...
 

Macro Definition Documentation

◆ LOG

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

Generic logging shortcut.

Definition at line 38 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 45 of file transport_api_cmd_connecting_peers.c.

47 {
48  struct ConnectPeersState *cps = cls;
49  const struct GNUNET_TESTING_Command *system_cmd;
50  const struct GNUNET_TESTING_System *tl_system;
51 
52 
53  const struct GNUNET_TESTING_Command *peer1_cmd;
55  struct GNUNET_PeerIdentity *peer;
56  char *addr;
57  char *addr_and_port;
58  enum GNUNET_NetworkType nt = 0;
59  uint32_t num;
60  struct GNUNET_TESTING_NodeConnection *pos_connection;
61  struct GNUNET_TESTING_AddressPrefix *pos_prefix;
62  unsigned int con_num = 0;
63  const enum GNUNET_GenericReturnValue *broadcast;
64  char *port;
65 
66  cps->is = is;
68  cps->start_peer_label);
70  &ah);
72  &broadcast);
73 
75  cps->create_label);
77  &tl_system);
78 
79  cps->tl_system = tl_system;
80 
82  "cps->num: %u \n",
83  cps->num);
84 
86  cps->topology);
87 
88  for (pos_connection = cps->node_connections_head; NULL != pos_connection;
89  pos_connection = pos_connection->next)
90  {
91  con_num++;
92  num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology);
93  for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
94  pos_prefix =
95  pos_prefix->next)
96  {
97  addr = GNUNET_TESTING_get_address (pos_connection,
98  pos_prefix->address_prefix);
99  if (NULL != addr)
100  {
101  if (0 == GNUNET_memcmp (pos_prefix->address_prefix, "udp"))
103  "validating memcmp\n");
104  if (GNUNET_YES == *broadcast)
106  "validating broadcast\n");
107  if ((0 == GNUNET_memcmp (pos_prefix->address_prefix, "udp")) &&
108  (GNUNET_YES == *broadcast) )
109  GNUNET_asprintf (&addr_and_port,
110  "%s:2086",
111  addr);
112  else
113  GNUNET_asprintf (&addr_and_port,
114  "%s:60002",
115  addr);
116  peer = GNUNET_TESTING_get_pub_key (num, tl_system);
118  "validating peer number %u with identity %s and address %s %u %s\n",
119  num,
120  GNUNET_i2s (peer),
121  addr_and_port,
122  *broadcast,
123  pos_prefix->address_prefix);
126  *) ah,
127  peer,
128  nt,
129  addr_and_port);
130  GNUNET_free (peer);
131  GNUNET_free (addr);
132  GNUNET_free (addr_and_port);
133  }
134  }
135  }
136  cps->con_num = con_num;
137 }
static uint16_t port
Port number.
Definition: gnunet-bcd.c:147
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
static struct GNUNET_NAT_AUTO_AutoHandle * ah
Handle to ongoing autoconfiguration.
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
char * GNUNET_TESTING_get_address(struct GNUNET_TESTING_NodeConnection *connection, char *prefix)
Get the address for a specific communicator from a connection.
Definition: testing.c:2289
struct GNUNET_TESTING_NodeConnection * GNUNET_TESTING_get_connections(unsigned int num, struct GNUNET_TESTING_NetjailTopology *topology)
Get the connections to other nodes for a specific node.
Definition: testing.c:2097
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.
Definition: testing.c:2263
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_test_system(const struct GNUNET_TESTING_Command *cmd, const struct GNUNET_TESTING_System **ret)
struct GNUNET_PeerIdentity * GNUNET_TESTING_get_pub_key(unsigned int num, const struct GNUNET_TESTING_System *tl_system)
Retrieve the public key from the test system with the unique node id.
Definition: testing.c:2172
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
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.
Definition: gnunet_common.h:96
@ 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:36
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.
const struct GNUNET_TESTING_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).
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.
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 protocolls this node is reachable.
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testing.c:103
Handle to the TRANSPORT subsystem for application management.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
enum GNUNET_GenericReturnValue GNUNET_TRANSPORT_get_trait_application_handle(const struct GNUNET_TESTING_Command *cmd, const struct GNUNET_TRANSPORT_ApplicationHandle **ret)
enum GNUNET_GenericReturnValue GNUNET_TRANSPORT_get_trait_broadcast(const struct GNUNET_TESTING_Command *cmd, const enum GNUNET_GenericReturnValue **ret)
#define LOG(kind,...)
Generic logging shortcut.

References 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_pub_key(), GNUNET_TESTING_get_trait_test_system(), GNUNET_TESTING_interpreter_lookup_command(), GNUNET_TRANSPORT_application_validate(), GNUNET_TRANSPORT_get_trait_application_handle(), GNUNET_TRANSPORT_get_trait_broadcast(), GNUNET_YES, is, ConnectPeersState::is, LOG, GNUNET_TESTING_AddressPrefix::next, GNUNET_TESTING_NodeConnection::next, ConnectPeersState::node_connections_head, nt, ConnectPeersState::num, peer, port, ConnectPeersState::start_peer_label, ConnectPeersState::tl_system, and ConnectPeersState::topology.

Here is the call 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 145 of file transport_api_cmd_connecting_peers.c.

147 {
148  const struct GNUNET_TESTING_Command *cmd;
149  struct ConnectPeersState *cps;
150  struct GNUNET_PeerIdentity *peer_connection;
151  struct GNUNET_TESTING_NodeConnection *pos_connection;
152  unsigned int num;
153  unsigned int con_num;
154  void *ret = NULL;
155 
157  "connect-peers");
158  cps = cmd->cls;
159  con_num = cps->con_num_notified;
160  for (pos_connection = cps->node_connections_head; NULL != pos_connection;
161  pos_connection = pos_connection->next)
162  {
163  num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology);
164  peer_connection = GNUNET_TESTING_get_pub_key (num, cps->tl_system);
165  if (0 == GNUNET_memcmp (peer,
166  peer_connection))
167  cps->con_num_notified++;
168  GNUNET_free (peer_connection);
169  }
170  if (cps->con_num == con_num)
172 
174  "con_num: %u add: %u num_notified: %u add_notified: %u\n",
175  cps->con_num,
176  cps->additional_connects,
177  cps->con_num_notified,
179  if (cps->con_num + cps->additional_connects == cps->con_num_notified
181  {
183  }
184  return ret;
185 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command_all(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
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_log, GNUNET_memcmp, GNUNET_TESTING_async_finish(), GNUNET_TESTING_calculate_num(), GNUNET_TESTING_get_pub_key(), GNUNET_TESTING_interpreter_lookup_command_all(), is, GNUNET_TESTING_NodeConnection::next, ConnectPeersState::node_connections_head, peer, ret, ConnectPeersState::tl_system, and ConnectPeersState::topology.

Here is the call 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 193 of file transport_api_cmd_connecting_peers.c.

194 {
195  struct ConnectPeersState *cps = cls;
196 
197  GNUNET_free (cps);
198 }

References GNUNET_free.

◆ 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 193 of file transport_api_cmd_connecting_peers.c.

210 {
211  struct ConnectPeersState *cps = cls;
212  struct GNUNET_TESTING_Trait traits[] = {
215  };
216  return GNUNET_TESTING_get_trait (traits,
217  ret,
218  trait,
219  index);
220 }
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" trait.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait(const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
Extract a trait.
unsigned int index
Index number associated with the trait.
struct GNUNET_TESTING_Trait GNUNET_TRANSPORT_make_trait_connect_peer_state(const struct ConnectPeersState *value)

◆ 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 
)

Create command.

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

Definition at line 193 of file transport_api_cmd_connecting_peers.c.

242 {
243  struct ConnectPeersState *cps;
244 
245  cps = GNUNET_new (struct ConnectPeersState);
247  cps->num = num;
248  cps->create_label = create_label;
249  cps->topology = topology;
252 
253  {
254  struct GNUNET_TESTING_Command cmd = {
255  .cls = cps,
256  .label = label,
257  .run = &connect_peers_run,
258  .ac = &cps->ac,
259  .cleanup = &connect_peers_cleanup,
260  .traits = &connect_peers_traits
261  };
262 
263  return cmd;
264  }
265 }
enum GNUNET_TESTBED_TopologyOption topology
The topology to generate.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
GNUNET_TRANSPORT_notify_connect_cb notify_connect
const char * label
Label for the command.
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.