summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-05-13 14:03:32 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-05-13 14:03:32 +0000
commite3942b151f9ba6371d6ba949f462fc1bac8fff2d (patch)
tree10ec97dd31a7f407dd8a7f53a9603912b86ac454 /src
parent36c25583810227d57cdec641b9203592594ba875 (diff)
- remove hostname/ip address from INIT message. They will be determined by the controller automatically
Diffstat (limited to 'src')
-rw-r--r--src/testbed/gnunet-service-testbed.c87
-rw-r--r--src/testbed/gnunet-service-testbed.h2
-rw-r--r--src/testbed/gnunet-service-testbed_links.c2
-rw-r--r--src/testbed/testbed.h2
-rw-r--r--src/testbed/testbed_api.c48
-rw-r--r--src/testbed/testbed_api_hosts.c1
6 files changed, 87 insertions, 55 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index 1b74ad1df..f3d629f5f 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -474,6 +474,48 @@ parse_shared_services (char *ss_str, struct GNUNET_CONFIGURATION_Handle *cfg)
/**
+ * Callback function invoked for each interface found.
+ *
+ * @param cls NULL
+ * @param name name of the interface (can be NULL for unknown)
+ * @param isDefault is this presumably the default interface
+ * @param addr address of this interface (can be NULL for unknown or unassigned)
+ * @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned)
+ * @param netmask the network mask (can be NULL for unknown or unassigned))
+ * @param addrlen length of the address
+ * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
+ */
+static int
+addr_proc (void *cls, const char *name, int isDefault,
+ const struct sockaddr *addr,
+ const struct sockaddr *broadcast_addr,
+ const struct sockaddr *netmask, socklen_t addrlen)
+{
+ struct Context *ctx = cls;
+ const struct sockaddr_in *in_addr;
+ char *ipaddr;
+ char *tmp;
+
+ if (sizeof (struct sockaddr_in) != addrlen)
+ return GNUNET_OK;
+ in_addr = (const struct sockaddr_in *) addr;
+ if (NULL == (ipaddr = inet_ntoa (in_addr->sin_addr)))
+ return GNUNET_OK;
+ if (NULL == ctx->master_ips)
+ {
+ ctx->master_ips = GNUNET_strdup (ipaddr);
+ return GNUNET_OK;
+ }
+ tmp = NULL;
+ (void) GNUNET_asprintf (&tmp, "%s; %s", ctx->master_ips, ipaddr);
+ GNUNET_free (ctx->master_ips);
+ ctx->master_ips = tmp;
+ return GNUNET_OK;
+}
+
+
+
+/**
* Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages
*
* @param cls NULL
@@ -486,11 +528,11 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client,
{
const struct GNUNET_TESTBED_InitMessage *msg;
struct GNUNET_TESTBED_Host *host;
- const char *controller_hostname;
char *ss_str;
struct GNUNET_TESTING_SharedService *ss;
+ char *hostname;
unsigned int cnt;
- uint16_t msize;
+ unsigned int len;
if (NULL != GST_context)
{
@@ -499,18 +541,11 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client,
return;
}
msg = (const struct GNUNET_TESTBED_InitMessage *) message;
- msize = ntohs (message->size);
- if (msize <= sizeof (struct GNUNET_TESTBED_InitMessage))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- msize -= sizeof (struct GNUNET_TESTBED_InitMessage);
- controller_hostname = (const char *) &msg[1];
- if ('\0' != controller_hostname[msize - 1])
+ len = GNUNET_OS_get_hostname_max_length ();
+ hostname = GNUNET_malloc (len);
+ if (0 != gethostname (hostname, len))
{
- GNUNET_break (0);
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "gethostname");
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
@@ -528,10 +563,18 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client,
GNUNET_SERVER_client_keep (client);
GST_context->client = client;
GST_context->host_id = ntohl (msg->host_id);
- GST_context->master_ip = GNUNET_strdup (controller_hostname);
- LOG_DEBUG ("Our IP: %s\n", GST_context->master_ip);
+ GNUNET_OS_network_interfaces_list (&addr_proc, GST_context);
+ if (NULL == GST_context->master_ips)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Testbed needs networking, but no network interfaces are found on this host. Exiting\n");
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ LOG_DEBUG ("Our IP addresses: %s\n", GST_context->master_ips);
GST_context->system =
- GNUNET_TESTING_system_create ("testbed", GST_context->master_ip,
+ GNUNET_TESTING_system_create ("testbed", GST_context->master_ips,
hostname, ss);
if (NULL != ss)
{
@@ -543,10 +586,9 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client,
GNUNET_free (ss);
ss = NULL;
}
- host =
- GNUNET_TESTBED_host_create_with_id (GST_context->host_id,
- GST_context->master_ip, NULL,
- our_config, 0);
+
+ host = GNUNET_TESTBED_host_create_with_id (GST_context->host_id, hostname,
+ NULL, our_config, 0);
host_list_add (host);
LOG_DEBUG ("Created master context with host ID: %u\n", GST_context->host_id);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -808,7 +850,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
GNUNET_free_non_null (GST_host_list);
if (NULL != GST_context)
{
- GNUNET_free_non_null (GST_context->master_ip);
+ GNUNET_free_non_null (GST_context->master_ips);
if (NULL != GST_context->system)
GNUNET_TESTING_system_destroy (GST_context->system, GNUNET_YES);
GNUNET_SERVER_client_drop (GST_context->client);
@@ -870,7 +912,8 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
static const struct GNUNET_SERVER_MessageHandler message_handlers[] = {
- {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0},
+ {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT,
+ sizeof (struct GNUNET_TESTBED_InitMessage)},
{&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, 0},
{&GST_handle_link_controllers, NULL,
GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS,
diff --git a/src/testbed/gnunet-service-testbed.h b/src/testbed/gnunet-service-testbed.h
index 345007cd7..ceb209877 100644
--- a/src/testbed/gnunet-service-testbed.h
+++ b/src/testbed/gnunet-service-testbed.h
@@ -260,7 +260,7 @@ struct Context
/**
* The network address of the master controller
*/
- char *master_ip;
+ char *master_ips;
/**
* The TESTING system handle for starting peers locally
diff --git a/src/testbed/gnunet-service-testbed_links.c b/src/testbed/gnunet-service-testbed_links.c
index 7b0006d1f..ad41dc9c5 100644
--- a/src/testbed/gnunet-service-testbed_links.c
+++ b/src/testbed/gnunet-service-testbed_links.c
@@ -1248,7 +1248,7 @@ GST_handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client,
lcc->client = client;
slave->lcc = lcc;
slave->controller_proc =
- GNUNET_TESTBED_controller_start (GST_context->master_ip,
+ GNUNET_TESTBED_controller_start (GST_context->master_ips,
GST_host_list[slave->host_id],
&slave_status_cb, slave);
new_route = GNUNET_malloc (sizeof (struct Route));
diff --git a/src/testbed/testbed.h b/src/testbed/testbed.h
index 904e7acba..635708376 100644
--- a/src/testbed/testbed.h
+++ b/src/testbed/testbed.h
@@ -54,8 +54,6 @@ GNUNET_NETWORK_STRUCT_BEGIN
* is interested in. In NBO.
*/
uint64_t event_mask GNUNET_PACKED;
-
- /* Followed by 0-terminated hostname of the controller */
};
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index 01df06729..80f940467 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -1436,10 +1436,9 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
GNUNET_TESTBED_ControllerCallback cc,
void *cc_cls)
{
- struct GNUNET_TESTBED_Controller *controller;
+ struct GNUNET_TESTBED_Controller *c;
struct GNUNET_TESTBED_InitMessage *msg;
const struct GNUNET_CONFIGURATION_Handle *cfg;
- const char *controller_hostname;
unsigned long long max_parallel_operations;
unsigned long long max_parallel_service_connections;
unsigned long long max_parallel_topology_config_operations;
@@ -1469,44 +1468,35 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
GNUNET_break (0);
return NULL;
}
- controller = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Controller));
- controller->cc = cc;
- controller->cc_cls = cc_cls;
- controller->event_mask = event_mask;
- controller->cfg = GNUNET_CONFIGURATION_dup (cfg);
- controller->client = GNUNET_CLIENT_connect ("testbed", controller->cfg);
- if (NULL == controller->client)
+ c = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Controller));
+ c->cc = cc;
+ c->cc_cls = cc_cls;
+ c->event_mask = event_mask;
+ c->cfg = GNUNET_CONFIGURATION_dup (cfg);
+ c->client = GNUNET_CLIENT_connect ("testbed", c->cfg);
+ if (NULL == c->client)
{
- GNUNET_TESTBED_controller_disconnect (controller);
+ GNUNET_TESTBED_controller_disconnect (c);
return NULL;
}
- GNUNET_TESTBED_mark_host_registered_at_ (host, controller);
- controller->host = host;
- controller->opq_parallel_operations =
+ GNUNET_TESTBED_mark_host_registered_at_ (host, c);
+ c->host = host;
+ c->opq_parallel_operations =
GNUNET_TESTBED_operation_queue_create_ ((unsigned int)
max_parallel_operations);
- controller->opq_parallel_service_connections =
+ c->opq_parallel_service_connections =
GNUNET_TESTBED_operation_queue_create_ ((unsigned int)
max_parallel_service_connections);
- controller->opq_parallel_topology_config_operations =
+ c->opq_parallel_topology_config_operations =
GNUNET_TESTBED_operation_queue_create_ ((unsigned int)
max_parallel_topology_config_operations);
- controller_hostname = GNUNET_TESTBED_host_get_hostname (host);
- if (NULL == controller_hostname)
- controller_hostname = "127.0.0.1";
- msg =
- GNUNET_malloc (sizeof (struct GNUNET_TESTBED_InitMessage) +
- strlen (controller_hostname) + 1);
+ msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_InitMessage));
msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_INIT);
- msg->header.size =
- htons (sizeof (struct GNUNET_TESTBED_InitMessage) +
- strlen (controller_hostname) + 1);
+ msg->header.size = htons (sizeof (struct GNUNET_TESTBED_InitMessage));
msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host));
- msg->event_mask = GNUNET_htonll (controller->event_mask);
- strcpy ((char *) &msg[1], controller_hostname);
- GNUNET_TESTBED_queue_message_ (controller,
- (struct GNUNET_MessageHeader *) msg);
- return controller;
+ msg->event_mask = GNUNET_htonll (c->event_mask);
+ GNUNET_TESTBED_queue_message_ (c, &msg->header);
+ return c;
}
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c
index c386d18a0..e76dada88 100644
--- a/src/testbed/testbed_api_hosts.c
+++ b/src/testbed/testbed_api_hosts.c
@@ -556,6 +556,7 @@ simple_resolve (const char *host)
in_addr = (const struct sockaddr_in *) res->ai_addr;
hostip = inet_ntoa (in_addr->sin_addr);
GNUNET_assert (NULL != hostip);
+ freeaddrinfo (res);
LOG_DEBUG ("Resolved [%s] to [%s]\n", host, hostip);
return hostip;
}