GNUnet 0.21.1
transport_api_cmd_backchannel_check.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_common.h"
28#include "gnunet_util_lib.h"
33
37#define LOG(kind, ...) GNUNET_log_from (kind, "udp-backchannel",__VA_ARGS__)
38
39#define UDP "udp"
40
44#define MAX_LINE_LENGTH 1024
45
51{
56
60 unsigned int node_n;
61
65 unsigned int namespace_n;
66
71
72 // Label of the cmd which started the test system.
73 const char *create_label;
74
79 uint32_t num;
80
85 const char *start_peer_label;
86
91
96
100 unsigned int con_num;
101
106
111
116
121
125 FILE *stream;
126};
127
132static void
133read_from_log (void *cls)
134{
135 struct CheckState *cs = cls;
136 char line[MAX_LINE_LENGTH + 1];
137 char *search_string;
138
139
141 "read_from_log\n");
142
143 cs->fh = GNUNET_DISK_file_open ("test.out",
146
147 cs->task = NULL;
148
149 /* read message from line and handle it */
150 cs->stream = fdopen (cs->fh->fd, "r");
151 memset (line, 0, MAX_LINE_LENGTH + 1);
152
153 // fgets (line, MAX_LINE_LENGTH, cs->stream);
154 // while (NULL != line && 0 != strcmp (line, ""))// '\0' != line[0])
155 while (NULL != fgets (line, MAX_LINE_LENGTH, cs->stream))
156 {
157 /*LOG (GNUNET_ERROR_TYPE_DEBUG,
158 "cs->received_backchannel_msgs: %u\n",
159 cs->received_backchannel_msgs);*/
160 /*if (NULL == strstr (line, "line"))
161 LOG (GNUNET_ERROR_TYPE_DEBUG,
162 "line: %s",
163 line);*/
164
165
166 for (int i = 0; i < cs->con_num; i++)
167 {
169 /*LOG (GNUNET_ERROR_TYPE_DEBUG,
170 "search %u %u: %s %p\n",
171 i,
172 cs->con_num,
173 cs->search_string[i],
174 cs->search_string);
175 fprintf (stderr,
176 line);*/
177 if (NULL != strstr (line,
179 // "Delivering backchannel message from 4TTC to F7B5 of type 1460 to udp"))
180 // cs->search_string[i]))
181 {
184 "received_backchannel_msgs %u con_num %u\n",
186 cs->con_num);
187 if (cs->received_backchannel_msgs == cs->con_num)
188 {
190 "search finished %lu %lu %u\n",
191 strlen (cs->search_string[i]),
192 strlen (
193 "Delivering backchannel message from 4TTC to F7B5 of type 1460 to udp"),
194 strcmp (
195 "Delivering backchannel message from 4TTC to F7B5 of type 1460 to udp",
196 cs->search_string[i]));
198 fclose (cs->stream);
199 return;
200 }
201 }
202 }
203 }
205 "read_from_log end\n");
206 fclose (cs->stream);
209 cs);
210 /*if (NULL == fgets (line, MAX_LINE_LENGTH, cs->stream))
211 {
212 LOG (GNUNET_ERROR_TYPE_DEBUG,
213 "read null\n");
214 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
215 &read_from_log,
216 cs);
217 return;
218 }*/
219 /*else {
220 cs->task =
221 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
222 cs->fh,
223 &read_from_log,
224 cs);
225
226
227 }*/
228}
229
230
233 struct CheckState *cs,
234 const struct GNUNET_TESTING_NetjailNode *node)
235// struct GNUNET_TESTING_NodeConnection *connection)
236{
237 // struct GNUNET_TESTING_NetjailTopology *topology = cs->topology;
238 // unsigned int node_n = connection->node_n;
239 // unsigned int namespace_n = connection->namespace_n;
240 // struct GNUNET_HashCode hc;
241 // struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
242 // struct GNUNET_HashCode hc_namespace;
243 /*struct GNUNET_ShortHashCode *key_namespace = GNUNET_new (struct
244 GNUNET_ShortHashCode);*/
245 // struct GNUNET_TESTING_NetjailNode *node;
246 struct GNUNET_TESTING_NodeConnection *pos_connection;
247 struct GNUNET_TESTING_AddressPrefix *pos_prefix;
248 // struct GNUNET_TESTING_NetjailNamespace *namespace;
249 // struct GNUNET_CONTAINER_MultiShortmap *map;
250
251 /* if (0 == connection->namespace_n) */
252 /* { */
253 /* map = topology->map_globals; */
254 /* } */
255 /* else */
256 /* { */
257 /* GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc_namespace); */
258 /* memcpy (key_namespace, */
259 /* &hc_namespace, */
260 /* sizeof (*key_namespace)); */
261 /* if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains ( */
262 /* topology->map_namespaces, */
263 /* key_namespace)) */
264 /* { */
265 /* namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces, */
266 /* key_namespace); */
267 /* map = namespace->nodes; */
268 /* } */
269 /* else */
270 /* GNUNET_assert (0); */
271 /* } */
272
273 /* GNUNET_CRYPTO_hash (&node_n, sizeof(node_n), &hc); */
274 /* memcpy (key, */
275 /* &hc, */
276 /* sizeof (*key)); */
277 /* if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains ( */
278 /* map, */
279 /* key)) */
280 /* { */
281 /* node = GNUNET_CONTAINER_multishortmap_get (cs->topology->map_globals, */
282 /* key); */
283 /* for (pos_connection = node->node_connections_head; NULL != pos_connection; */
284 /* pos_connection = pos_connection->next) */
285 /* { */
286 /* if ((node->namespace_n == pos_connection->namespace_n) && */
287 /* (node->node_n == pos_connection->node_n) ) */
288 /* { */
289 /* for (pos_prefix = pos_connection->address_prefixes_head; NULL != */
290 /* pos_prefix; */
291 /* pos_prefix = */
292 /* pos_prefix->next) */
293 /* { */
294 /* if (0 == strcmp (UDP, pos_prefix->address_prefix)) */
295 /* { */
296 /* return GNUNET_YES; */
297 /* } */
298 /* } */
299 /* } */
300 /* } */
301 /* } */
302
303 for (pos_connection = node->node_connections_head; NULL != pos_connection;
304 pos_connection = pos_connection->next)
305 {
307 "connect via udp %u %u %u %u\n",
308 node->namespace_n,
309 cs->namespace_n,
310 node->node_n,
311 cs->node_n);
312 if ((pos_connection->namespace_n == cs->namespace_n) &&
313 (pos_connection->node_n == cs->node_n) )
314 {
315 for (pos_prefix = pos_connection->address_prefixes_head; NULL !=
316 pos_prefix;
317 pos_prefix =
318 pos_prefix->next)
319 {
320 if (0 == strcmp (UDP, pos_prefix->address_prefix))
321 {
322 return GNUNET_YES;
323 }
324 }
325 }
326 }
327
328 return GNUNET_NO;
329}
330
331
332static void
333add_search_string (struct CheckState *cs, const struct
335{
336 unsigned int num;
337 struct GNUNET_PeerIdentity *peer;
338 struct GNUNET_PeerIdentity *us;
339 char *buf;
340 char *part_one = "Delivering backchannel message from ";
341 char *part_two = " to ";
342 char *part_three = " of type 1460 to udp";
343 char *peer_id;
344 char *us_id;
345
346 if (0 == node->namespace_n)
347 num = node->node_n;
348 else
349 num = (node->namespace_n - 1) * cs->topology->nodes_m + node->node_n
350 + cs->topology->nodes_x;
351
352 // num = GNUNET_TESTING_calculate_num (pos_connection, cs->topology);
353 peer = GNUNET_TESTING_get_peer (num, cs->tl_system);
355 "peer: %s num %u\n",
356 GNUNET_i2s (peer),
357 num);
358 us = GNUNET_TESTING_get_peer (cs->num, cs->tl_system);
360 "us: %s cs->num %d\n",
361 GNUNET_i2s (us),
362 cs->num);
363
365 "%s",
366 GNUNET_i2s (peer));
367 GNUNET_asprintf (&us_id,
368 "%s",
369 GNUNET_i2s (us));
370
371 if (0 < GNUNET_asprintf (&buf,
372 "%s%s%s%s%s",
373 part_one,
374 us_id,
375 part_two,
376 peer_id,
377 part_three))
378 {
380 cs->con_num,
381 buf);
382 /*LOG (GNUNET_ERROR_TYPE_DEBUG,
383 "con_num: %u search: %s %p\n",
384 cs->con_num,
385 cs->search_string[cs->con_num - 1],
386 cs->search_string);*/
387 }
388 else
389 GNUNET_assert (0);
390 GNUNET_free (peer);
391 GNUNET_free (us);
392}
393
394
399static void
402{
403 struct CheckState *cs = cls;
404 const struct GNUNET_TESTING_Command *system_cmd;
405 const struct GNUNET_TESTING_System *tl_system;
406 const struct GNUNET_TESTING_Command *peer1_cmd;
409 struct GNUNET_CONTAINER_MultiShortmapIterator *namespace_it;
410 struct GNUNET_ShortHashCode node_key;
411 struct GNUNET_ShortHashCode namespace_key;
412 const struct GNUNET_TESTING_NetjailNode *node;
413 const struct GNUNET_TESTING_NetjailNamespace *namespace;
414
416 "check run 1\n");
417
419 cs->start_peer_label);
421 &ah);
422
424 cs->create_label);
426 &tl_system);
427
428 cs->tl_system = tl_system;
429
431 cs->topology);
432
434 "check run 2\n");
435
436
438 cs->topology->map_globals);
439
441 &node_key,
442 (const
443 void**) &
444 node))
445 {
447 "namespace_n %u node_n %u\n",
448 node->namespace_n,
449 node->node_n);
451 {
452 add_search_string (cs, node);
453 }
454 }
455 GNUNET_free (node_it);
459 namespace_it,
460 &namespace_key,
461 (const
462 void**) &namespace))
463 {
465 "namespace_n %u\n",
466 node->namespace_n);
468 namespace->nodes);
470 &node_key,
471 (const
472 void**)
473 &node))
474 {
476 "namespace_n %u node_n %u\n",
477 node->namespace_n,
478 node->node_n);
480 {
481 add_search_string (cs, node);
482 }
483 }
484 GNUNET_free (node_it);
485 }
486
487 if (0 != cs->con_num)
488 {
489 cs->task =
491 cs);
492 }
493 else
495
496 GNUNET_free (namespace_it);
497}
498
499
504static int
506 const void **ret,
507 const char *trait,
508 unsigned int index)
509{
510 return GNUNET_OK;
511}
512
513
518static void
520{
521 struct ConnectPeersState *cs = cls;
522
523 GNUNET_free (cs);
524}
525
526
529 const char *start_peer_label,
530 const char *create_label,
531 uint32_t num,
532 unsigned int node_n,
533 unsigned int namespace_n,
535 topology)
536{
537 struct CheckState *cs;
538
539 cs = GNUNET_new (struct CheckState);
541 cs->num = num;
543 cs->topology = topology;
544 cs->node_n = node_n;
546
548 label,
552 &cs->ac);
553}
static int ret
Final status code.
Definition: gnunet-arm.c:94
static char * peer_id
Option –peer.
Definition: gnunet-cadet.c:42
struct GNUNET_TESTING_Interpreter * is
static char * line
Desired phone line (string to be converted to a hash).
static struct GNUNET_NAT_AUTO_AutoHandle * ah
Handle to ongoing autoconfiguration.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
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(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_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
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.
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)
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1237
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
struct GNUNET_CONTAINER_MultiShortmapIterator * GNUNET_CONTAINER_multishortmap_iterator_create(const struct GNUNET_CONTAINER_MultiShortmap *map)
Create an iterator for a multihashmap.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_iterator_next(struct GNUNET_CONTAINER_MultiShortmapIterator *iter, struct GNUNET_ShortHashCode *key, const void **value)
Retrieve the next element from the hash map at the iterator's position.
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ 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_array_append(arr, len, element)
Append an element to an array (growing the array by one).
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1305
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1278
#define GNUNET_TIME_UNIT_MINUTES
One minute.
Struct to store information needed in callbacks.
unsigned int con_num
Number of connections.
char ** search_string
Array with search strings.
FILE * stream
Stream to read log file lines.
const char * start_peer_label
Label of the cmd to start a peer.
struct GNUNET_TESTING_NodeConnection * node_connections_head
Connections to other peers.
unsigned int received_backchannel_msgs
Number of received backchannel messages.
uint32_t num
Number globally identifying the node.
const struct GNUNET_TESTING_System * tl_system
The testing system of this node.
struct GNUNET_TESTING_AsyncContext ac
Context for our asynchronous completion.
unsigned int node_n
The number of the node in a network namespace.
struct GNUNET_SCHEDULER_Task * task
Task which handles the reading.
unsigned int namespace_n
The number of the network namespace.
struct GNUNET_DISK_FileHandle * fh
File handle for log file.
struct GNUNET_TESTING_NetjailTopology * topology
The topology of the test setup.
Struct to store information needed in callbacks.
Handle used to access files (and pipes).
int fd
File handle on Unix-like systems.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Definition: scheduler.c:136
A 256-bit hashcode.
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.
State each asynchronous command must have in its closure.
A command to be run by the interpreter.
struct GNUNET_TESTING_CommandLabel label
Label for the command.
Global state of the interpreter, used by a command to access information about other commands.
Node in the netjail topology.
unsigned int namespace_n
The number of the subnet this node is running in.
struct GNUNET_TESTING_NodeConnection * node_connections_head
Head of the DLL with the connections which shall be established to other nodes.
unsigned int node_n
The number of this node in the subnet.
struct GNUNET_CONTAINER_MultiShortmap * map_globals
Hash map containing the global known nodes which are not natted.
unsigned int nodes_m
Number of nodes per subnet.
unsigned int nodes_x
Number of global known nodes.
struct GNUNET_CONTAINER_MultiShortmap * map_namespaces
Hash map containing the subnets (for natted nodes) of the topology.
struct GNUNET_TESTING_NodeConnection * next
Pointer to the next connection in the DLL.
unsigned int node_n
The number of the node this connection points to.
unsigned int namespace_n
The number of the subnet of the node this connection points to.
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
Handle to the TRANSPORT subsystem for application management.
static void add_search_string(struct CheckState *cs, const struct GNUNET_TESTING_NetjailNode *node)
static enum GNUNET_GenericReturnValue will_the_other_node_connect_via_udp(struct CheckState *cs, const struct GNUNET_TESTING_NetjailNode *node)
static void backchannel_check_cleanup(void *cls)
The cleanup function of this cmd frees resources the cmd allocated.
static void read_from_log(void *cls)
struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_backchannel_check(const char *label, const char *start_peer_label, const char *create_label, uint32_t num, unsigned int node_n, unsigned int namespace_n, struct GNUNET_TESTING_NetjailTopology *topology)
Create command.
static void backchannel_check_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
The run method of this cmd will connect to peers.
#define LOG(kind,...)
Generic logging shortcut.
static int backchannel_check_traits(void *cls, const void **ret, const char *trait, unsigned int index)
Trait function of this cmd does nothing.
#define MAX_LINE_LENGTH
Maximum length allowed for line input.