gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r22507 - gnunet/src/testbed
Date: Thu, 5 Jul 2012 21:59:34 +0200

Author: harsha
Date: 2012-07-05 21:59:34 +0200 (Thu, 05 Jul 2012)
New Revision: 22507

Modified:
   gnunet/src/testbed/gnunet-service-testbed.c
Log:
direct links to slave controllers

Modified: gnunet/src/testbed/gnunet-service-testbed.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed.c 2012-07-05 19:11:09 UTC (rev 
22506)
+++ gnunet/src/testbed/gnunet-service-testbed.c 2012-07-05 19:59:34 UTC (rev 
22507)
@@ -45,6 +45,9 @@
 #define LOG_DEBUG(...)                          \
   LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
 
+
+#define LIST_GROW_STEP 10
+
 struct Context
 {
   /**
@@ -229,7 +232,30 @@
 };
 
 
+
 /**
+ * Structure representing a connected(directly-linked) controller
+ */
+struct Slave
+{
+  /**
+   * The controller process handle if we had started the controller
+   */
+  struct GNUNET_TESTBED_ControllerProc *controller_proc;
+
+  /**
+   * The controller handle
+   */
+  struct GNUNET_TESTBED_Controller *controller;
+
+  /**
+   * The id of the host this controller is running on
+   */
+  uint32_t host;
+};
+
+
+/**
  * The master context; generated with the first INIT message
  */
 static struct Context *master_context;
@@ -283,6 +309,11 @@
 static struct Route **route_list;
 
 /**
+ * A list of directly linked neighbours
+ */
+static struct Slave **slave_list;
+
+/**
  * The hashmap of shared services
  */
 static struct GNUNET_CONTAINER_MultiHashMap *ss_map;
@@ -297,6 +328,11 @@
  */
 static uint32_t route_list_size;
 
+/**
+ * The size of directly linked neighbours list
+ */
+static uint32_t slave_list_size;
+
 /*********/
 /* Tasks */
 /*********/
@@ -540,6 +576,21 @@
 
 
 /**
+ * Callback for event from slave controllers
+ *
+ * @param cls struct Slave *
+ * @param event information about the event
+ */
+static void 
+slave_event_callback(void *cls,
+                     const struct GNUNET_TESTBED_EventInformation *event)
+{
+  GNUNET_break (0);
+}
+
+
+
+/**
  * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages
  *
  * @param cls NULL
@@ -758,6 +809,12 @@
   uint32_t slave_host_id;
   uint16_t msize;
    
+  if (NULL == master_context)
+  {
+    GNUNET_break (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    return;
+  }
   msize = ntohs (message->size);
   if (sizeof (struct GNUNET_TESTBED_ControllerLinkMessage) >= msize)
   {
@@ -788,31 +845,64 @@
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
-
-  config_size = ntohs (msg->config_size);
-  config = GNUNET_malloc (config_size);
-  dest_size = (uLongf) config_size;
-  msize -= sizeof (struct GNUNET_TESTBED_ControllerLinkMessage);
-  if (Z_OK != uncompress ((Bytef *) config, &dest_size,
-                          (const Bytef *) &msg[1], (uLong) msize))
+  if (slave_host_id == master_context->host_id) /* Link from us */
   {
-    GNUNET_break (0);           /* Compression error */
+    if ((delegated_host_id < slave_list_size) && 
+        (NULL != slave_list[delegated_host_id])) /* We have already added */
+    {
+      LOG (GNUNET_ERROR_TYPE_WARNING, "Host %u already connected\n",
+           delegated_host_id);
+      GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+      return;
+    }
+    config_size = ntohs (msg->config_size);
+    config = GNUNET_malloc (config_size);
+    dest_size = (uLongf) config_size;
+    msize -= sizeof (struct GNUNET_TESTBED_ControllerLinkMessage);
+    if (Z_OK != uncompress ((Bytef *) config, &dest_size,
+                            (const Bytef *) &msg[1], (uLong) msize))
+    {
+      GNUNET_break (0);           /* Compression error */
+      GNUNET_free (config);
+      GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+      return;
+    }
+    GNUNET_assert (config_size == dest_size);
+    cfg = GNUNET_CONFIGURATION_create (); /* Free here or in lcfcontext */
+    if (GNUNET_OK != GNUNET_CONFIGURATION_deserialize (cfg, config, 
config_size,
+                                                       GNUNET_NO))
+    {
+      GNUNET_break (0);           /* Configuration parsing error */
+      GNUNET_break (config);
+      GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+      return;
+    }
     GNUNET_free (config);
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-    return;
+    if (delegated_host_id >= slave_list_size)
+    {
+      slave_list_size += LIST_GROW_STEP;
+      slave_list = GNUNET_realloc (slave_list,
+                                   sizeof (struct Slave *) * slave_list_size);
+    }
+    struct Slave *slave;
+    slave = GNUNET_malloc (sizeof (struct Slave));
+    slave->host = delegated_host_id;
+    slave_list[delegated_host_id] = slave;
+    if (1 == msg->is_subordinate)
+    {
+      slave->controller_proc =
+        GNUNET_TESTBED_controller_start (host_list[delegated_host_id]);
+    }
+    slave->controller =
+      GNUNET_TESTBED_controller_connect (cfg, host_list[delegated_host_id],
+                                         master_context->event_mask,
+                                         &slave_event_callback, slave);
+    GNUNET_CONFIGURATION_destroy (cfg);        
   }
-  GNUNET_assert (config_size == dest_size);
-  cfg = GNUNET_CONFIGURATION_create (); /* Free here or in lcfcontext */
-  if (GNUNET_OK != GNUNET_CONFIGURATION_deserialize (cfg, config, config_size,
-                                                     GNUNET_NO))
-  {
-    GNUNET_break (0);           /* Configuration parsing error */
-    GNUNET_break (config);
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-    return;
-  }
-  GNUNET_free (config);
+  /* Route the request */
 
+  
+
   /* If delegated host and slave host are not same we have to forward
      towards delegated host */
   if (slave_host_id != delegated_host_id)
@@ -863,7 +953,6 @@
     GNUNET_break (0);           /* FIXME: Implement the slave controller
                                    startup */ 
   }  
-  GNUNET_CONFIGURATION_destroy (cfg);
 }
 
 




reply via email to

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