GNUnet  0.17.6
transport_api_cmd_connecting_peers.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2021 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_testing_ng_lib.h"
31 #include "gnunet_hello_lib.h"
33 #include "transport-testing-cmds.h"
34 
38 #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
39 
44 static void
45 connect_peers_run (void *cls,
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 
65  cps->is = is;
67  cps->start_peer_label);
69  &ah);
71  &broadcast);
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 
85  cps->topology);
86 
87  for (pos_connection = cps->node_connections_head; NULL != pos_connection;
88  pos_connection = pos_connection->next)
89  {
90  con_num++;
91  num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology);
92  for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
93  pos_prefix =
94  pos_prefix->next)
95  {
96  addr = GNUNET_TESTING_get_address (pos_connection,
97  pos_prefix->address_prefix);
98  if (NULL != addr)
99  {
100  if (0 == GNUNET_memcmp (pos_prefix->address_prefix, "udp"))
102  "validating memcmp\n");
103  if (GNUNET_YES == *broadcast)
105  "validating broadcast\n");
106  if ((0 == GNUNET_memcmp (pos_prefix->address_prefix, "udp")) &&
107  (GNUNET_YES == *broadcast) )
108  GNUNET_asprintf (&addr_and_port,
109  "%s:2086",
110  addr);
111  else
112  GNUNET_asprintf (&addr_and_port,
113  "%s:60002",
114  addr);
115  peer = GNUNET_TESTING_get_pub_key (num, tl_system);
117  "validating peer number %u with identity %s and address %s %u %s\n",
118  num,
119  GNUNET_i2s (peer),
120  addr_and_port,
121  *broadcast,
122  pos_prefix->address_prefix);
125  *) ah,
126  peer,
127  nt,
128  addr_and_port);
129  GNUNET_free (peer);
130  GNUNET_free (addr);
131  GNUNET_free (addr_and_port);
132  }
133  }
134  }
135  cps->con_num = con_num;
136 }
137 
138 
143 static void *
145  const struct GNUNET_PeerIdentity *peer)
146 {
147  const struct GNUNET_TESTING_Command *cmd;
148  struct ConnectPeersState *cps;
149  struct GNUNET_PeerIdentity *peer_connection;
150  struct GNUNET_TESTING_NodeConnection *pos_connection;
151  unsigned int num;
152  unsigned int con_num;
153  void *ret = NULL;
154 
156  "connect-peers");
157  cps = cmd->cls;
158  con_num = cps->con_num_notified;
159  for (pos_connection = cps->node_connections_head; NULL != pos_connection;
160  pos_connection = pos_connection->next)
161  {
162  num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology);
163  peer_connection = GNUNET_TESTING_get_pub_key (num, cps->tl_system);
164  if (0 == GNUNET_memcmp (peer,
165  peer_connection))
166  cps->con_num_notified++;
167  GNUNET_free (peer_connection);
168  }
169  if (cps->con_num_notified == con_num)
171 
173  "con_num: %u add: %u num_notified: %u add_notified: %u peer: %s\n",
174  cps->con_num,
175  cps->additional_connects,
176  cps->con_num_notified,
178  GNUNET_i2s (peer));
179  if ((cps->con_num == cps->con_num_notified) &&
181  {
183  }
184  return ret;
185 }
186 
187 
192 static void
194 {
195  struct ConnectPeersState *cps = cls;
196 
197  GNUNET_free (cps);
198 }
199 
200 
206 connect_peers_traits (void *cls,
207  const void **ret,
208  const char *trait,
209  unsigned int index)
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 }
221 
222 
236  const char *start_peer_label,
237  const char *create_label,
238  uint32_t num,
240  topology,
241  unsigned int additional_connects)
242 {
243  struct ConnectPeersState *cps;
244  unsigned int node_additional_connects;
245 
246  node_additional_connects = GNUNET_TESTING_get_additional_connects (num,
247  topology);
248 
250  "global: %u and local: %u additional_connects\n",
252  node_additional_connects);
253 
254  if (0 != node_additional_connects)
255  additional_connects = node_additional_connects;
256 
257  cps = GNUNET_new (struct ConnectPeersState);
259  cps->num = num;
260  cps->create_label = create_label;
261  cps->topology = topology;
264 
265  {
266  struct GNUNET_TESTING_Command cmd = {
267  .cls = cps,
268  .label = label,
269  .run = &connect_peers_run,
270  .ac = &cps->ac,
271  .cleanup = &connect_peers_cleanup,
272  .traits = &connect_peers_traits
273  };
274 
275  return cmd;
276  }
277 }
enum GNUNET_TESTBED_TopologyOption topology
The topology to generate.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
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.
Helper library for handling HELLOs.
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:2324
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.
Definition: testing.c:2387
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:2192
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:2298
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_test_system(const struct GNUNET_TESTING_Command *cmd, const struct GNUNET_TESTING_System **ret)
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
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:2216
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_Trait GNUNET_TESTING_trait_end(void)
"end" trait.
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_TESTING_get_trait(const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
Extract a trait.
Bandwidth allocation API for applications to interact with.
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_new(type)
Allocate a struct or union of the given type.
#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.
struct GNUNET_TESTING_AsyncContext ac
Context for our asynchronous completion.
unsigned int con_num
Number of connections.
uint32_t num
Number globally identifying the node.
unsigned int additional_connects_notified
Number of additional connects this cmd will wait for not triggered by this cmd we already have a noti...
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.
unsigned int con_num_notified
Number of connections we already have a notification for.
GNUNET_TRANSPORT_notify_connect_cb notify_connect
const char * start_peer_label
Label of the cmd to start a peer.
unsigned int additional_connects
Number of additional connects this cmd will wait for not triggered by this cmd.
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.
const char * label
Label for the command.
void * cls
Closure for all commands with command-specific context information.
Global state of the interpreter, used by a command to access information about other commands.
unsigned int additional_connects
Additional connects we do expect, beside the connects which are configured in the topology.
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
unsigned int index
Index number associated with the trait.
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)
struct GNUNET_TESTING_Trait GNUNET_TRANSPORT_make_trait_connect_peer_state(const struct ConnectPeersState *value)
enum GNUNET_GenericReturnValue GNUNET_TRANSPORT_get_trait_broadcast(const struct GNUNET_TESTING_Command *cmd, const enum GNUNET_GenericReturnValue **ret)
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.
#define LOG(kind,...)
Generic logging shortcut.
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.
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.