Fixed id counters' cycling
[oweals/gnunet.git] / src / mesh / test_mesh_small.c
index 1cb9d6181831e6540940f4fac38d5abcc2c197af..68fc9cc249be72141706d483242ff9925a4db722 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
@@ -55,7 +55,7 @@ struct StatsContext
 /**
  * Time to wait for stuff that should be rather fast
  */
-#define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
+#define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
 
 /**
  * DIFFERENT TESTS TO RUN
@@ -140,8 +140,6 @@ static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle;
 
 static char *topology_file;
 
-static char *data_filename;
-
 static struct GNUNET_TESTING_Daemon *d1;
 
 static GNUNET_PEER_Id pid1;
@@ -479,11 +477,17 @@ 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);
   if (test == MULTICAST)
   {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "***************** test: add peer 3\n");
     GNUNET_MESH_peer_request_connect_add(t, &d3->id);
   }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "***************** test: add peer 2\n");
+  GNUNET_MESH_peer_request_connect_add(t, &d2->id);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "***************** test: schedule timeout in 30s\n");
   if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
   {
     GNUNET_SCHEDULER_cancel (disconnect_task);
@@ -520,8 +524,14 @@ topo_cb (void *cls,
   if (p1 == pid1)
   {
     p2 = GNUNET_PEER_search(second);
-    GNUNET_assert(p2 < num_peers);
-    GNUNET_assert(p2 > 0);
+    if (p2 == 0 || p2 > num_peers)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  "***************** test: %s is UNKNOWN!? (%u)\n",
+                  GNUNET_i2s(second),
+                  p2);
+      return;
+    }
     mesh_peers[p2]++;
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "***************** test: %s IS a neighbor\n",
@@ -532,8 +542,14 @@ topo_cb (void *cls,
   if (p1 == pid1)
   {
     p2 = GNUNET_PEER_search(first);
-    GNUNET_assert(p2 < num_peers);
-    GNUNET_assert(p2 > 0);
+    if (p2 == 0 || p2 > num_peers)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  "***************** test: %s is UNKNOWN!? (%u)\n",
+                  GNUNET_i2s(first),
+                  p2);
+      return;
+    }
     mesh_peers[p2]++;
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "***************** test: %s IS a neighbor\n",
@@ -678,10 +694,13 @@ peergroup_ready (void *cls, const char *emsg)
   peers_running = GNUNET_TESTING_daemons_running (pg);
   for (i = 0; i < num_peers; i++)
   {
+    GNUNET_PEER_Id peer_id;
+
     d1 = GNUNET_TESTING_daemon_get (pg, i);
+    peer_id = GNUNET_PEER_intern(&d1->id);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "***************** test:   %u: %s\n",
-                GNUNET_PEER_intern(&d1->id),
+                peer_id,
                 GNUNET_i2s (&d1->id));
   }
   d1 = GNUNET_TESTING_daemon_get (pg, 0);
@@ -734,6 +753,12 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "***************** test: Problem with new connection (%s)\n",
                 emsg);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "***************** test:   (%s)\n",
+                GNUNET_i2s (first));
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "***************** test:   (%s)\n",
+                GNUNET_i2s (second));
   }
 
 }
@@ -753,6 +778,7 @@ 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 = 0;
   testing_cfg = GNUNET_CONFIGURATION_dup (cfg);
@@ -780,7 +806,7 @@ run (void *cls, char *const *args, const char *cfgfile,
     return;
   }
 
-  mesh_peers = GNUNET_malloc (sizeof(GNUNET_PEER_Id) * (num_peers + 1));
+  mesh_peers = GNUNET_malloc (sizeof(uint16_t) * (num_peers + 1));
 
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small",
@@ -801,27 +827,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 =
+    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);
+    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 =
@@ -883,6 +905,16 @@ main (int argc, char *argv[])
 #endif
     NULL
   };
+
+  /* Each peer is supposed to generate the following callbacks:
+   * 1 incoming tunnel (@dest)
+   * 1 connected peer (@orig)
+   * 1 received data packet (@dest)
+   * 1 received data packet (@orig)
+   * 1 received tunnel destroy (@dest)
+   * _________________________________
+   * 5 x ok expected per peer
+   */
   int ok_goal;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Start\n");