- remove hostname/ip address from INIT message. They will be determined by the contr...
authorSree Harsha Totakura <totakura@in.tum.de>
Mon, 13 May 2013 14:03:32 +0000 (14:03 +0000)
committerSree Harsha Totakura <totakura@in.tum.de>
Mon, 13 May 2013 14:03:32 +0000 (14:03 +0000)
src/testbed/gnunet-service-testbed.c
src/testbed/gnunet-service-testbed.h
src/testbed/gnunet-service-testbed_links.c
src/testbed/testbed.h
src/testbed/testbed_api.c
src/testbed/testbed_api_hosts.c

index 1b74ad1dfc4dfd14c6fccee5a31200f66c8c4530..f3d629f5f8b63064a544d8b420694b6a628b893b 100644 (file)
@@ -473,6 +473,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
  *
@@ -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,
index 345007cd757d7135376019f38db99b66f51f2d66..ceb209877f348a47924b8bc995a0b9804b5dd8c0 100644 (file)
@@ -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
index 7b0006d1fbf22e34cae44ad808de543fce8e5d49..ad41dc9c58fd0e70e8300643f6c191ae6bbb3c6d 100644 (file)
@@ -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));
index 904e7acbaa1a568df40d8e03babcb5d224ce0226..635708376b52fbf2f8f18e8a6c2f93eb95466d2c 100644 (file)
@@ -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 */
 };
 
 
index 01df06729a78641a34ff04c9af555b1528a5be08..80f940467d6b09d54e52dbe907cc5f6f8821ab14 100644 (file)
@@ -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;
 }
 
 
index c386d18a0edb1cff559038bec105137fbd21adfa..e76dada8891b3db31a400e18f2d49feeb3aa45ae 100644 (file)
@@ -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;
 }