fix test for peer restart
authorMatthias Wachs <wachs@net.in.tum.de>
Thu, 16 Feb 2012 14:28:37 +0000 (14:28 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Thu, 16 Feb 2012 14:28:37 +0000 (14:28 +0000)
src/transport/test_transport_api_restart_1peer.c

index 22c60356514348b5b881e38d02669053d5ebe11a..b005cbe064c9adb0c5136a85b70735ae6b579c2c 100644 (file)
@@ -65,8 +65,12 @@ static GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
 
 struct PeerContext *p1;
 
+int p1_connected;
+
 struct PeerContext *p2;
 
+int p2_connected;
+
 static GNUNET_TRANSPORT_TESTING_ConnectRequest cc;
 
 struct GNUNET_TRANSPORT_TransmitHandle *th;
@@ -217,8 +221,8 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
     }
     else
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Restarted peers connected, stopping test...\n");
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Restarted peers connected and message was sent, stopping test...\n");
       ok = 0;
       end ();
     }
@@ -303,9 +307,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_connected = GNUNET_YES;
     t = p1;
+  }
   if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))
+  {
+    p2_connected = GNUNET_YES;
     t = p2;
+  }
   GNUNET_assert (t != NULL);
 
   char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
@@ -315,8 +325,9 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
               t->no, GNUNET_i2s (peer));
   GNUNET_free (ps);
 
-  if ((restarted == GNUNET_YES) && (c == 4))
+  if ((restarted == GNUNET_YES) && ((p1_connected == GNUNET_YES) && (p2_connected == GNUNET_YES)))
   {
+    /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */
     send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL);
   }
 }
@@ -327,6 +338,15 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
 {
   struct PeerContext *p = cls;
 
+  if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
+  {
+    p1_connected = GNUNET_NO;
+  }
+  if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))
+  {
+    p2_connected = GNUNET_NO;
+  }
+
 
   char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
 
@@ -385,7 +405,8 @@ run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
-
+  p1_connected = GNUNET_NO;
+  p2_connected = GNUNET_NO;
   p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
                                             &notify_receive, &notify_connect,
                                             &notify_disconnect, &start_cb,