gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r22684 - gnunet/src/testbed
Date: Sun, 15 Jul 2012 16:30:22 +0200

Author: harsha
Date: 2012-07-15 16:30:22 +0200 (Sun, 15 Jul 2012)
New Revision: 22684

Modified:
   gnunet/src/testbed/gnunet-testbed-helper.c
   gnunet/src/testbed/test_gnunet_testbed_helper.c
Log:
config localization and service startup

Modified: gnunet/src/testbed/gnunet-testbed-helper.c
===================================================================
--- gnunet/src/testbed/gnunet-testbed-helper.c  2012-07-15 14:29:19 UTC (rev 
22683)
+++ gnunet/src/testbed/gnunet-testbed-helper.c  2012-07-15 14:30:22 UTC (rev 
22684)
@@ -24,10 +24,12 @@
  *          gnunet-service-testbed. This binary also receives configuration
  *          from the remove controller which is put in a temporary location
  *          with ports and paths fixed so that gnunet-service-testbed runs
- *          without any hurdels. This binary also kills the testbed service
+ *          without any hurdles. This binary also kills the testbed service
  *          should the connection from the remote controller is dropped
  * @author Sree Harsha Totakura <address@hidden> 
  */
+
+
 #include "platform.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_testing_lib-new.h"
@@ -101,6 +103,7 @@
 static void
 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  LOG_DEBUG ("Shutting down\n");
   if (GNUNET_SCHEDULER_NO_TASK != read_task_id)
   {
     GNUNET_SCHEDULER_cancel (read_task_id);
@@ -109,6 +112,23 @@
   (void) GNUNET_DISK_file_close (stdin_fd);
   GNUNET_SERVER_mst_destroy (tokenizer);  
   tokenizer = NULL;
+  if (NULL != testbed)
+  {
+    (void) GNUNET_OS_process_kill (testbed, SIGTERM);
+    GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (testbed));
+    GNUNET_OS_process_destroy (testbed);
+    testbed = NULL;
+  }
+  if (NULL != pipe_in)
+  {
+    (void) GNUNET_DISK_pipe_close (pipe_in);
+    pipe_in = NULL;
+  }
+  if (NULL != pipe_out)
+  {
+    (void) GNUNET_DISK_pipe_close (pipe_out);
+    pipe_out = NULL;
+  }
   if (NULL != test_system)
   {
     GNUNET_TESTING_system_destroy (test_system, GNUNET_YES);
@@ -183,6 +203,8 @@
   GNUNET_assert (NULL != test_system);
   GNUNET_assert (GNUNET_OK ==  GNUNET_TESTING_configuration_create
                  (test_system, cfg));
+  GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string 
+                 (cfg, "PATHS", "DEFAULTCONFIG", &config));
   pipe_in = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO);
   pipe_out = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_YES);
   if ((NULL == pipe_in) || (NULL == pipe_out))
@@ -190,14 +212,23 @@
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe");
     GNUNET_free (config);
     goto error;
-  }  
+  }
+  if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config))
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING, 
+         "Unable to write config file: %s -- exiting\n", config);
+    GNUNET_free (config);
+    goto error;
+  }
+  LOG_DEBUG ("Staring testbed with config: %s\n", config);
   testbed = GNUNET_OS_start_process 
     (GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR /*verbose? */, pipe_in, pipe_out,
      "gnunet-service-testbed", "gnunet-service-testbed", "-c", config, NULL);
+  GNUNET_free (config);
   if (NULL == testbed)
   {
     LOG (GNUNET_ERROR_TYPE_WARNING, 
-         "Unable to deserialize config -- exiting\n");
+         "Error staring gnunet-service-testbed -- exiting\n");
     goto error;
   }
   GNUNET_DISK_pipe_close_end (pipe_out, GNUNET_DISK_PIPE_END_WRITE);

Modified: gnunet/src/testbed/test_gnunet_testbed_helper.c
===================================================================
--- gnunet/src/testbed/test_gnunet_testbed_helper.c     2012-07-15 14:29:19 UTC 
(rev 22683)
+++ gnunet/src/testbed/test_gnunet_testbed_helper.c     2012-07-15 14:30:22 UTC 
(rev 22684)
@@ -26,6 +26,9 @@
 
 #include "platform.h"
 #include "gnunet_util_lib.h"
+#include "gnunet_testbed_service.h"
+
+#include "testbed_api.h"
 #include "testbed_helper.h"
 
 /**
@@ -43,7 +46,7 @@
 /**
  * Message to helper
  */
-static struct GNUNET_TESTBED_HelperInit msg;
+static struct GNUNET_TESTBED_HelperInit *msg;
 
 /**
  * Message send handle
@@ -60,7 +63,12 @@
  */
 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
 
+/**
+ * Configuratin handler
+ */
+static struct GNUNET_CONFIGURATION_Handle *cfg;
 
+
 /**
  * Shutdown nicely
  *
@@ -72,7 +80,10 @@
 {  
   if (GNUNET_SCHEDULER_NO_TASK != abort_task)
     GNUNET_SCHEDULER_cancel (abort_task);
-  GNUNET_HELPER_stop (helper);  
+  GNUNET_HELPER_stop (helper);
+  GNUNET_free_non_null (msg);
+  if (NULL != cfg)
+    GNUNET_CONFIGURATION_destroy (cfg);
 }
 
 
@@ -109,7 +120,7 @@
   GNUNET_assert (GNUNET_OK == result);
   if (GNUNET_SCHEDULER_NO_TASK == shutdown_task)
     shutdown_task = GNUNET_SCHEDULER_add_delayed 
-      (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
+      (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
        &do_shutdown, NULL);
 }
 
@@ -124,22 +135,42 @@
  */
 static void 
 run (void *cls, char *const *args, const char *cfgfile,
-     const struct GNUNET_CONFIGURATION_Handle * cfg)
+     const struct GNUNET_CONFIGURATION_Handle * cfg2)
 {
   static char * const binary_argv[] = {
     "gnunet-testbed-helper",
     NULL
     };
+  char *config;
+  char *xconfig;
+  const char *hostname = "127.0.0.1";
+  size_t config_size;
+  size_t xconfig_size;
+  uint16_t hostname_len;
+  uint16_t msg_size;
+
   helper = GNUNET_HELPER_start ("gnunet-testbed-helper", 
                                binary_argv,
                                 NULL, NULL);
   GNUNET_assert (NULL != helper);
-  msg.header.size = htons (sizeof (struct GNUNET_TESTBED_HelperInit));
-  msg.header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT);
-  msg.cname_size = htons (0);
-  msg.config_size = htons (0);
+  cfg = GNUNET_CONFIGURATION_dup (cfg2);  
+  config = GNUNET_CONFIGURATION_serialize (cfg, &config_size);
+  GNUNET_assert (NULL != config);
+  xconfig_size =
+    GNUNET_TESTBED_compress_config (config, config_size, &xconfig);
+  GNUNET_free (config);
+  hostname_len = strlen (hostname);
+  msg_size = xconfig_size + hostname_len + 1 + 
+    sizeof (struct GNUNET_TESTBED_HelperInit);
+  msg = GNUNET_realloc (xconfig, msg_size);
+  (void) memmove ( ((void *) &msg[1]) + hostname_len + 1, msg, xconfig_size);
+  msg->header.size = htons (msg_size);
+  msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT);
+  msg->cname_size = htons (hostname_len);
+  msg->config_size = htons (config_size);
+  (void) strcpy ((char *) &msg[1], hostname);
   shandle = GNUNET_HELPER_send (helper,
-                                &msg.header,
+                                &msg->header,
                                 GNUNET_NO, &cont_cb, NULL);
   GNUNET_assert (NULL != shandle);
   abort_task = GNUNET_SCHEDULER_add_delayed 




reply via email to

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