/**
- * 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);
/**
* @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
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);
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");
"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 =
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,
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));
*/
static struct Context *master_context;
+/**
+ * Our hostname; we give this to all the peers we start
+ */
+static char *hostname;
+
/***********/
/* Handles */
/***********/
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);
GNUNET_free (master_context);
master_context = NULL;
}
+ GNUNET_free_non_null (hostname);
}
{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);
&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);
{
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 =
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);
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);
* 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)
{
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);
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;
}
* 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);
#ifndef TESTBED_HELPER_H
#define TESTBED_HELPER_H
+GNUNET_NETWORK_STRUCT_BEGIN
+
/**
* Initialization message for gnunet-helper-testbed to start testbed service
*/
*/
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
*/
/* 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 */
};
* un-compressed */
};
+GNUNET_NETWORK_STRUCT_END
+
#endif
/* end of testbed_helper.h */
}
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);
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)
{
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;
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,
*/
char *controller;
+ /**
+ * our hostname
+ */
+ char *hostname;
+
/**
* Hostkeys data, contains "HOSTKEYFILESIZE * total_hostkeys" bytes.
*/
* @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
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)
{
}
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);
/**
- * 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);
}
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);
}
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);
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 ();
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"));