aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_api_disconnect.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-10-28 07:46:21 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-10-28 07:46:21 +0000
commit167f1b8cee643a2ab489918cb2f15d88079288e7 (patch)
treecbd52d1f63c3432390df4cd0fdb8c76fb43709c2 /src/transport/test_transport_api_disconnect.c
parent6d718cd3e1080627d1241fa61a8aa6d73de4bfa7 (diff)
downloadgnunet-167f1b8cee643a2ab489918cb2f15d88079288e7.tar.gz
gnunet-167f1b8cee643a2ab489918cb2f15d88079288e7.zip
fixing bug
Diffstat (limited to 'src/transport/test_transport_api_disconnect.c')
-rw-r--r--src/transport/test_transport_api_disconnect.c82
1 files changed, 49 insertions, 33 deletions
diff --git a/src/transport/test_transport_api_disconnect.c b/src/transport/test_transport_api_disconnect.c
index 3b294684d..4335272a7 100644
--- a/src/transport/test_transport_api_disconnect.c
+++ b/src/transport/test_transport_api_disconnect.c
@@ -21,7 +21,7 @@
21 * @file transport/test_transport_api_disconnect.c 21 * @file transport/test_transport_api_disconnect.c
22 * @brief base test case for transport implementations 22 * @brief base test case for transport implementations
23 * 23 *
24 * This test case serves tests disconnect notification if peer shutsdown 24 * This test case tests disconnect notifications in peer shutdown
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_common.h" 27#include "gnunet_common.h"
@@ -34,7 +34,7 @@
34#include "transport.h" 34#include "transport.h"
35#include "transport-testing.h" 35#include "transport-testing.h"
36 36
37#define VERBOSE GNUNET_YES 37#define VERBOSE GNUNET_EXTRA_LOGGING
38#define VERBOSE_ARM GNUNET_EXTRA_LOGGING 38#define VERBOSE_ARM GNUNET_EXTRA_LOGGING
39 39
40#define START_ARM GNUNET_YES 40#define START_ARM GNUNET_YES
@@ -92,10 +92,16 @@ end ()
92 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stopping peers\n"); 92 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stopping peers\n");
93 93
94 if (send_task != GNUNET_SCHEDULER_NO_TASK) 94 if (send_task != GNUNET_SCHEDULER_NO_TASK)
95 {
95 GNUNET_SCHEDULER_cancel (send_task); 96 GNUNET_SCHEDULER_cancel (send_task);
97 send_task = GNUNET_SCHEDULER_NO_TASK;
98 }
96 99
97 if (die_task != GNUNET_SCHEDULER_NO_TASK) 100 if (die_task != GNUNET_SCHEDULER_NO_TASK)
101 {
98 GNUNET_SCHEDULER_cancel (die_task); 102 GNUNET_SCHEDULER_cancel (die_task);
103 die_task = GNUNET_SCHEDULER_NO_TASK;
104 }
99 105
100 if (th != NULL) 106 if (th != NULL)
101 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); 107 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
@@ -103,10 +109,11 @@ end ()
103 109
104 if (p1 != NULL) 110 if (p1 != NULL)
105 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); 111 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
112 p1 = NULL;
113
106 if (p2 != NULL) 114 if (p2 != NULL)
107 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); 115 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
108 116 p2 = NULL;
109
110} 117}
111 118
112static void 119static void
@@ -116,15 +123,10 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
116 123
117 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); 124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
118 125
119
120 if (send_task != GNUNET_SCHEDULER_NO_TASK) 126 if (send_task != GNUNET_SCHEDULER_NO_TASK)
121 GNUNET_SCHEDULER_cancel (send_task);
122
123 if (cc != NULL)
124 { 127 {
125 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n")); 128 GNUNET_SCHEDULER_cancel (send_task);
126 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); 129 send_task = GNUNET_SCHEDULER_NO_TASK;
127 cc = NULL;
128 } 130 }
129 131
130 if (th != NULL) 132 if (th != NULL)
@@ -139,6 +141,41 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
139 ok = GNUNET_SYSERR; 141 ok = GNUNET_SYSERR;
140} 142}
141 143
144static void
145notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
146{
147 struct PeerContext *p = cls;
148 char * ps = strdup (GNUNET_i2s(&p->id));
149 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer %u (`%4s'): peer (`%s') disconnected from me!\n",
150 p->no, ps, GNUNET_i2s (peer));
151
152 if (th != NULL)
153 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
154 th = NULL;
155
156 if (shutdown_ == GNUNET_YES)
157 {
158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Complete, shutting down...\n");
159 GNUNET_SCHEDULER_add_now (&end, NULL);
160 }
161}
162
163
164static void
165stop_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
166{
167 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
168 return;
169
170 struct PeerContext * p = cls;
171 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down peer %u (`%s')\n",
172 p->no,
173 GNUNET_i2s (&p->id));
174 shutdown_ = GNUNET_YES;
175 GNUNET_TRANSPORT_TESTING_stop_peer(tth, p2);
176 p2 = NULL;
177 GNUNET_assert (p2 == NULL);
178}
142 179
143static void 180static void
144notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 181notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
@@ -165,9 +202,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
165 (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) 202 (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)))
166 { 203 {
167 ok = 1; 204 ok = 1;
168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down peer\n"); 205 GNUNET_SCHEDULER_add_now(stop_peer, p2);
169 shutdown_ = GNUNET_YES;
170 GNUNET_TRANSPORT_TESTING_stop_peer(tth, p2);
171 return; 206 return;
172 } 207 }
173} 208}
@@ -257,25 +292,6 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
257 292
258 293
259static void 294static void
260notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
261{
262 struct PeerContext *p = cls;
263 char * ps = strdup (GNUNET_i2s(&p->id));
264 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer %u (`%4s'): peer (`%s') disconnected from me!\n",
265 p->no, ps, GNUNET_i2s (peer));
266
267 if (th != NULL)
268 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
269 th = NULL;
270
271 if (shutdown_ == GNUNET_YES)
272 {
273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Complete, shutting down...\n");
274 GNUNET_SCHEDULER_add_now (&end, NULL);
275 }
276}
277
278static void
279testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) 295testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
280{ 296{
281 cc = NULL; 297 cc = NULL;