gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r24406 - gnunet/src/mesh


From: gnunet
Subject: [GNUnet-SVN] r24406 - gnunet/src/mesh
Date: Thu, 18 Oct 2012 20:00:10 +0200

Author: szengel
Date: 2012-10-18 20:00:10 +0200 (Thu, 18 Oct 2012)
New Revision: 24406

Modified:
   gnunet/src/mesh/gnunet-regex-profiler.c
   gnunet/src/mesh/regex_profiler_test.conf
Log:
regex profiler

Modified: gnunet/src/mesh/gnunet-regex-profiler.c
===================================================================
--- gnunet/src/mesh/gnunet-regex-profiler.c     2012-10-18 16:38:52 UTC (rev 
24405)
+++ gnunet/src/mesh/gnunet-regex-profiler.c     2012-10-18 18:00:10 UTC (rev 
24406)
@@ -34,223 +34,260 @@
 #include "gnunet_stream_lib.h"
 #include "gnunet_testbed_service.h"
 
-
 /**
- * Total number of hosts.
+ * DLL of operations
  */
-#define NUM_HOSTS 2
+struct DLLOperation
+{
+  /**
+   * The testbed operation handle
+   */
+  struct GNUNET_TESTBED_Operation *op;
 
-/**
- * Number of peers per host.
- */
-#define PEER_PER_HOST 1
+  /**
+   * Closure
+   */
+  void *cls;
 
-/**
- * Total number of peers.
- */
-#define TOTAL_PEERS (NUM_HOSTS * PEER_PER_HOST)
+  /**
+   * The next pointer for DLL
+   */
+  struct DLLOperation *next;
 
+  /**
+   * The prev pointer for DLL
+   */
+  struct DLLOperation *prev;
+};
 
+
 /**
- * Different states in test setup
+ * Available states during profiling
  */
-enum SetupState
+enum State
 {
   /**
-   * The initial state
+   * Initial state
    */
-  INIT,
+  STATE_INIT = 0,
 
   /**
-   * Connecting to slave controller
+   * Starting slaves
    */
-  LINKING,
+  STATE_SLAVES_STARTING,
 
-  LINKING_SLAVES,
+  /**
+   * Creating peers
+   */
+  STATE_PEERS_CREATING,
 
-  LINKING_SLAVES_SUCCESS,
+  /**
+   * Starting peers
+   */
+  STATE_PEERS_STARTING,
 
-  CONNECTING_PEERS,
+  /**
+   * Linking peers
+   */
+  STATE_PEERS_LINKING,
 
-  CREATING_PEER,
-
-  STARTING_PEER
+  /**
+   * Destroying peers; we can do this as the controller takes care of stopping 
a
+   * peer if it is running
+   */
+  STATE_PEERS_DESTROYING
 };
 
 
 /**
- * Event Mask for operation callbacks
+ * An array of hosts loaded from the hostkeys file
  */
-uint64_t event_mask;
+static struct GNUNET_TESTBED_Host **hosts;
 
 /**
- * Testbed operation handle
+ * Peer handles.
  */
-static struct GNUNET_TESTBED_Operation *op[NUM_HOSTS];
+struct Peer
+{
+  /**
+   * The actual testbed peer handle.
+   */
+  struct GNUNET_TESTBED_Peer *peer_handle;
 
+  /**
+   * Peer's mesh handle.
+   */
+  struct GNUNET_MESH_Handle *mesh_handle;
+
+  /**
+   * Host on which the peer is running.
+   */
+  struct GNUNET_TESTBED_Host *host_handle;
+
+  /**
+   * Testbed operation handle.
+   */
+  struct GNUNET_TESTBED_Operation *op_handle;
+};
+
 /**
- * Setup state.
+ * Array of peer handles used to pass to
+ * GNUNET_TESTBED_overlay_configure_topology
  */
-static enum SetupState state[NUM_HOSTS];
+struct GNUNET_TESTBED_Peer **peer_handles;
 
 /**
- * Abort task.
+ * The array of peers; we fill this as the peers are given to us by the testbed
  */
-static GNUNET_SCHEDULER_TaskIdentifier abort_task;
+static struct Peer *peers;
 
 /**
- * Global test result
+ * Host registration handle
  */
-static int result;
+static struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle;
 
 /**
- * Hosts successfully registered
+ * Handle to the master controller process
  */
-static unsigned int host_registered;
+struct GNUNET_TESTBED_ControllerProc *mc_proc;
 
 /**
- * Peers successfully started
+ * Handle to the master controller
  */
-static unsigned int peers_started;
+struct GNUNET_TESTBED_Controller *mc;
 
 /**
- * The master controller host
+ * Handle to global configuration
  */
-struct GNUNET_TESTBED_Host *master_host;
+struct GNUNET_CONFIGURATION_Handle *cfg;
 
 /**
- * The master controller process
+ * Head of the operations list
  */
-static struct GNUNET_TESTBED_ControllerProc *master_proc;
+struct DLLOperation *dll_op_head;
 
 /**
- * Handle to master controller
+ * Tail of the operations list
  */
-static struct GNUNET_TESTBED_Controller *master_ctrl;
+struct DLLOperation *dll_op_tail;
 
+/**
+ * Peer linking - topology operation
+ */
+struct GNUNET_TESTBED_Operation *topology_op;
 
 /**
- * Slave host registration handles
+ * Abort task identifier
  */
-static struct GNUNET_TESTBED_HostRegistrationHandle *rh;
+static GNUNET_SCHEDULER_TaskIdentifier abort_task;
 
+/**
+ * Host registration task identifier
+ */
+static GNUNET_SCHEDULER_TaskIdentifier register_hosts_task;
 
 /**
- * Handle to global configuration
+ * Global event mask for all testbed events
  */
-static struct GNUNET_CONFIGURATION_Handle *cfg;
+uint64_t event_mask;
 
 /**
- * Structure for storing host handles
+ * The starting time of a profiling step
  */
-struct Host
-{
-  /**
-   * IP address of this host.
-   */
-  char *ip;
+struct GNUNET_TIME_Absolute prof_start_time;
 
-  /**
-   * Host handle.
-   */
-  struct GNUNET_TESTBED_Host *host;
+/**
+ * Duration profiling step has taken
+ */
+struct GNUNET_TIME_Relative prof_time;
 
-  /**
-   * Registration state of this host.
-   */
-  int host_registered;
+/**
+ * Current peer id
+ */
+unsigned int peer_id;
 
-  /**
-   * Operation handle.
-   */
-  struct GNUNET_TESTBED_Operation *op;
+/**
+ * Number of peers to be started by the profiler
+ */
+static unsigned int num_peers;
 
-  /**
-   * Host state.
-   */
-  enum SetupState state;
-};
+/**
+ * Number of hosts in the hosts array
+ */
+static unsigned int num_hosts;
 
 /**
- * List of slaves.
+ * Number of random links to be established between peers
  */
-static struct Host slaves[NUM_HOSTS] = { {"192.168.1.33", NULL, 0, NULL, INIT},
-{"192.168.1.34", NULL, 0, NULL, INIT}
-};
+static unsigned int num_links;
 
 /**
- * Structure for holding peer's handles.
+ * Global testing status
  */
-struct PeerData
-{
-  /**
-   * Handle to testbed peer.
-   */
-  struct GNUNET_TESTBED_Peer *peer;
+static int result;
 
-  /**
-   * Peer's mesh handle.
-   */
-  struct GNUNET_MESH_Handle *mesh_handle;
-
-  /**
-   * The service connect operation to stream
-   */
-  struct GNUNET_TESTBED_Operation *op;
-
-  /**
-   * Peer setup state.
-   */
-  enum SetupState state;
-
-  /**
-   * Our Peer id
-   */
-  struct GNUNET_PeerIdentity our_id;
-};
-
 /**
- * The peers
+ * current state of profiling
  */
-struct PeerData peers[TOTAL_PEERS];
+enum State state;
 
 
-
 /**
- * Close sockets and stop testing deamons nicely
+ * Shutdown nicely
+ *
+ * @param cls NULL
+ * @param tc the task context
  */
-void
-do_close (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+static void
+do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  unsigned int i;
+  struct DLLOperation *dll_op;
+  unsigned int nhost;
 
   if (GNUNET_SCHEDULER_NO_TASK != abort_task)
     GNUNET_SCHEDULER_cancel (abort_task);
-
-  for (i = 0; i < TOTAL_PEERS; i++)
+  if (GNUNET_SCHEDULER_NO_TASK != register_hosts_task)
+    GNUNET_SCHEDULER_cancel (register_hosts_task);
+  if (NULL != reg_handle)
+    GNUNET_TESTBED_cancel_registration (reg_handle);
+  if (NULL != topology_op)
+    GNUNET_TESTBED_operation_cancel (topology_op);
+  for (nhost = 0; nhost < num_hosts; nhost++)
+    if (NULL != hosts[nhost])
+      GNUNET_TESTBED_host_destroy (hosts[nhost]);
+  GNUNET_free_non_null (hosts);
+  while (NULL != (dll_op = dll_op_head))
   {
-    if (NULL != peers[i].mesh_handle)
-      GNUNET_MESH_disconnect (peers[i].mesh_handle);
-    if (NULL != peers[i].op)
-      GNUNET_TESTBED_operation_done (peers[i].op);
+    GNUNET_TESTBED_operation_cancel (dll_op->op);
+    GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
+    GNUNET_free (dll_op);
   }
+  if (NULL != mc)
+    GNUNET_TESTBED_controller_disconnect (mc);
+  if (NULL != mc_proc)
+    GNUNET_TESTBED_controller_stop (mc_proc);
+  if (NULL != cfg)
+    GNUNET_CONFIGURATION_destroy (cfg);
 
-  GNUNET_SCHEDULER_shutdown (); /* For shutting down testbed */
+  //FIXME       GNUNET_MESH_disconnect (peers[i].mesh_handle);
+
+  GNUNET_SCHEDULER_shutdown ();        /* Stop scheduler to shutdown testbed 
run */
 }
 
 
 /**
- * Something went wrong and timed out. Kill everything and set error flag.
+ * abort task to run on test timed out
  *
- * @param cls close.
- * @param tc task context.
+ * @param cls NULL
+ * @param tc the task context
  */
 static void
 do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: ABORT\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
+  abort_task = GNUNET_SCHEDULER_NO_TASK;
   result = GNUNET_SYSERR;
-  abort_task = 0;
+  GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
 }
 
 
@@ -310,7 +347,7 @@
 mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
                  void *ca_result, const char *emsg)
 {
-  long i = (long) cls;
+  struct Peer *peer = (struct Peer *) cls;
 
   if (NULL != emsg)
   {
@@ -318,8 +355,14 @@
     GNUNET_assert (0);
   }
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh connect callback for peer %i\n",
-              i);
+  GNUNET_assert (peer->op_handle == op);
+  GNUNET_assert (peer->mesh_handle == ca_result);
+
+  GNUNET_TESTBED_operation_done (op);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh connect callback for peer\n");
+
+  //GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
 }
 
 
@@ -334,8 +377,9 @@
 void *
 mesh_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
-  struct PeerData *peer = (struct PeerData *) cls;
 
+  struct Peer *peer = (struct Peer *) cls;
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh connect adapter\n");
 
   static struct GNUNET_MESH_MessageHandler handlers[] = {
@@ -350,7 +394,7 @@
       GNUNET_MESH_connect (cfg, cls, &mesh_inbound_tunnel_handler,
                            &mesh_tunnel_end_handler, handlers, apptypes);
 
-  return NULL;
+  return peer->mesh_handle;
 }
 
 
@@ -364,6 +408,10 @@
 void
 mesh_da (void *cls, void *op_result)
 {
+  struct Peer *peer = (struct Peer *) cls;
+
+  GNUNET_assert (peer->mesh_handle == op_result);
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh disconnect adapter\n");
 }
 
@@ -376,27 +424,54 @@
  * @param emsg NULL on success; otherwise an error description
  */
 static void
-peer_start_cb (void *cls, const char *emsg)
+peer_churn_cb (void *cls, const char *emsg)
 {
-  unsigned int cnt;
-  long i = (long) cls;
+  struct DLLOperation *dll_op = cls;
+  struct GNUNET_TESTBED_Operation *op;
+  static unsigned int started_peers;
+  unsigned int peer_cnt;
 
-  GNUNET_TESTBED_operation_done (op[i]);
-  peers_started++;
-  // FIXME create and start rest of PEERS_PER_HOST
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u peer(s) started\n", peers_started);
-
-  if (TOTAL_PEERS == peers_started)
+  op = dll_op->op;
+  GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
+  GNUNET_free (dll_op);
+  if (NULL != emsg)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers started.\n");
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Linking slave controllers\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+         _("An operation has failed while starting peers\n"));
+    GNUNET_TESTBED_operation_done (op);
+    GNUNET_SCHEDULER_cancel (abort_task);
+    abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
+    return;
+  }
+  GNUNET_TESTBED_operation_done (op);
+  if (++started_peers == num_peers)
+  {
+    prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
+    printf ("All peers started successfully in %.2f seconds\n",
+            ((double) prof_time.rel_value) / 1000.00);
+    result = GNUNET_OK;
+    if (0 == num_links)
+    {
+      GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+      return;
+    }
 
-    for (cnt = 0; cnt < NUM_HOSTS - 1; cnt++)
+    peer_handles = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer *) * 
num_peers);
+    for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
+      peer_handles[peer_cnt] = peers[peer_cnt].peer_handle;
+
+    state = STATE_PEERS_LINKING;
+    /* Do overlay connect */
+    prof_start_time = GNUNET_TIME_absolute_get ();
+    topology_op =
+        GNUNET_TESTBED_overlay_configure_topology (NULL, num_peers, 
peer_handles,
+                                                   
GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
+                                                   num_links);
+    if (NULL == topology_op)
     {
-      state[cnt] = LINKING_SLAVES;
-      op[cnt] =
-          GNUNET_TESTBED_get_slave_config ((void *) (long) cnt, master_ctrl,
-                                           slaves[cnt + 1].host);
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Cannot create topology, op handle was NULL\n");
+      GNUNET_assert (0);
     }
   }
 }
@@ -414,348 +489,398 @@
 static void
 peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
 {
-  long i = (long) cls;
-  long peer_id;
+  struct DLLOperation *dll_op = cls;
+  struct Peer *peer_ptr;
+  static unsigned int created_peers;
+  unsigned int peer_cnt;
 
-//   GNUNET_TESTBED_operation_done(op[i]);
-  peer_id = i;                  // FIXME  A * i + B
-  peers[peer_id].peer = peer;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Peer %i created\n", peer_id);
-  op[i] = GNUNET_TESTBED_peer_start (NULL, peer, peer_start_cb, (void *) i);
+  if (NULL != emsg)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+         _("Creating a peer failed. Error: %s\n"), emsg);
+    GNUNET_TESTBED_operation_done (dll_op->op);
+    GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
+    GNUNET_free (dll_op);
+    GNUNET_SCHEDULER_cancel (abort_task);
+    abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
+    return;
+  }
+
+  peer_ptr = dll_op->cls;
+  GNUNET_assert (NULL == peer_ptr->peer_handle);
+  peer_ptr->peer_handle = peer;
+  GNUNET_TESTBED_operation_done (dll_op->op);
+  GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
+  GNUNET_free (dll_op);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %i created on host %s\n",
+              created_peers,
+              GNUNET_TESTBED_host_get_hostname (peer_ptr->host_handle));
+
+  if (++created_peers == num_peers)
+  {
+    prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
+    printf ("All peers created successfully in %.2f seconds\n",
+            ((double) prof_time.rel_value) / 1000.00);
+    /* Now peers are to be started */
+    state = STATE_PEERS_STARTING;
+    prof_start_time = GNUNET_TIME_absolute_get ();
+    for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
+    {
+      dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
+      dll_op->op = GNUNET_TESTBED_peer_start (dll_op, 
peers[peer_cnt].peer_handle,
+                                              &peer_churn_cb, dll_op);
+      GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
+    }
+  }
 }
 
 
 /**
- * Signature of the event handler function called by the
- * respective event controller.
+ * Controller event callback
  *
- * @param cls closure
- * @param event information about the event
+ * @param cls NULL
+ * @param event the controller event
  */
 static void
-controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
+controller_event_cb (void *cls,
+                     const struct GNUNET_TESTBED_EventInformation *event)
 {
-  long i;
+  struct DLLOperation *dll_op;
+  struct GNUNET_TESTBED_Operation *op;
 
-  switch (event->type)
+  switch (state)
   {
-  case GNUNET_TESTBED_ET_PEER_START:
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Peer started\n");
-    /* event->details.peer_start.peer; */
-    /* event->details.peer_start.host; */
-
-    break;
-  case GNUNET_TESTBED_ET_PEER_STOP:
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer stopped\n");
-    break;
-  case GNUNET_TESTBED_ET_CONNECT:
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Overlay Connected\n");
-    for (i = 0; i < TOTAL_PEERS; i++)
+  case STATE_SLAVES_STARTING:
+    switch (event->type)
     {
-      GNUNET_TESTBED_service_connect (NULL, peers[i].peer, "mesh",
-                                      &mesh_connect_cb, (void *) i, &mesh_ca,
-                                      &mesh_da, NULL);
-    }
-    break;
-  case GNUNET_TESTBED_ET_OPERATION_FINISHED:
-    if (NULL != event->details.operation_finished.emsg)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testbed error: %s\n",
-                  event->details.operation_finished.emsg);
-      GNUNET_assert (0);
-    }
+    case GNUNET_TESTBED_ET_OPERATION_FINISHED:
+      {
+        static unsigned int slaves_started;
+        unsigned int peer_cnt;
 
-    i = (long) event->details.operation_finished.op_cls;
-    switch (state[i])
-    {
-    case INIT:
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  Init: %u\n", i);
-      GNUNET_TESTBED_operation_done (event->details.
-                                     operation_finished.operation);
-      op[i] = NULL;
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  Operation %u finished\n", i);
-      break;
-    }
-    case LINKING:
-    {
-      GNUNET_assert (NULL != slaves[i].op);
+        dll_op = event->details.operation_finished.op_cls;
+        GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
+        GNUNET_free (dll_op);
+        op = event->details.operation_finished.operation;
+        if (NULL != event->details.operation_finished.emsg)
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+               _("An operation has failed while starting slaves\n"));
+          GNUNET_TESTBED_operation_done (op);
+          GNUNET_SCHEDULER_cancel (abort_task);
+          abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
+          return;
+        }
+        GNUNET_TESTBED_operation_done (op);
+        /* Proceed to start peers */
+        if (++slaves_started == num_hosts - 1)
+        {
+          printf ("All slaves started successfully\n");
+          state = STATE_PEERS_CREATING;
+          prof_start_time = GNUNET_TIME_absolute_get ();
+          peers = GNUNET_malloc (sizeof (struct Peer) * num_peers);
+          for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
+          {
+            GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating peer %i on host 
%s\n",
+                        peer_cnt,
+                        GNUNET_TESTBED_host_get_hostname (hosts[peer_cnt % 
num_hosts]));
 
-      GNUNET_TESTBED_operation_done (slaves[i].op);
-      slaves[i].op = NULL;
+            peers[peer_cnt].host_handle = hosts[peer_cnt % num_hosts];
 
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  Operation %u finished\n", i);
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   Linked host %i\n", i);
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   Creating peer...\n");
-
-      state[i] = CREATING_PEER;
-      op[i] =
-          GNUNET_TESTBED_peer_create (master_ctrl, slaves[i].host, cfg,
-                                      peer_create_cb, (void *) i);
+            dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
+            dll_op->cls = &peers[peer_cnt];
+            dll_op->op = GNUNET_TESTBED_peer_create (mc,
+                                                     hosts[peer_cnt % 
num_hosts],
+                                                     cfg,
+                                                     &peer_create_cb,
+                                                     dll_op);
+            GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, 
dll_op);
+          }
+        }
+      }
       break;
+    default:
+      GNUNET_assert (0);
     }
-    case CREATING_PEER:
+    break;
+  case STATE_PEERS_STARTING:
+    switch (event->type)
     {
-      GNUNET_TESTBED_operation_done (event->details.
-                                     operation_finished.operation);
-      op[i] = NULL;
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  Operation %u finished\n", i);
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  Peer create\n");
+    case GNUNET_TESTBED_ET_OPERATION_FINISHED:
+      /* Control reaches here when peer start fails */
+    case GNUNET_TESTBED_ET_PEER_START:
+      /* we handle peer starts in peer_churn_cb */
       break;
+    default:
+      GNUNET_assert (0);
     }
-    case LINKING_SLAVES:
+    break;
+  case STATE_PEERS_LINKING:
+   switch (event->type)
     {
-      struct GNUNET_CONFIGURATION_Handle *slave_cfg;
-
-      GNUNET_assert (NULL != event->details.operation_finished.generic);
-      slave_cfg =
-          GNUNET_CONFIGURATION_dup ((struct GNUNET_CONFIGURATION_Handle *)
-                                    event->details.operation_finished.generic);
-      GNUNET_TESTBED_operation_done (event->details.
-                                     operation_finished.operation);
-      op[i] = NULL;
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  Operation %u finished\n", i);
-      state[i] = LINKING_SLAVES_SUCCESS;
-      op[i] =
-          GNUNET_TESTBED_controller_link ((void *) (long) i, master_ctrl,
-                                          slaves[i + 1].host, slaves[i].host,
-                                          slave_cfg, GNUNET_NO);
-      GNUNET_CONFIGURATION_destroy (slave_cfg);
+    case GNUNET_TESTBED_ET_OPERATION_FINISHED:
+      /* Control reaches here when a peer linking operation fails */
+      if (NULL != event->details.operation_finished.emsg)
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+             _("An operation has failed while linking\n"));
+        GNUNET_SCHEDULER_cancel (abort_task);
+        abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
+      }
       break;
-    }
-    case LINKING_SLAVES_SUCCESS:
-    {
-      unsigned int peer_cnt;
-      struct GNUNET_TESTBED_Peer *peer_handles[TOTAL_PEERS];
+    case GNUNET_TESTBED_ET_CONNECT:
+      {
+        static unsigned int established_links;
+        unsigned int peer_cnt;
 
-      GNUNET_TESTBED_operation_done (event->details.
-                                     operation_finished.operation);
-      op[i] = NULL;
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  Operation %u finished\n", i);
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Linking slave %i succeeded\n", i);
-      state[0] = CONNECTING_PEERS;
-
-      for (peer_cnt = 0; peer_cnt < TOTAL_PEERS; peer_cnt++)
-      {
-        peer_handles[peer_cnt] = peers[peer_cnt].peer;
+        if (0 == established_links)
+          printf ("Establishing links\n .");
+        else
+        {
+          printf (".");
+          fflush (stdout);
+        }
+        if (++established_links == num_links)
+        {
+          prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
+          printf ("\n%u links established in %.2f seconds\n",
+                  num_links, ((double) prof_time.rel_value) / 1000.00);
+          result = GNUNET_OK;
+          GNUNET_free (peer_handles);
+          printf ("\nConnecting to mesh service...\n");
+          for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
+          {
+            peers[peer_cnt].op_handle = GNUNET_TESTBED_service_connect (NULL,
+                                                                        
peers[peer_cnt].peer_handle,
+                                                                        "mesh",
+                                                                        
&mesh_connect_cb,
+                                                                        
&peers[peer_cnt],
+                                                                        
&mesh_ca,
+                                                                        
&mesh_da,
+                                                                        
&peers[peer_cnt]);
+          }
+        }
       }
-      op[0] =
-          GNUNET_TESTBED_overlay_configure_topology (NULL, TOTAL_PEERS,
-                                                     peer_handles,
-                                                     
GNUNET_TESTBED_TOPOLOGY_LINE);
-      GNUNET_assert (NULL != op[0]);
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peers...\n");
       break;
-    }
-    case CONNECTING_PEERS:
-    {
-      GNUNET_TESTBED_operation_done (event->details.
-                                     operation_finished.operation);
-      op[i] = NULL;
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  Operation %u finished\n", i);
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n");
-      break;
-    }
     default:
-      GNUNET_break (0);
+      GNUNET_assert (0);
     }
     break;
   default:
-    GNUNET_break (0);
+    GNUNET_assert (0);
   }
 }
 
 
 /**
- * Callback which will be called to after a host registration succeeded or
- * failed. Registration of all slave hosts is continued and linking of the 
hosts
- * is started.
+ * Task to register all hosts available in the global host list
  *
- * @param cls not used.
- * @param emsg the error message; NULL if host registration is successful.
+ * @param cls NULL
+ * @param tc the scheduler task context
  */
 static void
-registration_cont (void *cls, const char *emsg)
+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)
 {
-  struct Host *slave = (struct Host *) cls;
-
-  if (NULL != emsg || NULL == slave)
+  reg_handle = NULL;
+  if (NULL != emsg)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg);
-    GNUNET_assert (0);
+    GNUNET_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);
+}
 
-  state[host_registered] = LINKING;
-  slave->state = LINKING;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Linking host %u\n", host_registered);
-  slave->op =
-      GNUNET_TESTBED_controller_link ((void *) (long) host_registered,
-                                      master_ctrl, slave->host, NULL, cfg,
-                                      GNUNET_YES);
-  host_registered++;
-  if (NUM_HOSTS != host_registered)
+/**
+ * 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)
+{
+  struct DLLOperation *dll_op;
+  static unsigned int reg_host;
+  unsigned int slave;
+
+  register_hosts_task = GNUNET_SCHEDULER_NO_TASK;
+  if (reg_host == num_hosts - 1)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Registering host %u with ip %s\n",
-                host_registered, slaves[host_registered].ip);
-    rh = GNUNET_TESTBED_register_host (master_ctrl,
-                                       slaves[host_registered].host,
-                                       &registration_cont,
-                                       &slaves[host_registered]);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "All hosts successfully registered\n");
+    /* Start slaves */
+    state = STATE_SLAVES_STARTING;
+    for (slave = 1; slave < num_hosts; slave++)
+    {
+      dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
+      dll_op->op = GNUNET_TESTBED_controller_link (dll_op,
+                                                   mc,
+                                                   hosts[slave],
+                                                   hosts[0],
+                                                   cfg,
+                                                   GNUNET_YES);
+      GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
+    }
     return;
   }
+  reg_handle = GNUNET_TESTBED_register_host (mc, hosts[++reg_host],
+                                             host_registration_completion,
+                                             NULL);
 }
 
 
 /**
- * Callback to signal successfull startup of the controller process. If the
- * startup was successfull the master controller and all slave hosts are
- * created. Registering the slave hosts is started and continued in
- * registration_cont.
+ * Callback to signal successfull startup of the controller process
  *
- * @param cls not used.
- * @param config the configuration with which the controller has been started;
+ * @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)
+status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int 
status)
 {
-  unsigned int i;
-
-  if (NULL == config || GNUNET_OK != 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 |= (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);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to master controller\n");
-  master_ctrl =
-      GNUNET_TESTBED_controller_connect (config, master_host, event_mask,
-                                         &controller_cb, NULL);
-  GNUNET_assert (NULL != master_ctrl);
-
-  for (i = 0; i < NUM_HOSTS; i++)
+  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);
+  event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
+  mc = GNUNET_TESTBED_controller_connect (config, hosts[0], event_mask,
+                                          &controller_event_cb, NULL);
+  if (NULL == mc)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Creating host %u with ip %s\n", i,
-                slaves[i].ip);
-    slaves[i].host = GNUNET_TESTBED_host_create (slaves[i].ip, NULL, 0);
-    GNUNET_assert (NULL != slaves[i].host);
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                _("Unable to connect to master controller -- Check config\n"));
+    abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
+    return;
   }
-  host_registered = 0;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Registering host %u with ip %s\n",
-              host_registered, slaves[0].ip);
-  rh = GNUNET_TESTBED_register_host (master_ctrl, slaves[0].host,
-                                     &registration_cont, &slaves[0]);
-  GNUNET_assert (NULL != rh);
+  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 run function.
+ * Main function that will be run by the scheduler.
  *
- * @param cls not used.
- * @param args arguments passed to GNUNET_PROGRAM_run
- * @param cfgfile the path to configuration file
- * @param config the configuration file handle
+ * @param cls closure
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be 
NULL!)
+ * @param config configuration
  */
 static void
 run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *config)
 {
-  master_host = GNUNET_TESTBED_host_create ("192.168.1.33", NULL, 0);
-  GNUNET_assert (NULL != master_host);
+  unsigned int nhost;
+
+  if (NULL == args[0])
+  {
+    fprintf (stderr, _("No hosts-file specified on command line\n"));
+    return;
+  }
+  if (0 == num_peers)
+  {
+    result = GNUNET_OK;
+    return;
+  }
+  num_hosts = GNUNET_TESTBED_hosts_load_from_file (args[0], &hosts);
+  if (0 == num_hosts)
+  {
+    fprintf (stderr, _("No hosts loaded. Need at least one host\n"));
+    return;
+  }
+  for (nhost = 0; nhost < num_hosts; nhost++)
+  {
+    if (GNUNET_YES != GNUNET_TESTBED_is_host_habitable (hosts[nhost]))
+    {
+      fprintf (stderr, _("Host %s cannot start testbed\n"),
+                         GNUNET_TESTBED_host_get_hostname (hosts[nhost]));
+      break;
+    }
+  }
+  if (num_hosts != nhost)
+  {
+    fprintf (stderr, _("Exiting\n"));
+    GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+    return;
+  }
+  if (NULL == config)
+  {
+    fprintf (stderr, _("No configuration file given. Exiting\n"));
+    GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+    return;
+  }
+
   cfg = GNUNET_CONFIGURATION_dup (config);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting master controller\n");
-  master_proc =
-      GNUNET_TESTBED_controller_start ("192.168.1.33", master_host, cfg,
-                                       status_cb, NULL);
+  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_MINUTES, 60), &do_abort,
+                                    (GNUNET_TIME_UNIT_SECONDS, 5), &do_abort,
                                     NULL);
 }
 
 
 /**
- * Main function for profiling the regex/mesh implementation.  Checks if all 
ssh
- * connections to each of the hosts in 'slave_ips' is possible before setting 
up
- * the testbed.
+ * Main function.
  *
- * @param argc argument count.
- * @param argv argument values.
- *
- * @return 0 on success.
+ * @return 0 on success
  */
 int
-main (int argc, char **argv)
+main (int argc, char *const *argv)
 {
-  int ret;
-  int test_hosts;
-  unsigned int i;
-
-  struct GNUNET_GETOPT_CommandLineOption options[] = {
+  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+    { 'p', "num-peers", "COUNT",
+      gettext_noop ("create COUNT number of peers"),
+      GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_peers },
+    { 'n', "num-links", "COUNT",
+      gettext_noop ("create COUNT number of random links"),
+      GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_links },
     GNUNET_GETOPT_OPTION_END
   };
-  char *const argv2[] = { "gnunet-regex-profiler",
-    "-c", "regex_profiler_test.conf",
-    NULL
-  };
+  int ret;
 
-  test_hosts = GNUNET_OK;
-  for (i = 0; i < NUM_HOSTS; i++)
-  {
-    char *const remote_args[] = {
-      "ssh", "-o", "BatchMode=yes", slaves[i].ip,
-      "gnunet-helper-testbed --help > /dev/null", NULL
-    };
-    struct GNUNET_OS_Process *auxp;
-    enum GNUNET_OS_ProcessStatusType type;
-    unsigned long code;
+  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+    return 2;
 
-    fprintf (stderr, "Testing host %i\n", i);
-    auxp =
-        GNUNET_OS_start_process_vap (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, 
NULL,
-                                     NULL, "ssh", remote_args);
-    GNUNET_assert (NULL != auxp);
-    do
-    {
-      ret = GNUNET_OS_process_status (auxp, &type, &code);
-      GNUNET_assert (GNUNET_SYSERR != ret);
-      (void) usleep (300);
-    }
-    while (GNUNET_NO == ret);
-    (void) GNUNET_OS_process_wait (auxp);
-    GNUNET_OS_process_destroy (auxp);
-    if (0 != code)
-    {
-      fprintf (stderr,
-               "Unable to run the test as this system is not configured "
-               "to use password less SSH logins to host %s.\n", slaves[i].ip);
-      test_hosts = GNUNET_SYSERR;
-    }
-  }
-  if (test_hosts != GNUNET_OK)
-  {
-    fprintf (stderr, "Some hosts have failed the ssh check. Exiting.\n");
-    return 1;
-  }
-  fprintf (stderr, "START.\n");
-
   result = GNUNET_SYSERR;
-
   ret =
-      GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
-                          "gnunet-regex-profiler", "nohelp", options, &run,
-                          NULL);
-
-  fprintf (stderr, "END.\n");
-
-  if (GNUNET_SYSERR == result || GNUNET_OK != ret)
+      GNUNET_PROGRAM_run (argc, argv, "gnunet-regex-profiler [OPTIONS] 
hosts-file",
+                          _("Profiler for regex/mesh"),
+                          options, &run, NULL);
+  if (GNUNET_OK != ret)
+    return ret;
+  if (GNUNET_OK != result)
     return 1;
   return 0;
 }

Modified: gnunet/src/mesh/regex_profiler_test.conf
===================================================================
--- gnunet/src/mesh/regex_profiler_test.conf    2012-10-18 16:38:52 UTC (rev 
24405)
+++ gnunet/src/mesh/regex_profiler_test.conf    2012-10-18 18:00:10 UTC (rev 
24406)
@@ -1,8 +1,11 @@
-[lockmanager]
+[testbed]
 AUTOSTART = NO
-ACCEPT_FROM = 127.0.0.1;
+PORT = 12113
+ACCEPT_FROM = 127.0.0.1; 192.168.1.0/24;
 HOSTNAME = localhost
-PORT = 12101
+MAX_PARALLEL_TOPOLOGY_CONFIG_OPERATIONS = 5
+MAX_PARALLEL_OVERLAY_CONNECT_OPERATIONS = 5
+#PREFIX = xterm -geometry 100x85 -T peer1 -e libtool --mode=execute gdb --args
 
 [fs]
 AUTOSTART = NO
@@ -12,19 +15,9 @@
 
 [mesh]
 AUTOSTART = YES
-ACCEPT_FROM = 127.0.0.1;
-HOSTNAME = localhost
-PORT = 10700
-# PREFIX = valgrind --leak-check=full
-# PREFIX = xterm -geometry 100x85 -T peer1 -e gdb --args
 
 [dht]
-DEBUG = NO
-AUTOSTART = YES
-ACCEPT_FROM6 = ::1;
-ACCEPT_FROM = 127.0.0.1;
-HOSTNAME = localhost
-PORT = 12100
+AUTOSTART = NO
 
 [block]
 plugins = dht test
@@ -47,9 +40,10 @@
 
 [core]
 PORT = 12092
+AUTOSTART = YES
 
 [arm]
-DEFAULTSERVICES = core lockmanager statistics
+DEFAULTSERVICES = core
 PORT = 12366
 DEBUG = NO
 
@@ -58,12 +52,10 @@
 PORT = 12368
 
 [TESTING]
+NUM_PEERS = 5
 WEAKRANDOM = YES
-
-[testing_old]
-NUM_PEERS = 5
 DEBUG = YES
-HOSTKEYSFILE = ${DATADIR}/testing_hostkeys.dat
+HOSTKEYSFILE = ../../contrib/testing_hostkeys.dat
 MAX_CONCURRENT_SSH = 10
 USE_PROGRESSBARS = YES
 PEERGROUP_TIMEOUT = 2400 s
@@ -72,7 +64,7 @@
 HOSTKEY = $SERVICEHOME/.hostkey
 
 [PATHS]
-SERVICEHOME = /tmp/test-stream/
+SERVICEHOME = /tmp/test-testbed/
 
 [dns]
 AUTOSTART = NO
@@ -83,5 +75,5 @@
 [vpn]
 AUTOSTART = NO
 
-[testbed]
-PORT = 12099
+[nat]
+RETURN_LOCAL_ADDRESSES = YES




reply via email to

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