gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r24291 - gnunet/src/testbed
Date: Fri, 12 Oct 2012 15:40:16 +0200

Author: harsha
Date: 2012-10-12 15:40:16 +0200 (Fri, 12 Oct 2012)
New Revision: 24291

Modified:
   gnunet/src/testbed/gnunet-testbed-profiler.c
   gnunet/src/testbed/testbed_api.c
Log:
host registrations in profiler

Modified: gnunet/src/testbed/gnunet-testbed-profiler.c
===================================================================
--- gnunet/src/testbed/gnunet-testbed-profiler.c        2012-10-12 13:39:15 UTC 
(rev 24290)
+++ gnunet/src/testbed/gnunet-testbed-profiler.c        2012-10-12 13:40:16 UTC 
(rev 24291)
@@ -29,8 +29,40 @@
 #include "gnunet_testbed_service.h"
 #include "testbed_api_hosts.h"
 
+/**
+ * Generic loggins shorthand
+ */
+#define LOG(kind,...)                                           \
+  GNUNET_log_from (kind, "testbed-api-testbed", __VA_ARGS__)
 
 /**
+ * DLL of operations
+ */
+struct DLLOperation
+{
+  /**
+   * The testbed operation handle
+   */
+  struct GNUNET_TESTBED_Operation *op;
+
+  /**
+   * Closure
+   */
+  void *cls;
+
+  /**
+   * The next pointer for DLL
+   */
+  struct DLLOperation *next;
+
+  /**
+   * The prev pointer for DLL
+   */
+  struct DLLOperation *prev;
+};
+
+
+/**
  * An array of hosts loaded from the hostkeys file
  */
 static struct GNUNET_TESTBED_Host **hosts;
@@ -46,11 +78,41 @@
 static struct GNUNET_TESTBED_Operation *op;
 
 /**
+ * Host registration handle
+ */
+static struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle;
+
+/**
+ * Handle to the master controller process
+ */
+struct GNUNET_TESTBED_ControllerProc *mc_proc;
+
+/**
+ * Handle to the master controller
+ */
+struct GNUNET_TESTBED_Controller *mc;
+
+/**
+ * Handle to global configuration
+ */
+struct GNUNET_CONFIGURATION_Handle *cfg;
+
+/**
  * Abort task identifier
  */
 static GNUNET_SCHEDULER_TaskIdentifier abort_task;
 
 /**
+ * Host registration task identifier
+ */
+static GNUNET_SCHEDULER_TaskIdentifier register_hosts_task;
+
+/**
+ * Global event mask for all testbed events
+ */
+uint64_t event_mask;
+
+/**
  * Current peer id
  */
 unsigned int peer_id;
@@ -84,12 +146,20 @@
 
   if (GNUNET_SCHEDULER_NO_TASK != abort_task)
     GNUNET_SCHEDULER_cancel (abort_task);
+  if (GNUNET_SCHEDULER_NO_TASK != register_hosts_task)
+    GNUNET_SCHEDULER_cancel (register_hosts_task);
   GNUNET_free_non_null (peers);
+  if (NULL != reg_handle)
+    GNUNET_TESTBED_cancel_registration (reg_handle);
   for (nhost = 0; nhost < num_hosts; nhost++)
     if (NULL != hosts[nhost])
       GNUNET_TESTBED_host_destroy (hosts[nhost]);
   GNUNET_free_non_null (hosts);
-  GNUNET_SCHEDULER_shutdown ();        /* Stop scheduler to shutdown testbed 
run */
+  if (NULL != mc_proc)
+    GNUNET_TESTBED_controller_stop (mc_proc);
+  if (NULL != cfg)
+    GNUNET_CONFIGURATION_destroy (cfg);
+  GNUNET_SCHEDULER_shutdown ();        /* Stop scheduler to shutdown testbed 
run */  
 }
 
 
@@ -102,29 +172,14 @@
 static void
 do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Profiling timedout -- Aborting\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
   abort_task = GNUNET_SCHEDULER_NO_TASK;
+  result = GNUNET_SYSERR;
   GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
 }
 
 
 /**
- * Task to be executed when peers are ready
- *
- * @param cls NULL
- * @param tc the task context
- */
-static void
-master_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  result = GNUNET_OK;
-  GNUNET_assert (NULL != peers[0]);
-  op = GNUNET_TESTBED_peer_stop (peers[0], NULL, NULL);
-  GNUNET_assert (NULL != op);
-}
-
-
-/**
  * Controller event callback
  *
  * @param cls NULL
@@ -155,6 +210,101 @@
 
 
 /**
+ * Task to register all hosts available in the global host list
+ *
+ * @param cls NULL
+ * @param tc the scheduler task context
+ */
+static void
+register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+
+
+/**
+ * Callback which will be called to after a host registration succeeded or 
failed
+ *
+ * @param cls the closure
+ * @param emsg the error message; NULL if host registration is successful
+ */
+static void
+host_registration_completion (void *cls, const char *emsg)
+{
+  reg_handle = NULL;
+  if (NULL != emsg)
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+         _("Host registration failed for a host. Error: %s\n"), emsg);
+    GNUNET_SCHEDULER_cancel (abort_task);
+    abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
+    return;
+  }
+  register_hosts_task = GNUNET_SCHEDULER_add_now (&register_hosts, NULL);
+}
+
+
+/**
+ * Task to register all hosts available in the global host list
+ *
+ * @param cls NULL
+ * @param tc the scheduler task context
+ */
+static void
+register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  static unsigned int reg_host;
+
+  register_hosts_task = GNUNET_SCHEDULER_NO_TASK;
+  if (reg_host == num_hosts)
+  {
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+         "All hosts successfully registered\n");
+    /* Start peer create task */
+  }
+  reg_handle = GNUNET_TESTBED_register_host (mc, hosts[reg_host++],
+                                             host_registration_completion,
+                                             NULL);
+}
+
+
+/**
+ * Callback to signal successfull startup of the controller process
+ *
+ * @param cls the closure from GNUNET_TESTBED_controller_start()
+ * @param cfg the configuration with which the controller has been started;
+ *          NULL if status is not GNUNET_OK
+ * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
+ *          GNUNET_TESTBED_controller_stop() shouldn't be called in this case
+ */
+static void
+status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int 
status)
+{
+  GNUNET_SCHEDULER_cancel (abort_task);
+  if (GNUNET_OK != status)
+  {
+    mc_proc = NULL;
+    abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
+    return;
+  }
+  event_mask = 0;
+  event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
+  event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
+  event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
+  event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT);
+  mc = GNUNET_TESTBED_controller_connect (config, hosts[0], event_mask,
+                                          &controller_event_cb, NULL);
+  if (NULL == mc)
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+         _("Unable to connect to master controller -- Check config\n"));
+    abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
+    return;
+  }
+  register_hosts_task = GNUNET_SCHEDULER_add_now (&register_hosts, NULL);
+  abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+                                             &do_abort, NULL);
+}
+
+
+/**
  * Main function that will be run by the scheduler.
  *
  * @param cls closure
@@ -166,7 +316,6 @@
 run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *config)
 {
-  uint64_t event_mask;
   unsigned int nhost;
 
   if (NULL == args[0])
@@ -182,7 +331,7 @@
   num_hosts = GNUNET_TESTBED_hosts_load_from_file (args[0], &hosts);
   if (0 == num_hosts)
   {
-    fprintf (stderr, _("No hosts loaded\n"));
+    fprintf (stderr, _("No hosts loaded. Need atleast one host\n"));
     return;
   }
   for (nhost = 0; nhost < num_hosts; nhost++)
@@ -196,17 +345,18 @@
   }
   if (num_hosts != nhost)
   {
+    fprintf (stderr, _("Exiting\n"));
     GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
     return;
   }
-  peers = GNUNET_malloc (num_peers * sizeof (struct GNUNET_TESTBED_Peer *));
-  event_mask = 0;
-  event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
-  event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
-  event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
-  event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT);
-  GNUNET_TESTBED_run (NULL, config, num_peers, event_mask, 
&controller_event_cb,
-                      NULL, &master_task, NULL);
+  cfg = GNUNET_CONFIGURATION_dup (config);
+  mc_proc = 
+      GNUNET_TESTBED_controller_start (GNUNET_TESTBED_host_get_hostname_ 
+                                       (hosts[0]),
+                                       hosts[0],
+                                       cfg,
+                                       status_cb,
+                                       NULL);
   abort_task =
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
                                     (GNUNET_TIME_UNIT_SECONDS, 5), &do_abort,

Modified: gnunet/src/testbed/testbed_api.c
===================================================================
--- gnunet/src/testbed/testbed_api.c    2012-10-12 13:39:15 UTC (rev 24290)
+++ gnunet/src/testbed/testbed_api.c    2012-10-12 13:40:16 UTC (rev 24291)
@@ -1683,6 +1683,8 @@
   memcpy (&msg[1], service_name, service_name_size);
   GNUNET_TESTBED_queue_message_ (controller,
                                  (struct GNUNET_MessageHeader *) msg);
+  GNUNET_break (0);             /* This function is not yet implemented on the
+                                   testbed service */
 }
 
 




reply via email to

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