gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r23195 - gnunet/src/testbed


From: gnunet
Subject: [GNUnet-SVN] r23195 - gnunet/src/testbed
Date: Fri, 10 Aug 2012 17:33:26 +0200

Author: harsha
Date: 2012-08-10 17:33:26 +0200 (Fri, 10 Aug 2012)
New Revision: 23195

Modified:
   gnunet/src/testbed/gnunet-service-testbed.c
   gnunet/src/testbed/testbed.h
   gnunet/src/testbed/testbed_api.c
Log:
controller hostname in init

Modified: gnunet/src/testbed/gnunet-service-testbed.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed.c 2012-08-10 14:01:22 UTC (rev 
23194)
+++ gnunet/src/testbed/gnunet-service-testbed.c 2012-08-10 15:33:26 UTC (rev 
23195)
@@ -935,8 +935,8 @@
 {
   const struct GNUNET_TESTBED_InitMessage *msg;
   struct GNUNET_TESTBED_Host *host;
-  void *addr;
-  size_t addrlen;
+  const char *controller_hostname;
+  uint16_t msize;
 
   if (NULL != master_context)
   {
@@ -944,29 +944,26 @@
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
-  msg = (const struct GNUNET_TESTBED_InitMessage *) message;  
+  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])
+  {
+    GNUNET_break (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    return;
+  }    
   master_context = GNUNET_malloc (sizeof (struct Context));
   master_context->client = client;
   master_context->host_id = ntohl (msg->host_id);
-  GNUNET_assert (GNUNET_OK == 
-                GNUNET_SERVER_client_get_address (client, &addr, &addrlen));
-  master_context->master_ip = GNUNET_malloc (NI_MAXHOST);
-  if (0 != getnameinfo (addr, addrlen, master_context->master_ip, NI_MAXHOST,
-                       NULL, 0, NI_NUMERICHOST))
-  {
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-        "Cannot determine the ip of master controller: %s\n", STRERROR 
(errno));
-    GNUNET_free (addr);
-    GNUNET_free (master_context->master_ip);
-    GNUNET_assert (0);
-  }
-  GNUNET_free (addr);
-  if (0 == strcasecmp (master_context->master_ip, "localhost"))
-  {                            /* Hack for connections via unix sockets */
-    LOG_DEBUG ("May be using local sockets - assuming loopback for master 
ip\n");
-    GNUNET_free (master_context->master_ip);
-    master_context->master_ip = strdup ("127.0.0.1");
-  }
+  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);
@@ -2031,8 +2028,7 @@
 {
   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_ADDHOST, 0},
       {&handle_configure_shared_service, NULL,
        GNUNET_MESSAGE_TYPE_TESTBED_SERVICESHARE, 0},

Modified: gnunet/src/testbed/testbed.h
===================================================================
--- gnunet/src/testbed/testbed.h        2012-08-10 14:01:22 UTC (rev 23194)
+++ gnunet/src/testbed/testbed.h        2012-08-10 15:33:26 UTC (rev 23195)
@@ -54,6 +54,8 @@
    * is interested in.  In NBO.
    */
   uint64_t event_mask GNUNET_PACKED;
+
+  /* Followed by 0-terminated hostname of the controller */
 };
 
 

Modified: gnunet/src/testbed/testbed_api.c
===================================================================
--- gnunet/src/testbed/testbed_api.c    2012-08-10 14:01:22 UTC (rev 23194)
+++ gnunet/src/testbed/testbed_api.c    2012-08-10 15:33:26 UTC (rev 23195)
@@ -997,6 +997,7 @@
 {
   struct GNUNET_TESTBED_Controller *controller;
   struct GNUNET_TESTBED_InitMessage *msg;
+  const char *controller_hostname;
   unsigned long long max_parallel_peer_create;
 
   if (GNUNET_OK !=
@@ -1021,7 +1022,7 @@
   if (NULL == host)
   {
     host = GNUNET_TESTBED_host_create_by_id_ (0);
-    if (NULL == host)
+    if (NULL == host)           /* If the above host create fails */
     {
       LOG (GNUNET_ERROR_TYPE_WARNING,
           "Treating NULL host as localhost. Multiple references to localhost "
@@ -1037,14 +1038,19 @@
   controller->opq_peer_create =
     GNUNET_TESTBED_operation_queue_create_ ((unsigned int)
                                             max_parallel_peer_create);
-  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 (controller->event_mask);
+  strcpy ((char *) &msg[1], controller_hostname);
   GNUNET_TESTBED_queue_message_ (controller, (struct GNUNET_MessageHeader *)
-                                 msg);
-  
+                                 msg);  
   return controller;
 }
 
@@ -1342,7 +1348,8 @@
 
 
 /**
- * Creates a helper initialization message. Only for testing.
+ * Creates a helper initialization message. This function is here because we
+ * want to use this in testing
  *
  * @param cname the ip address of the controlling host
  * @param cfg the configuration that has to used to start the testbed service




reply via email to

[Prev in Thread] Current Thread [Next in Thread]