gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r17830 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r17830 - gnunet/src/transport
Date: Fri, 28 Oct 2011 09:46:21 +0200

Author: wachs
Date: 2011-10-28 09:46:21 +0200 (Fri, 28 Oct 2011)
New Revision: 17830

Modified:
   gnunet/src/transport/test_transport_api_disconnect.c
Log:
fixing bug


Modified: gnunet/src/transport/test_transport_api_disconnect.c
===================================================================
--- gnunet/src/transport/test_transport_api_disconnect.c        2011-10-28 
01:54:03 UTC (rev 17829)
+++ gnunet/src/transport/test_transport_api_disconnect.c        2011-10-28 
07:46:21 UTC (rev 17830)
@@ -21,7 +21,7 @@
  * @file transport/test_transport_api_disconnect.c
  * @brief base test case for transport implementations
  *
- * This test case serves tests disconnect notification if peer shutsdown
+ * This test case tests disconnect notifications in peer shutdown
  */
 #include "platform.h"
 #include "gnunet_common.h"
@@ -34,7 +34,7 @@
 #include "transport.h"
 #include "transport-testing.h"
 
-#define VERBOSE GNUNET_YES
+#define VERBOSE GNUNET_EXTRA_LOGGING
 #define VERBOSE_ARM GNUNET_EXTRA_LOGGING
 
 #define START_ARM GNUNET_YES
@@ -92,10 +92,16 @@
   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stopping peers\n");
 
   if (send_task != GNUNET_SCHEDULER_NO_TASK)
+  {
     GNUNET_SCHEDULER_cancel (send_task);
+    send_task = GNUNET_SCHEDULER_NO_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);
@@ -103,10 +109,11 @@
 
   if (p1 != NULL)
     GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
+  p1 = NULL;
+
   if (p2 != NULL)
     GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
-
-
+  p2 = NULL;
 }
 
 static void
@@ -116,15 +123,10 @@
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
 
-
   if (send_task != GNUNET_SCHEDULER_NO_TASK)
+  {
     GNUNET_SCHEDULER_cancel (send_task);
-
-  if (cc != NULL)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n"));
-    GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
-    cc = NULL;
+    send_task = GNUNET_SCHEDULER_NO_TASK;
   }
 
   if (th != NULL)
@@ -139,8 +141,43 @@
   ok = GNUNET_SYSERR;
 }
 
+static void
+notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
+{
+  struct PeerContext *p = cls;
+  char * ps = strdup (GNUNET_i2s(&p->id));
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer %u (`%4s'): peer (`%s') 
disconnected from me!\n",
+              p->no, ps, GNUNET_i2s (peer));
 
+  if (th != NULL)
+    GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
+  th = NULL;
+
+  if (shutdown_ == GNUNET_YES)
+  {
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Complete, shutting down...\n");
+  GNUNET_SCHEDULER_add_now (&end, NULL);
+  }
+}
+
+
 static void
+stop_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+    return;
+
+  struct PeerContext * p = cls;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down peer %u (`%s')\n",
+      p->no,
+      GNUNET_i2s (&p->id));
+  shutdown_ = GNUNET_YES;
+  GNUNET_TRANSPORT_TESTING_stop_peer(tth, p2);
+  p2 = NULL;
+  GNUNET_assert (p2 == NULL);
+}
+
+static void
 notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
                 const struct GNUNET_MessageHeader *message,
                 const struct GNUNET_ATS_Information *ats,
@@ -165,9 +202,7 @@
       (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)))
   {
     ok = 1;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down peer\n");
-    shutdown_ = GNUNET_YES;
-    GNUNET_TRANSPORT_TESTING_stop_peer(tth, p2);
+    GNUNET_SCHEDULER_add_now(stop_peer, p2);
     return;
   }
 }
@@ -257,25 +292,6 @@
 
 
 static void
-notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
-{
-  struct PeerContext *p = cls;
-  char * ps = strdup (GNUNET_i2s(&p->id));
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer %u (`%4s'): peer (`%s') 
disconnected from me!\n",
-              p->no, ps, GNUNET_i2s (peer));
-
-  if (th != NULL)
-    GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
-  th = NULL;
-
-  if (shutdown_ == GNUNET_YES)
-  {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Complete, shutting down...\n");
-  GNUNET_SCHEDULER_add_now (&end, NULL);
-  }
-}
-
-static void
 testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
 {
   cc = NULL;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]