aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorharsha <harsha@140774ce-b5e7-0310-ab8b-a85725594a96>2012-10-05 14:12:49 +0000
committerharsha <harsha@140774ce-b5e7-0310-ab8b-a85725594a96>2012-10-05 14:12:49 +0000
commit8710fd4c322ec873cabe78e2ed71bfb28d71da3b (patch)
treee56d091c02b989535754dbd723c39d30620aa905
parentda200edbc17888e3f2f27ff770744feabf2e82b2 (diff)
testing now includes valid hostname rewriting
git-svn-id: https://gnunet.org/svn/gnunet@24196 140774ce-b5e7-0310-ab8b-a85725594a96
-rw-r--r--src/include/gnunet_testing_lib-new.h25
-rw-r--r--src/testbed/gnunet-helper-testbed.c30
-rw-r--r--src/testbed/gnunet-service-testbed.c10
-rw-r--r--src/testbed/test_gnunet_helper_testbed.c2
-rw-r--r--src/testbed/testbed_api.c17
-rw-r--r--src/testbed/testbed_api.h2
-rw-r--r--src/testbed/testbed_helper.h13
-rw-r--r--src/testing/gnunet-testing.c4
-rw-r--r--src/testing/test_testing_peerstartup.c2
-rw-r--r--src/testing/test_testing_portreservation.c2
-rw-r--r--src/testing/testing.c40
-rw-r--r--src/transport/transport-testing.c2
12 files changed, 112 insertions, 37 deletions
diff --git a/src/include/gnunet_testing_lib-new.h b/src/include/gnunet_testing_lib-new.h
index 802839d170..aef8c763db 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 bc7f223af0..0e70645c75 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 c4a30f12cd..0736f59979 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 7fce9a5d84..db889c1ec7 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 953488af1a..1d99c7e3f6 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 c464b0ad5a..020d951a26 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 aee2c5b478..8a3ea55e0e 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
*/
@@ -45,12 +47,21 @@ 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
*/
uint16_t config_size GNUNET_PACKED;
/* 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 77d2cf4151..cc5c6f50ce 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 990486467d..7f78827f65 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 4815d47fda..6640316331 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 ecef4f2668..8a5ff66797 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -74,6 +74,11 @@ struct GNUNET_TESTING_System
char *controller;
/**
+ * our hostname
+ */
+ char *hostname;
+
+ /**
* Hostkeys data, contains "HOSTKEYFILESIZE * total_hostkeys" bytes.
*/
char *hostkeys_data;
@@ -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 660b9c6b44..f1c06ebc01 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"));