implemented controller_start success callback
authorSree Harsha Totakura <totakura@in.tum.de>
Wed, 18 Jul 2012 11:56:05 +0000 (11:56 +0000)
committerSree Harsha Totakura <totakura@in.tum.de>
Wed, 18 Jul 2012 11:56:05 +0000 (11:56 +0000)
src/testbed/test_gnunet_testbed_helper.c
src/testbed/testbed_api.c

index 78f6ee69d0287b8e5c90b9b03824be83ef8a9f82..a0e1dd619204b118ff67aa34f3865f0d7e2c372a 100644 (file)
@@ -151,6 +151,8 @@ mst_cb (void *cls, void *client, const struct GNUNET_MessageHeader *message)
   uLongf xconfig_size;
     
   msg = (const struct GNUNET_TESTBED_HelperReply *) message;
+  config_size = 0;
+  xconfig_size = 0;
   GNUNET_assert (sizeof (struct GNUNET_TESTBED_HelperReply) 
                  < ntohs (msg->header.size));
   GNUNET_assert (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY 
@@ -161,6 +163,7 @@ mst_cb (void *cls, void *client, const struct GNUNET_MessageHeader *message)
   config = GNUNET_malloc (config_size);
   GNUNET_assert (Z_OK == uncompress ((Bytef *) config, &config_size,
                                      (const Bytef *) &msg[1], xconfig_size));
+  GNUNET_free (config);
   if (GNUNET_SCHEDULER_NO_TASK == shutdown_task)
     shutdown_task = GNUNET_SCHEDULER_add_delayed 
       (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
index 3a42e87a8a145579da148861669d8fd9b7d66edf..1815c5ec8c824a8b5d5a49c84ae8a01feb250add 100644 (file)
@@ -430,6 +430,11 @@ struct GNUNET_TESTBED_ControllerProc
    */
   struct GNUNET_HELPER_Handle *helper;
 
+  /**
+   * The host where the helper is run
+   */
+  struct GNUNET_TESTBED_Host *host;
+
   /**
    * The controller error callback
    */
@@ -439,7 +444,6 @@ struct GNUNET_TESTBED_ControllerProc
    * The closure for the above callback
    */
   void *cls;
-
   /**
    * The send handle for the helper
    */
@@ -455,6 +459,11 @@ struct GNUNET_TESTBED_ControllerProc
    */
   char *dst;
 
+  /**
+   * The configuration of the running testbed service
+   */
+  struct GNUNET_CONFIGURATION_Handle *cfg;
+
 };
 
 
@@ -473,7 +482,32 @@ struct GNUNET_TESTBED_ControllerProc
 static int helper_mst (void *cls, void *client,
                        const struct GNUNET_MessageHeader *message)
 {
-  GNUNET_break (0);
+  struct GNUNET_TESTBED_ControllerProc *cp = cls;
+  const struct GNUNET_TESTBED_HelperReply *msg;
+  char *config;
+  uLongf config_size;
+  uLongf xconfig_size;
+    
+  msg = (const struct GNUNET_TESTBED_HelperReply *) message;
+  GNUNET_assert (sizeof (struct GNUNET_TESTBED_HelperReply) 
+                < ntohs (msg->header.size));
+  GNUNET_assert (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY 
+                 == ntohs (msg->header.type));
+  config_size = (uLongf) ntohs (msg->config_size);
+  xconfig_size = (uLongf) (ntohs (msg->header.size)
+                           - sizeof (struct GNUNET_TESTBED_HelperReply));
+  config = GNUNET_malloc (config_size);
+  GNUNET_assert (Z_OK == uncompress ((Bytef *) config, &config_size,
+                                     (const Bytef *) &msg[1], xconfig_size));
+  GNUNET_assert (NULL == cp->cfg);
+  cp->cfg = GNUNET_CONFIGURATION_create ();
+  GNUNET_assert (GNUNET_CONFIGURATION_deserialize (cp->cfg, config, 
+                                                  config_size, GNUNET_NO));
+  /* Change the hostname so that we can connect to it */
+  GNUNET_CONFIGURATION_set_value_string (cp->cfg, "testbed", "hostname", 
+                                        (NULL == cp->cfg) ? "localhost" :
+                                        GNUNET_TESTBED_host_get_hostname_ (cp->host));
+  cp->cb (cp->cls, cp->cfg, GNUNET_OK);
   return GNUNET_OK;
 }
 
@@ -587,6 +621,7 @@ GNUNET_TESTBED_controller_start (const char *controller_ip,
     GNUNET_free (cp);
     return NULL;
   }
+  cp->host = host;
   cp->cb = cb;
   cp->cls = cls;
   msg = GNUNET_TESTBED_create_helper_init_msg_ (controller_ip, cfg);