gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r22607 - in gnunet/src: include testbed


From: gnunet
Subject: [GNUnet-SVN] r22607 - in gnunet/src: include testbed
Date: Wed, 11 Jul 2012 17:06:03 +0200

Author: harsha
Date: 2012-07-11 17:06:03 +0200 (Wed, 11 Jul 2012)
New Revision: 22607

Modified:
   gnunet/src/include/gnunet_testbed_service.h
   gnunet/src/testbed/Makefile.am
   gnunet/src/testbed/gnunet-service-testbed.c
   gnunet/src/testbed/test_testbed_api.c
   gnunet/src/testbed/test_testbed_api_hosts.c
   gnunet/src/testbed/testbed_api.c
Log:
fixes for controller_start() API changes

Modified: gnunet/src/include/gnunet_testbed_service.h
===================================================================
--- gnunet/src/include/gnunet_testbed_service.h 2012-07-11 14:22:18 UTC (rev 
22606)
+++ gnunet/src/include/gnunet_testbed_service.h 2012-07-11 15:06:03 UTC (rev 
22607)
@@ -29,6 +29,7 @@
 #define GNUNET_TESTBED_SERVICE_H
 
 #include "gnunet_util_lib.h"
+#include "gnunet_testing_lib-new.h"
 
 #ifdef __cplusplus
 extern "C"

Modified: gnunet/src/testbed/Makefile.am
===================================================================
--- gnunet/src/testbed/Makefile.am      2012-07-11 14:22:18 UTC (rev 22606)
+++ gnunet/src/testbed/Makefile.am      2012-07-11 15:06:03 UTC (rev 22607)
@@ -46,6 +46,7 @@
  $(top_builddir)/src/hello/libgnunethello.la \
  -lm \
  $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
  $(LTLIBINTL)
 libgnunettestbed_la_LDFLAGS = \
  $(GN_LIB_LDFLAGS) \

Modified: gnunet/src/testbed/gnunet-service-testbed.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed.c 2012-07-11 14:22:18 UTC (rev 
22606)
+++ gnunet/src/testbed/gnunet-service-testbed.c 2012-07-11 15:06:03 UTC (rev 
22607)
@@ -385,7 +385,12 @@
  */
 static struct GNUNET_TESTING_System *test_system;
 
+/**
+ * Our configuration; we also use this as template for starting other 
controllers
+ */
+static struct GNUNET_CONFIGURATION_Handle *config;
 
+
 /**
  * Function called to notify a client about the connection begin ready to queue
  * more data.  "buf" will be NULL and "size" zero if the connection was closed
@@ -692,7 +697,28 @@
 }
 
 
+/**
+ * Callback for unexpected slave shutdowns
+ *
+ * @param cls closure
+ * @param emsg error message if available; can be NULL, which does NOT mean
+ *             that there was no error
+ */
+static void 
+slave_shutdown_handler (void *cls, const char *emsg)
+{
+  struct Slave *slave;
 
+  slave = (struct Slave *) cls;
+  slave->controller_proc = NULL;
+  LOG (GNUNET_ERROR_TYPE_WARNING,
+       "Unexpected slave shutdown\n");
+  if (NULL != emsg)
+    LOG (GNUNET_ERROR_TYPE_WARNING, "Error: %s\n", emsg);
+  GNUNET_SCHEDULER_shutdown ();        /* We too shutdown */
+}
+
+
 /**
  * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages
  *
@@ -1011,7 +1037,10 @@
     if (1 == msg->is_subordinate)
     {
       slave->controller_proc =
-        GNUNET_TESTBED_controller_start (host_list[delegated_host_id]);
+        GNUNET_TESTBED_controller_start (test_system,
+                                        host_list[delegated_host_id],
+                                        cfg, &slave_shutdown_handler,
+                                        slave);
     }
     slave->controller =
       GNUNET_TESTBED_controller_connect (cfg, host_list[delegated_host_id],
@@ -1378,13 +1407,14 @@
       {NULL}
     };
 
+  config = GNUNET_CONFIGURATION_dup (cfg);
   GNUNET_SERVER_add_handlers (server,
                               message_handlers);
   GNUNET_SERVER_disconnect_notify (server,
                                    &client_disconnect_cb,
                                    NULL);
   ss_map = GNUNET_CONTAINER_multihashmap_create (5);
-  test_system = GNUNET_TESTING_system_create ("testbed_peers", NULL);
+  test_system = GNUNET_TESTING_system_create ("testbed", NULL);
   
   fh = GNUNET_DISK_get_handle_from_native (stdin);
   if (NULL == fh)

Modified: gnunet/src/testbed/test_testbed_api.c
===================================================================
--- gnunet/src/testbed/test_testbed_api.c       2012-07-11 14:22:18 UTC (rev 
22606)
+++ gnunet/src/testbed/test_testbed_api.c       2012-07-11 15:06:03 UTC (rev 
22607)
@@ -43,6 +43,11 @@
   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
 
 /**
+ * The testing system we work with
+ */
+struct GNUNET_TESTING_System *test_system;
+
+/**
  * Our localhost
  */
 static struct GNUNET_TESTBED_Host *host;
@@ -75,7 +80,7 @@
 /**
  * Handle to configuration
  */
-static const struct GNUNET_CONFIGURATION_Handle *cfg;
+static struct GNUNET_CONFIGURATION_Handle *cfg;
 
 /**
  * Handle to operation
@@ -107,10 +112,12 @@
   if (NULL != reg_handle)
     GNUNET_TESTBED_cancel_registration (reg_handle);
   GNUNET_TESTBED_controller_disconnect (controller);
+  GNUNET_CONFIGURATION_destroy (cfg);
   if (NULL != cp)
     GNUNET_TESTBED_controller_stop (cp);
   GNUNET_TESTBED_host_destroy (neighbour);
   GNUNET_TESTBED_host_destroy (host);
+  GNUNET_TESTING_system_destroy (test_system, GNUNET_YES);
 }
 
 
@@ -182,19 +189,19 @@
      const struct GNUNET_CONFIGURATION_Handle *config)
 {
   uint64_t event_mask;
-  struct GNUNET_CONFIGURATION_Handle *cdup;
 
-  cfg = config;
+  test_system = GNUNET_TESTING_system_create ("test_testbed", 
+                                             "127.0.0.1");
   host = GNUNET_TESTBED_host_create (NULL, NULL, 0);
   GNUNET_assert (NULL != host);
-  cdup = GNUNET_CONFIGURATION_dup (config);
-  cp = GNUNET_TESTBED_controller_start (system, host, cdup, NULL, NULL);
+  cfg = GNUNET_CONFIGURATION_dup (config);
+  cp = GNUNET_TESTBED_controller_start (test_system, host, cfg, NULL, NULL);
   event_mask = 0;
   event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START);
   event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP);
   event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT);
   event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED);
-  controller = GNUNET_TESTBED_controller_connect (config, host, event_mask,
+  controller = GNUNET_TESTBED_controller_connect (cfg, host, event_mask,
                                                   &controller_cb, NULL);
   GNUNET_assert (NULL != controller);
   neighbour = GNUNET_TESTBED_host_create ("localhost", NULL, 0);

Modified: gnunet/src/testbed/test_testbed_api_hosts.c
===================================================================
--- gnunet/src/testbed/test_testbed_api_hosts.c 2012-07-11 14:22:18 UTC (rev 
22606)
+++ gnunet/src/testbed/test_testbed_api_hosts.c 2012-07-11 15:06:03 UTC (rev 
22607)
@@ -70,7 +70,8 @@
 run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
-  char *const binary_args[] = {NULL};
+  char *const binary_args[] = {"gnunet-service-testbed",
+                              NULL};
 
   host = GNUNET_TESTBED_host_create ("localhost", NULL, 0);
   GNUNET_assert (NULL != host);
@@ -82,7 +83,7 @@
   GNUNET_assert (host == GNUNET_TESTBED_host_lookup_by_id_ (0));
   helper_handle = GNUNET_TESTBED_host_run_ (host, binary_args);
   GNUNET_assert (NULL != helper_handle);
-  GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (2), &do_shutdown, NULL);
+  GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (1), &do_shutdown, NULL);
 }
 
 

Modified: gnunet/src/testbed/testbed_api.c
===================================================================
--- gnunet/src/testbed/testbed_api.c    2012-07-11 14:22:18 UTC (rev 22606)
+++ gnunet/src/testbed/testbed_api.c    2012-07-11 15:06:03 UTC (rev 22607)
@@ -329,6 +329,7 @@
   }
 }
 
+
 /**
  * Function called to notify a client about the connection begin ready to queue
  * more data.  "buf" will be NULL and "size" zero if the connection was closed
@@ -433,25 +434,85 @@
 
 
 /**
+ * Context to use while starting a controller
+ */
+struct ControllerStartContext
+{
+  /**
+   * The error callback
+   */
+  GNUNET_TESTBED_ControllerErrorCallback cec;
+
+  /**
+   * Closure for the above callback
+   */
+  void *cec_cls;
+
+  /**
+   * error message if any
+   */
+  char *emsg;
+};
+
+
+/**
  * Starts a controller process at the host
  *
+ * @param system used for reserving ports if host is NULL and to determine
+ *               which 'host' to set as TRUSTED ('controller') when starting 
testbed remotely
  * @param host the host where the controller has to be started; NULL for 
localhost
- * @return the controller process handle
+ * @param cfg template configuration to use for the remote controller; will
+ *            be modified to contain the actual host/port/unixpath used for
+ *            the testbed service
+ * @param cec function called if the contoller dies unexpectedly; will not be 
+ *            invoked after GNUNET_TESTBED_controller_stop, if 'cec' was 
called,
+ *            GNUNET_TESTBED_controller_stop must no longer be called; will
+ *            never be called in the same task as 
'GNUNET_TESTBED_controller_start'
+ *            (synchronous errors will be signalled by returning NULL)
+ * @param cec_cls closure for 'cec'
+ * @return the controller process handle, NULL on errors
  */
 struct GNUNET_TESTBED_ControllerProc *
-GNUNET_TESTBED_controller_start (struct GNUNET_TESTBED_Host *host)
+GNUNET_TESTBED_controller_start (struct GNUNET_TESTING_System *system,
+                                struct GNUNET_TESTBED_Host *host,
+                                struct GNUNET_CONFIGURATION_Handle *cfg,
+                                GNUNET_TESTBED_ControllerErrorCallback cec,
+                                void *cec_cls)
 {
   struct GNUNET_TESTBED_ControllerProc *cproc;
-  char * const binary_argv[] = {
-    "gnunet-service-testbed",
-    NULL
-  };
+  //struct ControllerStartContext *csc;
+  char *cfg_filename;
 
-  cproc = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ControllerProc));
-  cproc->helper = GNUNET_TESTBED_host_run_ (host, binary_argv);
-  if (NULL == cproc->helper)
+  if ((NULL == host) || (0 == GNUNET_TESTBED_host_get_id_ (host)))
   {
-    GNUNET_free (cproc);
+    if (GNUNET_OK != GNUNET_TESTING_configuration_create (system, cfg))
+      return NULL;
+    GNUNET_assert 
+      (GNUNET_OK == 
+       GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "DEFAULTCONFIG",
+                                             &cfg_filename));
+    if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, cfg_filename))
+    {
+      GNUNET_break (0);
+      return NULL;
+    }
+    char * const binary_argv[] = {
+      "gnunet-service-testbed",
+      "-c", cfg_filename,
+      NULL
+    };
+    cproc = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ControllerProc));
+    cproc->helper = GNUNET_TESTBED_host_run_ (host, binary_argv);
+    GNUNET_free (cfg_filename);
+    if (NULL == cproc->helper)
+    {
+      GNUNET_free (cproc);
+      return NULL;
+    }
+  }
+  else
+  {
+    GNUNET_break (0);
     return NULL;
   }
   return cproc;




reply via email to

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