aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_api_cmd_backchannel_check.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/transport_api_cmd_backchannel_check.c')
-rw-r--r--src/transport/transport_api_cmd_backchannel_check.c602
1 files changed, 0 insertions, 602 deletions
diff --git a/src/transport/transport_api_cmd_backchannel_check.c b/src/transport/transport_api_cmd_backchannel_check.c
deleted file mode 100644
index 4ffd96210..000000000
--- a/src/transport/transport_api_cmd_backchannel_check.c
+++ /dev/null
@@ -1,602 +0,0 @@
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
21/**
22 * @file testing_api_cmd_backchannel_check.c
23 * @brief cmd to start a peer.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_common.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_testing_ng_lib.h"
30#include "gnunet_testing_netjail_lib.h"
31#include "gnunet_transport_application_service.h"
32#include "gnunet_hello_lib.h"
33#include "gnunet_transport_service.h"
34#include "transport-testing-cmds.h"
35
36/**
37 * Generic logging shortcut
38 */
39#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
40
41#define UDP "udp"
42
43/**
44 * Maximum length allowed for line input.
45 */
46#define MAX_LINE_LENGTH 1024
47
48/**
49 * Struct to store information needed in callbacks.
50 *
51 */
52struct CheckState
53{
54 /**
55 * Context for our asynchronous completion.
56 */
57 struct GNUNET_TESTING_AsyncContext ac;
58
59 /**
60 * The number of the node in a network namespace.
61 */
62 unsigned int node_n;
63
64 /**
65 * The number of the network namespace.
66 */
67 unsigned int namespace_n;
68
69 /**
70 * The testing system of this node.
71 */
72 const struct GNUNET_TESTING_System *tl_system;
73
74 // Label of the cmd which started the test system.
75 const char *create_label;
76
77 /**
78 * Number globally identifying the node.
79 *
80 */
81 uint32_t num;
82
83 /**
84 * Label of the cmd to start a peer.
85 *
86 */
87 const char *start_peer_label;
88
89 /**
90 * The topology of the test setup.
91 */
92 struct GNUNET_TESTING_NetjailTopology *topology;
93
94 /**
95 * Connections to other peers.
96 */
97 struct GNUNET_TESTING_NodeConnection *node_connections_head;
98
99 /**
100 * Number of connections.
101 */
102 unsigned int con_num;
103
104 /**
105 * Number of received backchannel messages.
106 */
107 unsigned int received_backchannel_msgs;
108
109 /**
110 * Array with search strings.
111 */
112 char **search_string;
113
114 /**
115 * File handle for log file.
116 */
117 struct GNUNET_DISK_FileHandle *fh;
118
119 /**
120 * Task which handles the reading
121 */
122 struct GNUNET_SCHEDULER_Task *task;
123
124 /**
125 * Stream to read log file lines.
126 */
127 FILE *stream;
128};
129
130/**
131 *
132 * @param cls The cmd state CheckState.
133 */
134static void
135read_from_log (void *cls)
136{
137 struct CheckState *cs = cls;
138 char line[MAX_LINE_LENGTH + 1];
139 char *search_string;
140
141
142 LOG (GNUNET_ERROR_TYPE_DEBUG,
143 "read_from_log\n");
144
145 cs->fh = GNUNET_DISK_file_open ("test.out",
146 GNUNET_DISK_OPEN_READ,
147 GNUNET_DISK_PERM_USER_READ);
148
149 cs->task = NULL;
150
151 /* read message from line and handle it */
152 cs->stream = fdopen (cs->fh->fd, "r");
153 memset (line, 0, MAX_LINE_LENGTH + 1);
154
155 // fgets (line, MAX_LINE_LENGTH, cs->stream);
156 // while (NULL != line && 0 != strcmp (line, ""))// '\0' != line[0])
157 while (NULL != fgets (line, MAX_LINE_LENGTH, cs->stream))
158 {
159 /*LOG (GNUNET_ERROR_TYPE_DEBUG,
160 "cs->received_backchannel_msgs: %u\n",
161 cs->received_backchannel_msgs);*/
162 /*if (NULL == strstr (line, "line"))
163 LOG (GNUNET_ERROR_TYPE_DEBUG,
164 "line: %s",
165 line);*/
166
167
168 for (int i = 0; i < cs->con_num; i++)
169 {
170 search_string = cs->search_string[i];
171 /*LOG (GNUNET_ERROR_TYPE_DEBUG,
172 "search %u %u: %s %p\n",
173 i,
174 cs->con_num,
175 cs->search_string[i],
176 cs->search_string);
177 fprintf (stderr,
178 line);*/
179 if (NULL != strstr (line,
180 search_string))
181 // "Delivering backchannel message from 4TTC to F7B5 of type 1460 to udp"))
182 // cs->search_string[i]))
183 {
184 cs->received_backchannel_msgs++;
185 LOG (GNUNET_ERROR_TYPE_DEBUG,
186 "received_backchannel_msgs %u con_num %u\n",
187 cs->received_backchannel_msgs,
188 cs->con_num);
189 if (cs->received_backchannel_msgs == cs->con_num)
190 {
191 LOG (GNUNET_ERROR_TYPE_DEBUG,
192 "search finished %lu %lu %u\n",
193 strlen (cs->search_string[i]),
194 strlen (
195 "Delivering backchannel message from 4TTC to F7B5 of type 1460 to udp"),
196 strcmp (
197 "Delivering backchannel message from 4TTC to F7B5 of type 1460 to udp",
198 cs->search_string[i]));
199 GNUNET_TESTING_async_finish (&cs->ac);
200 fclose (cs->stream);
201 return;
202 }
203 }
204 }
205 }
206 LOG (GNUNET_ERROR_TYPE_DEBUG,
207 "read_from_log end\n");
208 fclose (cs->stream);
209 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
210 &read_from_log,
211 cs);
212 /*if (NULL == fgets (line, MAX_LINE_LENGTH, cs->stream))
213 {
214 LOG (GNUNET_ERROR_TYPE_DEBUG,
215 "read null\n");
216 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
217 &read_from_log,
218 cs);
219 return;
220 }*/
221 /*else {
222 cs->task =
223 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
224 cs->fh,
225 &read_from_log,
226 cs);
227
228
229 }*/
230}
231
232
233static enum GNUNET_GenericReturnValue
234will_the_other_node_connect_via_udp (
235 struct CheckState *cs,
236 const struct GNUNET_TESTING_NetjailNode *node)
237// struct GNUNET_TESTING_NodeConnection *connection)
238{
239 // struct GNUNET_TESTING_NetjailTopology *topology = cs->topology;
240 // unsigned int node_n = connection->node_n;
241 // unsigned int namespace_n = connection->namespace_n;
242 // struct GNUNET_HashCode hc;
243 // struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
244 // struct GNUNET_HashCode hc_namespace;
245 /*struct GNUNET_ShortHashCode *key_namespace = GNUNET_new (struct
246 GNUNET_ShortHashCode);*/
247 // struct GNUNET_TESTING_NetjailNode *node;
248 struct GNUNET_TESTING_NodeConnection *pos_connection;
249 struct GNUNET_TESTING_AddressPrefix *pos_prefix;
250 // struct GNUNET_TESTING_NetjailNamespace *namespace;
251 // struct GNUNET_CONTAINER_MultiShortmap *map;
252
253 /* if (0 == connection->namespace_n) */
254 /* { */
255 /* map = topology->map_globals; */
256 /* } */
257 /* else */
258 /* { */
259 /* GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc_namespace); */
260 /* memcpy (key_namespace, */
261 /* &hc_namespace, */
262 /* sizeof (*key_namespace)); */
263 /* if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains ( */
264 /* topology->map_namespaces, */
265 /* key_namespace)) */
266 /* { */
267 /* namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces, */
268 /* key_namespace); */
269 /* map = namespace->nodes; */
270 /* } */
271 /* else */
272 /* GNUNET_assert (0); */
273 /* } */
274
275 /* GNUNET_CRYPTO_hash (&node_n, sizeof(node_n), &hc); */
276 /* memcpy (key, */
277 /* &hc, */
278 /* sizeof (*key)); */
279 /* if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains ( */
280 /* map, */
281 /* key)) */
282 /* { */
283 /* node = GNUNET_CONTAINER_multishortmap_get (cs->topology->map_globals, */
284 /* key); */
285 /* for (pos_connection = node->node_connections_head; NULL != pos_connection; */
286 /* pos_connection = pos_connection->next) */
287 /* { */
288 /* if ((node->namespace_n == pos_connection->namespace_n) && */
289 /* (node->node_n == pos_connection->node_n) ) */
290 /* { */
291 /* for (pos_prefix = pos_connection->address_prefixes_head; NULL != */
292 /* pos_prefix; */
293 /* pos_prefix = */
294 /* pos_prefix->next) */
295 /* { */
296 /* if (0 == strcmp (UDP, pos_prefix->address_prefix)) */
297 /* { */
298 /* return GNUNET_YES; */
299 /* } */
300 /* } */
301 /* } */
302 /* } */
303 /* } */
304
305 for (pos_connection = node->node_connections_head; NULL != pos_connection;
306 pos_connection = pos_connection->next)
307 {
308 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
309 "connect via udp %u %u %u %u\n",
310 node->namespace_n,
311 cs->namespace_n,
312 node->node_n,
313 cs->node_n);
314 if ((pos_connection->namespace_n == cs->namespace_n) &&
315 (pos_connection->node_n == cs->node_n) )
316 {
317 for (pos_prefix = pos_connection->address_prefixes_head; NULL !=
318 pos_prefix;
319 pos_prefix =
320 pos_prefix->next)
321 {
322 if (0 == strcmp (UDP, pos_prefix->address_prefix))
323 {
324 return GNUNET_YES;
325 }
326 }
327 }
328 }
329
330 return GNUNET_NO;
331}
332
333static void
334add_search_string (struct CheckState *cs, const struct
335 GNUNET_TESTING_NetjailNode *node)
336{
337 unsigned int num;
338 struct GNUNET_PeerIdentity *peer;
339 struct GNUNET_PeerIdentity *us;
340 char *buf;
341 char *part_one = "Delivering backchannel message from ";
342 char *part_two = " to ";
343 char *part_three = " of type 1460 to udp";
344 char *peer_id;
345 char *us_id;
346
347 if (0 == node->namespace_n)
348 num = node->node_n;
349 else
350 num = (node->namespace_n - 1) * cs->topology->nodes_m + node->node_n
351 + cs->topology->nodes_x;
352
353 // num = GNUNET_TESTING_calculate_num (pos_connection, cs->topology);
354 peer = GNUNET_TESTING_get_pub_key (num, cs->tl_system);
355 LOG (GNUNET_ERROR_TYPE_DEBUG,
356 "peer: %s num %u\n",
357 GNUNET_i2s (peer),
358 num);
359 us = GNUNET_TESTING_get_pub_key (cs->num, cs->tl_system);
360 LOG (GNUNET_ERROR_TYPE_DEBUG,
361 "us: %s cs->num %d\n",
362 GNUNET_i2s (us),
363 cs->num);
364
365 GNUNET_asprintf (&peer_id,
366 "%s",
367 GNUNET_i2s (peer));
368 GNUNET_asprintf (&us_id,
369 "%s",
370 GNUNET_i2s (us));
371
372 if (0 < GNUNET_asprintf (&buf,
373 "%s%s%s%s%s",
374 part_one,
375 us_id,
376 part_two,
377 peer_id,
378 part_three))
379 {
380 GNUNET_array_append (cs->search_string,
381 cs->con_num,
382 buf);
383 /*LOG (GNUNET_ERROR_TYPE_DEBUG,
384 "con_num: %u search: %s %p\n",
385 cs->con_num,
386 cs->search_string[cs->con_num - 1],
387 cs->search_string);*/
388 }
389 else
390 GNUNET_assert (0);
391}
392
393
394/**
395 * The run method of this cmd will connect to peers.
396 *
397 */
398static void
399backchannel_check_run (void *cls,
400 struct GNUNET_TESTING_Interpreter *is)
401{
402 struct CheckState *cs = cls;
403 // char *buf;
404 // char *part_one = "Delivering backchannel message from ";
405 // char *part_two = " of type 1460 to udp";
406 const struct GNUNET_TESTING_Command *system_cmd;
407 const struct GNUNET_TESTING_System *tl_system;
408 const struct GNUNET_TESTING_Command *peer1_cmd;
409 const struct GNUNET_TRANSPORT_ApplicationHandle *ah;
410 // struct GNUNET_PeerIdentity *peer;
411 // uint32_t num;
412 // struct GNUNET_TESTING_NodeConnection *pos_connection;
413 // unsigned int con_num = 0;
414 struct GNUNET_CONTAINER_MultiShortmapIterator *node_it;
415 struct GNUNET_CONTAINER_MultiShortmapIterator *namespace_it;
416 struct GNUNET_ShortHashCode node_key;
417 struct GNUNET_ShortHashCode namespace_key;
418 const struct GNUNET_TESTING_NetjailNode *node;
419 const struct GNUNET_TESTING_NetjailNamespace *namespace;
420
421 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
422 cs->start_peer_label);
423 GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd,
424 &ah);
425
426 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
427 cs->create_label);
428 GNUNET_TESTING_get_trait_test_system (system_cmd,
429 &tl_system);
430
431 cs->tl_system = tl_system;
432
433 cs->node_connections_head = GNUNET_TESTING_get_connections (cs->num,
434 cs->topology);
435
436 LOG (GNUNET_ERROR_TYPE_DEBUG,
437 "check run\n");
438
439
440 node_it = GNUNET_CONTAINER_multishortmap_iterator_create (
441 cs->topology->map_globals);
442
443 while (GNUNET_YES == GNUNET_CONTAINER_multishortmap_iterator_next (node_it,
444 &node_key,
445 (const
446 void**) &
447 node))
448 {
449 LOG (GNUNET_ERROR_TYPE_DEBUG,
450 "namespace_n %u node_n %u\n",
451 node->namespace_n,
452 node->node_n);
453 if (GNUNET_YES == will_the_other_node_connect_via_udp (cs, node))
454 {
455 add_search_string (cs, node);
456 }
457 }
458 namespace_it = GNUNET_CONTAINER_multishortmap_iterator_create (
459 cs->topology->map_namespaces);
460 while (GNUNET_YES == GNUNET_CONTAINER_multishortmap_iterator_next (
461 namespace_it,
462 &namespace_key,
463 (const
464 void**) &namespace))
465 {
466 LOG (GNUNET_ERROR_TYPE_DEBUG,
467 "namespace_n %u\n",
468 node->namespace_n);
469 node_it = GNUNET_CONTAINER_multishortmap_iterator_create (
470 namespace->nodes);
471 while (GNUNET_YES == GNUNET_CONTAINER_multishortmap_iterator_next (node_it,
472 &node_key,
473 (const
474 void**)
475 &node))
476 {
477 LOG (GNUNET_ERROR_TYPE_DEBUG,
478 "namespace_n %u node_n %u\n",
479 node->namespace_n,
480 node->node_n);
481 if (GNUNET_YES == will_the_other_node_connect_via_udp (cs, node))
482 {
483 add_search_string (cs, node);
484 }
485 }
486 }
487 /* for (pos_connection = cs->node_connections_head; NULL != pos_connection; */
488 /* pos_connection = pos_connection->next) */
489 /* { */
490
491 /* if (GNUNET_YES == will_the_other_node_connect_via_udp (cs, node)) */
492 /* { */
493 /* num = GNUNET_TESTING_calculate_num (pos_connection, cs->topology); */
494 /* peer = GNUNET_TESTING_get_pub_key (num, tl_system); */
495 /* LOG (GNUNET_ERROR_TYPE_DEBUG, */
496 /* "peer: %s\n", */
497 /* GNUNET_i2s (peer)); */
498
499 /* if (0 < GNUNET_asprintf (&buf, */
500 /* "%s%s%s", */
501 /* part_one, */
502 /* GNUNET_i2s (peer), */
503 /* part_two)) */
504 /* { */
505 /* GNUNET_array_append (cs->search_string, */
506 /* con_num, */
507 /* buf); */
508 /* /\*LOG (GNUNET_ERROR_TYPE_DEBUG, */
509 /* "con_num: %u search: %s %p\n", */
510 /* con_num, */
511 /* cs->search_string[con_num - 1], */
512 /* cs->search_string);*\/ */
513 /* } */
514 /* else */
515 /* GNUNET_assert (0); */
516 /* } */
517
518
519 /* } */
520 // cs->con_num = con_num;
521 if (0 != cs->con_num)
522 {
523 cs->task =
524 GNUNET_SCHEDULER_add_now (&read_from_log,
525 cs);
526 }
527 else
528 GNUNET_TESTING_async_finish (&cs->ac);
529
530}
531
532
533/**
534 * Trait function of this cmd does nothing.
535 *
536 */
537static int
538backchannel_check_traits (void *cls,
539 const void **ret,
540 const char *trait,
541 unsigned int index)
542{
543 return GNUNET_OK;
544}
545
546
547/**
548 * The cleanup function of this cmd frees resources the cmd allocated.
549 *
550 */
551static void
552backchannel_check_cleanup (void *cls)
553{
554 struct ConnectPeersState *cs = cls;
555
556 GNUNET_free (cs);
557}
558
559
560/**
561 * Create command.
562 *
563 * @param label name for command.
564 * @param start_peer_label Label of the cmd to start a peer.
565 * @param create_label Label of the cmd to create the testing system.
566 * @param num Number globally identifying the node.
567 * @param node_n The number of the node in a network namespace.
568 * @param namespace_n The number of the network namespace.
569 * @param The topology for the test setup.
570 * @return command.
571 */
572struct GNUNET_TESTING_Command
573GNUNET_TRANSPORT_cmd_backchannel_check (const char *label,
574 const char *start_peer_label,
575 const char *create_label,
576 uint32_t num,
577 unsigned int node_n,
578 unsigned int namespace_n,
579 struct GNUNET_TESTING_NetjailTopology *
580 topology)
581{
582 struct CheckState *cs;
583
584 cs = GNUNET_new (struct CheckState);
585 cs->start_peer_label = start_peer_label;
586 cs->num = num;
587 cs->create_label = create_label;
588 cs->topology = topology;
589 cs->node_n = node_n;
590 cs->namespace_n = namespace_n;
591
592 struct GNUNET_TESTING_Command cmd = {
593 .cls = cs,
594 .label = label,
595 .run = &backchannel_check_run,
596 .ac = &cs->ac,
597 .cleanup = &backchannel_check_cleanup,
598 .traits = &backchannel_check_traits
599 };
600
601 return cmd;
602}