From f50072ff43b084ae76ae17fed0610f315db81255 Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Sun, 15 Jul 2012 14:30:22 +0000 Subject: [PATCH] config localization and service startup --- src/testbed/gnunet-testbed-helper.c | 37 ++++++++++++++++-- src/testbed/test_gnunet_testbed_helper.c | 49 +++++++++++++++++++----- 2 files changed, 74 insertions(+), 12 deletions(-) diff --git a/src/testbed/gnunet-testbed-helper.c b/src/testbed/gnunet-testbed-helper.c index 5993702dc..4c202193b 100644 --- a/src/testbed/gnunet-testbed-helper.c +++ b/src/testbed/gnunet-testbed-helper.c @@ -24,10 +24,12 @@ * gnunet-service-testbed. This binary also receives configuration * from the remove controller which is put in a temporary location * with ports and paths fixed so that gnunet-service-testbed runs - * without any hurdels. This binary also kills the testbed service + * without any hurdles. This binary also kills the testbed service * should the connection from the remote controller is dropped * @author Sree Harsha Totakura */ + + #include "platform.h" #include "gnunet_util_lib.h" #include "gnunet_testing_lib-new.h" @@ -101,6 +103,7 @@ static int ret; static void shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { + LOG_DEBUG ("Shutting down\n"); if (GNUNET_SCHEDULER_NO_TASK != read_task_id) { GNUNET_SCHEDULER_cancel (read_task_id); @@ -109,6 +112,23 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) (void) GNUNET_DISK_file_close (stdin_fd); GNUNET_SERVER_mst_destroy (tokenizer); tokenizer = NULL; + if (NULL != testbed) + { + (void) GNUNET_OS_process_kill (testbed, SIGTERM); + GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (testbed)); + GNUNET_OS_process_destroy (testbed); + testbed = NULL; + } + if (NULL != pipe_in) + { + (void) GNUNET_DISK_pipe_close (pipe_in); + pipe_in = NULL; + } + if (NULL != pipe_out) + { + (void) GNUNET_DISK_pipe_close (pipe_out); + pipe_out = NULL; + } if (NULL != test_system) { GNUNET_TESTING_system_destroy (test_system, GNUNET_YES); @@ -183,6 +203,8 @@ tokenizer_cb (void *cls, void *client, GNUNET_assert (NULL != test_system); GNUNET_assert (GNUNET_OK == GNUNET_TESTING_configuration_create (test_system, cfg)); + GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string + (cfg, "PATHS", "DEFAULTCONFIG", &config)); pipe_in = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO); pipe_out = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_YES); if ((NULL == pipe_in) || (NULL == pipe_out)) @@ -190,14 +212,23 @@ tokenizer_cb (void *cls, void *client, GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe"); GNUNET_free (config); goto error; - } + } + if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config)) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Unable to write config file: %s -- exiting\n", config); + GNUNET_free (config); + goto error; + } + LOG_DEBUG ("Staring testbed with config: %s\n", config); testbed = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR /*verbose? */, pipe_in, pipe_out, "gnunet-service-testbed", "gnunet-service-testbed", "-c", config, NULL); + GNUNET_free (config); if (NULL == testbed) { LOG (GNUNET_ERROR_TYPE_WARNING, - "Unable to deserialize config -- exiting\n"); + "Error staring gnunet-service-testbed -- exiting\n"); goto error; } GNUNET_DISK_pipe_close_end (pipe_out, GNUNET_DISK_PIPE_END_WRITE); diff --git a/src/testbed/test_gnunet_testbed_helper.c b/src/testbed/test_gnunet_testbed_helper.c index 30f562bad..a2f8936ab 100644 --- a/src/testbed/test_gnunet_testbed_helper.c +++ b/src/testbed/test_gnunet_testbed_helper.c @@ -26,6 +26,9 @@ #include "platform.h" #include "gnunet_util_lib.h" +#include "gnunet_testbed_service.h" + +#include "testbed_api.h" #include "testbed_helper.h" /** @@ -43,7 +46,7 @@ static struct GNUNET_HELPER_Handle *helper; /** * Message to helper */ -static struct GNUNET_TESTBED_HelperInit msg; +static struct GNUNET_TESTBED_HelperInit *msg; /** * Message send handle @@ -60,6 +63,11 @@ static GNUNET_SCHEDULER_TaskIdentifier abort_task; */ static GNUNET_SCHEDULER_TaskIdentifier shutdown_task; +/** + * Configuratin handler + */ +static struct GNUNET_CONFIGURATION_Handle *cfg; + /** * Shutdown nicely @@ -72,7 +80,10 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) { if (GNUNET_SCHEDULER_NO_TASK != abort_task) GNUNET_SCHEDULER_cancel (abort_task); - GNUNET_HELPER_stop (helper); + GNUNET_HELPER_stop (helper); + GNUNET_free_non_null (msg); + if (NULL != cfg) + GNUNET_CONFIGURATION_destroy (cfg); } @@ -109,7 +120,7 @@ cont_cb (void *cls, int result) GNUNET_assert (GNUNET_OK == result); if (GNUNET_SCHEDULER_NO_TASK == shutdown_task) shutdown_task = GNUNET_SCHEDULER_add_delayed - (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), + (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), &do_shutdown, NULL); } @@ -124,22 +135,42 @@ cont_cb (void *cls, int result) */ static void run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle * cfg) + const struct GNUNET_CONFIGURATION_Handle * cfg2) { static char * const binary_argv[] = { "gnunet-testbed-helper", NULL }; + char *config; + char *xconfig; + const char *hostname = "127.0.0.1"; + size_t config_size; + size_t xconfig_size; + uint16_t hostname_len; + uint16_t msg_size; + helper = GNUNET_HELPER_start ("gnunet-testbed-helper", binary_argv, NULL, NULL); GNUNET_assert (NULL != helper); - msg.header.size = htons (sizeof (struct GNUNET_TESTBED_HelperInit)); - msg.header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT); - msg.cname_size = htons (0); - msg.config_size = htons (0); + cfg = GNUNET_CONFIGURATION_dup (cfg2); + config = GNUNET_CONFIGURATION_serialize (cfg, &config_size); + GNUNET_assert (NULL != config); + xconfig_size = + GNUNET_TESTBED_compress_config (config, config_size, &xconfig); + GNUNET_free (config); + hostname_len = strlen (hostname); + msg_size = xconfig_size + hostname_len + 1 + + sizeof (struct GNUNET_TESTBED_HelperInit); + msg = GNUNET_realloc (xconfig, msg_size); + (void) memmove ( ((void *) &msg[1]) + hostname_len + 1, msg, xconfig_size); + msg->header.size = htons (msg_size); + msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT); + msg->cname_size = htons (hostname_len); + msg->config_size = htons (config_size); + (void) strcpy ((char *) &msg[1], hostname); shandle = GNUNET_HELPER_send (helper, - &msg.header, + &msg->header, GNUNET_NO, &cont_cb, NULL); GNUNET_assert (NULL != shandle); abort_task = GNUNET_SCHEDULER_add_delayed -- 2.25.1