guix-env: some update.
[oweals/gnunet.git] / src / testbed / test_testbed_api_3peers_3controllers.c
index 2f08fb475d4039d6ff67e25dc82d0d95c6f2bd5a..0ee1fc5669996f3d10a4c24adb73545a6298d713 100644 (file)
@@ -1,6 +1,6 @@
 /*
       This file is part of GNUnet
-      (C) 2008--2012 Christian Grothoff (and other contributing authors)
+      Copyright (C) 2008--2013 GNUnet e.V.
 
       GNUnet is free software; you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
       You should have received a copy of the GNU General Public License
       along with GNUnet; see the file COPYING.  If not, write to the
-      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-      Boston, MA 02111-1307, USA.
+      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+      Boston, MA 02110-1301, USA.
  */
 
 /**
@@ -31,7 +31,7 @@
  *                  A
  *                 / \
  *                /   \
- *               B === C 
+ *               B === C
  * A is the master controller and B, C are slave controllers. B links to C
  * laterally.
  * Peers are mapped to controllers in the following relations:
@@ -151,12 +151,12 @@ struct GNUNET_TESTBED_HostHabitableCheckHandle *hc_handle;
 /**
  * Abort task identifier
  */
-static GNUNET_SCHEDULER_TaskIdentifier abort_task;
+static struct GNUNET_SCHEDULER_Task * abort_task;
 
 /**
  * Delayed connect job identifier
  */
-static GNUNET_SCHEDULER_TaskIdentifier delayed_connect_task;
+static struct GNUNET_SCHEDULER_Task * delayed_connect_task;
 
 /**
  * Different stages in testing
@@ -254,16 +254,15 @@ static enum Stage result;
  * Shutdown nicely
  *
  * @param cls NULL
- * @param tc the task context
  */
 static void
-do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_shutdown (void *cls)
 {
-  if (GNUNET_SCHEDULER_NO_TASK != abort_task)
+  if (NULL != abort_task)
     GNUNET_SCHEDULER_cancel (abort_task);
   if (NULL != hc_handle)
     GNUNET_TESTBED_is_host_habitable_cancel (hc_handle);
-  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == delayed_connect_task);
+  GNUNET_assert (NULL == delayed_connect_task);
   if (NULL != common_operation)
     GNUNET_TESTBED_operation_done (common_operation);
   if (NULL != reg_handle)
@@ -288,25 +287,25 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * abort task to run on test timed out
  *
  * @param cls NULL
- * @param tc the task context
  */
 static void
-do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_abort (void *cls)
 {
   LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
-  abort_task = GNUNET_SCHEDULER_NO_TASK;
-  if (GNUNET_SCHEDULER_NO_TASK != delayed_connect_task)
+  abort_task = NULL;
+  if (NULL != delayed_connect_task)
   {
     GNUNET_SCHEDULER_cancel (delayed_connect_task);
-    delayed_connect_task = GNUNET_SCHEDULER_NO_TASK;
+    delayed_connect_task = NULL;
   }
-  do_shutdown (cls, tc);
+  do_shutdown (cls);
 }
 
+
 static void
 abort_test ()
 {
-  if (GNUNET_SCHEDULER_NO_TASK != abort_task)
+  if (NULL != abort_task)
     GNUNET_SCHEDULER_cancel (abort_task);
   abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
 }
@@ -320,7 +319,7 @@ abort_test ()
  * @param emsg error message in case the operation has failed; will be NULL if
  *          operation has executed successfully.
  */
-static void 
+static void
 op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg);
 
 
@@ -328,20 +327,20 @@ op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg);
  * task for delaying a connect
  *
  * @param cls NULL
- * @param tc the task context
  */
 static void
-do_delayed_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_delayed_connect (void *cls)
 {
-  delayed_connect_task = GNUNET_SCHEDULER_NO_TASK;
+  delayed_connect_task = NULL;
   if (NULL != common_operation)
   {
     GNUNET_break (0);
-    abort_test();
+    abort_test ();
     return;
   }
-  common_operation = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, 
-                                                    peer1.peer, peer2.peer);
+  common_operation =
+      GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer1.peer,
+                                      peer2.peer);
 }
 
 
@@ -353,33 +352,32 @@ do_delayed_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * @param emsg error message in case the operation has failed; will be NULL if
  *          operation has executed successfully.
  */
-static void 
+static void
 op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
 {
   if (common_operation != op)
   {
     GNUNET_break (0);
-    abort_test();
+    abort_test ();
     return;
   }
-  
-  switch(result)
+
+  switch (result)
   {
   case PEER3_STARTED:
   case PEERS_2_3_CONNECTED:
-  case PEERS_1_2_CONNECTED: 
+  case PEERS_1_2_CONNECTED:
     break;
   default:
     GNUNET_break (0);
-    abort_test();
+    abort_test ();
     return;
   }
-  if ((NULL != peer1.operation) ||
-      (NULL != peer2.operation) ||
+  if ((NULL != peer1.operation) || (NULL != peer2.operation) ||
       (NULL != peer3.operation))
   {
     GNUNET_break (0);
-    abort_test();
+    abort_test ();
     return;
   }
 }
@@ -400,12 +398,10 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
   switch (result)
   {
   case CONTROLLER1_UP:
-    if ((NULL == peer1.operation) ||
-        (NULL == peer) ||
-        (NULL != peer1.peer))
+    if ((NULL == peer1.operation) || (NULL == peer) || (NULL != peer1.peer))
     {
       GNUNET_break (0);
-      abort_test();
+      abort_test ();
       return;
     }
     peer1.peer = peer;
@@ -414,12 +410,10 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
     peer1.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
     break;
   case CONTROLLER2_UP:
-    if ((NULL == peer2.operation) ||
-        (NULL == peer) ||
-        (NULL != peer2.peer))
+    if ((NULL == peer2.operation) || (NULL == peer) || (NULL != peer2.peer))
     {
       GNUNET_break (0);
-      abort_test();
+      abort_test ();
       return;
     }
     peer2.peer = peer;
@@ -428,12 +422,10 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
     peer2.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
     break;
   case CONTROLLER3_UP:
-    if ((NULL == peer3.operation) ||
-        (NULL == peer) ||
-        (NULL != peer3.peer))
+    if ((NULL == peer3.operation) || (NULL == peer) || (NULL != peer3.peer))
     {
       GNUNET_break (0);
-      abort_test();
+      abort_test ();
       return;
     }
     peer3.peer = peer;
@@ -443,9 +435,9 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
     break;
   default:
     GNUNET_break (0);
-    abort_test();
+    abort_test ();
     return;
-  }  
+  }
 }
 
 
@@ -462,35 +454,35 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
   switch (event->type)
   {
   case GNUNET_TESTBED_ET_OPERATION_FINISHED:
-    if ((NULL != event->details.operation_finished.op_cls)
-        || (NULL != event->details.operation_finished.emsg))
+    if ((NULL != event->op_cls) ||
+        (NULL != event->details.operation_finished.emsg))
     {
       GNUNET_break (0);
-      abort_test();
+      abort_test ();
       return;
     }
     switch (result)
-    {      
+    {
     case PEERS_STOPPED:
       if (NULL != event->details.operation_finished.generic)
       {
         GNUNET_break (0);
-        abort_test();
+        abort_test ();
         return;
       }
-      if (event->details.operation_finished.operation == peer1.operation)
+      if (event->op == peer1.operation)
       {
         GNUNET_TESTBED_operation_done (peer1.operation);
         peer1.operation = NULL;
         peer1.peer = NULL;
       }
-      else if (event->details.operation_finished.operation == peer2.operation)
+      else if (event->op == peer2.operation)
       {
         GNUNET_TESTBED_operation_done (peer2.operation);
         peer2.operation = NULL;
         peer2.peer = NULL;
       }
-      else if (event->details.operation_finished.operation == peer3.operation)
+      else if (event->op == peer3.operation)
       {
         GNUNET_TESTBED_operation_done (peer3.operation);
         peer3.operation = NULL;
@@ -499,7 +491,7 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
       else
       {
         GNUNET_break (0);
-        abort_test();
+        abort_test ();
         return;
       }
       if ((NULL == peer1.peer) && (NULL == peer2.peer) && (NULL == peer3.peer))
@@ -513,7 +505,7 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
           (NULL == common_operation))
       {
         GNUNET_break (0);
-        abort_test();
+        abort_test ();
         return;
       }
       GNUNET_TESTBED_operation_done (common_operation);
@@ -525,7 +517,7 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
       if (NULL == peer2.operation)
       {
         GNUNET_break (0);
-        abort_test();
+        abort_test ();
         return;
       }
       break;
@@ -534,7 +526,7 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
           (NULL == common_operation))
       {
         GNUNET_break (0);
-        abort_test();
+        abort_test ();
         return;
       }
       GNUNET_TESTBED_operation_done (common_operation);
@@ -546,24 +538,24 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
       if (NULL == peer3.operation)
       {
         GNUNET_break (0);
-        abort_test();
+        abort_test ();
         return;
       }
       break;
     default:
       GNUNET_break (0);
-      abort_test();
+      abort_test ();
       return;
     }
     break;
-  case GNUNET_TESTBED_ET_PEER_START:    
+  case GNUNET_TESTBED_ET_PEER_START:
     switch (result)
     {
     case PEER1_CREATED:
       if (event->details.peer_start.host != host)
       {
         GNUNET_break (0);
-        abort_test();
+        abort_test ();
         return;
       }
       peer1.is_running = GNUNET_YES;
@@ -571,14 +563,14 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
       peer1.operation = NULL;
       result = PEER1_STARTED;
       common_operation =
-          GNUNET_TESTBED_controller_link (NULL, controller1, neighbour1, NULL, cfg,
-                                          GNUNET_YES); 
+          GNUNET_TESTBED_controller_link (NULL, controller1, neighbour1, NULL,
+                                          GNUNET_YES);
       break;
     case PEER2_CREATED:
       if (event->details.peer_start.host != neighbour1)
       {
         GNUNET_break (0);
-        abort_test();
+        abort_test ();
         return;
       }
       peer2.is_running = GNUNET_YES;
@@ -588,16 +580,16 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
       if (NULL != common_operation)
       {
         GNUNET_break (0);
-        abort_test();
+        abort_test ();
         return;
       }
       common_operation =
-          GNUNET_TESTBED_controller_link (NULL, controller1, neighbour2, NULL, cfg,
+          GNUNET_TESTBED_controller_link (NULL, controller1, neighbour2, NULL,
                                           GNUNET_YES);
       if (NULL == common_operation)
       {
         GNUNET_break (0);
-        abort_test();
+        abort_test ();
         return;
       }
       break;
@@ -605,7 +597,7 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
       if (event->details.peer_start.host != neighbour2)
       {
         GNUNET_break (0);
-        abort_test();
+        abort_test ();
         return;
       }
       peer3.is_running = GNUNET_YES;
@@ -618,15 +610,15 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
       break;
     default:
       GNUNET_break (0);
-      abort_test();
+      abort_test ();
       return;
-    }    
+    }
     break;
   case GNUNET_TESTBED_ET_PEER_STOP:
     if (PEERS_CONNECTED_2 != result)
     {
       GNUNET_break (0);
-      abort_test();
+      abort_test ();
       return;
     }
     if (event->details.peer_stop.peer == peer1.peer)
@@ -647,11 +639,10 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
     else
     {
       GNUNET_break (0);
-      abort_test();
+      abort_test ();
       return;
     }
-    if ((GNUNET_NO == peer1.is_running) &&
-        (GNUNET_NO == peer2.is_running) &&
+    if ((GNUNET_NO == peer1.is_running) && (GNUNET_NO == peer2.is_running) &&
         (GNUNET_NO == peer3.is_running))
     {
       result = PEERS_STOPPED;
@@ -661,13 +652,11 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
     }
     break;
   case GNUNET_TESTBED_ET_CONNECT:
-    if ((NULL != peer1.operation) ||
-        (NULL != peer2.operation) ||
-        (NULL != peer3.operation) ||
-        (NULL == common_operation))
+    if ((NULL != peer1.operation) || (NULL != peer2.operation) ||
+        (NULL != peer3.operation) || (NULL == common_operation))
     {
       GNUNET_break (0);
-      abort_test();
+      abort_test ();
       return;
     }
     switch (result)
@@ -677,57 +666,57 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
           (event->details.peer_connect.peer2 != peer1.peer))
       {
         GNUNET_break (0);
-        abort_test();
+        abort_test ();
         return;
       }
       GNUNET_TESTBED_operation_done (common_operation);
       common_operation = NULL;
       result = PEERS_1_2_CONNECTED;
       LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n");
-      common_operation = 
+      common_operation =
           GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer,
-                                         peer3.peer);
+                                          peer3.peer);
       break;
     case PEERS_1_2_CONNECTED:
       if ((event->details.peer_connect.peer1 != peer2.peer) ||
           (event->details.peer_connect.peer2 != peer3.peer))
       {
         GNUNET_break (0);
-        abort_test();
+        abort_test ();
         return;
       }
       GNUNET_TESTBED_operation_done (common_operation);
       common_operation = NULL;
       result = PEERS_2_3_CONNECTED;
       delayed_connect_task =
-          GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (3),
-                                        &do_delayed_connect, NULL);
+          GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (3), &do_delayed_connect,
+                                        NULL);
       break;
     case PEERS_2_3_CONNECTED:
       if ((event->details.peer_connect.peer1 != peer1.peer) ||
           (event->details.peer_connect.peer2 != peer2.peer))
       {
         GNUNET_break (0);
-        abort_test();
+        abort_test ();
         return;
       }
       GNUNET_TESTBED_operation_done (common_operation);
       common_operation = NULL;
       result = PEERS_CONNECTED_2;
       LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected again\n");
-      peer1.operation = GNUNET_TESTBED_peer_stop (peer1.peer, NULL, NULL);
-      peer2.operation = GNUNET_TESTBED_peer_stop (peer2.peer, NULL, NULL);
-      peer3.operation = GNUNET_TESTBED_peer_stop (peer3.peer, NULL, NULL);
+      peer1.operation = GNUNET_TESTBED_peer_stop (NULL, peer1.peer, NULL, NULL);
+      peer2.operation = GNUNET_TESTBED_peer_stop (NULL, peer2.peer, NULL, NULL);
+      peer3.operation = GNUNET_TESTBED_peer_stop (NULL, peer3.peer, NULL, NULL);
       break;
     default:
       GNUNET_break (0);
-      abort_test();
+      abort_test ();
       return;
     }
     break;
   default:
     GNUNET_break (0);
-    abort_test();
+    abort_test ();
     return;
   }
 }
@@ -745,20 +734,20 @@ registration_comp (void *cls, const char *emsg)
   reg_handle = NULL;
   if (cls == neighbour1)
   {
-    neighbour2 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, 0);
+    neighbour2 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, cfg, 0);
     if (NULL == neighbour2)
     {
       GNUNET_break (0);
-      abort_test();
+      abort_test ();
       return;
     }
     reg_handle =
-        GNUNET_TESTBED_register_host (controller1, neighbour2, &registration_comp,
-                                      neighbour2);
+        GNUNET_TESTBED_register_host (controller1, neighbour2,
+                                      &registration_comp, neighbour2);
     if (NULL == reg_handle)
     {
       GNUNET_break (0);
-      abort_test();
+      abort_test ();
       return;
     }
     return;
@@ -766,7 +755,7 @@ registration_comp (void *cls, const char *emsg)
   if (cls != neighbour2)
   {
     GNUNET_break (0);
-    abort_test();
+    abort_test ();
     return;
   }
   peer1.operation =
@@ -775,7 +764,7 @@ registration_comp (void *cls, const char *emsg)
   if (NULL == peer1.operation)
   {
     GNUNET_break (0);
-    abort_test();
+    abort_test ();
     return;
   }
 }
@@ -791,15 +780,16 @@ registration_comp (void *cls, const char *emsg)
  *          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)
 {
   uint64_t event_mask;
-  
+
   if (GNUNET_OK != status)
   {
     GNUNET_break (0);
     cp1 = NULL;
-    abort_test();
+    abort_test ();
     return;
   }
   event_mask = 0;
@@ -811,37 +801,37 @@ status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int stat
   {
   case INIT:
     controller1 =
-        GNUNET_TESTBED_controller_connect (config, host, event_mask, &controller_cb,
-                                           NULL);
+        GNUNET_TESTBED_controller_connect (host, event_mask,
+                                           &controller_cb, NULL);
     if (NULL == controller1)
     {
       GNUNET_break (0);
-      abort_test();
+      abort_test ();
       return;
     }
     result = CONTROLLER1_UP;
-    neighbour1 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, 0);
+    neighbour1 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, cfg, 0);
     if (NULL == neighbour1)
     {
       GNUNET_break (0);
-      abort_test();
+      abort_test ();
       return;
     }
     reg_handle =
-        GNUNET_TESTBED_register_host (controller1, neighbour1, &registration_comp,
-                                      neighbour1);
+        GNUNET_TESTBED_register_host (controller1, neighbour1,
+                                      &registration_comp, neighbour1);
     if (NULL == reg_handle)
     {
       GNUNET_break (0);
-      abort_test();
+      abort_test ();
       return;
     }
     break;
   default:
     GNUNET_break (0);
-    abort_test();
+    abort_test ();
     return;
-  }  
+  }
 }
 
 
@@ -853,10 +843,12 @@ status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int stat
  * @param cls NULL
  * @param host the host whose status is being reported; will be NULL if the host
  *          given to GNUNET_TESTBED_is_host_habitable() is NULL
- * @param status GNUNET_YES if it is habitable; GNUNET_NO if not
+ * @param status #GNUNET_YES if it is habitable; #GNUNET_NO if not
  */
-static void 
-host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *_host, int status)
+static void
+host_habitable_cb (void *cls,
+                  const struct GNUNET_TESTBED_Host *_host,
+                   int status)
 {
   hc_handle = NULL;
   if (GNUNET_NO == status)
@@ -866,13 +858,13 @@ host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *_host, int statu
                    "to use password less SSH logins to localhost.\n"
                    "Skipping test\n");
     GNUNET_SCHEDULER_cancel (abort_task);
-    abort_task = GNUNET_SCHEDULER_NO_TASK;
-    (void) GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+    abort_task = NULL;
+    GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
     result = SKIP;
     return;
   }
-  cp1 = GNUNET_TESTBED_controller_start ("127.0.0.1", host, cfg, status_cb,
-                                         NULL);
+  cp1 =
+      GNUNET_TESTBED_controller_start ("127.0.0.1", host, status_cb, NULL);
 }
 
 
@@ -888,16 +880,18 @@ static void
 run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *config)
 {
-  host = GNUNET_TESTBED_host_create (NULL, NULL, 0);
+  cfg = GNUNET_CONFIGURATION_dup (config);
+  host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0);
   if (NULL == host)
   {
     GNUNET_break (0);
-    abort_test();
+    abort_test ();
     return;
   }
-  if (NULL == (hc_handle = GNUNET_TESTBED_is_host_habitable (host, config,
-                                                             &host_habitable_cb,
-                                                             NULL)))
+  if (NULL ==
+      (hc_handle =
+       GNUNET_TESTBED_is_host_habitable (host, config, &host_habitable_cb,
+                                         NULL)))
   {
     GNUNET_TESTBED_host_destroy (host);
     host = NULL;
@@ -908,7 +902,6 @@ run (void *cls, char *const *args, const char *cfgfile,
     result = SKIP;
     return;
   }
-  cfg = GNUNET_CONFIGURATION_dup (config);
   abort_task =
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
                                     (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort,
@@ -923,8 +916,8 @@ int
 main (int argc, char **argv)
 {
   char *const argv2[] = { "test_testbed_api_3peers_3controllers",
-                          "-c", "test_testbed_api.conf",
-                          NULL
+    "-c", "test_testbed_api.conf",
+    NULL
   };
   struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_OPTION_END