- revert 27104
authorSree Harsha Totakura <totakura@in.tum.de>
Fri, 17 May 2013 09:23:41 +0000 (09:23 +0000)
committerSree Harsha Totakura <totakura@in.tum.de>
Fri, 17 May 2013 09:23:41 +0000 (09:23 +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

index f3d629f5f8b63064a544d8b420694b6a628b893b..1b74ad1dfc4dfd14c6fccee5a31200f66c8c4530 100644 (file)
@@ -473,48 +473,6 @@ 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
  *
@@ -528,11 +486,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;
-  unsigned int len;
+  uint16_t msize;
 
   if (NULL != GST_context)
   {
@@ -541,11 +499,18 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client,
     return;
   }
   msg = (const struct GNUNET_TESTBED_InitMessage *) message;
-  len = GNUNET_OS_get_hostname_max_length ();
-  hostname = GNUNET_malloc (len);
-  if (0 != gethostname (hostname, len))
+  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])
   {
-    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "gethostname");
+    GNUNET_break (0);
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
@@ -563,18 +528,10 @@ 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);
-  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->master_ip = GNUNET_strdup (controller_hostname);
+  LOG_DEBUG ("Our IP: %s\n", GST_context->master_ip);
   GST_context->system =
-      GNUNET_TESTING_system_create ("testbed", GST_context->master_ips,
+      GNUNET_TESTING_system_create ("testbed", GST_context->master_ip,
                                     hostname, ss);
   if (NULL != ss)
   {
@@ -586,9 +543,10 @@ 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, hostname,
-                                             NULL, our_config, 0);
+  host =
+      GNUNET_TESTBED_host_create_with_id (GST_context->host_id,
+                                          GST_context->master_ip, 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);
@@ -850,7 +808,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_ips);
+    GNUNET_free_non_null (GST_context->master_ip);
     if (NULL != GST_context->system)
       GNUNET_TESTING_system_destroy (GST_context->system, GNUNET_YES);
     GNUNET_SERVER_client_drop (GST_context->client);
@@ -912,8 +870,7 @@ 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,
-     sizeof (struct GNUNET_TESTBED_InitMessage)},
+    {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0},
     {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, 0},
     {&GST_handle_link_controllers, NULL,
      GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS,
index ceb209877f348a47924b8bc995a0b9804b5dd8c0..345007cd757d7135376019f38db99b66f51f2d66 100644 (file)
@@ -260,7 +260,7 @@ struct Context
   /**
    * The network address of the master controller
    */
-  char *master_ips;
+  char *master_ip;
 
   /**
    * The TESTING system handle for starting peers locally
index ad41dc9c58fd0e70e8300643f6c191ae6bbb3c6d..7b0006d1fbf22e34cae44ad808de543fce8e5d49 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_ips,
+        GNUNET_TESTBED_controller_start (GST_context->master_ip,
                                          GST_host_list[slave->host_id],
                                          &slave_status_cb, slave);
     new_route = GNUNET_malloc (sizeof (struct Route));
index 635708376b52fbf2f8f18e8a6c2f93eb95466d2c..904e7acbaa1a568df40d8e03babcb5d224ce0226 100644 (file)
@@ -54,6 +54,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
    * is interested in.  In NBO.
    */
   uint64_t event_mask GNUNET_PACKED;
+
+  /* Followed by 0-terminated hostname of the controller */
 };
 
 
index 93bdb03e5bd4f76e3e4dd98490033021d6838c67..e1068a2b6e2a9ac7b23c88aafa4d7df18b8d05de 100644 (file)
@@ -1440,9 +1440,10 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
                                    GNUNET_TESTBED_ControllerCallback cc,
                                    void *cc_cls)
 {
-  struct GNUNET_TESTBED_Controller *c;
+  struct GNUNET_TESTBED_Controller *controller;
   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;
@@ -1472,35 +1473,44 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
     GNUNET_break (0);
     return NULL;
   }
-  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)
+  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)
   {
-    GNUNET_TESTBED_controller_disconnect (c);
+    GNUNET_TESTBED_controller_disconnect (controller);
     return NULL;
   }
-  GNUNET_TESTBED_mark_host_registered_at_ (host, c);
-  c->host = host;
-  c->opq_parallel_operations =
+  GNUNET_TESTBED_mark_host_registered_at_ (host, controller);
+  controller->host = host;
+  controller->opq_parallel_operations =
       GNUNET_TESTBED_operation_queue_create_ ((unsigned int)
                                               max_parallel_operations);
-  c->opq_parallel_service_connections =
+  controller->opq_parallel_service_connections =
       GNUNET_TESTBED_operation_queue_create_ ((unsigned int)
                                               max_parallel_service_connections);
-  c->opq_parallel_topology_config_operations =
+  controller->opq_parallel_topology_config_operations =
       GNUNET_TESTBED_operation_queue_create_ ((unsigned int)
                                               max_parallel_topology_config_operations);
-  msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_InitMessage));
+  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->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_INIT);
-  msg->header.size = htons (sizeof (struct GNUNET_TESTBED_InitMessage));
+  msg->header.size =
+      htons (sizeof (struct GNUNET_TESTBED_InitMessage) +
+             strlen (controller_hostname) + 1);
   msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host));
-  msg->event_mask = GNUNET_htonll (c->event_mask);
-  GNUNET_TESTBED_queue_message_ (c, &msg->header);
-  return c;
+  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;
 }