GNUnet 0.21.1
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"
32
36#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
37
42static void
45{
46 struct ConnectPeersState *cps = cls;
47 const struct GNUNET_TESTING_Command *system_cmd;
48 const struct GNUNET_TESTING_System *tl_system;
49
50
51 const struct GNUNET_TESTING_Command *peer1_cmd;
53 struct GNUNET_PeerIdentity *peer;
54 char *addr;
55 char *addr_and_port;
56 enum GNUNET_NetworkType nt = 0;
57 uint32_t num;
58 struct GNUNET_TESTING_NodeConnection *pos_connection;
59 struct GNUNET_TESTING_AddressPrefix *pos_prefix;
60 unsigned int con_num = 0;
61 const enum GNUNET_GenericReturnValue *broadcast;
62
63 cps->is = is;
65 cps->start_peer_label);
66 if (GNUNET_YES == cps->wait_for_connect)
67 {
69 "Wait for connect.\n");
71 &ah);
72 }
73 else
74 {
76 "Not waiting for connect.\n");
78 &ah);
79 }
80
82 &broadcast);
83
85 cps->create_label);
87 &tl_system);
88
89 cps->tl_system = tl_system;
90
92 "cps->num: %u \n",
93 cps->num);
94
96 cps->topology);
97
98 for (pos_connection = cps->node_connections_head; NULL != pos_connection;
99 pos_connection = pos_connection->next)
100 {
101 con_num++;
102 num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology);
103 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
104 pos_prefix =
105 pos_prefix->next)
106 {
107 addr = GNUNET_TESTING_get_address (pos_connection,
108 pos_prefix->address_prefix);
109 if (NULL != addr)
110 {
111 char *natted_p = strstr (pos_prefix->address_prefix, "_");
112
114 "0 validating peer number %s %s %s\n",
115 natted_p,
116 pos_prefix->address_prefix,
117 addr);
118 if (0 == GNUNET_memcmp (pos_prefix->address_prefix, "udp"))
120 "validating memcmp\n");
121 if (GNUNET_YES == *broadcast)
123 "validating broadcast\n");
124 if ((0 == GNUNET_memcmp (pos_prefix->address_prefix, "udp")) &&
125 (GNUNET_YES == *broadcast) )
126 GNUNET_asprintf (&addr_and_port,
127 "%s:2086",
128 addr);
129 else if (NULL == natted_p)
130 GNUNET_asprintf (&addr_and_port,
131 "%s:60002",
132 addr);
133 else if (NULL != natted_p)
134 {
135 char *prefix;
136 char *rest;
137 char *address;
138
139 prefix = strtok (addr, "_");
140 rest = strtok (NULL, "_");
141 strtok (rest, "-");
142 address = strtok (NULL, "-");
143
144 GNUNET_asprintf (&addr_and_port,
145 "%s-%s:0",
146 prefix,
147 address);
148
149 }
150 peer = GNUNET_TESTING_get_peer (num, tl_system);
152 "validating peer number %u with identity %s and address %s %u %s and handle %p\n",
153 num,
154 GNUNET_i2s (peer),
155 addr_and_port,
156 *broadcast,
157 pos_prefix->address_prefix,
158 ah);
161 *) ah,
162 peer,
163 nt,
164 addr_and_port);
165 GNUNET_free (peer);
166 GNUNET_free (addr);
167 GNUNET_free (addr_and_port);
168 }
169 }
170 }
171 cps->con_num = con_num;
172}
173
174
179static void *
181 const struct GNUNET_PeerIdentity *peer)
182{
183 const struct GNUNET_TESTING_Command *cmd;
184 struct ConnectPeersState *cps;
185 struct GNUNET_PeerIdentity *peer_connection;
186 unsigned int num;
187 unsigned int con_num;
188 void *ret = NULL;
189
191 "connect-peers");
192 cps = cmd->cls; // WTF? Never go directly into cls of another command! FIXME!
193 con_num = cps->con_num_notified;
194 for (struct GNUNET_TESTING_NodeConnection *pos_connection =
196 NULL != pos_connection;
197 pos_connection = pos_connection->next)
198 {
199 num = GNUNET_TESTING_calculate_num (pos_connection,
200 cps->topology);
201 peer_connection = GNUNET_TESTING_get_peer (num,
202 cps->tl_system);
203 if (0 == GNUNET_memcmp (peer,
204 peer_connection))
205 cps->con_num_notified++;
206 GNUNET_free (peer_connection);
207 }
208 if (cps->con_num_notified == con_num)
210
212 "con_num: %u add: %u num_notified: %u add_notified: %u peer: %s\n",
213 cps->con_num,
215 cps->con_num_notified,
217 GNUNET_i2s (peer));
218 if ((cps->con_num == cps->con_num_notified) &&
220 {
222 }
223 return ret;
224}
225
226
231static void
233{
234 struct ConnectPeersState *cps = cls;
235
236 GNUNET_free (cps);
237}
238
239
246 const void **ret,
247 const char *trait,
248 unsigned int index)
249{
250 struct ConnectPeersState *cps = cls;
251 struct GNUNET_TESTING_Trait traits[] = {
252 GNUNET_TRANSPORT_TESTING_make_trait_connect_peer_state ((const void *) cps),
254 };
255 return GNUNET_TESTING_get_trait (traits,
256 ret,
257 trait,
258 index);
259}
260
261
264 const char *start_peer_label,
265 const char *create_label,
266 uint32_t num,
268 topology,
269 unsigned int additional_connects,
270 unsigned int wait_for_connect)
271{
272 struct ConnectPeersState *cps;
273 unsigned int node_additional_connects;
274
275 node_additional_connects = GNUNET_TESTING_get_additional_connects (num,
276 topology);
277
279 "global: %u and local: %u additional_connects\n",
281 node_additional_connects);
282
283 if (0 != node_additional_connects)
284 additional_connects = node_additional_connects;
285
286 cps = GNUNET_new (struct ConnectPeersState);
288 cps->num = num;
290 cps->topology = topology;
294
296 return GNUNET_TESTING_command_new (cps,
297 label,
301 &cps->ac);
302 else
303 return GNUNET_TESTING_command_new (cps,
304 label,
308 NULL);
309}
310
311
312// FIXME: likely not ideally placed here, move to its own file
static int ret
Final status code.
Definition: gnunet-arm.c:94
struct GNUNET_TESTING_Interpreter * is
static int prefix
If printing the value of PREFIX has been requested.
Definition: gnunet-config.c:59
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.
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
#define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT(prefix, name, type)
Create C implementation for a trait with name name for statically allocated data of type type.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new(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.
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.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command_all(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
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:2447
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.
Definition: testing.c:2251
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:2361
char * GNUNET_TESTING_get_address(struct GNUNET_TESTING_NodeConnection *connection, const char *prefix)
Get the address for a specific communicator from a connection.
Definition: testing.c:2387
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_test_system(const struct GNUNET_TESTING_Command *cmd, const struct GNUNET_TESTING_System **ret)
Bandwidth allocation API for applications to interact with.
#define GNUNET_TRANSPORT_TESTING_SIMPLE_TRAITS(op, prefix)
Call op on all simple traits.
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.
Definition: testing.c:2276
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_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:44
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...
GNUNET_TESTING_notify_connect_cb notify_connect
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 wait_for_connect
Flag indicating, whether the command is waiting for peers to connect that are configured to connect.
unsigned int con_num_notified
Number of connections we already have a notification for.
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.
struct GNUNET_TESTING_CommandLabel 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:122
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
unsigned int index
Index number associated with the trait.
Handle to the TRANSPORT subsystem for application management.
static void connect_peers_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
The run method of this cmd will connect to 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.
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.