From: Sree Harsha Totakura Date: Tue, 17 Jul 2012 12:12:05 +0000 (+0000) Subject: separated helper init message X-Git-Tag: initial-import-from-subversion-38251~12453 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=d13336f8ed7f3758fb2db45fd07496b34910952f;p=oweals%2Fgnunet.git separated helper init message --- diff --git a/src/testbed/test_gnunet_testbed_helper.c b/src/testbed/test_gnunet_testbed_helper.c index 654e5dd3e..26baf82a7 100644 --- a/src/testbed/test_gnunet_testbed_helper.c +++ b/src/testbed/test_gnunet_testbed_helper.c @@ -30,6 +30,7 @@ #include "testbed_api.h" #include "testbed_helper.h" +#include "testbed_api_hosts.h" /** * Generic logging shortcut @@ -141,34 +142,14 @@ run (void *cls, char *const *args, const char *cfgfile, "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; + const char *controller_name = "127.0.0.1"; helper = GNUNET_HELPER_start ("gnunet-testbed-helper", binary_argv, NULL, NULL, NULL); GNUNET_assert (NULL != helper); 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); + msg = GNUNET_TESTBED_create_helper_init_msg_ (controller_name, cfg); shandle = GNUNET_HELPER_send (helper, &msg->header, GNUNET_NO, &cont_cb, NULL); diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c index 56df4dede..fd129283e 100644 --- a/src/testbed/testbed_api_hosts.c +++ b/src/testbed/testbed_api_hosts.c @@ -33,6 +33,7 @@ #include "gnunet_hello_lib.h" #include "gnunet_container_lib.h" +#include "testbed_api.h" #include "testbed_api_hosts.h" /** @@ -488,4 +489,43 @@ GNUNET_TESTBED_is_host_registered_ (const struct GNUNET_TESTBED_Host *host, } +/** + * Creates a helper initialization message. Only for testing. + * + * @param cname the ip address of the controlling host + * @param cfg the configuration that has to used to start the testbed service + * thru helper + * @return the initialization message + */ +struct GNUNET_TESTBED_HelperInit * +GNUNET_TESTBED_create_helper_init_msg_ (const char *cname, + const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + struct GNUNET_TESTBED_HelperInit *msg; + char *config; + char *xconfig; + size_t config_size; + size_t xconfig_size; + uint16_t cname_len; + uint16_t msg_size; + + config = GNUNET_CONFIGURATION_serialize (cfg, &config_size); + GNUNET_assert (NULL != config); + xconfig_size = + GNUNET_TESTBED_compress_config (config, config_size, &xconfig); + GNUNET_free (config); + cname_len = strlen (cname); + msg_size = xconfig_size + cname_len + 1 + + sizeof (struct GNUNET_TESTBED_HelperInit); + msg = GNUNET_realloc (xconfig, msg_size); + (void) memmove ( ((void *) &msg[1]) + cname_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 (cname_len); + msg->config_size = htons (config_size); + (void) strcpy ((char *) &msg[1], cname); + return msg; +} + + /* end of testbed_api_hosts.c */ diff --git a/src/testbed/testbed_api_hosts.h b/src/testbed/testbed_api_hosts.h index b9a62698c..cc88d78a3 100644 --- a/src/testbed/testbed_api_hosts.h +++ b/src/testbed/testbed_api_hosts.h @@ -23,11 +23,12 @@ * @brief internal API to access the 'hosts' subsystem * @author Christian Grothoff */ + #ifndef NEW_TESTING_API_HOSTS_H #define NEW_TESTING_API_HOSTS_H #include "gnunet_testbed_service.h" -#include "gnunet_helper_lib.h" +#include "testbed_helper.h" /** @@ -181,5 +182,20 @@ GNUNET_TESTBED_is_host_registered_ (const struct GNUNET_TESTBED_Host *host, const struct GNUNET_TESTBED_Controller *controller); + +/** + * Creates a helper initialization message. Only for testing. + * + * @param cname the ip address of the controlling host + * @param cfg the configuration that has to used to start the testbed service + * thru helper + * @return the initialization message + */ +struct GNUNET_TESTBED_HelperInit * +GNUNET_TESTBED_create_helper_init_msg_ (const char *cname, + const struct GNUNET_CONFIGURATION_Handle *cfg); + + + #endif /* end of testbed_api_hosts.h */