diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2023-08-15 21:41:31 +0200 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2023-08-15 21:42:52 +0200 |
commit | ecfbd79c029090dfbc657194adae2d229273fb9d (patch) | |
tree | ecf018cabed401aad699e7cfeaf1e6f9050dd95e /src/testing/gnunet-cmds-helper.c | |
parent | 3c5eb7a406b3b0d2b47c00eabbff7a3984ce3429 (diff) | |
download | gnunet-ecfbd79c029090dfbc657194adae2d229273fb9d.tar.gz gnunet-ecfbd79c029090dfbc657194adae2d229273fb9d.zip |
-minor bugfixes, adding FIXMEs
Diffstat (limited to 'src/testing/gnunet-cmds-helper.c')
-rw-r--r-- | src/testing/gnunet-cmds-helper.c | 243 |
1 files changed, 132 insertions, 111 deletions
diff --git a/src/testing/gnunet-cmds-helper.c b/src/testing/gnunet-cmds-helper.c index de50aca3a..4428d4402 100644 --- a/src/testing/gnunet-cmds-helper.c +++ b/src/testing/gnunet-cmds-helper.c | |||
@@ -69,8 +69,8 @@ | |||
69 | * if the start script was not started from within a new namespace | 69 | * if the start script was not started from within a new namespace |
70 | * created by unshare. The UPNP test case needs public IP | 70 | * created by unshare. The UPNP test case needs public IP |
71 | * addresse for miniupnpd to function. | 71 | * addresse for miniupnpd to function. |
72 | * FIXME We should introduce a switch indicating if public | 72 | * FIXME We should introduce a switch indicating if public |
73 | * addresses should be used or not. This info has to be | 73 | * addresses should be used or not. This info has to be |
74 | * propagated from the start script to the c code. | 74 | * propagated from the start script to the c code. |
75 | #define KNOWN_BASE_IP "172.16.151." | 75 | #define KNOWN_BASE_IP "172.16.151." |
76 | 76 | ||
@@ -276,7 +276,8 @@ write_task (void *cls) | |||
276 | * | 276 | * |
277 | */ | 277 | */ |
278 | static void | 278 | static void |
279 | write_message (struct GNUNET_MessageHeader *message, size_t msg_length) | 279 | write_message (struct GNUNET_MessageHeader *message, |
280 | size_t msg_length) | ||
280 | { | 281 | { |
281 | struct WriteContext *wc; | 282 | struct WriteContext *wc; |
282 | 283 | ||
@@ -292,6 +293,7 @@ write_message (struct GNUNET_MessageHeader *message, size_t msg_length) | |||
292 | wc); | 293 | wc); |
293 | } | 294 | } |
294 | 295 | ||
296 | |||
295 | static void | 297 | static void |
296 | delay_shutdown_cb () | 298 | delay_shutdown_cb () |
297 | { | 299 | { |
@@ -333,11 +335,11 @@ finished_cb (enum GNUNET_GenericReturnValue rv) | |||
333 | write_message ((struct GNUNET_MessageHeader *) reply, msg_length); | 335 | write_message ((struct GNUNET_MessageHeader *) reply, msg_length); |
334 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
335 | "message send\n"); | 337 | "message send\n"); |
336 | 338 | // FIXME: bad hack, do not write 1s, have continuation after write_message() is done! | |
337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 339 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
338 | "delaying shutdown\n"); | 340 | "delaying shutdown\n"); |
339 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 341 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
340 | delay_shutdown_cb, | 342 | &delay_shutdown_cb, |
341 | NULL); | 343 | NULL); |
342 | } | 344 | } |
343 | 345 | ||
@@ -354,10 +356,10 @@ finished_cb (enum GNUNET_GenericReturnValue rv) | |||
354 | * #GNUNET_NO to stop further processing (no error) | 356 | * #GNUNET_NO to stop further processing (no error) |
355 | * #GNUNET_SYSERR to stop further processing with error | 357 | * #GNUNET_SYSERR to stop further processing with error |
356 | */ | 358 | */ |
357 | static int | 359 | static enum GNUNET_GenericReturnValue |
358 | tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) | 360 | tokenizer_cb (void *cls, |
361 | const struct GNUNET_MessageHeader *message) | ||
359 | { | 362 | { |
360 | |||
361 | struct NodeIdentifier *ni = cls; | 363 | struct NodeIdentifier *ni = cls; |
362 | const struct GNUNET_TESTING_CommandHelperInit *msg; | 364 | const struct GNUNET_TESTING_CommandHelperInit *msg; |
363 | struct GNUNET_TESTING_CommandHelperReply *reply; | 365 | struct GNUNET_TESTING_CommandHelperReply *reply; |
@@ -377,114 +379,130 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) | |||
377 | "Received message type %u and size %u\n", | 379 | "Received message type %u and size %u\n", |
378 | type, | 380 | type, |
379 | msize); | 381 | msize); |
380 | if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT == ntohs (message->type)) | 382 | switch (type) |
381 | { | 383 | { |
382 | msg = (const struct GNUNET_TESTING_CommandHelperInit *) message; | 384 | case GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT: |
383 | plugin_name_size = ntohs (msg->plugin_name_size); | ||
384 | if ((sizeof(struct GNUNET_TESTING_CommandHelperInit) + plugin_name_size) > msize) | ||
385 | { | 385 | { |
386 | GNUNET_break (0); | 386 | msg = (const struct GNUNET_TESTING_CommandHelperInit *) message; |
387 | LOG (GNUNET_ERROR_TYPE_WARNING, | 387 | plugin_name_size = ntohs (msg->plugin_name_size); |
388 | "Received unexpected message -- exiting\n"); | 388 | if ((sizeof(struct GNUNET_TESTING_CommandHelperInit) + plugin_name_size) > |
389 | goto error; | 389 | msize) |
390 | { | ||
391 | GNUNET_break (0); | ||
392 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
393 | "Received unexpected message -- exiting\n"); | ||
394 | goto error; | ||
395 | } | ||
396 | plugin_name = GNUNET_malloc (plugin_name_size + 1); | ||
397 | GNUNET_strlcpy (plugin_name, | ||
398 | ((char *) &msg[1]), | ||
399 | plugin_name_size + 1); | ||
400 | |||
401 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-cmd"); | ||
402 | |||
403 | plugin = GNUNET_new (struct TestcasePlugin); | ||
404 | plugin->api = GNUNET_PLUGIN_load (plugin_name, | ||
405 | NULL); | ||
406 | plugin->library_name = GNUNET_strdup (basename (plugin_name)); | ||
407 | |||
408 | plugin->global_n = ni->global_n; | ||
409 | plugin->local_m = ni->local_m; | ||
410 | plugin->n = ni->n; | ||
411 | plugin->m = ni->m; | ||
412 | |||
413 | GNUNET_asprintf (&router_ip, | ||
414 | ROUTER_BASE_IP "%s", | ||
415 | plugin->n); | ||
416 | { | ||
417 | char dummy; | ||
418 | |||
419 | if (1 != | ||
420 | sscanf (plugin->n, | ||
421 | "%u%c", | ||
422 | &namespace_n, | ||
423 | &dummy)) | ||
424 | { | ||
425 | // FIXME: how to handle error nicely? | ||
426 | GNUNET_break (0); | ||
427 | namespace_n = 0; | ||
428 | } | ||
429 | } | ||
430 | |||
431 | if (0 == namespace_n) | ||
432 | { | ||
433 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
434 | "known node n: %s\n", | ||
435 | plugin->n); | ||
436 | GNUNET_asprintf (&node_ip, | ||
437 | KNOWN_BASE_IP "%s", | ||
438 | plugin->m); | ||
439 | } | ||
440 | else | ||
441 | { | ||
442 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
443 | "subnet node n: %s\n", | ||
444 | plugin->n); | ||
445 | GNUNET_asprintf (&node_ip, | ||
446 | NODE_BASE_IP "%s", | ||
447 | plugin->m); | ||
448 | } | ||
449 | |||
450 | is = plugin->api->start_testcase (&write_message, | ||
451 | router_ip, | ||
452 | node_ip, | ||
453 | plugin->m, | ||
454 | plugin->n, | ||
455 | plugin->local_m, | ||
456 | ni->topology_data, | ||
457 | ni->read_file, | ||
458 | &finished_cb); | ||
459 | GNUNET_free (node_ip); | ||
460 | GNUNET_free (binary); | ||
461 | GNUNET_free (router_ip); | ||
462 | GNUNET_free (plugin_name); | ||
463 | |||
464 | msg_length = sizeof(struct GNUNET_TESTING_CommandHelperReply); | ||
465 | reply = GNUNET_new (struct GNUNET_TESTING_CommandHelperReply); | ||
466 | reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY); | ||
467 | reply->header.size = htons ((uint16_t) msg_length); | ||
468 | write_message (&reply->header, | ||
469 | msg_length); | ||
470 | return GNUNET_OK; | ||
390 | } | 471 | } |
391 | plugin_name = GNUNET_malloc (plugin_name_size + 1); | 472 | case GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_CROSSABLE: |
392 | GNUNET_strlcpy (plugin_name, | ||
393 | ((char *) &msg[1]), | ||
394 | plugin_name_size + 1); | ||
395 | |||
396 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-cmd"); | ||
397 | |||
398 | plugin = GNUNET_new (struct TestcasePlugin); | ||
399 | plugin->api = GNUNET_PLUGIN_load (plugin_name, | ||
400 | NULL); | ||
401 | plugin->library_name = GNUNET_strdup (basename (plugin_name)); | ||
402 | |||
403 | plugin->global_n = ni->global_n; | ||
404 | plugin->local_m = ni->local_m; | ||
405 | plugin->n = ni->n; | ||
406 | plugin->m = ni->m; | ||
407 | |||
408 | router_ip = GNUNET_malloc (strlen (ROUTER_BASE_IP) + strlen (plugin->n) | ||
409 | + 1); | ||
410 | strcpy (router_ip, ROUTER_BASE_IP); | ||
411 | strcat (router_ip, plugin->n); | ||
412 | |||
413 | sscanf (plugin->n, "%u", &namespace_n); | ||
414 | |||
415 | if (0 == namespace_n) | ||
416 | { | 473 | { |
417 | LOG (GNUNET_ERROR_TYPE_ERROR, | 474 | const char *barrier_name; |
418 | "known node n: %s\n", | 475 | struct CommandBarrierCrossable *adm = (struct |
419 | plugin->n); | 476 | CommandBarrierCrossable *) message; |
420 | node_ip = GNUNET_malloc (strlen (KNOWN_BASE_IP) + strlen (plugin->m) + 1); | 477 | |
421 | strcat (node_ip, KNOWN_BASE_IP); | 478 | barrier_name = (const char *) &adm[1]; |
479 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
480 | "cross barrier %s\n", | ||
481 | barrier_name); | ||
482 | TST_interpreter_finish_attached_cmds (is, | ||
483 | barrier_name); | ||
484 | return GNUNET_OK; | ||
422 | } | 485 | } |
423 | else | 486 | case GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED: |
424 | { | 487 | { |
425 | LOG (GNUNET_ERROR_TYPE_ERROR, | 488 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
426 | "subnet node n: %s\n", | 489 | "all peers started\n"); |
427 | plugin->n); | 490 | plugin->api->all_peers_started (); |
428 | node_ip = GNUNET_malloc (strlen (NODE_BASE_IP) + strlen (plugin->m) + 1); | 491 | return GNUNET_OK; |
429 | strcat (node_ip, NODE_BASE_IP); | ||
430 | } | 492 | } |
431 | strcat (node_ip, plugin->m); | 493 | case GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED: |
432 | 494 | { | |
433 | is = plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m, | 495 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
434 | 496 | "all local tests prepared\n"); | |
435 | plugin->n, plugin->local_m, ni->topology_data, | 497 | plugin->api->all_local_tests_prepared (); |
436 | ni->read_file, &finished_cb); | 498 | return GNUNET_OK; |
437 | GNUNET_free (node_ip); | 499 | } |
438 | GNUNET_free (binary); | 500 | default: |
439 | GNUNET_free (router_ip); | ||
440 | GNUNET_free (plugin_name); | ||
441 | |||
442 | msg_length = sizeof(struct GNUNET_TESTING_CommandHelperReply); | ||
443 | reply = GNUNET_new (struct GNUNET_TESTING_CommandHelperReply); | ||
444 | reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY); | ||
445 | reply->header.size = htons ((uint16_t) msg_length); | ||
446 | |||
447 | write_message ((struct GNUNET_MessageHeader *) reply, msg_length); | ||
448 | |||
449 | return GNUNET_OK; | ||
450 | } | ||
451 | else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_CROSSABLE == ntohs ( | ||
452 | message->type)) | ||
453 | { | ||
454 | const char *barrier_name; | ||
455 | struct CommandBarrierCrossable *adm = (struct CommandBarrierCrossable *) message; | ||
456 | |||
457 | barrier_name = (const char *) &adm[1]; | ||
458 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
459 | "cross barrier %s\n", | ||
460 | barrier_name); | ||
461 | TST_interpreter_finish_attached_cmds (is, barrier_name); | ||
462 | return GNUNET_OK; | ||
463 | } | ||
464 | else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs ( | ||
465 | message->type)) | ||
466 | { | ||
467 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
468 | "all peers started\n"); | ||
469 | plugin->api->all_peers_started (); | ||
470 | return GNUNET_OK; | ||
471 | } | ||
472 | else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED == ntohs ( | ||
473 | message->type)) | ||
474 | { | ||
475 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
476 | "all local tests prepared\n"); | ||
477 | plugin->api->all_local_tests_prepared (); | ||
478 | return GNUNET_OK; | ||
479 | } | ||
480 | else | ||
481 | { | ||
482 | LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); | 501 | LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); |
483 | goto error; | 502 | goto error; |
484 | } | 503 | } |
485 | 504 | ||
486 | 505 | error: | |
487 | error: | ||
488 | status = GNUNET_SYSERR; | 506 | status = GNUNET_SYSERR; |
489 | LOG (GNUNET_ERROR_TYPE_ERROR, | 507 | LOG (GNUNET_ERROR_TYPE_ERROR, |
490 | "tokenizer shutting down!\n"); | 508 | "tokenizer shutting down!\n"); |
@@ -560,14 +578,16 @@ run (void *cls, | |||
560 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 578 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
561 | "Starting interpreter loop helper...\n"); | 579 | "Starting interpreter loop helper...\n"); |
562 | 580 | ||
563 | tokenizer = GNUNET_MST_create (&tokenizer_cb, ni); | 581 | tokenizer = GNUNET_MST_create (&tokenizer_cb, |
582 | ni); | ||
564 | stdin_fd = GNUNET_DISK_get_handle_from_native (stdin); | 583 | stdin_fd = GNUNET_DISK_get_handle_from_native (stdin); |
565 | stdout_fd = GNUNET_DISK_get_handle_from_native (stdout); | 584 | stdout_fd = GNUNET_DISK_get_handle_from_native (stdout); |
566 | read_task_id = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 585 | read_task_id = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
567 | stdin_fd, | 586 | stdin_fd, |
568 | &read_task, | 587 | &read_task, |
569 | NULL); | 588 | NULL); |
570 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 589 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, |
590 | NULL); | ||
571 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 591 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
572 | "Interpreter loop helper started.\n"); | 592 | "Interpreter loop helper started.\n"); |
573 | } | 593 | } |
@@ -605,8 +625,9 @@ main (int argc, char **argv) | |||
605 | { | 625 | { |
606 | struct NodeIdentifier *ni; | 626 | struct NodeIdentifier *ni; |
607 | struct GNUNET_SIGNAL_Context *shc_chld; | 627 | struct GNUNET_SIGNAL_Context *shc_chld; |
608 | struct GNUNET_GETOPT_CommandLineOption options[] = | 628 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
609 | { GNUNET_GETOPT_OPTION_END }; | 629 | GNUNET_GETOPT_OPTION_END |
630 | }; | ||
610 | int ret; | 631 | int ret; |
611 | unsigned int sscanf_ret; | 632 | unsigned int sscanf_ret; |
612 | int i; | 633 | int i; |
@@ -667,8 +688,8 @@ main (int argc, char **argv) | |||
667 | return 1; | 688 | return 1; |
668 | } | 689 | } |
669 | shc_chld = | 690 | shc_chld = |
670 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); | 691 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, |
671 | 692 | &sighandler_child_death); | |
672 | ret = GNUNET_PROGRAM_run (argc, | 693 | ret = GNUNET_PROGRAM_run (argc, |
673 | argv, | 694 | argv, |
674 | "gnunet-cmds-helper", | 695 | "gnunet-cmds-helper", |