From c4240e04b4cd3956f88c3b1da988345fcd4414fc Mon Sep 17 00:00:00 2001 From: t3sserakt Date: Fri, 2 Jul 2021 20:31:52 +0200 Subject: - stopping testbed, starting testbed for every node, fixing bugs, implement traits to start peers on nodes --- src/include/gnunet_testbed_ng_service.h | 31 +- src/include/gnunet_testing_ng_lib.h | 2 +- src/testbed/Makefile.am | 1 + src/testbed/netjail_core.sh | 4 +- src/testbed/netjail_exec.sh | 11 +- src/testbed/test_testbed_api_cmd_netjail.c | 35 +-- src/testbed/testbed_api_cmd_controller.c | 104 +------ .../testbed_api_cmd_netjail_start_testbed.c | 327 +++++++++++++++------ src/testbed/testbed_api_cmd_netjail_stop_testbed.c | 143 +++++++++ src/testbed/testbed_api_hosts.c | 57 ++-- src/testbed/testbed_api_hosts.h | 4 + src/testing/testing_api_loop.c | 25 +- src/util/child_management.c | 3 + 13 files changed, 474 insertions(+), 273 deletions(-) create mode 100644 src/testbed/testbed_api_cmd_netjail_stop_testbed.c diff --git a/src/include/gnunet_testbed_ng_service.h b/src/include/gnunet_testbed_ng_service.h index b19a6e958..9845b3be6 100644 --- a/src/include/gnunet_testbed_ng_service.h +++ b/src/include/gnunet_testbed_ng_service.h @@ -197,11 +197,7 @@ GNUNET_TESTBED_get_trait_controller (const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Command GNUNET_TESTBED_cmd_controller (const char *label, - const char *trusted_ip, - const char *hostname, - const char *username, - uint16_t port, - struct GNUNET_CONFIGURATION_Handle *cfg, + const char *host, uint64_t event_mask); void @@ -225,6 +221,7 @@ GNUNET_TESTBED_cmd_netjail_start (const char *label, char *local_m, char *global_n); + /** * Create command. * @@ -234,11 +231,9 @@ GNUNET_TESTBED_cmd_netjail_start (const char *label, */ struct GNUNET_TESTING_Command GNUNET_TESTBED_cmd_netjail_start_testbed (const char *label, - char *const binary_argv[], char *local_m, - char *global_n, - GNUNET_MessageTokenizerCallback cb, - GNUNET_HELPER_ExceptionCallback exp_cb); + char *global_n); + /** * Create command. @@ -252,4 +247,22 @@ GNUNET_TESTBED_cmd_netjail_stop (const char *label, char *local_m, char *global_n); + +struct GNUNET_TESTING_Command +GNUNET_TESTBED_cmd_stop_testbed (const char *label, + const char *helper_start_label, + char *local_m, + char *global_n); + + +int +GNUNET_TESTBED_get_trait_helper_handles (const struct + GNUNET_TESTING_Command *cmd, + struct GNUNET_HELPER_Handle ***helper); + + +int +GNUNET_TESTBED_get_trait_hosts (const struct + GNUNET_TESTING_Command *cmd, + struct GNUNET_TESTBED_Host ***hosts); #endif diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h index dd83bbe82..a794562a9 100644 --- a/src/include/gnunet_testing_ng_lib.h +++ b/src/include/gnunet_testing_ng_lib.h @@ -240,7 +240,7 @@ GNUNET_TESTING_interpreter_get_current_label ( * @param is interpreter state. */ void -GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is); +GNUNET_TESTING_interpreter_fail (); /** diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am index 486c4a4f8..79989bae7 100644 --- a/src/testbed/Makefile.am +++ b/src/testbed/Makefile.am @@ -94,6 +94,7 @@ lib_LTLIBRARIES = \ libgnunettestbed_la_SOURCES = \ testbed_api_cmd_netjail_start.c \ testbed_api_cmd_netjail_start_testbed.c \ + testbed_api_cmd_netjail_stop_testbed.c \ testbed_api_cmd_netjail_stop.c \ testbed_api.c testbed_api.h testbed.h \ testbed_api_hosts.c testbed_api_hosts.h testbed_helper.h \ diff --git a/src/testbed/netjail_core.sh b/src/testbed/netjail_core.sh index d25948bc7..792b1df24 100755 --- a/src/testbed/netjail_core.sh +++ b/src/testbed/netjail_core.sh @@ -99,8 +99,8 @@ netjail_node_exec() { } netjail_node_exec_without_fds() { - local NODE=$1 - shift 3 + NODE=$1 + shift 1 unshare -fp --kill-child -- ip netns exec $NODE sudo -u $JAILOR -- $@ } diff --git a/src/testbed/netjail_exec.sh b/src/testbed/netjail_exec.sh index 274a8b037..3e5d39c1c 100755 --- a/src/testbed/netjail_exec.sh +++ b/src/testbed/netjail_exec.sh @@ -6,14 +6,11 @@ set -x export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" -LOCAL_M=$1 -M=$2 -N=$3 +M=$1 +N=$2 NODE=$(netjail_print_name "N" $N $M) -INDEX=$(($LOCAL_M * ($N - 1) + $M - 1)) -FD_X=$(($INDEX * 2 + 3 + 0)) -FD_Y=$(($INDEX * 2 + 3 + 1)) -netjail_node_exec_without_fds $NODE $@ + +netjail_node_exec_without_fds $NODE $3 diff --git a/src/testbed/test_testbed_api_cmd_netjail.c b/src/testbed/test_testbed_api_cmd_netjail.c index d29ebdcb4..e5fc0877e 100644 --- a/src/testbed/test_testbed_api_cmd_netjail.c +++ b/src/testbed/test_testbed_api_cmd_netjail.c @@ -28,22 +28,6 @@ #include "gnunet_testbed_ng_service.h" #include "gnunet_util_lib.h" -#define HELPER_TESTBED_BINARY "../testbed/gnunet-helper-testbed" - -static int -tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called tokenizer.\n"); - return GNUNET_OK; -} - - -static void -exp_cb (void *cls) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n"); -} - /** * Main function to run the test cases. @@ -54,20 +38,19 @@ exp_cb (void *cls) static void run (void *cls) { - char *const binary_argv[3] = {HELPER_TESTBED_BINARY, NULL}; - struct GNUNET_TESTING_Command commands[] = { GNUNET_TESTBED_cmd_netjail_start ("netjail-start-1", - "1", + "2", "2"), - GNUNET_TESTBED_cmd_netjail_start_testbed ("netjail-exec-1", - binary_argv, - "1", + GNUNET_TESTBED_cmd_netjail_start_testbed ("netjail-start-testbed-1", "2", - &tokenizer_cb, - &exp_cb), + "2"), + GNUNET_TESTBED_cmd_stop_testbed ("stop-testbed", + "netjail-start-testbed-1", + "2", + "2"), GNUNET_TESTBED_cmd_netjail_stop ("netjail-stop-1", - "1", + "2", "2"), GNUNET_TESTING_cmd_end () }; @@ -90,5 +73,7 @@ main (int argc, GNUNET_SCHEDULER_run (&run, NULL); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Test finished!\n"); return rv; } diff --git a/src/testbed/testbed_api_cmd_controller.c b/src/testbed/testbed_api_cmd_controller.c index e3044eaa7..794b1ccf3 100644 --- a/src/testbed/testbed_api_cmd_controller.c +++ b/src/testbed/testbed_api_cmd_controller.c @@ -38,26 +38,6 @@ GNUNET_log (kind, __VA_ARGS__) -/** - * abort task to run on test timed out - * - * @param cls NULL - * @param tc the task context - */ -static void -do_abort (void *cls) -{ - struct ControllerState *cs = cls; - - if (GNUNET_NO == cs->host_ready) - { - LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); - cs->abort_task = NULL; - GNUNET_TESTBED_shutdown_controller (cs); - } -} - - /** * * @@ -98,83 +78,20 @@ controller_cb (void *cls, } -/** - * Callback which will be called to after a host registration succeeded or failed - * - * @param cls the host which has been registered - * @param emsg the error message; NULL if host registration is successful - */ static void -registration_comp (void *cls, - const char *emsg) -{ - struct ControllerState *cs = cls; - - if (NULL != emsg) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - "There was an error during host registration: %s\n", - emsg); - GNUNET_TESTBED_shutdown_controller (cs); - } - else - { - cs->reg_handle = NULL; - cs->host_ready = GNUNET_YES; - } -} - - -/** - * Callback to signal successful startup of the controller process - * - * @param cls the closure from GNUNET_TESTBED_controller_start() - * @param cfg the configuration with which the controller has been started; - * NULL if status is not #GNUNET_OK - * @param status #GNUNET_OK if the startup is successful; #GNUNET_SYSERR if not, - * GNUNET_TESTBED_controller_stop() shouldn't be called in this case - */ -static void -controller_status_cb (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg_, - int status) +controller_run (void *cls, + const struct GNUNET_TESTING_Command *cmd, + struct GNUNET_TESTING_Interpreter *is) { struct ControllerState *cs = cls; - if (GNUNET_OK != status) - { - cs->cp = NULL; - return; - } + cs->is = is; cs->controller = GNUNET_TESTBED_controller_connect (cs->host, cs->event_mask, &controller_cb, cs); - cs->reg_handle = - GNUNET_TESTBED_register_host (cs->controller, cs->host, ®istration_comp, - cs); -} -static void -controller_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, - struct GNUNET_TESTING_Interpreter *is) -{ - struct ControllerState *cs = cls; - - cs->is = is; - cs->host = GNUNET_TESTBED_host_create (cs->hostname, cs->username, cs->cfg, - cs->port); - cs->cp = GNUNET_TESTBED_controller_start (cs->trusted_ip, - cs->host, - &controller_status_cb, - cs); - cs->abort_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MINUTES, 5), - &do_abort, - cs); } /** @@ -264,22 +181,15 @@ GNUNET_TESTBED_shutdown_controller (struct ControllerState *cs) struct GNUNET_TESTING_Command GNUNET_TESTBED_cmd_controller (const char *label, - const char *trusted_ip, - const char *hostname, - const char *username, - uint16_t port, - struct GNUNET_CONFIGURATION_Handle *cfg, + const char *host, uint64_t event_mask) { struct ControllerState *cs; cs = GNUNET_new (struct ControllerState); cs->event_mask = event_mask; - cs->trusted_ip = trusted_ip; - cs->hostname = hostname; - cs->username = username; - cs->port = port; - cs->cfg = cfg; + cs->hostname = host; + struct GNUNET_TESTING_Command cmd = { .cls = cs, diff --git a/src/testbed/testbed_api_cmd_netjail_start_testbed.c b/src/testbed/testbed_api_cmd_netjail_start_testbed.c index da51350a1..786084917 100644 --- a/src/testbed/testbed_api_cmd_netjail_start_testbed.c +++ b/src/testbed/testbed_api_cmd_netjail_start_testbed.c @@ -27,20 +27,20 @@ #include "gnunet_testing_ng_lib.h" #include "gnunet_testbed_ng_service.h" #include "testbed_api.h" +#include "testbed_api_hosts.h" #define NETJAIL_EXEC_SCRIPT "./netjail_exec.sh" + struct NetJailState { /** * The process handle */ - struct GNUNET_HELPER_Handle *helper; - - GNUNET_MessageTokenizerCallback cb; + struct GNUNET_HELPER_Handle **helper; - GNUNET_HELPER_ExceptionCallback exp_cb; + unsigned int n_helper; char *binary_name; @@ -48,19 +48,36 @@ struct NetJailState char *global_n; - char **binary_argv; - /** * The send handle for the helper */ - struct GNUNET_HELPER_SendHandle *shandle; + struct GNUNET_HELPER_SendHandle **shandle; + + unsigned int n_shandle; /** * The message corresponding to send handle */ - struct GNUNET_MessageHeader *msg; + struct GNUNET_MessageHeader **msg; + + unsigned int n_msg; + + unsigned int number_of_testbeds_started; + + /** + * The host where the controller is running + */ + struct GNUNET_TESTBED_Host **host; + + unsigned int n_host; }; +struct TestbedCount +{ + unsigned int count; + + struct NetJailState *ns; +}; /** * @@ -93,40 +110,66 @@ netjail_exec_traits (void *cls, const char *trait, unsigned int index) { - return GNUNET_OK; + struct NetJailState *ns = cls; + struct GNUNET_HELPER_Handle **helper = ns->helper; + struct GNUNET_TESTBED_Host **hosts = ns->host; + + + struct GNUNET_TESTING_Trait traits[] = { + { + .index = 0, + .trait_name = "helper_handles", + .ptr = (const void *) helper, + }, + { + .index = 1, + .trait_name = "hosts", + .ptr = (const void *) hosts, + }, + GNUNET_TESTING_trait_end () + }; + + return GNUNET_TESTING_get_trait (traits, + ret, + trait, + index); } -// TODO This would be a useful macro. /** - * Function to join NULL terminated list of arguments + * Offer handles to testbed helper from trait * - * @param argv1 the NULL terminated list of arguments. Cannot be NULL. - * @param argv2 the NULL terminated list of arguments. Cannot be NULL. - * @return the joined NULL terminated arguments + * @param cmd command to extract the message from. + * @param pt pointer to message. + * @return #GNUNET_OK on success. */ -static char ** -join_argv (const char *const *argv1, const char *const *argv2) +int +GNUNET_TESTBED_get_trait_helper_handles (const struct + GNUNET_TESTING_Command *cmd, + struct GNUNET_HELPER_Handle ***helper) { - char **argvj; - char *argv; - unsigned int carg = 0; - unsigned int cnt; - - carg = 0; - argvj = NULL; - for (cnt = 0; NULL != argv1[cnt]; cnt++) - { - argv = GNUNET_strdup (argv1[cnt]); - GNUNET_array_append (argvj, carg, argv); - } - for (cnt = 0; NULL != argv2[cnt]; cnt++) - { - argv = GNUNET_strdup (argv2[cnt]); - GNUNET_array_append (argvj, carg, argv); - } - GNUNET_array_append (argvj, carg, NULL); - return argvj; + return cmd->traits (cmd->cls, + (const void **) helper, + "helper_handles", + (unsigned int) 0); +} + +/** + * Offer handles to testbed helper from trait + * + * @param cmd command to extract the message from. + * @param pt pointer to message. + * @return #GNUNET_OK on success. + */ +int +GNUNET_TESTBED_get_trait_hosts (const struct + GNUNET_TESTING_Command *cmd, + struct GNUNET_TESTBED_Host ***hosts) +{ + return cmd->traits (cmd->cls, + (const void **) hosts, + "hosts", + (unsigned int) 1); } @@ -141,41 +184,95 @@ join_argv (const char *const *argv1, const char *const *argv2) static void clear_msg (void *cls, int result) { - struct NetJailState *ns = cls; - - GNUNET_assert (NULL != ns->shandle); - ns->shandle = NULL; - GNUNET_free (ns->msg); - ns->msg = NULL; + struct TestbedCount *tbc = cls; + struct NetJailState *ns = tbc->ns; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "clear_msg tbc->count: %d\n", + tbc->count); + GNUNET_assert (NULL != ns->shandle[tbc->count - 1]); + ns->shandle[tbc->count - 1] = NULL; + GNUNET_free (ns->msg[tbc->count - 1]); + ns->msg[tbc->count - 1] = NULL; } /** -* Run the "hello world" CMD. -* -* @param cls closure. -* @param cmd CMD being run. -* @param is interpreter state. -*/ + * Functions with this signature are called whenever a + * complete message is received by the tokenizer. + * + * Do not call GNUNET_SERVER_mst_destroy in callback + * + * @param cls closure + * @param client identification of the client + * @param message the actual message + * + * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing + */ +static int +helper_mst (void *cls, const struct GNUNET_MessageHeader *message) +{ + struct TestbedCount *tbc = cls; + struct NetJailState *ns = tbc->ns; + struct GNUNET_TESTBED_Host *host = ns->host[tbc->count - 1]; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "helper_mst tbc->count: %d\n", + tbc->count); + GNUNET_TESTBED_extract_cfg (host, message); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received message from helper.\n"); + ns->number_of_testbeds_started++; + return GNUNET_OK; +} + + static void -netjail_exec_run (void *cls, - const struct GNUNET_TESTING_Command *cmd, - struct GNUNET_TESTING_Interpreter *is) +exp_cb (void *cls) { - struct NetJailState *ns = cls; - char **helper_argv; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n"); + GNUNET_TESTING_interpreter_fail (); +} + + +static void +start_testbed (struct NetJailState *ns, struct + GNUNET_CONFIGURATION_Handle *config, + char *n_char, + char *m_char) +{ + struct GNUNET_CONFIGURATION_Handle *cfg; struct GNUNET_TESTBED_HelperInit *msg; - struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); + struct TestbedCount *tbc; char *const script_argv[] = {NETJAIL_EXEC_SCRIPT, - ns->local_m, - "1", - "1", + m_char, + n_char, + GNUNET_OS_get_libexec_binary_path ( + HELPER_TESTBED_BINARY), NULL}; - GNUNET_MessageTokenizerCallback cb = ns->cb; - GNUNET_HELPER_ExceptionCallback exp_cb = ns->exp_cb; + unsigned int m = atoi (m_char); + unsigned int n = atoi (n_char); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "m: %d n: %d\n", + m, + n); + + tbc = GNUNET_new (struct TestbedCount); + tbc->ns = ns; + tbc->count = (n - 1) * atoi (ns->local_m) + m; + + cfg = GNUNET_CONFIGURATION_dup (config); + + GNUNET_array_append (ns->host, ns->n_host, + GNUNET_TESTBED_host_create_with_id (tbc->count - 1, + NULL, + NULL, + cfg, + 0)); if ((GNUNET_YES != GNUNET_DISK_file_test ("test_testbed_api.conf")) || - (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, + (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (config, "test_testbed_api.conf"))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -184,29 +281,87 @@ netjail_exec_run (void *cls, "test_testbed_api.conf"); } - helper_argv = join_argv ((const char **) script_argv, - (const char **) ns->binary_argv); - - ns->helper = GNUNET_HELPER_start (GNUNET_YES, - NETJAIL_EXEC_SCRIPT, - helper_argv, - cb, - exp_cb, - ns); - - msg = GNUNET_TESTBED_create_helper_init_msg_ ("127.0.0.1", NULL, cfg); - ns->msg = &msg->header; - ns->shandle = GNUNET_HELPER_send (ns->helper, &msg->header, GNUNET_NO, - &clear_msg, ns); - if (NULL == ns->shandle) + GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start ( + GNUNET_YES, + NETJAIL_EXEC_SCRIPT, + script_argv, + & + helper_mst, + exp_cb, + tbc)); + + struct GNUNET_HELPER_Handle *helper = ns->helper[tbc->count - 1]; + + msg = GNUNET_TESTBED_create_helper_init_msg_ ("127.0.0.1", NULL, config); + GNUNET_array_append (ns->msg, ns->n_msg, &msg->header); + + GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send ( + helper, + &msg->header, + GNUNET_NO, + &clear_msg, + tbc)); + if (NULL == ns->shandle[tbc->count - 1]) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Send handle is NULL!\n"); GNUNET_free (msg); + GNUNET_TESTING_interpreter_fail (); } } +/** +* Run the "hello world" CMD. +* +* @param cls closure. +* @param cmd CMD being run. +* @param is interpreter state. +*/ +static void +netjail_exec_run (void *cls, + const struct GNUNET_TESTING_Command *cmd, + struct GNUNET_TESTING_Interpreter *is) +{ + char str_m[12]; + char str_n[12]; + struct NetJailState *ns = cls; + struct GNUNET_CONFIGURATION_Handle *config = + GNUNET_CONFIGURATION_create (); + + for (int i = 1; i <= atoi (ns->global_n); i++) { + for (int j = 1; j <= atoi (ns->local_m); j++) + { + sprintf (str_n, "%d", i); + sprintf (str_m, "%d", j); + start_testbed (ns, config, + str_n, + str_m); + } + } +} + + +static int +netjail_start_finish (void *cls, + GNUNET_SCHEDULER_TaskCallback cont, + void *cont_cls) +{ + unsigned int ret = GNUNET_NO; + struct NetJailState *ns = cls; + + if (ns->number_of_testbeds_started == atoi (ns->local_m) * atoi ( + ns->global_n)) + { + ret = GNUNET_YES; + cont (cont_cls); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "All helper started!\n"); + } + return ret; +} + + /** * Create command. * @@ -216,40 +371,20 @@ netjail_exec_run (void *cls, */ struct GNUNET_TESTING_Command GNUNET_TESTBED_cmd_netjail_start_testbed (const char *label, - char *const binary_argv[], char *local_m, - char *global_n, - GNUNET_MessageTokenizerCallback cb, - GNUNET_HELPER_ExceptionCallback exp_cb) + char *global_n) { struct NetJailState *ns; - unsigned int append_cnt; - char **argvj; - char *argv; - unsigned int carg = 0; ns = GNUNET_new (struct NetJailState); - argvj = NULL; - for (append_cnt = 0; NULL != binary_argv[append_cnt]; append_cnt++) - { - argv = GNUNET_strdup (binary_argv[append_cnt]); - GNUNET_array_append (argvj, - carg, - argv); - } - GNUNET_array_append (argvj, carg, NULL); - - ns->binary_argv = argvj; - ns->local_m = local_m; ns->global_n = global_n; - ns->cb = cb; - ns->exp_cb = exp_cb; struct GNUNET_TESTING_Command cmd = { .cls = ns, .label = label, .run = &netjail_exec_run, + .finish = &netjail_start_finish, .cleanup = &netjail_exec_cleanup, .traits = &netjail_exec_traits }; diff --git a/src/testbed/testbed_api_cmd_netjail_stop_testbed.c b/src/testbed/testbed_api_cmd_netjail_stop_testbed.c new file mode 100644 index 000000000..9a9d489a7 --- /dev/null +++ b/src/testbed/testbed_api_cmd_netjail_stop_testbed.c @@ -0,0 +1,143 @@ +/* + This file is part of GNUnet + Copyright (C) 2021 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + SPDX-License-Identifier: AGPL3.0-or-later + */ + +/** + * @file testing/testing_api_cmd_hello_world.c + * @brief Command to start the netjail peers. + * @author t3sserakt + */ +#include "platform.h" +#include "gnunet_testing_ng_lib.h" +#include "gnunet_testbed_ng_service.h" +#include "testbed_api.h" +#include "testbed_api_hosts.h" + + +struct StopHelperState +{ + + const char *helper_start_label; + + /** + * The process handle + */ + struct GNUNET_HELPER_Handle **helper; + + char *local_m; + + char *global_n; +}; + + +/** +* +* +* @param cls closure +* @param cmd current CMD being cleaned up. +*/ +static void +stop_testbed_cleanup (void *cls, + const struct GNUNET_TESTING_Command *cmd) +{ + +} + + +/** +* +* +* @param cls closure. +* @param[out] ret result +* @param trait name of the trait. +* @param index index number of the object to offer. +* @return #GNUNET_OK on success. +*/ +static int +stop_testbed_traits (void *cls, + const void **ret, + const char *trait, + unsigned int index) +{ + return GNUNET_OK; +} + + +/** +* Run the "hello world" CMD. +* +* @param cls closure. +* @param cmd CMD being run. +* @param is interpreter state. +*/ +static void +stop_testbed_run (void *cls, + const struct GNUNET_TESTING_Command *cmd, + struct GNUNET_TESTING_Interpreter *is) +{ + struct StopHelperState *shs = cls; + struct GNUNET_HELPER_Handle **helper; + const struct GNUNET_TESTING_Command *start_helper_cmd; + + start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command ( + shs->helper_start_label); + GNUNET_TESTBED_get_trait_helper_handles (start_helper_cmd, + &helper); + + for (int i = 1; i <= atoi (shs->global_n); i++) { + for (int j = 1; j <= atoi (shs->local_m); j++) + { + GNUNET_HELPER_stop (helper[(i - 1) * atoi (shs->local_m) + j - 1], + GNUNET_YES); + } + } +} + + +/** + * Create command. + * + * @param label name for command. + * @param binaryname to exec. + * @return command. + */ +struct GNUNET_TESTING_Command +GNUNET_TESTBED_cmd_stop_testbed (const char *label, + const char *helper_start_label, + char *local_m, + char *global_n + ) +{ + struct StopHelperState *shs; + + shs = GNUNET_new (struct StopHelperState); + shs->helper_start_label = helper_start_label; + shs->local_m = local_m; + shs->global_n = global_n; + + struct GNUNET_TESTING_Command cmd = { + .cls = shs, + .label = label, + .run = &stop_testbed_run, + .cleanup = &stop_testbed_cleanup, + .traits = &stop_testbed_traits + }; + + return cmd; +} diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c index 26d2553e0..d0a460fe6 100644 --- a/src/testbed/testbed_api_hosts.c +++ b/src/testbed/testbed_api_hosts.c @@ -56,7 +56,7 @@ do \ { \ if (cond) \ - break; \ + break; \ LOG (GNUNET_ERROR_TYPE_ERROR, "API violation detected: %s\n", errstr); \ GNUNET_assert (0); \ } while (0) @@ -964,22 +964,10 @@ gen_rsh_suffix_args (const char *const *append_args) } -/** - * Functions with this signature are called whenever a - * complete message is received by the tokenizer. - * - * Do not call GNUNET_SERVER_mst_destroy in callback - * - * @param cls closure - * @param client identification of the client - * @param message the actual message - * - * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing - */ -static int -helper_mst (void *cls, const struct GNUNET_MessageHeader *message) +void +GNUNET_TESTBED_extract_cfg (struct GNUNET_TESTBED_Host *host, const struct + GNUNET_MessageHeader *message) { - struct GNUNET_TESTBED_ControllerProc *cp = cls; const struct GNUNET_TESTBED_HelperReply *msg; const char *hostname; char *config; @@ -1001,22 +989,43 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message) xconfig_size)); /* Replace the configuration template present in the host with the controller's running configuration */ - GNUNET_CONFIGURATION_destroy (cp->host->cfg); - cp->host->cfg = GNUNET_CONFIGURATION_create (); - GNUNET_assert (GNUNET_CONFIGURATION_deserialize (cp->host->cfg, + GNUNET_CONFIGURATION_destroy (host->cfg); + host->cfg = GNUNET_CONFIGURATION_create (); + GNUNET_assert (GNUNET_CONFIGURATION_deserialize (host->cfg, config, config_size, NULL)); GNUNET_free (config); - if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host))) + if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (host))) hostname = "localhost"; /* Change the hostname so that we can connect to it */ - GNUNET_CONFIGURATION_set_value_string (cp->host->cfg, + GNUNET_CONFIGURATION_set_value_string (host->cfg, "testbed", "hostname", hostname); - cp->host->locked = GNUNET_NO; - cp->host->controller_started = GNUNET_YES; + host->locked = GNUNET_NO; +} + +/** + * Functions with this signature are called whenever a + * complete message is received by the tokenizer. + * + * Do not call GNUNET_SERVER_mst_destroy in callback + * + * @param cls closure + * @param client identification of the client + * @param message the actual message + * + * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing + */ +static int +helper_mst (void *cls, const struct GNUNET_MessageHeader *message) +{ + struct GNUNET_TESTBED_ControllerProc *cp = cls; + struct GNUNET_TESTBED_Host *host = cp->host; + + GNUNET_TESTBED_extract_cfg (host, message); + cp->cb (cp->cls, cp->host->cfg, GNUNET_OK); return GNUNET_OK; } @@ -1323,7 +1332,7 @@ habitability_check (void *cls) h->auxp = NULL; ret = (0 != code) ? GNUNET_NO : GNUNET_YES; -call_cb: + call_cb: if (NULL != h->auxp) GNUNET_OS_process_destroy (h->auxp); cb = h->cb; diff --git a/src/testbed/testbed_api_hosts.h b/src/testbed/testbed_api_hosts.h index 291cab859..ab7dd8808 100644 --- a/src/testbed/testbed_api_hosts.h +++ b/src/testbed/testbed_api_hosts.h @@ -218,6 +218,10 @@ GNUNET_TESTBED_controller_destroy_ (struct GNUNET_TESTBED_ControllerProc void GNUNET_TESTBED_host_resolve_ (struct GNUNET_TESTBED_Host *host); +void +GNUNET_TESTBED_extract_cfg (struct GNUNET_TESTBED_Host *host, const struct + GNUNET_MessageHeader *message); + #endif /* end of testbed_api_hosts.h */ diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c index ccee76898..82f6d0cab 100644 --- a/src/testing/testing_api_loop.c +++ b/src/testing/testing_api_loop.c @@ -204,7 +204,7 @@ run_finish_task_next (void *cls) } else { - GNUNET_TESTING_interpreter_fail (is); + GNUNET_TESTING_interpreter_fail (); } } @@ -232,7 +232,7 @@ run_finish_task_sync (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "The command with label %s did not finish its asynchronous task in time.\n", cmd->label); - GNUNET_TESTING_interpreter_fail (is); + GNUNET_TESTING_interpreter_fail (); } if (GNUNET_YES == finished) @@ -246,7 +246,7 @@ run_finish_task_sync (void *cls) } else { - GNUNET_TESTING_interpreter_fail (is); + GNUNET_TESTING_interpreter_fail (); } } @@ -321,7 +321,7 @@ GNUNET_TESTING_cmd_make_unblocking (const struct GNUNET_TESTING_Command cmd) * @param is interpreter of the test */ void -GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is) +GNUNET_TESTING_interpreter_fail () { struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip]; @@ -411,9 +411,9 @@ interpreter_run (void *cls) ftc = GNUNET_new (struct FinishTaskClosure); ftc->cmd = cmd; ftc->is = is; - cmd->finish_task = GNUNET_SCHEDULER_add_delayed (CHECK_FINISHED_PERIOD, - &run_finish_task_next, - ftc); + is->finish_task = GNUNET_SCHEDULER_add_delayed (CHECK_FINISHED_PERIOD, + &run_finish_task_next, + ftc); } else { @@ -448,11 +448,12 @@ do_shutdown (void *cls) j++) { cmd->cleanup (cmd->cls, cmd); - if (NULL != cmd->finish_task) - { - GNUNET_SCHEDULER_cancel (cmd->finish_task); - cmd->finish_task = NULL; - } + } + + if (NULL != is->finish_task) + { + GNUNET_SCHEDULER_cancel (is->finish_task); + cmd->finish_task = NULL; } if (NULL != is->task) diff --git a/src/util/child_management.c b/src/util/child_management.c index 7775bfc3d..11fde4a61 100644 --- a/src/util/child_management.c +++ b/src/util/child_management.c @@ -222,6 +222,9 @@ GNUNET_wait_child_cancel (struct GNUNET_ChildWaitHandle *cwh) if (NULL == cwh_head) { child_management_done (); + } + if (NULL != sig_task) + { GNUNET_SCHEDULER_cancel (sig_task); sig_task = NULL; } -- cgit v1.2.3