From 87566df009e48391b08d3f1cdf3dedf7debcac7b Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Fri, 5 Oct 2012 14:12:49 +0000 Subject: testing now includes valid hostname rewriting --- src/include/gnunet_testing_lib-new.h | 25 +++++++++++-------- src/testbed/gnunet-helper-testbed.c | 30 +++++++++++++++++++--- src/testbed/gnunet-service-testbed.c | 10 +++++++- src/testbed/test_gnunet_helper_testbed.c | 2 +- src/testbed/testbed_api.c | 17 ++++++++++--- src/testbed/testbed_api.h | 2 ++ src/testbed/testbed_helper.h | 13 ++++++++++ src/testing/gnunet-testing.c | 4 +-- src/testing/test_testing_peerstartup.c | 2 +- src/testing/test_testing_portreservation.c | 2 +- src/testing/testing.c | 40 ++++++++++++++++++++---------- src/transport/transport-testing.c | 2 +- 12 files changed, 112 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/include/gnunet_testing_lib-new.h b/src/include/gnunet_testing_lib-new.h index 802839d17..aef8c763d 100644 --- a/src/include/gnunet_testing_lib-new.h +++ b/src/include/gnunet_testing_lib-new.h @@ -59,21 +59,23 @@ struct GNUNET_TESTING_Peer; /** - * Create a system handle. There must only be one system - * handle per operating system. Uses a default range for allowed ports. - * Ports are still tested for availability. + * Create a system handle. There must only be one system handle per operating + * system. Uses a default range for allowed ports. Ports are still tested for + * availability. * - * @param testdir only the directory name without any path. This is used for - * all service homes; the directory will be created in a temporary - * location depending on the underlying OS - * @param controller hostname of the controlling host, - * service configurations are modified to allow - * control connections from this host; can be NULL + * @param testdir only the directory name without any path. This is used for all + * service homes; the directory will be created in a temporary location + * depending on the underlying OS + * @param controller hostname of the controlling host, service configurations + * are modified to allow control connections from this host; can be NULL + * @param hostname the hostname of the system we are using for testing; NULL for + * localhost * @return handle to this system, NULL on error */ struct GNUNET_TESTING_System * GNUNET_TESTING_system_create (const char *testdir, - const char *controller); + const char *controller, + const char *hostname); /** @@ -89,6 +91,8 @@ GNUNET_TESTING_system_create (const char *testdir, * @param controller hostname of the controlling host, * service configurations are modified to allow * control connections from this host; can be NULL + * @param hostname the hostname of the system we are using for testing; NULL for + * localhost * @param lowport lowest port number this system is allowed to allocate (inclusive) * @param highport highest port number this system is allowed to allocate (exclusive) * @return handle to this system, NULL on error @@ -96,6 +100,7 @@ GNUNET_TESTING_system_create (const char *testdir, struct GNUNET_TESTING_System * GNUNET_TESTING_system_create_with_portrange (const char *testdir, const char *controller, + const char *hostname, uint16_t lowport, uint16_t highport); diff --git a/src/testbed/gnunet-helper-testbed.c b/src/testbed/gnunet-helper-testbed.c index bc7f223af..0e70645c7 100644 --- a/src/testbed/gnunet-helper-testbed.c +++ b/src/testbed/gnunet-helper-testbed.c @@ -226,14 +226,18 @@ tokenizer_cb (void *cls, void *client, struct GNUNET_CONFIGURATION_Handle *cfg; struct WriteContext *wc; char *controller; + char *hostname; char *config; char *xconfig; size_t config_size; uLongf ul_config_size; size_t xconfig_size; uint16_t cname_size; - - if ((sizeof (struct GNUNET_TESTBED_HelperInit) >= ntohs (message->size)) || + uint16_t hostname_size; + uint16_t msize; + + msize = ntohs (message->size); + if ((sizeof (struct GNUNET_TESTBED_HelperInit) >= msize) || (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT != ntohs (message->type))) { LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); @@ -248,6 +252,14 @@ tokenizer_cb (void *cls, void *client, "Controller name cannot be empty -- exiting\n"); goto error; } + hostname_size = ntohs (msg->hostname_size); + if ((sizeof (struct GNUNET_TESTBED_HelperInit) + cname_size + 1 + + hostname_size) >= msize) + { + GNUNET_break (0); + LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); + goto error; + } ul_config_size = (uLongf) ntohs (msg->config_size); config = GNUNET_malloc (ul_config_size); xconfig_size = @@ -255,7 +267,7 @@ tokenizer_cb (void *cls, void *client, sizeof (struct GNUNET_TESTBED_HelperInit)); if (Z_OK != uncompress ((Bytef *) config, &ul_config_size, - (const Bytef *) (controller + cname_size + 1), + (const Bytef *) (controller + cname_size + 1 + hostname_size), (uLongf) xconfig_size)) { LOG (GNUNET_ERROR_TYPE_WARNING, @@ -273,7 +285,17 @@ tokenizer_cb (void *cls, void *client, goto error; } GNUNET_free (config); - test_system = GNUNET_TESTING_system_create ("testbed-helper", controller); + hostname = NULL; + if (0 != hostname_size) + { + hostname = GNUNET_malloc (hostname_size + 1); + (void) strncpy (hostname, ((char *) &msg[1]) + cname_size + 1, hostname_size); + hostname[hostname_size] = '\0'; + } + test_system = GNUNET_TESTING_system_create ("testbed-helper", controller, + hostname); + GNUNET_free_non_null (hostname); + hostname = NULL; GNUNET_assert (NULL != test_system); GNUNET_assert (GNUNET_OK == GNUNET_TESTING_configuration_create (test_system, cfg)); diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index c4a30f12c..0736f5997 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c @@ -538,6 +538,11 @@ struct LinkControllersContext */ static struct Context *master_context; +/** + * Our hostname; we give this to all the peers we start + */ +static char *hostname; + /***********/ /* Handles */ /***********/ @@ -1237,7 +1242,7 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client, master_context->master_ip = GNUNET_strdup (controller_hostname); LOG_DEBUG ("Master Controller IP: %s\n", master_context->master_ip); master_context->system = - GNUNET_TESTING_system_create ("testbed", master_context->master_ip); + GNUNET_TESTING_system_create ("testbed", master_context->master_ip, hostname); host = GNUNET_TESTBED_host_create_with_id (master_context->host_id, NULL, NULL, 0); @@ -2832,6 +2837,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_free (master_context); master_context = NULL; } + GNUNET_free_non_null (hostname); } @@ -2896,6 +2902,8 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server, {NULL} }; + GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string + (cfg, "testbed", "HOSTNAME", &hostname)); GNUNET_SERVER_add_handlers (server, message_handlers); GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL); ss_map = GNUNET_CONTAINER_multihashmap_create (5); diff --git a/src/testbed/test_gnunet_helper_testbed.c b/src/testbed/test_gnunet_helper_testbed.c index 7fce9a5d8..db889c1ec 100644 --- a/src/testbed/test_gnunet_helper_testbed.c +++ b/src/testbed/test_gnunet_helper_testbed.c @@ -212,7 +212,7 @@ run (void *cls, char *const *args, const char *cfgfile, &mst_cb, &exp_cb, NULL); GNUNET_assert (NULL != helper); cfg = GNUNET_CONFIGURATION_dup (cfg2); - msg = GNUNET_TESTBED_create_helper_init_msg_ (controller_name, cfg); + msg = GNUNET_TESTBED_create_helper_init_msg_ (controller_name, NULL, cfg); shandle = GNUNET_HELPER_send (helper, &msg->header, GNUNET_NO, &cont_cb, NULL); GNUNET_assert (NULL != shandle); diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 953488af1..1d99c7e3f 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c @@ -1338,10 +1338,12 @@ GNUNET_TESTBED_controller_start (const char *controller_ip, { struct GNUNET_TESTBED_ControllerProc *cp; struct GNUNET_TESTBED_HelperInit *msg; + const char *hostname; static char *const binary_argv[] = { HELPER_TESTBED_BINARY, NULL }; + hostname = NULL; cp = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ControllerProc)); if ((NULL == host) || (0 == GNUNET_TESTBED_host_get_id_ (host))) cp->helper = @@ -1352,7 +1354,6 @@ GNUNET_TESTBED_controller_start (const char *controller_ip, char *remote_args[8]; unsigned int argp; const char *username; - const char *hostname; username = GNUNET_TESTBED_host_get_username_ (host); hostname = GNUNET_TESTBED_host_get_hostname_ (host); @@ -1386,7 +1387,7 @@ GNUNET_TESTBED_controller_start (const char *controller_ip, cp->host = host; cp->cb = cb; cp->cls = cls; - msg = GNUNET_TESTBED_create_helper_init_msg_ (controller_ip, cfg); + msg = GNUNET_TESTBED_create_helper_init_msg_ (controller_ip, hostname, cfg); cp->msg = &msg->header; cp->shandle = GNUNET_HELPER_send (cp->helper, &msg->header, GNUNET_NO, &clear_msg, cp); @@ -1915,12 +1916,14 @@ GNUNET_TESTBED_overlay_write_topology_to_file (struct GNUNET_TESTBED_Controller * want to use this in testing * * @param cname the ip address of the controlling host + * @param hostname the hostname of the destination this message is intended for * @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 char *hostname, const struct GNUNET_CONFIGURATION_Handle *cfg) { @@ -1930,6 +1933,7 @@ GNUNET_TESTBED_create_helper_init_msg_ (const char *cname, size_t config_size; size_t xconfig_size; uint16_t cname_len; + uint16_t hostname_len; uint16_t msg_size; config = GNUNET_CONFIGURATION_serialize (cfg, &config_size); @@ -1938,15 +1942,22 @@ GNUNET_TESTBED_create_helper_init_msg_ (const char *cname, GNUNET_TESTBED_compress_config_ (config, config_size, &xconfig); GNUNET_free (config); cname_len = strlen (cname); + hostname_len = (NULL == hostname) ? 0 : strlen (hostname); msg_size = xconfig_size + cname_len + 1 + sizeof (struct GNUNET_TESTBED_HelperInit); + msg_size += hostname_len; msg = GNUNET_realloc (xconfig, msg_size); - (void) memmove (((void *) &msg[1]) + cname_len + 1, msg, xconfig_size); + (void) memmove (((void *) &msg[1]) + cname_len + 1 + hostname_len, + 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->hostname_size = htons (hostname_len); msg->config_size = htons (config_size); (void) strcpy ((char *) &msg[1], cname); + if (0 != hostname_len) + (void) strncpy (((char *) &msg[1]) + cname_len + 1, hostname, hostname_len); return msg; } diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h index c464b0ad5..020d951a2 100644 --- a/src/testbed/testbed_api.h +++ b/src/testbed/testbed_api.h @@ -356,12 +356,14 @@ GNUNET_TESTBED_operation_add_ (struct GNUNET_TESTBED_Operation *op); * Creates a helper initialization message. Only for testing. * * @param cname the ip address of the controlling host + * @param hostname the hostname of the destination this message is intended for * @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 char *hostname, const struct GNUNET_CONFIGURATION_Handle *cfg); diff --git a/src/testbed/testbed_helper.h b/src/testbed/testbed_helper.h index aee2c5b47..8a3ea55e0 100644 --- a/src/testbed/testbed_helper.h +++ b/src/testbed/testbed_helper.h @@ -28,6 +28,8 @@ #ifndef TESTBED_HELPER_H #define TESTBED_HELPER_H +GNUNET_NETWORK_STRUCT_BEGIN + /** * Initialization message for gnunet-helper-testbed to start testbed service */ @@ -44,6 +46,12 @@ struct GNUNET_TESTBED_HelperInit */ uint16_t cname_size GNUNET_PACKED; + /** + * The hostname size excluding the NULL termination character - strlen + * (hostname); cannot be zero + */ + uint16_t hostname_size GNUNET_PACKED; + /** * The size of the uncompressed configuration */ @@ -51,6 +59,9 @@ struct GNUNET_TESTBED_HelperInit /* Followed by NULL terminated controller hostname */ + /* Followed by hostname of the machine on which helper runs. This is not NULL + terminated */ + /* Followed by serialized and compressed configuration which should be * config_size long when un-compressed */ }; @@ -74,6 +85,8 @@ struct GNUNET_TESTBED_HelperReply * un-compressed */ }; +GNUNET_NETWORK_STRUCT_END + #endif /* end of testbed_helper.h */ diff --git a/src/testing/gnunet-testing.c b/src/testing/gnunet-testing.c index 77d2cf415..cc5c6f50c 100644 --- a/src/testing/gnunet-testing.c +++ b/src/testing/gnunet-testing.c @@ -77,7 +77,7 @@ create_unique_cfgs (const char * template, const unsigned int no) } fail = GNUNET_NO; - system = GNUNET_TESTING_system_create ("testing", NULL /* controller */); + system = GNUNET_TESTING_system_create ("testing", NULL /* controller */, NULL); for (cur = 0; cur < no; cur++) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating configuration no. %u \n", cur); @@ -124,7 +124,7 @@ create_hostkeys (const unsigned int no) struct GNUNET_CRYPTO_RsaPrivateKey *pk; struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pkb; - system = GNUNET_TESTING_system_create ("testing", NULL); + system = GNUNET_TESTING_system_create ("testing", NULL, NULL); pk = GNUNET_TESTING_hostkey_get (system, create_no, &id); if (NULL == pk) { diff --git a/src/testing/test_testing_peerstartup.c b/src/testing/test_testing_peerstartup.c index 990486467..7f78827f6 100644 --- a/src/testing/test_testing_peerstartup.c +++ b/src/testing/test_testing_peerstartup.c @@ -90,7 +90,7 @@ run (void *cls, char *const *args, const char *cfgfile, struct GNUNET_PeerIdentity id; system = GNUNET_TESTING_system_create ("test-gnunet-testing", - "127.0.0.1"); + "127.0.0.1", NULL); GNUNET_assert (NULL != system); new_cfg = GNUNET_CONFIGURATION_dup (cfg); emsg = NULL; diff --git a/src/testing/test_testing_portreservation.c b/src/testing/test_testing_portreservation.c index 4815d47fd..664031633 100644 --- a/src/testing/test_testing_portreservation.c +++ b/src/testing/test_testing_portreservation.c @@ -45,7 +45,7 @@ run (void *cls, char *const *args, const char *cfgfile, uint16_t old_port1; system = GNUNET_TESTING_system_create ("/tmp/gnunet-testing-new", - "localhost"); + "localhost", NULL); GNUNET_assert (NULL != system); new_port1 = GNUNET_TESTING_reserve_port (system, GNUNET_YES); LOG (GNUNET_ERROR_TYPE_DEBUG, diff --git a/src/testing/testing.c b/src/testing/testing.c index ecef4f266..8a5ff6679 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -73,6 +73,11 @@ struct GNUNET_TESTING_System */ char *controller; + /** + * our hostname + */ + char *hostname; + /** * Hostkeys data, contains "HOSTKEYFILESIZE * total_hostkeys" bytes. */ @@ -262,6 +267,8 @@ hostkeys_unload (struct GNUNET_TESTING_System *system) * @param controller hostname of the controlling host, * service configurations are modified to allow * control connections from this host; can be NULL + * @param hostname the hostname of the system we are using for testing; NULL for + * localhost * @param lowport lowest port number this system is allowed to allocate (inclusive) * @param highport highest port number this system is allowed to allocate (exclusive) * @return handle to this system, NULL on error @@ -269,6 +276,7 @@ hostkeys_unload (struct GNUNET_TESTING_System *system) struct GNUNET_TESTING_System * GNUNET_TESTING_system_create_with_portrange (const char *testdir, const char *controller, + const char *hostname, uint16_t lowport, uint16_t highport) { @@ -286,6 +294,8 @@ GNUNET_TESTING_system_create_with_portrange (const char *testdir, } if (NULL != controller) system->controller = GNUNET_strdup (controller); + if (NULL != hostname) + system->hostname = GNUNET_strdup (hostname); if (GNUNET_OK != hostkeys_load (system)) { GNUNET_TESTING_system_destroy (system, GNUNET_YES); @@ -296,24 +306,27 @@ GNUNET_TESTING_system_create_with_portrange (const char *testdir, /** - * Create a system handle. There must only be one system - * handle per operating system. - * - * @param testdir only the directory name without any path. This is used for - * all service homes; the directory will be created in a temporary - * location depending on the underlying OS + * Create a system handle. There must only be one system handle per operating + * system. Uses a default range for allowed ports. Ports are still tested for + * availability. * - * @param controller hostname of the controlling host, - * service configurations are modified to allow - * control connections from this host; can be NULL + * @param testdir only the directory name without any path. This is used for all + * service homes; the directory will be created in a temporary location + * depending on the underlying OS + * @param controller hostname of the controlling host, service configurations + * are modified to allow control connections from this host; can be NULL + * @param hostname the hostname of the system we are using for testing; NULL for + * localhost * @return handle to this system, NULL on error */ struct GNUNET_TESTING_System * GNUNET_TESTING_system_create (const char *testdir, - const char *controller) + const char *controller, + const char *hostname) { return GNUNET_TESTING_system_create_with_portrange (testdir, controller, + hostname, LOW_PORT, HIGH_PORT); } @@ -336,6 +349,7 @@ GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, GNUNET_DISK_directory_remove (system->tmppath); GNUNET_free (system->tmppath); GNUNET_free_non_null (system->controller); + GNUNET_free_non_null (system->hostname); GNUNET_free (system); } @@ -635,9 +649,9 @@ update_config (void *cls, const char *section, const char *option, GNUNET_break(0); /* FIXME */ } } - if ((0 == strcmp (option, "HOSTNAME")) && (NULL != uc->system->controller)) + if (0 == strcmp (option, "HOSTNAME")) { - value = uc->system->controller; + value = (NULL == uc->system->hostname) ? "localhost" : uc->system->hostname; } GNUNET_free (single_variable); GNUNET_free (per_host_variable); @@ -1119,7 +1133,7 @@ GNUNET_TESTING_service_run (const char *testdir, struct GNUNET_CONFIGURATION_Handle *cfg; GNUNET_log_setup (testdir, "WARNING", NULL); - system = GNUNET_TESTING_system_create (testdir, "127.0.0.1"); + system = GNUNET_TESTING_system_create (testdir, "127.0.0.1", NULL); if (NULL == system) return 1; cfg = GNUNET_CONFIGURATION_create (); diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c index 660b9c6b4..f1c06ebc0 100644 --- a/src/transport/transport-testing.c +++ b/src/transport/transport-testing.c @@ -584,7 +584,7 @@ GNUNET_TRANSPORT_TESTING_init () tth = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TESTING_handle)); /* Init testing the testing lib */ - tth->tl_system = GNUNET_TESTING_system_create ("transport-testing", NULL); + tth->tl_system = GNUNET_TESTING_system_create ("transport-testing", NULL, NULL); if (NULL == tth->tl_system) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize testing library!\n")); -- cgit v1.2.3