diff options
Diffstat (limited to 'src/transport/transport_api_cmd_backchannel_check.c')
-rw-r--r-- | src/transport/transport_api_cmd_backchannel_check.c | 554 |
1 files changed, 0 insertions, 554 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 d672e3ae8..000000000 --- a/src/transport/transport_api_cmd_backchannel_check.c +++ /dev/null | |||
@@ -1,554 +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_from (kind, "udp-backchannel",__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 | */ | ||
52 | struct 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 | */ | ||
134 | static void | ||
135 | read_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 | |||
233 | static enum GNUNET_GenericReturnValue | ||
234 | will_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 | |||
333 | static void | ||
334 | add_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_peer (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_peer (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 | GNUNET_free (peer); | ||
392 | GNUNET_free (us); | ||
393 | } | ||
394 | |||
395 | |||
396 | /** | ||
397 | * The run method of this cmd will connect to peers. | ||
398 | * | ||
399 | */ | ||
400 | static void | ||
401 | backchannel_check_run (void *cls, | ||
402 | struct GNUNET_TESTING_Interpreter *is) | ||
403 | { | ||
404 | struct CheckState *cs = cls; | ||
405 | const struct GNUNET_TESTING_Command *system_cmd; | ||
406 | const struct GNUNET_TESTING_System *tl_system; | ||
407 | const struct GNUNET_TESTING_Command *peer1_cmd; | ||
408 | const struct GNUNET_TRANSPORT_ApplicationHandle *ah; | ||
409 | struct GNUNET_CONTAINER_MultiShortmapIterator *node_it; | ||
410 | struct GNUNET_CONTAINER_MultiShortmapIterator *namespace_it; | ||
411 | struct GNUNET_ShortHashCode node_key; | ||
412 | struct GNUNET_ShortHashCode namespace_key; | ||
413 | const struct GNUNET_TESTING_NetjailNode *node; | ||
414 | const struct GNUNET_TESTING_NetjailNamespace *namespace; | ||
415 | |||
416 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
417 | "check run 1\n"); | ||
418 | |||
419 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is, | ||
420 | cs->start_peer_label); | ||
421 | GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd, | ||
422 | &ah); | ||
423 | |||
424 | system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, | ||
425 | cs->create_label); | ||
426 | GNUNET_TESTING_get_trait_test_system (system_cmd, | ||
427 | &tl_system); | ||
428 | |||
429 | cs->tl_system = tl_system; | ||
430 | |||
431 | cs->node_connections_head = GNUNET_TESTING_get_connections (cs->num, | ||
432 | cs->topology); | ||
433 | |||
434 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
435 | "check run 2\n"); | ||
436 | |||
437 | |||
438 | node_it = GNUNET_CONTAINER_multishortmap_iterator_create ( | ||
439 | cs->topology->map_globals); | ||
440 | |||
441 | while (GNUNET_YES == GNUNET_CONTAINER_multishortmap_iterator_next (node_it, | ||
442 | &node_key, | ||
443 | (const | ||
444 | void**) & | ||
445 | node)) | ||
446 | { | ||
447 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
448 | "namespace_n %u node_n %u\n", | ||
449 | node->namespace_n, | ||
450 | node->node_n); | ||
451 | if (GNUNET_YES == will_the_other_node_connect_via_udp (cs, node)) | ||
452 | { | ||
453 | add_search_string (cs, node); | ||
454 | } | ||
455 | } | ||
456 | GNUNET_free (node_it); | ||
457 | namespace_it = GNUNET_CONTAINER_multishortmap_iterator_create ( | ||
458 | cs->topology->map_namespaces); | ||
459 | while (GNUNET_YES == GNUNET_CONTAINER_multishortmap_iterator_next ( | ||
460 | namespace_it, | ||
461 | &namespace_key, | ||
462 | (const | ||
463 | void**) &namespace)) | ||
464 | { | ||
465 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
466 | "namespace_n %u\n", | ||
467 | node->namespace_n); | ||
468 | node_it = GNUNET_CONTAINER_multishortmap_iterator_create ( | ||
469 | namespace->nodes); | ||
470 | while (GNUNET_YES == GNUNET_CONTAINER_multishortmap_iterator_next (node_it, | ||
471 | &node_key, | ||
472 | (const | ||
473 | void**) | ||
474 | &node)) | ||
475 | { | ||
476 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
477 | "namespace_n %u node_n %u\n", | ||
478 | node->namespace_n, | ||
479 | node->node_n); | ||
480 | if (GNUNET_YES == will_the_other_node_connect_via_udp (cs, node)) | ||
481 | { | ||
482 | add_search_string (cs, node); | ||
483 | } | ||
484 | } | ||
485 | GNUNET_free (node_it); | ||
486 | } | ||
487 | |||
488 | if (0 != cs->con_num) | ||
489 | { | ||
490 | cs->task = | ||
491 | GNUNET_SCHEDULER_add_now (&read_from_log, | ||
492 | cs); | ||
493 | } | ||
494 | else | ||
495 | GNUNET_TESTING_async_finish (&cs->ac); | ||
496 | |||
497 | GNUNET_free (namespace_it); | ||
498 | } | ||
499 | |||
500 | |||
501 | /** | ||
502 | * Trait function of this cmd does nothing. | ||
503 | * | ||
504 | */ | ||
505 | static int | ||
506 | backchannel_check_traits (void *cls, | ||
507 | const void **ret, | ||
508 | const char *trait, | ||
509 | unsigned int index) | ||
510 | { | ||
511 | return GNUNET_OK; | ||
512 | } | ||
513 | |||
514 | |||
515 | /** | ||
516 | * The cleanup function of this cmd frees resources the cmd allocated. | ||
517 | * | ||
518 | */ | ||
519 | static void | ||
520 | backchannel_check_cleanup (void *cls) | ||
521 | { | ||
522 | struct ConnectPeersState *cs = cls; | ||
523 | |||
524 | GNUNET_free (cs); | ||
525 | } | ||
526 | |||
527 | |||
528 | struct GNUNET_TESTING_Command | ||
529 | GNUNET_TRANSPORT_cmd_backchannel_check (const char *label, | ||
530 | const char *start_peer_label, | ||
531 | const char *create_label, | ||
532 | uint32_t num, | ||
533 | unsigned int node_n, | ||
534 | unsigned int namespace_n, | ||
535 | struct GNUNET_TESTING_NetjailTopology * | ||
536 | topology) | ||
537 | { | ||
538 | struct CheckState *cs; | ||
539 | |||
540 | cs = GNUNET_new (struct CheckState); | ||
541 | cs->start_peer_label = start_peer_label; | ||
542 | cs->num = num; | ||
543 | cs->create_label = create_label; | ||
544 | cs->topology = topology; | ||
545 | cs->node_n = node_n; | ||
546 | cs->namespace_n = namespace_n; | ||
547 | |||
548 | return GNUNET_TESTING_command_new (cs, | ||
549 | label, | ||
550 | &backchannel_check_run, | ||
551 | &backchannel_check_cleanup, | ||
552 | &backchannel_check_traits, | ||
553 | &cs->ac); | ||
554 | } | ||