aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_api_bidirectional_connect.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-06-28 15:22:34 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-06-28 15:22:34 +0000
commite320c9b96c3e70c61a5969aa01ea6700b9b2e546 (patch)
treeca18e3d52e708238d9d0e5ce87749d991d19d3c2 /src/transport/test_transport_api_bidirectional_connect.c
parentcf19b5082fe8de33e38957f54d28647635b46b60 (diff)
downloadgnunet-e320c9b96c3e70c61a5969aa01ea6700b9b2e546.tar.gz
gnunet-e320c9b96c3e70c61a5969aa01ea6700b9b2e546.zip
fixes in tests: scheduling, removing connect request:
Diffstat (limited to 'src/transport/test_transport_api_bidirectional_connect.c')
-rw-r--r--src/transport/test_transport_api_bidirectional_connect.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/src/transport/test_transport_api_bidirectional_connect.c b/src/transport/test_transport_api_bidirectional_connect.c
index 6745b9abb..4decf0531 100644
--- a/src/transport/test_transport_api_bidirectional_connect.c
+++ b/src/transport/test_transport_api_bidirectional_connect.c
@@ -75,7 +75,10 @@ end ()
75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); 75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
76 76
77 if (send_task != GNUNET_SCHEDULER_NO_TASK) 77 if (send_task != GNUNET_SCHEDULER_NO_TASK)
78 {
78 GNUNET_SCHEDULER_cancel (send_task); 79 GNUNET_SCHEDULER_cancel (send_task);
80 send_task = GNUNET_SCHEDULER_NO_TASK;
81 }
79 82
80 if (die_task != GNUNET_SCHEDULER_NO_TASK) 83 if (die_task != GNUNET_SCHEDULER_NO_TASK)
81 GNUNET_SCHEDULER_cancel (die_task); 84 GNUNET_SCHEDULER_cancel (die_task);
@@ -96,7 +99,10 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
96 die_task = GNUNET_SCHEDULER_NO_TASK; 99 die_task = GNUNET_SCHEDULER_NO_TASK;
97 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); 100 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
98 if (send_task != GNUNET_SCHEDULER_NO_TASK) 101 if (send_task != GNUNET_SCHEDULER_NO_TASK)
102 {
99 GNUNET_SCHEDULER_cancel (send_task); 103 GNUNET_SCHEDULER_cancel (send_task);
104 send_task = GNUNET_SCHEDULER_NO_TASK;
105 }
100 106
101 if (NULL != cc2) 107 if (NULL != cc2)
102 { 108 {
@@ -223,6 +229,7 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
223 static int c; 229 static int c;
224 230
225 c++; 231 c++;
232 GNUNET_assert (NULL != cls);
226 struct PeerContext *p = cls; 233 struct PeerContext *p = cls;
227 struct PeerContext *t = NULL; 234 struct PeerContext *t = NULL;
228 235
@@ -234,7 +241,7 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
234 241
235 char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); 242 char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
236 243
237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 244 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
238 "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps, 245 "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps,
239 t->no, GNUNET_i2s (peer)); 246 t->no, GNUNET_i2s (peer));
240 GNUNET_free (ps); 247 GNUNET_free (ps);
@@ -247,10 +254,18 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
247 struct PeerContext *p = cls; 254 struct PeerContext *p = cls;
248 char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); 255 char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
249 256
250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 257 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
251 "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps, 258 "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps,
252 GNUNET_i2s (peer)); 259 GNUNET_i2s (peer));
253 260
261 if (GNUNET_SCHEDULER_NO_TASK != send_task)
262 {
263
264 GNUNET_SCHEDULER_cancel(send_task);
265 GNUNET_break (0);
266 send_task = GNUNET_SCHEDULER_NO_TASK;
267 }
268
254 if (th != NULL) 269 if (th != NULL)
255 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); 270 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
256 th = NULL; 271 th = NULL;
@@ -260,24 +275,31 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
260static void 275static void
261testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) 276testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
262{ 277{
263 if (cls == cc1) 278 static int connected = GNUNET_NO;
279 GNUNET_break (0);
280 if ((cls == cc1) && (NULL != cc2))
264 { 281 {
265 cc1 = NULL; 282 GNUNET_break (0);
266 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc2); 283 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc2);
267 } 284 }
268 if (cls == cc2) 285 if ((cls == cc2) && (NULL != cc1))
269 { 286 {
270 cc2 = NULL; 287 GNUNET_break (0);
271 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc1); 288 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc1);
272 } 289 }
290 cc1 = NULL;
291 cc2 = NULL;
273 292
293 if (connected > 0)
294 return;
295 connected ++;
274 char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); 296 char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
275 297
276 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", 298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n",
277 p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); 299 p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id));
278 GNUNET_free (p1_c); 300 GNUNET_free (p1_c);
279 301GNUNET_break (0);
280 send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); 302 send_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL);
281} 303}
282 304
283 305
@@ -302,10 +324,10 @@ start_cb (struct PeerContext *p, void *cls)
302 324
303 cc1 = 325 cc1 =
304 GNUNET_TRANSPORT_TESTING_connect_peers (tth, p2, p1, &testing_connect_cb, 326 GNUNET_TRANSPORT_TESTING_connect_peers (tth, p2, p1, &testing_connect_cb,
305 NULL); 327 cc1);
306 cc2 = 328 cc2 =
307 GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, 329 GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
308 NULL); 330 cc2);
309} 331}
310 332
311static void 333static void