-indentation
[oweals/gnunet.git] / src / transport / test_transport_api_monitoring.c
index d06ac638109a31364c9b6b6170bb534176de9d73..221d588adf05e8723f6e49fc472848c2fd6d8d2c 100644 (file)
@@ -84,6 +84,9 @@ static int p1_c = GNUNET_NO;
 
 static int p2_c = GNUNET_NO;
 
+static int p1_c_notify = GNUNET_NO;
+
+static int p2_c_notify = GNUNET_NO;
 
 static void
 end ()
@@ -95,12 +98,22 @@ end ()
     GNUNET_SCHEDULER_cancel (send_task);
 
   if (die_task != GNUNET_SCHEDULER_NO_TASK)
+  {
     GNUNET_SCHEDULER_cancel (die_task);
+    die_task = GNUNET_SCHEDULER_NO_TASK;
+  }
 
   if (th != NULL)
     GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
   th = NULL;
 
+  if (NULL != p1)
+    GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
+  p1 = NULL;
+  if (NULL != p2)
+    GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
+  p2 = NULL;
+
   if (NULL != pmc_p1)
   {
     GNUNET_TRANSPORT_monitor_peers_cancel (pmc_p1);
@@ -112,10 +125,7 @@ end ()
     pmc_p2 = NULL;
   }
 
-  GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
-  p1 = NULL;
-  GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
-  p2 = NULL;
+
 
   ok = 0;
 }
@@ -260,12 +270,24 @@ sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
               p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s);
   GNUNET_free (receiver_s);
   s_sending = GNUNET_YES;
-  th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, TEST_MESSAGE_SIZE, 0,
+  th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, TEST_MESSAGE_SIZE,
                                                TIMEOUT_TRANSMIT, &notify_ready,
                                                p1);
 }
 
 
+static void
+done ()
+{
+  if ((GNUNET_YES == p1_c) && (GNUNET_YES == p2_c) && p1_c_notify && p2_c_notify)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Both peers state to be connected\n");
+    ok = 0;
+    end();
+  }
+}
+
+
 static void
 notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
 {
@@ -276,9 +298,15 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
   struct PeerContext *t = NULL;
 
   if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
+  {
+    p1_c_notify = GNUNET_YES;
     t = p1;
+  }
   if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))
+  {
+    p2_c_notify = GNUNET_YES;
     t = p2;
+  }
   GNUNET_assert (t != NULL);
 
   char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
@@ -286,6 +314,8 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps,
               t->no, GNUNET_i2s (peer));
+  if (p1_c_notify && p2_c_notify)
+    GNUNET_SCHEDULER_add_now(&done, NULL);
   GNUNET_free (ps);
 }
 
@@ -349,15 +379,6 @@ start_cb (struct PeerContext *p, void *cls)
 
 }
 
-static void done ()
-{
-  if ((GNUNET_YES == p1_c) && (GNUNET_YES == p2_c))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Both peers state to be connected\n");
-    ok = 0;
-    end();
-  }
-}
 
 static void monitor1_cb (void *cls,
                         const struct GNUNET_PeerIdentity *peer,
@@ -368,8 +389,8 @@ static void monitor1_cb (void *cls,
   if ((NULL == peer) || (NULL == p1))
     return;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Monitor 1: %s %s %s\n",
-      GNUNET_i2s (peer), GNUNET_TRANSPORT_p2s(state), GNUNET_STRINGS_absolute_time_to_string(state_timeout));
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Monitor 1: %s %s %s\n",
+      GNUNET_i2s (peer), GNUNET_TRANSPORT_ps2s(state), GNUNET_STRINGS_absolute_time_to_string(state_timeout));
   if ((0 == memcmp (peer, &p2->id, sizeof (p2->id)) &&
       (GNUNET_YES == GNUNET_TRANSPORT_is_connected(state)) &&
       GNUNET_NO == p1_c) )
@@ -390,8 +411,8 @@ static void monitor2_cb (void *cls,
   if ((NULL == peer) || (NULL == p2))
     return;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Monitor 2: %s %s %s\n",
-      GNUNET_i2s (peer), GNUNET_TRANSPORT_p2s (state), GNUNET_STRINGS_absolute_time_to_string(state_timeout));
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Monitor 2: %s %s %s\n",
+      GNUNET_i2s (peer), GNUNET_TRANSPORT_ps2s (state), GNUNET_STRINGS_absolute_time_to_string(state_timeout));
   if ((0 == memcmp (peer, &p1->id, sizeof (p1->id)) &&
       (GNUNET_YES == GNUNET_TRANSPORT_is_connected(state)) &&
       GNUNET_NO == p2_c) )
@@ -418,13 +439,14 @@ run (void *cls, char *const *args, const char *cfgfile,
                                             &notify_disconnect, &start_cb,
                                             NULL);
   pmc_p1 = GNUNET_TRANSPORT_monitor_peers (p1->cfg, NULL, GNUNET_NO, GNUNET_TIME_UNIT_FOREVER_REL, &monitor1_cb, NULL);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 started\n");
 
   p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
                                             &notify_receive, &notify_connect,
                                             &notify_disconnect, &start_cb,
                                             NULL);
   pmc_p2 = GNUNET_TRANSPORT_monitor_peers (p2->cfg, NULL, GNUNET_NO, GNUNET_TIME_UNIT_FOREVER_REL, &monitor2_cb, NULL);
-
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 started\n");
   if ((p1 == NULL) || (p2 == NULL))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n");