tracking forwarded operations
[oweals/gnunet.git] / src / testbed / testbed_api_testbed.c
index 6e6145aaa3e2bfd370058e48910cef90b62bb027..02b20d2145873377de23cf84c1ac17a7303111d0 100644 (file)
@@ -199,7 +199,7 @@ start_peers_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   for (peer = 0; peer < rc->num_peers; peer++)
   {
     dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
-    dll_op->op = GNUNET_TESTBED_peer_start (rc->peers[peer]);
+    dll_op->op = GNUNET_TESTBED_peer_start (NULL, rc->peers[peer], NULL, NULL);
     dll_op->cls = rc->peers[peer];
     GNUNET_CONTAINER_DLL_insert_tail (rc->dll_op_head, rc->dll_op_tail, dll_op);
   }
@@ -413,7 +413,7 @@ controller_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
 /**
  * Stops the testbed run and releases any used resources
  *
- * @param rc the tesbed run handle
+ * @param cls the tesbed run handle
  * @param tc the task context from scheduler
  */
 void
@@ -428,6 +428,26 @@ shutdown_run_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     if (NULL != rc->peers)
     {
       rc->peer_count = 0;
+      /* Check if some peers are stopped */
+      for (peer = 0; peer < rc->num_peers; peer++)
+      {
+        if (PS_STOPPED != rc->peers[peer]->state)
+          break;
+      }
+      if (peer == rc->num_peers)
+      {
+        /* All peers are stopped */
+        rc->state = RC_PEERS_STOPPED;
+        for (peer = 0; peer < rc->num_peers; peer++)
+        {
+          dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
+          dll_op->op = GNUNET_TESTBED_peer_destroy (rc->peers[peer]);
+          GNUNET_CONTAINER_DLL_insert_tail (rc->dll_op_head, rc->dll_op_tail,
+                                            dll_op);
+        }
+        return;
+      }
+      /* Some peers are stopped */
       for (peer = 0; peer < rc->num_peers; peer++)
       {
         if (PS_STARTED != rc->peers[peer]->state)
@@ -436,7 +456,7 @@ shutdown_run_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
           continue;
         }
         dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
-        dll_op->op = GNUNET_TESTBED_peer_stop (rc->peers[peer]);
+        dll_op->op = GNUNET_TESTBED_peer_stop (rc->peers[peer], NULL, NULL);
         dll_op->cls = rc->peers[peer];
         GNUNET_CONTAINER_DLL_insert_tail (rc->dll_op_head, rc->dll_op_tail,
                                           dll_op);
@@ -470,9 +490,13 @@ shutdown_run_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  *                   or-ed values of "1LL" shifted by the
  *                   respective 'enum GNUNET_TESTBED_EventType'
  *                   (i.e.  "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
- * @param cc controller callback to invoke on events
+ * @param cc controller callback to invoke on events; This callback is called
+ *          for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
+ *          set in the event_mask as this is the only way get access to the
+ *          handle of each peer
  * @param cc_cls closure for cc
  * @param master task to run once the testbed is ready
+ * @param master_cls
  */
 void
 GNUNET_TESTBED_run (const char *host_filename,