Adapted timeout for slower buildbots
[oweals/gnunet.git] / src / mesh / test_mesh_small_unicast_far.c
index d5a768f98cffe15637b4a886071524f12a8131cb..cc9995b48bee1cd9a603d0f290ad790b76f482e1 100644 (file)
@@ -24,7 +24,7 @@
  */
 #include "platform.h"
 #include "gnunet_testing_lib.h"
-#include "gnunet_mesh_service_new.h"
+#include "gnunet_mesh_service.h"
 
 #define VERBOSE GNUNET_YES
 #define REMOVE_DIR GNUNET_YES
@@ -120,8 +120,6 @@ static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle;
 
 static char *topology_file;
 
-static char *data_filename;
-
 static struct GNUNET_TESTING_Daemon *d1;
 
 static struct GNUNET_TESTING_Daemon *d2;
@@ -150,7 +148,8 @@ shutdown_callback (void *cls, const char *emsg)
   else
   {
 #if VERBOSE
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: All peers successfully shut down!\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "test: All peers successfully shut down!\n");
 #endif
   }
 }
@@ -191,10 +190,10 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "test: disconnecting mesh service of peers\n");
   disconnect_task = GNUNET_SCHEDULER_NO_TASK;
-  GNUNET_MESH_disconnect(h1);
-  GNUNET_MESH_disconnect(h2);
+  GNUNET_MESH_disconnect (h1);
+  GNUNET_MESH_disconnect (h2);
   GNUNET_SCHEDULER_cancel (shutdown_handle);
-  shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL);
+  shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
 }
 
 
@@ -210,16 +209,14 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  *         (can be NULL -- that's not an error)
  */
 static void *
-incoming_tunnel (void *cls,
-                 struct GNUNET_MESH_Tunnel * tunnel,
-                 const struct GNUNET_PeerIdentity * initiator,
-                 const struct GNUNET_ATS_Information * atsi)
+incoming_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
+                 const struct GNUNET_PeerIdentity *initiator,
+                 const struct GNUNET_ATS_Information *atsi)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "test: Incoming tunnel from %s\n",
-              GNUNET_i2s(initiator));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Incoming tunnel from %s\n",
+              GNUNET_i2s (initiator));
   GNUNET_SCHEDULER_cancel (disconnect_task);
-  disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_mesh_peers, NULL);
+  disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers, NULL);
   ok = 0;
   return NULL;
 }
@@ -240,7 +237,7 @@ tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
 #if VERBOSE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: tunnel disconnected\n");
 #endif
-  
+
   return;
 }
 
@@ -253,9 +250,8 @@ tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
 static void
 dh (void *cls, const struct GNUNET_PeerIdentity *peer)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "test: peer %s disconnected\n",
-              GNUNET_i2s(peer));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: peer %s disconnected\n",
+              GNUNET_i2s (peer));
   return;
 }
 
@@ -271,9 +267,8 @@ static void
 ch (void *cls, const struct GNUNET_PeerIdentity *peer,
     const struct GNUNET_ATS_Information *atsi)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "test: peer %s connected\n",
-              GNUNET_i2s(peer));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: peer %s connected\n",
+              GNUNET_i2s (peer));
   return;
 }
 
@@ -282,11 +277,12 @@ static void
 do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n");
-  GNUNET_MESH_peer_request_connect_add(t, &d2->id);
+  GNUNET_MESH_peer_request_connect_add (t, &d2->id);
   GNUNET_SCHEDULER_cancel (disconnect_task);
-  disconnect_task = GNUNET_SCHEDULER_add_delayed(
-          GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30),
-                               &disconnect_mesh_peers, NULL);
+  disconnect_task =
+      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+                                    (GNUNET_TIME_UNIT_SECONDS, 30),
+                                    &disconnect_mesh_peers, NULL);
 }
 
 
@@ -302,10 +298,9 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: connect_mesh_service\n");
 
-  GNUNET_PEER_resolve(11, &id);
+  GNUNET_PEER_resolve (11, &id);
   d2 = GNUNET_TESTING_daemon_get_by_id (pg, &id);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "test: Peer searched: %s\n",
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Peer searched: %s\n",
               GNUNET_i2s (&d2->id));
   app = (GNUNET_MESH_ApplicationType) 0;
 
@@ -317,20 +312,10 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
               "test: connecting to mesh service of peer %s\n",
               GNUNET_i2s (&d2->id));
 #endif
-  h1 = GNUNET_MESH_connect (d1->cfg,
-                            10,
-                            NULL,
-                            NULL,
-                            &tunnel_cleaner,
-                            handlers,
-                            &app);
-  h2 = GNUNET_MESH_connect (d2->cfg,
-                            10,
-                            NULL,
-                            &incoming_tunnel,
-                            &tunnel_cleaner,
-                            handlers,
+  h1 = GNUNET_MESH_connect (d1->cfg, 10, NULL, NULL, &tunnel_cleaner, handlers,
                             &app);
+  h2 = GNUNET_MESH_connect (d2->cfg, 10, NULL, &incoming_tunnel,
+                            &tunnel_cleaner, handlers, &app);
 #if VERBOSE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "test: connected to mesh service of peer %s\n",
@@ -341,9 +326,9 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 #endif
   t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, NULL);
   test_task =
-      GNUNET_SCHEDULER_add_delayed(
-          GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 6),
-          &do_test, NULL);
+      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+                                    (GNUNET_TIME_UNIT_SECONDS, 6), &do_test,
+                                    NULL);
 }
 
 
@@ -364,8 +349,8 @@ peergroup_ready (void *cls, const char *emsg)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "test: Peergroup callback called with error, aborting test!\n");
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "test: Error from testing: `%s'\n", emsg);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Error from testing: `%s'\n",
+                emsg);
     ok++;
     GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
     return;
@@ -375,8 +360,7 @@ peergroup_ready (void *cls, const char *emsg)
               "************************************************************\n");
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "test: Peer Group started successfully!\n");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "test: Have %u connections\n",
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Have %u connections\n",
               total_connections);
 #endif
 
@@ -392,18 +376,14 @@ peergroup_ready (void *cls, const char *emsg)
   for (i = 0; i < num_peers; i++)
   {
     d1 = GNUNET_TESTING_daemon_get (pg, i);
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "test:   %u: %s\n",
-                GNUNET_PEER_intern(&d1->id),
-                GNUNET_i2s (&d1->id));
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test:   %u: %s\n",
+                GNUNET_PEER_intern (&d1->id), GNUNET_i2s (&d1->id));
   }
   d1 = GNUNET_TESTING_daemon_get (pg, 0);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "test: Peer looking: %s\n",
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Peer looking: %s\n",
               GNUNET_i2s (&d1->id));
 
-  GNUNET_SCHEDULER_add_now (&connect_mesh_service,
-                                NULL);
+  GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL);
   disconnect_task =
       GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
 
@@ -439,8 +419,7 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
   else
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "test: Problem with new connection (%s)\n",
-                emsg);
+                "test: Problem with new connection (%s)\n", emsg);
   }
 
 }
@@ -460,6 +439,8 @@ run (void *cls, char *const *args, const char *cfgfile,
   char *temp_str;
   unsigned long long temp_wait;
   struct GNUNET_TESTING_Host *hosts;
+  char *data_filename;
+
 
   ok = 1;
   testing_cfg = GNUNET_CONFIGURATION_dup (cfg);
@@ -495,7 +476,7 @@ run (void *cls, char *const *args, const char *cfgfile,
     }
   }
 
-  mesh_peers = GNUNET_malloc (sizeof(GNUNET_PEER_Id) * (num_peers + 1));
+  mesh_peers = GNUNET_malloc (sizeof (GNUNET_PEER_Id) * (num_peers + 1));
 
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small",
@@ -516,27 +497,23 @@ run (void *cls, char *const *args, const char *cfgfile,
     return;
   }
 
-  if (GNUNET_OK !=
+  if (GNUNET_OK ==
       GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_mesh_small",
                                              "data_output_file",
                                              &data_filename))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Option test_mesh_small:data_output_file is required!\n");
-    return;
-  }
-
-  data_file =
-      GNUNET_DISK_file_open (data_filename,
-                             GNUNET_DISK_OPEN_READWRITE |
-                             GNUNET_DISK_OPEN_CREATE,
-                             GNUNET_DISK_PERM_USER_READ |
-                             GNUNET_DISK_PERM_USER_WRITE);
-  if (data_file == NULL)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
-                data_filename);
-    GNUNET_free (data_filename);
+    data_file =
+        GNUNET_DISK_file_open (data_filename,
+                               GNUNET_DISK_OPEN_READWRITE |
+                               GNUNET_DISK_OPEN_CREATE,
+                               GNUNET_DISK_PERM_USER_READ |
+                               GNUNET_DISK_PERM_USER_WRITE);
+    if (data_file == NULL)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
+                  data_filename);
+      GNUNET_free (data_filename);
+    }
   }
 
   wait_time =
@@ -589,8 +566,8 @@ int
 main (int argc, char *argv[])
 {
   GNUNET_PROGRAM_run (argc, argv, "test_mesh_small_unicast",
-                      gettext_noop ("Test mesh unicast in a small network."), options,
-                      &run, NULL);
+                      gettext_noop ("Test mesh unicast in a small network."),
+                      options, &run, NULL);
 #if REMOVE_DIR
   GNUNET_DISK_directory_remove ("/tmp/test_mesh_small_unicast");
 #endif