- stop using message types of payload on service side
[oweals/gnunet.git] / src / mesh / test_mesh_small.c
index f51fb9706660b587d1d3ff25ff74a50603c7827e..efe939876f7960dcc0703181dd40c0052672192f 100644 (file)
@@ -54,6 +54,7 @@
 #define SPEED_ACK 4
 #define SPEED_MIN 5
 #define SPEED_NOBUF 6
+#define P2P_SIGNAL 10
 
 /**
  * Which test are we running?
@@ -233,7 +234,6 @@ show_end_data (void)
 static void
 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  fprintf(stderr, "b");
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n");
   shutdown_handle = GNUNET_SCHEDULER_NO_TASK;
 }
@@ -251,7 +251,6 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   long line = (long) cls;
   unsigned int i;
 
-  fprintf(stderr, "a");
   for (i = 0; i < 3; i++)
     if (NULL != t_op[i])
     {
@@ -286,6 +285,11 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 }
 
 
+/**
+ * Abort test: schedule disconnect and shutdown immediately
+ * 
+ * @param line Line in the code the abort is requested from (__LINE__).
+ */
 void
 abort_test (long line)
 {
@@ -293,9 +297,9 @@ abort_test (long line)
   {
     GNUNET_SCHEDULER_cancel (disconnect_task);
   }
-    disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
-                                                    &disconnect_mesh_peers,
-                                                    (void *) line);
+  disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
+                                                  &disconnect_mesh_peers,
+                                                  (void *) line);
 }
 
 /**
@@ -385,7 +389,7 @@ tmt_rdy (void *cls, size_t size, void *buf)
   if (size < size_payload || NULL == buf)
   {
     GNUNET_break (0);
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "size %u, buf %p, data_sent %u, data_received %u\n",
                 size,
                 buf,
@@ -527,8 +531,16 @@ data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx,
         return GNUNET_OK;
       show_end_data();
     }
-    GNUNET_MESH_tunnel_destroy (t);
-    t = NULL;
+    if (test == P2P_SIGNAL)
+    {
+      GNUNET_MESH_tunnel_destroy (incoming_t);
+      incoming_t = NULL;
+    }
+    else
+    {
+      GNUNET_MESH_tunnel_destroy (t);
+      t = NULL;
+    }
   }
 
   if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
@@ -653,6 +665,16 @@ dh (void *cls, const struct GNUNET_PeerIdentity *peer)
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "peer %s disconnected\n",
               GNUNET_i2s (peer));
+  if (P2P_SIGNAL == test)
+  {
+    ok ++;
+    if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
+    {
+      GNUNET_SCHEDULER_cancel (disconnect_task);
+    }
+    disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers,
+                                                (void *) __LINE__);
+  }
   return;
 }
 
@@ -673,7 +695,7 @@ ch (void *cls, const struct GNUNET_PeerIdentity *peer,
   struct GNUNET_PeerIdentity *dest;
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "peer %s connected\n", GNUNET_i2s (peer));
+              "%ld peer %s connected\n", i, GNUNET_i2s (peer));
 
   if (0 == memcmp (p_id[2], peer, sizeof (struct GNUNET_PeerIdentity)) &&
       i == 0L)
@@ -690,6 +712,7 @@ ch (void *cls, const struct GNUNET_PeerIdentity *peer,
   switch (test)
   {
     case UNICAST:
+    case P2P_SIGNAL:
     case SPEED:
     case SPEED_ACK:
       // incoming_t is NULL unless we send a relevant data packet
@@ -761,10 +784,10 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
   {
     GNUNET_SCHEDULER_cancel (disconnect_task);
-    disconnect_task =
-        GNUNET_SCHEDULER_add_delayed (TIMEOUT, &disconnect_mesh_peers,
-                                      (void *) __LINE__);
   }
+  disconnect_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+                                                  &disconnect_mesh_peers,
+                                                  (void *) __LINE__);
 }
 
 /**
@@ -792,6 +815,7 @@ pi_cb (void *cls,
     return;
   }
   p_id[i] = pinfo->result.id;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  id: %s\n", GNUNET_i2s (p_id[i]));
   p_ids++;
   if ((MULTICAST == test && p_ids < 3) || p_ids < 2)
     return;
@@ -822,7 +846,7 @@ tmain (void *cls,
   peers_running = num_peers;
   h1 = meshes[0];
   h2 = meshes[num_peers - 1];
-  t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, (void *) 1L);
+  t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, (void *) 0L);
   if (SPEED_MIN == test)
   {
     GNUNET_MESH_tunnel_speed_min(t);
@@ -885,6 +909,13 @@ main (int argc, char *argv[])
     test_name = "multicast";
     ok_goal = 10;
   }
+  else if (strstr (argv[0], "test_mesh_small_signal") != NULL)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SIGNAL\n");
+    test = P2P_SIGNAL;
+    test_name = "signal";
+    ok_goal = 5;
+  }
   else if (strstr (argv[0], "test_mesh_small_speed_ack") != NULL)
   {
    /* Each peer is supposed to generate the following callbacks:
@@ -949,7 +980,7 @@ main (int argc, char *argv[])
   }
 
   p_ids = 0;
-  GNUNET_MESH_TEST_run (test_name,
+  GNUNET_MESH_TEST_run ("test_mesh_small",
                         "test_mesh_small.conf",
                         5,
                         &tmain,