aboutsummaryrefslogtreecommitdiff
path: root/src/cadet
diff options
context:
space:
mode:
Diffstat (limited to 'src/cadet')
-rw-r--r--src/cadet/cadet_api.c10
-rw-r--r--src/cadet/cadet_path.c67
-rw-r--r--src/cadet/gnunet-cadet-profiler.c224
-rw-r--r--src/cadet/gnunet-cadet.c135
-rw-r--r--src/cadet/gnunet-service-cadet.c4
-rw-r--r--src/cadet/gnunet-service-cadet_channel.c14
-rw-r--r--src/cadet/gnunet-service-cadet_connection.c51
-rw-r--r--src/cadet/gnunet-service-cadet_dht.c8
-rw-r--r--src/cadet/gnunet-service-cadet_peer.c33
-rw-r--r--src/cadet/gnunet-service-cadet_tunnel.c70
-rw-r--r--src/cadet/test_cadet.c118
-rw-r--r--src/cadet/test_cadet_local.c48
-rw-r--r--src/cadet/test_cadet_single.c46
13 files changed, 383 insertions, 445 deletions
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c
index 6894d2482..d5b0688e6 100644
--- a/src/cadet/cadet_api.c
+++ b/src/cadet/cadet_api.c
@@ -1,20 +1,22 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2011 GNUnet e.V. 3 Copyright (C) 2011 GNUnet e.V.
4
4 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
6 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation; either version 3, or (at your
7 option) any later version. 8 option) any later version.
9
8 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details. 13 General Public License for more details.
14
12 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
13 along with GNUnet; see the file COPYING. If not, write to the 16 along with GNUnet; see the file COPYING. If not, write to the
14 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
15 Boston, MA 02110-1301, USA. 18 Boston, MA 02110-1301, USA.
16*/ 19*/
17
18/** 20/**
19 * @file cadet/cadet_api.c 21 * @file cadet/cadet_api.c
20 * @brief cadet api: client implementation of new cadet service 22 * @brief cadet api: client implementation of new cadet service
@@ -702,12 +704,8 @@ static void
702reconnect_cbk (void *cls) 704reconnect_cbk (void *cls)
703{ 705{
704 struct GNUNET_CADET_Handle *h = cls; 706 struct GNUNET_CADET_Handle *h = cls;
705 const struct GNUNET_SCHEDULER_TaskContext *tc;
706 707
707 h->reconnect_task = NULL; 708 h->reconnect_task = NULL;
708 tc = GNUNET_SCHEDULER_get_task_context ();
709 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
710 return;
711 do_reconnect (h); 709 do_reconnect (h);
712} 710}
713 711
@@ -718,7 +716,7 @@ reconnect_cbk (void *cls)
718 * 716 *
719 * @param h handle to the cadet 717 * @param h handle to the cadet
720 * 718 *
721 * @return GNUNET_YES in case of sucess, GNUNET_NO otherwise (service down...) 719 * @return #GNUNET_YES in case of sucess, #GNUNET_NO otherwise (service down...)
722 */ 720 */
723static void 721static void
724reconnect (struct GNUNET_CADET_Handle *h) 722reconnect (struct GNUNET_CADET_Handle *h)
diff --git a/src/cadet/cadet_path.c b/src/cadet/cadet_path.c
index 47241292b..0358d64ca 100644
--- a/src/cadet/cadet_path.c
+++ b/src/cadet/cadet_path.c
@@ -33,10 +33,7 @@
33 33
34/** 34/**
35 * @brief Destroy a path after some time has past. 35 * @brief Destroy a path after some time has past.
36 * 36 * Removes the path from the peer (must not be used for direct paths).
37 * If the path is returned from DHT again after a while, try again.
38 *
39 * Removes the path from the peer (except for direct paths).
40 * 37 *
41 * @param cls Closure (path to destroy). 38 * @param cls Closure (path to destroy).
42 */ 39 */
@@ -45,28 +42,17 @@ path_destroy_delayed (void *cls)
45{ 42{
46 struct CadetPeerPath *path = cls; 43 struct CadetPeerPath *path = cls;
47 struct CadetPeer *peer; 44 struct CadetPeer *peer;
48 const struct GNUNET_SCHEDULER_TaskContext *tc;
49 45
50 LOG (GNUNET_ERROR_TYPE_INFO, "Destroy delayed %p (%u)\n", path, path->length);
51 path->path_delete = NULL; 46 path->path_delete = NULL;
52 47 LOG (GNUNET_ERROR_TYPE_INFO,
53 /* During shutdown, the peers peermap might not exist anymore. */ 48 "Destroy delayed %p (%u)\n",
54 tc = GNUNET_SCHEDULER_get_task_context (); 49 path,
55 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) == 0) 50 path->length);
56 { 51 GNUNET_assert (2 < path->length);
57 if (2 >= path->length) 52 peer = GCP_get_short (path->peers[path->length - 1],
58 { 53 GNUNET_NO);
59 /* This is not the place to destroy direct paths, only core_disconnect 54 GNUNET_assert (NULL != peer);
60 * should do it and never delay it. 55 GCP_remove_path (peer, path);
61 */
62 GNUNET_break (0);
63 }
64 peer = GCP_get_short (path->peers[path->length - 1], GNUNET_NO);
65 if (NULL != peer)
66 GCP_remove_path (peer, path);
67 }
68 else
69 path_destroy (path);
70} 56}
71 57
72 58
@@ -74,7 +60,6 @@ path_destroy_delayed (void *cls)
74 * Create a new path 60 * Create a new path
75 * 61 *
76 * @param length How many hops will the path have. 62 * @param length How many hops will the path have.
77 *
78 * @return A newly allocated path with a peer array of the specified length. 63 * @return A newly allocated path with a peer array of the specified length.
79 */ 64 */
80struct CadetPeerPath * 65struct CadetPeerPath *
@@ -125,7 +110,9 @@ path_duplicate (const struct CadetPeerPath *path)
125 unsigned int i; 110 unsigned int i;
126 111
127 aux = path_new (path->length); 112 aux = path_new (path->length);
128 memcpy (aux->peers, path->peers, path->length * sizeof (GNUNET_PEER_Id)); 113 memcpy (aux->peers,
114 path->peers,
115 path->length * sizeof (GNUNET_PEER_Id));
129 for (i = 0; i < aux->length; i++) 116 for (i = 0; i < aux->length; i++)
130 GNUNET_PEER_change_rc (aux->peers[i], 1); 117 GNUNET_PEER_change_rc (aux->peers[i], 1);
131 return aux; 118 return aux;
@@ -167,9 +154,13 @@ path_invalidate (struct CadetPeerPath *p)
167 if (NULL != p->path_delete) 154 if (NULL != p->path_delete)
168 return; 155 return;
169 156
170 LOG (GNUNET_ERROR_TYPE_INFO, "Invalidating path %p (%u)\n", p, p->length); 157 LOG (GNUNET_ERROR_TYPE_INFO,
171 p->path_delete = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 158 "Invalidating path %p (%u)\n",
172 &path_destroy_delayed, p); 159 p,
160 p->length);
161 p->path_delete
162 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
163 &path_destroy_delayed, p);
173} 164}
174 165
175 166
@@ -242,8 +233,8 @@ path_build_from_peer_ids (struct GNUNET_PeerIdentity *peers,
242 * @param p1 First path 233 * @param p1 First path
243 * @param p2 Second path 234 * @param p2 Second path
244 * 235 *
245 * @return GNUNET_YES if both paths are equivalent 236 * @return #GNUNET_YES if both paths are equivalent
246 * GNUNET_NO otherwise 237 * #GNUNET_NO otherwise
247 */ 238 */
248int 239int
249path_equivalent (const struct CadetPeerPath *p1, 240path_equivalent (const struct CadetPeerPath *p1,
@@ -293,7 +284,7 @@ path_is_valid (const struct CadetPeerPath *path)
293 * 284 *
294 * @param p the path to destroy 285 * @param p the path to destroy
295 * 286 *
296 * @return GNUNET_OK on success 287 * @return #GNUNET_OK on success
297 */ 288 */
298int 289int
299path_destroy (struct CadetPeerPath *p) 290path_destroy (struct CadetPeerPath *p)
@@ -301,7 +292,10 @@ path_destroy (struct CadetPeerPath *p)
301 if (NULL == p) 292 if (NULL == p)
302 return GNUNET_OK; 293 return GNUNET_OK;
303 294
304 LOG (GNUNET_ERROR_TYPE_INFO, "destroying path %p (%u)\n", p, p->length); 295 LOG (GNUNET_ERROR_TYPE_INFO,
296 "destroying path %p (%u)\n",
297 p,
298 p->length);
305 GNUNET_PEER_decrement_rcs (p->peers, p->length); 299 GNUNET_PEER_decrement_rcs (p->peers, p->length);
306 GNUNET_free_non_null (p->peers); 300 GNUNET_free_non_null (p->peers);
307 if (NULL != p->path_delete) 301 if (NULL != p->path_delete)
@@ -322,7 +316,8 @@ path_destroy (struct CadetPeerPath *p)
322 * 0 if they are identical. 316 * 0 if they are identical.
323 */ 317 */
324int 318int
325path_cmp (const struct CadetPeerPath *p1, const struct CadetPeerPath *p2) 319path_cmp (const struct CadetPeerPath *p1,
320 const struct CadetPeerPath *p2)
326{ 321{
327 if (p1->length > p2->length) 322 if (p1->length > p2->length)
328 return 1; 323 return 1;
@@ -330,7 +325,9 @@ path_cmp (const struct CadetPeerPath *p1, const struct CadetPeerPath *p2)
330 if (p1->length < p2->length) 325 if (p1->length < p2->length)
331 return -1; 326 return -1;
332 327
333 return memcmp (p1->peers, p2->peers, sizeof (GNUNET_PEER_Id) * p1->length); 328 return memcmp (p1->peers,
329 p2->peers,
330 sizeof (GNUNET_PEER_Id) * p1->length);
334} 331}
335 332
336 333
diff --git a/src/cadet/gnunet-cadet-profiler.c b/src/cadet/gnunet-cadet-profiler.c
index ffa993f8e..b2a07cb0c 100644
--- a/src/cadet/gnunet-cadet-profiler.c
+++ b/src/cadet/gnunet-cadet-profiler.c
@@ -147,7 +147,12 @@ struct CadetPeer
147 /** 147 /**
148 * Task to do the next ping. 148 * Task to do the next ping.
149 */ 149 */
150 struct GNUNET_SCHEDULER_Task * ping_task; 150 struct GNUNET_SCHEDULER_Task *ping_task;
151
152 /**
153 * NTR operation for the next ping.
154 */
155 struct GNUNET_CADET_TransmitHandle *ping_ntr;
151 156
152 float mean[number_rounds]; 157 float mean[number_rounds];
153 float var[number_rounds]; 158 float var[number_rounds];
@@ -179,7 +184,7 @@ static struct GNUNET_TESTBED_Operation *stats_op;
179/** 184/**
180 * Operation to get peer ids. 185 * Operation to get peer ids.
181 */ 186 */
182struct CadetPeer *peers; 187static struct CadetPeer *peers;
183 188
184/** 189/**
185 * Peer ids counter. 190 * Peer ids counter.
@@ -207,19 +212,14 @@ static unsigned long long peers_pinging;
207static struct GNUNET_CADET_TEST_Context *test_ctx; 212static struct GNUNET_CADET_TEST_Context *test_ctx;
208 213
209/** 214/**
210 * Task called to shutdown test.
211 */
212static struct GNUNET_SCHEDULER_Task * shutdown_handle;
213
214/**
215 * Task called to disconnect peers, before shutdown. 215 * Task called to disconnect peers, before shutdown.
216 */ 216 */
217static struct GNUNET_SCHEDULER_Task * disconnect_task; 217static struct GNUNET_SCHEDULER_Task *disconnect_task;
218 218
219/** 219/**
220 * Task to perform tests 220 * Task to perform tests
221 */ 221 */
222static struct GNUNET_SCHEDULER_Task * test_task; 222static struct GNUNET_SCHEDULER_Task *test_task;
223 223
224/** 224/**
225 * Round number. 225 * Round number.
@@ -241,6 +241,11 @@ static unsigned int peers_warmup;
241 */ 241 */
242static int test_finished; 242static int test_finished;
243 243
244/**
245 * Task running each round of the benchmark.
246 */
247static struct GNUNET_SCHEDULER_Task *round_task;
248
244 249
245/** 250/**
246 * START THE TEST ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES. 251 * START THE TEST ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES.
@@ -310,19 +315,6 @@ show_end_data (void)
310 315
311 316
312/** 317/**
313 * Shut down peergroup, clean up.
314 *
315 * @param cls Closure (unused).
316 */
317static void
318shutdown_task (void *cls)
319{
320 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Ending test.\n");
321 shutdown_handle = NULL;
322}
323
324
325/**
326 * Disconnect from cadet services af all peers, call shutdown. 318 * Disconnect from cadet services af all peers, call shutdown.
327 * 319 *
328 * @param cls Closure (unused). 320 * @param cls Closure (unused).
@@ -334,7 +326,8 @@ disconnect_cadet_peers (void *cls)
334 unsigned int i; 326 unsigned int i;
335 327
336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
337 "disconnecting cadet service, called from line %ld\n", line); 329 "disconnecting cadet service, called from line %ld\n",
330 line);
338 disconnect_task = NULL; 331 disconnect_task = NULL;
339 for (i = 0; i < peers_total; i++) 332 for (i = 0; i < peers_total; i++)
340 { 333 {
@@ -346,28 +339,56 @@ disconnect_cadet_peers (void *cls)
346 339
347 if (NULL != peers[i].ch) 340 if (NULL != peers[i].ch)
348 { 341 {
349 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u: channel %p\n", i, peers[i].ch); 342 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
343 "%u: channel %p\n", i, peers[i].ch);
350 GNUNET_CADET_channel_destroy (peers[i].ch); 344 GNUNET_CADET_channel_destroy (peers[i].ch);
351 } 345 }
352 if (NULL != peers[i].warmup_ch) 346 if (NULL != peers[i].warmup_ch)
353 { 347 {
354 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u: warmup channel %p\n", 348 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
349 "%u: warmup channel %p\n",
355 i, peers[i].warmup_ch); 350 i, peers[i].warmup_ch);
356 GNUNET_CADET_channel_destroy (peers[i].warmup_ch); 351 GNUNET_CADET_channel_destroy (peers[i].warmup_ch);
357 } 352 }
358 if (NULL != peers[i].incoming_ch) 353 if (NULL != peers[i].incoming_ch)
359 { 354 {
360 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u: incoming channel %p\n", 355 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
356 "%u: incoming channel %p\n",
361 i, peers[i].incoming_ch); 357 i, peers[i].incoming_ch);
362 GNUNET_CADET_channel_destroy (peers[i].incoming_ch); 358 GNUNET_CADET_channel_destroy (peers[i].incoming_ch);
363 } 359 }
364 } 360 }
365 GNUNET_CADET_TEST_cleanup (test_ctx); 361 GNUNET_CADET_TEST_cleanup (test_ctx);
366 if (NULL != shutdown_handle) 362 GNUNET_SCHEDULER_shutdown ();
363}
364
365
366/**
367 * Shut down peergroup, clean up.
368 *
369 * @param cls Closure (unused).
370 */
371static void
372shutdown_task (void *cls)
373{
374 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
375 "Ending test.\n");
376 if (NULL != disconnect_task)
367 { 377 {
368 GNUNET_SCHEDULER_cancel (shutdown_handle); 378 GNUNET_SCHEDULER_cancel (disconnect_task);
379 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
380 (void *) __LINE__);
381 }
382 if (NULL != round_task)
383 {
384 GNUNET_SCHEDULER_cancel (round_task);
385 round_task = NULL;
386 }
387 if (NULL != test_task)
388 {
389 GNUNET_SCHEDULER_cancel (test_task);
390 test_task = NULL;
369 } 391 }
370 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
371} 392}
372 393
373 394
@@ -418,13 +439,16 @@ stats_cont (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
418 * @param subsystem name of subsystem that created the statistic 439 * @param subsystem name of subsystem that created the statistic
419 * @param name the name of the datum 440 * @param name the name of the datum
420 * @param value the current value 441 * @param value the current value
421 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not 442 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
422 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration 443 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
423 */ 444 */
424static int 445static int
425stats_iterator (void *cls, const struct GNUNET_TESTBED_Peer *peer, 446stats_iterator (void *cls,
426 const char *subsystem, const char *name, 447 const struct GNUNET_TESTBED_Peer *peer,
427 uint64_t value, int is_persistent) 448 const char *subsystem,
449 const char *name,
450 uint64_t value,
451 int is_persistent)
428{ 452{
429 uint32_t i; 453 uint32_t i;
430 454
@@ -444,16 +468,13 @@ stats_iterator (void *cls, const struct GNUNET_TESTBED_Peer *peer,
444static void 468static void
445collect_stats (void *cls) 469collect_stats (void *cls)
446{ 470{
447 const struct GNUNET_SCHEDULER_TaskContext *tc; 471 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
448 472 "Start collecting statistics...\n");
449 tc = GNUNET_SCHEDULER_get_task_context (); 473 stats_op = GNUNET_TESTBED_get_statistics (peers_total,
450 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0) 474 testbed_handles,
451 return;
452
453 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start collecting statistics...\n");
454 stats_op = GNUNET_TESTBED_get_statistics (peers_total, testbed_handles,
455 NULL, NULL, 475 NULL, NULL,
456 stats_iterator, stats_cont, NULL); 476 &stats_iterator,
477 &stats_cont, NULL);
457} 478}
458 479
459 480
@@ -465,17 +486,12 @@ collect_stats (void *cls)
465static void 486static void
466finish_profiler (void *cls) 487finish_profiler (void *cls)
467{ 488{
468 const struct GNUNET_SCHEDULER_TaskContext *tc;
469
470 tc = GNUNET_SCHEDULER_get_task_context ();
471 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
472 return;
473
474 test_finished = GNUNET_YES; 489 test_finished = GNUNET_YES;
475 show_end_data(); 490 show_end_data ();
476 GNUNET_SCHEDULER_add_now (&collect_stats, NULL); 491 GNUNET_SCHEDULER_add_now (&collect_stats, NULL);
477} 492}
478 493
494
479/** 495/**
480 * Set the total number of running peers. 496 * Set the total number of running peers.
481 * 497 *
@@ -515,9 +531,15 @@ adjust_running_peers (unsigned int target)
515 run ? "arting" : "opping", r, GNUNET_i2s (&peers[r].id)); 531 run ? "arting" : "opping", r, GNUNET_i2s (&peers[r].id));
516 532
517 if (NULL != peers[r].ping_task) 533 if (NULL != peers[r].ping_task)
534 {
518 GNUNET_SCHEDULER_cancel (peers[r].ping_task); 535 GNUNET_SCHEDULER_cancel (peers[r].ping_task);
519 peers[r].ping_task = NULL; 536 peers[r].ping_task = NULL;
520 537 }
538 if (NULL != peers[r].ping_ntr)
539 {
540 GNUNET_CADET_notify_transmit_ready_cancel (peers[r].ping_ntr);
541 peers[r].ping_ntr = NULL;
542 }
521 peers[r].up = run; 543 peers[r].up = run;
522 544
523 if (NULL != peers[r].ch) 545 if (NULL != peers[r].ch)
@@ -547,12 +569,6 @@ adjust_running_peers (unsigned int target)
547static void 569static void
548next_rnd (void *cls) 570next_rnd (void *cls)
549{ 571{
550 const struct GNUNET_SCHEDULER_TaskContext *tc;
551
552 tc = GNUNET_SCHEDULER_get_task_context ();
553 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
554 return;
555
556 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ROUND %ld\n", current_round); 572 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ROUND %ld\n", current_round);
557 if (0.0 == rounds[current_round]) 573 if (0.0 == rounds[current_round])
558 { 574 {
@@ -563,7 +579,9 @@ next_rnd (void *cls)
563 adjust_running_peers (rounds[current_round] * peers_total); 579 adjust_running_peers (rounds[current_round] * peers_total);
564 current_round++; 580 current_round++;
565 581
566 GNUNET_SCHEDULER_add_delayed (round_time, &next_rnd, NULL); 582 round_task = GNUNET_SCHEDULER_add_delayed (round_time,
583 &next_rnd,
584 NULL);
567} 585}
568 586
569 587
@@ -616,21 +634,19 @@ static void
616ping (void *cls) 634ping (void *cls)
617{ 635{
618 struct CadetPeer *peer = cls; 636 struct CadetPeer *peer = cls;
619 const struct GNUNET_SCHEDULER_TaskContext *tc;
620 637
621 peer->ping_task = NULL; 638 peer->ping_task = NULL;
622 tc = GNUNET_SCHEDULER_get_task_context (); 639 if (GNUNET_YES == test_finished)
623 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)
624 || GNUNET_YES == test_finished)
625 return; 640 return;
626 641 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
627 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u -> %u (%u)\n", 642 "%u -> %u (%u)\n",
628 get_index (peer), get_index (peer->dest), peer->data_sent); 643 get_index (peer),
629 644 get_index (peer->dest),
630 GNUNET_CADET_notify_transmit_ready (peer->ch, GNUNET_NO, 645 peer->data_sent);
631 GNUNET_TIME_UNIT_FOREVER_REL, 646 peer->ping_ntr = GNUNET_CADET_notify_transmit_ready (peer->ch, GNUNET_NO,
632 sizeof (struct CadetPingMessage), 647 GNUNET_TIME_UNIT_FOREVER_REL,
633 &tmt_rdy_ping, peer); 648 sizeof (struct CadetPingMessage),
649 &tmt_rdy_ping, peer);
634} 650}
635 651
636/** 652/**
@@ -640,12 +656,13 @@ ping (void *cls)
640 * @param tc Task context. 656 * @param tc Task context.
641 */ 657 */
642static void 658static void
643pong (struct GNUNET_CADET_Channel *channel, const struct CadetPingMessage *ping) 659pong (struct GNUNET_CADET_Channel *channel,
660 const struct CadetPingMessage *ping)
644{ 661{
645 struct CadetPingMessage *copy; 662 struct CadetPingMessage *copy;
646 663
647 copy = GNUNET_new (struct CadetPingMessage); 664 copy = GNUNET_new (struct CadetPingMessage);
648 memcpy (copy, ping, sizeof (*ping)); 665 *copy = *ping;
649 GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO, 666 GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
650 GNUNET_TIME_UNIT_FOREVER_REL, 667 GNUNET_TIME_UNIT_FOREVER_REL,
651 sizeof (struct CadetPingMessage), 668 sizeof (struct CadetPingMessage),
@@ -666,7 +683,9 @@ tmt_rdy_ping (void *cls, size_t size, void *buf)
666 struct CadetPeer *peer = (struct CadetPeer *) cls; 683 struct CadetPeer *peer = (struct CadetPeer *) cls;
667 struct CadetPingMessage *msg = buf; 684 struct CadetPingMessage *msg = buf;
668 685
669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tmt_rdy called, filling buffer\n"); 686 peer->ping_ntr = NULL;
687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
688 "tmt_rdy called, filling buffer\n");
670 if (size < sizeof (struct CadetPingMessage) || NULL == buf) 689 if (size < sizeof (struct CadetPingMessage) || NULL == buf)
671 { 690 {
672 GNUNET_break (GNUNET_YES == test_finished); 691 GNUNET_break (GNUNET_YES == test_finished);
@@ -827,7 +846,8 @@ incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel,
827 * with the channel is stored 846 * with the channel is stored
828 */ 847 */
829static void 848static void
830channel_cleaner (void *cls, const struct GNUNET_CADET_Channel *channel, 849channel_cleaner (void *cls,
850 const struct GNUNET_CADET_Channel *channel,
831 void *channel_ctx) 851 void *channel_ctx)
832{ 852{
833 long n = (long) cls; 853 long n = (long) cls;
@@ -874,13 +894,8 @@ start_test (void *cls)
874{ 894{
875 enum GNUNET_CADET_ChannelOption flags; 895 enum GNUNET_CADET_ChannelOption flags;
876 unsigned long i; 896 unsigned long i;
877 const struct GNUNET_SCHEDULER_TaskContext *tc;
878 897
879 test_task = NULL; 898 test_task = NULL;
880 tc = GNUNET_SCHEDULER_get_task_context ();
881 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
882 return;
883
884 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start profiler\n"); 899 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start profiler\n");
885 900
886 flags = GNUNET_CADET_OPTION_DEFAULT; 901 flags = GNUNET_CADET_OPTION_DEFAULT;
@@ -909,7 +924,9 @@ start_test (void *cls)
909 number_rounds + 1), 924 number_rounds + 1),
910 &disconnect_cadet_peers, 925 &disconnect_cadet_peers,
911 (void *) __LINE__); 926 (void *) __LINE__);
912 GNUNET_SCHEDULER_add_delayed (round_time, &next_rnd, NULL); 927 round_task = GNUNET_SCHEDULER_add_delayed (round_time,
928 &next_rnd,
929 NULL);
913} 930}
914 931
915 932
@@ -939,6 +956,7 @@ warmup (void)
939 } 956 }
940} 957}
941 958
959
942/** 960/**
943 * Callback to be called when the requested peer information is available 961 * Callback to be called when the requested peer information is available
944 * 962 *
@@ -950,9 +968,9 @@ warmup (void)
950 */ 968 */
951static void 969static void
952peer_id_cb (void *cls, 970peer_id_cb (void *cls,
953 struct GNUNET_TESTBED_Operation *op, 971 struct GNUNET_TESTBED_Operation *op,
954 const struct GNUNET_TESTBED_PeerInformation *pinfo, 972 const struct GNUNET_TESTBED_PeerInformation *pinfo,
955 const char *emsg) 973 const char *emsg)
956{ 974{
957 long n = (long) cls; 975 long n = (long) cls;
958 976
@@ -991,6 +1009,7 @@ peer_id_cb (void *cls,
991 &start_test, NULL); 1009 &start_test, NULL);
992} 1010}
993 1011
1012
994/** 1013/**
995 * test main: start test when all peers are connected 1014 * test main: start test when all peers are connected
996 * 1015 *
@@ -1009,7 +1028,8 @@ tmain (void *cls,
1009{ 1028{
1010 unsigned long i; 1029 unsigned long i;
1011 1030
1012 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test main\n"); 1031 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1032 "test main\n");
1013 test_ctx = ctx; 1033 test_ctx = ctx;
1014 GNUNET_assert (peers_total == num_peers); 1034 GNUNET_assert (peers_total == num_peers);
1015 peers_running = num_peers; 1035 peers_running = num_peers;
@@ -1017,11 +1037,12 @@ tmain (void *cls,
1017 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, 1037 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
1018 &disconnect_cadet_peers, 1038 &disconnect_cadet_peers,
1019 (void *) __LINE__); 1039 (void *) __LINE__);
1020 shutdown_handle = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 1040 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1021 &shutdown_task, NULL);
1022 for (i = 0; i < peers_total; i++) 1041 for (i = 0; i < peers_total; i++)
1023 { 1042 {
1024 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requesting id %ld\n", i); 1043 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1044 "requesting id %ld\n",
1045 i);
1025 peers[i].up = GNUNET_YES; 1046 peers[i].up = GNUNET_YES;
1026 peers[i].cadet = cadetes[i]; 1047 peers[i].cadet = cadetes[i];
1027 peers[i].op = 1048 peers[i].op =
@@ -1047,25 +1068,35 @@ main (int argc, char *argv[])
1047 1068
1048 if (4 > argc) 1069 if (4 > argc)
1049 { 1070 {
1050 fprintf (stderr, "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n", argv[0]); 1071 fprintf (stderr,
1051 fprintf (stderr, "example: %s 30s 16 1 Y\n", argv[0]); 1072 "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n",
1073 argv[0]);
1074 fprintf (stderr,
1075 "example: %s 30s 16 1 Y\n",
1076 argv[0]);
1052 return 1; 1077 return 1;
1053 } 1078 }
1054 1079
1055 if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[1], &round_time)) 1080 if (GNUNET_OK !=
1081 GNUNET_STRINGS_fancy_time_to_relative (argv[1],
1082 &round_time))
1056 { 1083 {
1057 fprintf (stderr, "%s is not a valid time\n", argv[1]); 1084 fprintf (stderr,
1085 "%s is not a valid time\n",
1086 argv[1]);
1058 return 1; 1087 return 1;
1059 } 1088 }
1060 1089
1061 peers_total = atoll (argv[2]); 1090 peers_total = atoll (argv[2]);
1062 if (2 > peers_total) 1091 if (2 > peers_total)
1063 { 1092 {
1064 fprintf (stderr, "%s peers is not valid (> 2)\n", argv[1]); 1093 fprintf (stderr,
1094 "%s peers is not valid (> 2)\n",
1095 argv[1]);
1065 return 1; 1096 return 1;
1066 } 1097 }
1067 peers = GNUNET_malloc (sizeof (struct CadetPeer) * peers_total); 1098 peers = GNUNET_new_array (peers_total,
1068 1099 struct CadetPeer);
1069 peers_pinging = atoll (argv[3]); 1100 peers_pinging = atoll (argv[3]);
1070 1101
1071 if (peers_total < 2 * peers_pinging) 1102 if (peers_total < 2 * peers_pinging)
@@ -1077,7 +1108,8 @@ main (int argc, char *argv[])
1077 1108
1078 do_warmup = (5 > argc || argv[4][0] != 'N'); 1109 do_warmup = (5 > argc || argv[4][0] != 'N');
1079 1110
1080 ids = GNUNET_CONTAINER_multipeermap_create (2 * peers_total, GNUNET_YES); 1111 ids = GNUNET_CONTAINER_multipeermap_create (2 * peers_total,
1112 GNUNET_YES);
1081 GNUNET_assert (NULL != ids); 1113 GNUNET_assert (NULL != ids);
1082 p_ids = 0; 1114 p_ids = 0;
1083 test_finished = GNUNET_NO; 1115 test_finished = GNUNET_NO;
diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c
index 14b499aae..6453392d8 100644
--- a/src/cadet/gnunet-cadet.c
+++ b/src/cadet/gnunet-cadet.c
@@ -72,22 +72,22 @@ static uint32_t listen_port;
72/** 72/**
73 * Request echo service 73 * Request echo service
74 */ 74 */
75int echo; 75static int echo;
76 76
77/** 77/**
78 * Request a debug dump 78 * Request a debug dump
79 */ 79 */
80int dump; 80static int dump;
81 81
82/** 82/**
83 * Time of last echo request. 83 * Time of last echo request.
84 */ 84 */
85struct GNUNET_TIME_Absolute echo_time; 85static struct GNUNET_TIME_Absolute echo_time;
86 86
87/** 87/**
88 * Task for next echo request. 88 * Task for next echo request.
89 */ 89 */
90struct GNUNET_SCHEDULER_Task * echo_task; 90static struct GNUNET_SCHEDULER_Task *echo_task;
91 91
92/** 92/**
93 * Peer to connect to. 93 * Peer to connect to.
@@ -102,8 +102,7 @@ static uint32_t target_port;
102/** 102/**
103 * Data pending in netcat mode. 103 * Data pending in netcat mode.
104 */ 104 */
105size_t data_size; 105static size_t data_size;
106
107 106
108/** 107/**
109 * Cadet handle. 108 * Cadet handle.
@@ -123,8 +122,17 @@ static struct GNUNET_CADET_TransmitHandle *th;
123/** 122/**
124 * Shutdown task handle. 123 * Shutdown task handle.
125 */ 124 */
126struct GNUNET_SCHEDULER_Task * sd; 125static struct GNUNET_SCHEDULER_Task *sd;
127 126
127/**
128 * Task for reading from stdin.
129 */
130static struct GNUNET_SCHEDULER_Task *rd_task;
131
132/**
133 * Task for main job.
134 */
135static struct GNUNET_SCHEDULER_Task *job;
128 136
129 137
130static void 138static void
@@ -195,7 +203,8 @@ conn_2s (uint16_t status)
195static void 203static void
196shutdown_task (void *cls) 204shutdown_task (void *cls)
197{ 205{
198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n"); 206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
207 "Shutdown\n");
199 if (NULL != th) 208 if (NULL != th)
200 { 209 {
201 GNUNET_CADET_notify_transmit_ready_cancel (th); 210 GNUNET_CADET_notify_transmit_ready_cancel (th);
@@ -209,7 +218,22 @@ shutdown_task (void *cls)
209 if (NULL != mh) 218 if (NULL != mh)
210 { 219 {
211 GNUNET_CADET_disconnect (mh); 220 GNUNET_CADET_disconnect (mh);
212 mh = NULL; 221 mh = NULL;
222 }
223 if (NULL != rd_task)
224 {
225 GNUNET_SCHEDULER_cancel (rd_task);
226 rd_task = NULL;
227 }
228 if (NULL != echo_task)
229 {
230 GNUNET_SCHEDULER_cancel (echo_task);
231 echo_task = NULL;
232 }
233 if (NULL != job)
234 {
235 GNUNET_SCHEDULER_cancel (job);
236 job = NULL;
213 } 237 }
214} 238}
215 239
@@ -227,7 +251,7 @@ shutdown_task (void *cls)
227 * @param buf where the callee should write the message 251 * @param buf where the callee should write the message
228 * @return number of bytes written to buf 252 * @return number of bytes written to buf
229 */ 253 */
230size_t 254static size_t
231data_ready (void *cls, size_t size, void *buf) 255data_ready (void *cls, size_t size, void *buf)
232{ 256{
233 struct GNUNET_MessageHeader *msg; 257 struct GNUNET_MessageHeader *msg;
@@ -271,13 +295,6 @@ static void
271read_stdio (void *cls) 295read_stdio (void *cls)
272{ 296{
273 static char buf[60000]; 297 static char buf[60000];
274 const struct GNUNET_SCHEDULER_TaskContext *tc;
275
276 tc = GNUNET_SCHEDULER_get_task_context ();
277 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
278 {
279 return;
280 }
281 298
282 data_size = read (0, buf, 60000); 299 data_size = read (0, buf, 60000);
283 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "stdio read %u bytes\n", data_size); 300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "stdio read %u bytes\n", data_size);
@@ -305,10 +322,10 @@ listen_stdio (void)
305 322
306 rs = GNUNET_NETWORK_fdset_create (); 323 rs = GNUNET_NETWORK_fdset_create ();
307 GNUNET_NETWORK_fdset_set_native (rs, 0); 324 GNUNET_NETWORK_fdset_set_native (rs, 0);
308 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 325 rd_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
309 GNUNET_TIME_UNIT_FOREVER_REL, 326 GNUNET_TIME_UNIT_FOREVER_REL,
310 rs, NULL, 327 rs, NULL,
311 &read_stdio, NULL); 328 &read_stdio, NULL);
312 GNUNET_NETWORK_fdset_destroy (rs); 329 GNUNET_NETWORK_fdset_destroy (rs);
313} 330}
314 331
@@ -408,12 +425,8 @@ channel_incoming (void *cls,
408static void 425static void
409send_echo (void *cls) 426send_echo (void *cls)
410{ 427{
411 const struct GNUNET_SCHEDULER_TaskContext *tc; 428 if (NULL == ch)
412
413 tc = GNUNET_SCHEDULER_get_task_context ();
414 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) || NULL == ch)
415 return; 429 return;
416
417 GNUNET_assert (NULL == th); 430 GNUNET_assert (NULL == th);
418 th = GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO, 431 th = GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO,
419 GNUNET_TIME_UNIT_FOREVER_REL, 432 GNUNET_TIME_UNIT_FOREVER_REL,
@@ -432,7 +445,8 @@ request_dump (void *cls)
432{ 445{
433 GNUNET_CADET_request_dump (mh); 446 GNUNET_CADET_request_dump (mh);
434 GNUNET_SCHEDULER_cancel (sd); 447 GNUNET_SCHEDULER_cancel (sd);
435 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &shutdown_task, NULL); 448 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
449 &shutdown_task, NULL);
436} 450}
437 451
438 452
@@ -466,7 +480,7 @@ create_channel (void *cls)
466 if (GNUNET_NO == echo) 480 if (GNUNET_NO == echo)
467 listen_stdio (); 481 listen_stdio ();
468 else 482 else
469 GNUNET_SCHEDULER_add_now (send_echo, NULL); 483 echo_task = GNUNET_SCHEDULER_add_now (&send_echo, NULL);
470} 484}
471 485
472 486
@@ -561,8 +575,11 @@ data_callback (void *cls,
561 * (0 = unknown, 1 = ourselves, 2 = neighbor) 575 * (0 = unknown, 1 = ourselves, 2 = neighbor)
562 */ 576 */
563static void 577static void
564peers_callback (void *cls, const struct GNUNET_PeerIdentity *peer, 578peers_callback (void *cls,
565 int tunnel, unsigned int n_paths, unsigned int best_path) 579 const struct GNUNET_PeerIdentity *peer,
580 int tunnel,
581 unsigned int n_paths,
582 unsigned int best_path)
566{ 583{
567 if (NULL == peer) 584 if (NULL == peer)
568 { 585 {
@@ -589,7 +606,7 @@ peers_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
589 * Each path starts with the local peer. 606 * Each path starts with the local peer.
590 * Each path ends with the destination peer (given in @c peer). 607 * Each path ends with the destination peer (given in @c peer).
591 */ 608 */
592void 609static void
593peer_callback (void *cls, 610peer_callback (void *cls,
594 const struct GNUNET_PeerIdentity *peer, 611 const struct GNUNET_PeerIdentity *peer,
595 int tunnel, 612 int tunnel,
@@ -629,7 +646,7 @@ peer_callback (void *cls,
629 * @param estate Encryption state. 646 * @param estate Encryption state.
630 * @param cstate Connectivity state. 647 * @param cstate Connectivity state.
631 */ 648 */
632void 649static void
633tunnels_callback (void *cls, 650tunnels_callback (void *cls,
634 const struct GNUNET_PeerIdentity *peer, 651 const struct GNUNET_PeerIdentity *peer,
635 unsigned int channels, 652 unsigned int channels,
@@ -665,7 +682,7 @@ tunnels_callback (void *cls,
665 * @param estate Encryption status. 682 * @param estate Encryption status.
666 * @param cstate Connectivity status. 683 * @param cstate Connectivity status.
667 */ 684 */
668void 685static void
669tunnel_callback (void *cls, 686tunnel_callback (void *cls,
670 const struct GNUNET_PeerIdentity *peer, 687 const struct GNUNET_PeerIdentity *peer,
671 unsigned int n_channels, 688 unsigned int n_channels,
@@ -691,7 +708,7 @@ tunnel_callback (void *cls,
691 } 708 }
692 if (GNUNET_YES != monitor_mode) 709 if (GNUNET_YES != monitor_mode)
693 { 710 {
694 GNUNET_SCHEDULER_shutdown(); 711 GNUNET_SCHEDULER_shutdown ();
695 } 712 }
696 return; 713 return;
697} 714}
@@ -705,14 +722,7 @@ tunnel_callback (void *cls,
705static void 722static void
706get_peers (void *cls) 723get_peers (void *cls)
707{ 724{
708 const struct GNUNET_SCHEDULER_TaskContext *tc; 725 job = NULL;
709
710 tc = GNUNET_SCHEDULER_get_task_context ();
711 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
712 {
713 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
714 return;
715 }
716 GNUNET_CADET_get_peers (mh, &peers_callback, NULL); 726 GNUNET_CADET_get_peers (mh, &peers_callback, NULL);
717} 727}
718 728
@@ -727,6 +737,7 @@ show_peer (void *cls)
727{ 737{
728 struct GNUNET_PeerIdentity pid; 738 struct GNUNET_PeerIdentity pid;
729 739
740 job = NULL;
730 if (GNUNET_OK != 741 if (GNUNET_OK !=
731 GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id, 742 GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
732 strlen (peer_id), 743 strlen (peer_id),
@@ -741,6 +752,7 @@ show_peer (void *cls)
741 GNUNET_CADET_get_peer (mh, &pid, peer_callback, NULL); 752 GNUNET_CADET_get_peer (mh, &pid, peer_callback, NULL);
742} 753}
743 754
755
744/** 756/**
745 * Call CADET's meta API, get all tunnels known to a peer. 757 * Call CADET's meta API, get all tunnels known to a peer.
746 * 758 *
@@ -749,14 +761,7 @@ show_peer (void *cls)
749static void 761static void
750get_tunnels (void *cls) 762get_tunnels (void *cls)
751{ 763{
752 const struct GNUNET_SCHEDULER_TaskContext *tc; 764 job = NULL;
753
754 tc = GNUNET_SCHEDULER_get_task_context ();
755 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
756 {
757 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
758 return;
759 }
760 GNUNET_CADET_get_tunnels (mh, &tunnels_callback, NULL); 765 GNUNET_CADET_get_tunnels (mh, &tunnels_callback, NULL);
761} 766}
762 767
@@ -779,7 +784,7 @@ show_tunnel (void *cls)
779 fprintf (stderr, 784 fprintf (stderr,
780 _("Invalid tunnel owner `%s'\n"), 785 _("Invalid tunnel owner `%s'\n"),
781 tunnel_id); 786 tunnel_id);
782 GNUNET_SCHEDULER_shutdown(); 787 GNUNET_SCHEDULER_shutdown ();
783 return; 788 return;
784 } 789 }
785 GNUNET_CADET_get_tunnel (mh, &pid, tunnel_callback, NULL); 790 GNUNET_CADET_get_tunnel (mh, &pid, tunnel_callback, NULL);
@@ -794,7 +799,8 @@ show_tunnel (void *cls)
794static void 799static void
795show_channel (void *cls) 800show_channel (void *cls)
796{ 801{
797 802 job = NULL;
803 GNUNET_break (0);
798} 804}
799 805
800 806
@@ -806,7 +812,8 @@ show_channel (void *cls)
806static void 812static void
807show_connection (void *cls) 813show_connection (void *cls)
808{ 814{
809 815 job = NULL;
816 GNUNET_break (0);
810} 817}
811 818
812 819
@@ -819,7 +826,9 @@ show_connection (void *cls)
819 * @param cfg configuration 826 * @param cfg configuration
820 */ 827 */
821static void 828static void
822run (void *cls, char *const *args, const char *cfgfile, 829run (void *cls,
830 char *const *args,
831 const char *cfgfile,
823 const struct GNUNET_CONFIGURATION_Handle *cfg) 832 const struct GNUNET_CONFIGURATION_Handle *cfg)
824{ 833{
825 GNUNET_CADET_InboundChannelNotificationHandler *newch = NULL; 834 GNUNET_CADET_InboundChannelNotificationHandler *newch = NULL;
@@ -871,32 +880,32 @@ run (void *cls, char *const *args, const char *cfgfile,
871 else if (NULL != peer_id) 880 else if (NULL != peer_id)
872 { 881 {
873 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show peer\n"); 882 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show peer\n");
874 GNUNET_SCHEDULER_add_now (&show_peer, NULL); 883 job = GNUNET_SCHEDULER_add_now (&show_peer, NULL);
875 } 884 }
876 else if (NULL != tunnel_id) 885 else if (NULL != tunnel_id)
877 { 886 {
878 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show tunnel\n"); 887 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show tunnel\n");
879 GNUNET_SCHEDULER_add_now (&show_tunnel, NULL); 888 job = GNUNET_SCHEDULER_add_now (&show_tunnel, NULL);
880 } 889 }
881 else if (NULL != channel_id) 890 else if (NULL != channel_id)
882 { 891 {
883 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show channel\n"); 892 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show channel\n");
884 GNUNET_SCHEDULER_add_now (&show_channel, NULL); 893 job = GNUNET_SCHEDULER_add_now (&show_channel, NULL);
885 } 894 }
886 else if (NULL != conn_id) 895 else if (NULL != conn_id)
887 { 896 {
888 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show connection\n"); 897 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show connection\n");
889 GNUNET_SCHEDULER_add_now (&show_connection, NULL); 898 job = GNUNET_SCHEDULER_add_now (&show_connection, NULL);
890 } 899 }
891 else if (GNUNET_YES == request_peers) 900 else if (GNUNET_YES == request_peers)
892 { 901 {
893 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all peers\n"); 902 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all peers\n");
894 GNUNET_SCHEDULER_add_now (&get_peers, NULL); 903 job = GNUNET_SCHEDULER_add_now (&get_peers, NULL);
895 } 904 }
896 else if (GNUNET_YES == request_tunnels) 905 else if (GNUNET_YES == request_tunnels)
897 { 906 {
898 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all tunnels\n"); 907 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all tunnels\n");
899 GNUNET_SCHEDULER_add_now (&get_tunnels, NULL); 908 job = GNUNET_SCHEDULER_add_now (&get_tunnels, NULL);
900 } 909 }
901 else 910 else
902 { 911 {
@@ -913,11 +922,9 @@ run (void *cls, char *const *args, const char *cfgfile,
913 ports); 922 ports);
914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done\n"); 923 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done\n");
915 if (NULL == mh) 924 if (NULL == mh)
916 GNUNET_SCHEDULER_add_now (shutdown_task, NULL); 925 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
917 else 926 else
918 sd = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 927 sd = GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
919 shutdown_task, NULL);
920
921} 928}
922 929
923 930
diff --git a/src/cadet/gnunet-service-cadet.c b/src/cadet/gnunet-service-cadet.c
index a2e00300b..3a07f0ee5 100644
--- a/src/cadet/gnunet-service-cadet.c
+++ b/src/cadet/gnunet-service-cadet.c
@@ -135,8 +135,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
135 stats = GNUNET_STATISTICS_create ("cadet", c); 135 stats = GNUNET_STATISTICS_create ("cadet", c);
136 136
137 /* Scheduled the task to clean up when shutdown is called */ 137 /* Scheduled the task to clean up when shutdown is called */
138 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, 138 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
139 NULL); 139 NULL);
140 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "reading key\n"); 140 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "reading key\n");
141 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (c); 141 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (c);
142 GNUNET_assert (NULL != my_private_key); 142 GNUNET_assert (NULL != my_private_key);
diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c
index debae7d77..d4f9754da 100644
--- a/src/cadet/gnunet-service-cadet_channel.c
+++ b/src/cadet/gnunet-service-cadet_channel.c
@@ -730,13 +730,8 @@ channel_retransmit_message (void *cls)
730 struct CadetChannel *ch; 730 struct CadetChannel *ch;
731 struct GNUNET_CADET_Data *payload; 731 struct GNUNET_CADET_Data *payload;
732 int fwd; 732 int fwd;
733 const struct GNUNET_SCHEDULER_TaskContext *tc;
734 733
735 rel->retry_task = NULL; 734 rel->retry_task = NULL;
736 tc = GNUNET_SCHEDULER_get_task_context ();
737 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
738 return;
739
740 ch = rel->ch; 735 ch = rel->ch;
741 copy = rel->head_sent; 736 copy = rel->head_sent;
742 if (NULL == copy) 737 if (NULL == copy)
@@ -765,15 +760,11 @@ static void
765channel_recreate (void *cls) 760channel_recreate (void *cls)
766{ 761{
767 struct CadetChannelReliability *rel = cls; 762 struct CadetChannelReliability *rel = cls;
768 const struct GNUNET_SCHEDULER_TaskContext *tc;
769 763
770 rel->retry_task = NULL; 764 rel->retry_task = NULL;
771 tc = GNUNET_SCHEDULER_get_task_context ();
772 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
773 return;
774
775 LOG (GNUNET_ERROR_TYPE_DEBUG, "RE-CREATE\n"); 765 LOG (GNUNET_ERROR_TYPE_DEBUG, "RE-CREATE\n");
776 GNUNET_STATISTICS_update (stats, "# data retransmitted", 1, GNUNET_NO); 766 GNUNET_STATISTICS_update (stats,
767 "# data retransmitted", 1, GNUNET_NO);
777 768
778 if (rel == rel->ch->root_rel) 769 if (rel == rel->ch->root_rel)
779 { 770 {
@@ -787,7 +778,6 @@ channel_recreate (void *cls)
787 { 778 {
788 GNUNET_break (0); 779 GNUNET_break (0);
789 } 780 }
790
791} 781}
792 782
793 783
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c
index d11368a79..188041feb 100644
--- a/src/cadet/gnunet-service-cadet_connection.c
+++ b/src/cadet/gnunet-service-cadet_connection.c
@@ -1192,11 +1192,10 @@ connection_maintain (struct CadetConnection *c, int fwd)
1192 * 1192 *
1193 * @param c Connection to keep alive. 1193 * @param c Connection to keep alive.
1194 * @param fwd Direction. 1194 * @param fwd Direction.
1195 * @param shutdown Are we shutting down? (Don't send traffic)
1196 * Non-zero value for true, not necessarily GNUNET_YES.
1197 */ 1195 */
1198static void 1196static void
1199connection_keepalive (struct CadetConnection *c, int fwd, int shutdown) 1197connection_keepalive (struct CadetConnection *c,
1198 int fwd)
1200{ 1199{
1201 GCC_check_connections (); 1200 GCC_check_connections ();
1202 LOG (GNUNET_ERROR_TYPE_DEBUG, 1201 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1207,10 +1206,6 @@ connection_keepalive (struct CadetConnection *c, int fwd, int shutdown)
1207 c->fwd_maintenance_task = NULL; 1206 c->fwd_maintenance_task = NULL;
1208 else 1207 else
1209 c->bck_maintenance_task = NULL; 1208 c->bck_maintenance_task = NULL;
1210
1211 if (GNUNET_NO != shutdown)
1212 return;
1213
1214 connection_maintain (c, fwd); 1209 connection_maintain (c, fwd);
1215 GCC_check_connections (); 1210 GCC_check_connections ();
1216 /* Next execution will be scheduled by message_sent or _maintain*/ 1211 /* Next execution will be scheduled by message_sent or _maintain*/
@@ -1225,13 +1220,11 @@ connection_keepalive (struct CadetConnection *c, int fwd, int shutdown)
1225static void 1220static void
1226connection_fwd_keepalive (void *cls) 1221connection_fwd_keepalive (void *cls)
1227{ 1222{
1228 const struct GNUNET_SCHEDULER_TaskContext *tc; 1223 struct CadetConnection *c = cls;
1229 1224
1230 GCC_check_connections (); 1225 GCC_check_connections ();
1231 tc = GNUNET_SCHEDULER_get_task_context (); 1226 connection_keepalive (c,
1232 connection_keepalive ((struct CadetConnection *) cls, 1227 GNUNET_YES);
1233 GNUNET_YES,
1234 tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN);
1235 GCC_check_connections (); 1228 GCC_check_connections ();
1236} 1229}
1237 1230
@@ -1244,13 +1237,11 @@ connection_fwd_keepalive (void *cls)
1244static void 1237static void
1245connection_bck_keepalive (void *cls) 1238connection_bck_keepalive (void *cls)
1246{ 1239{
1247 const struct GNUNET_SCHEDULER_TaskContext *tc; 1240 struct CadetConnection *c = cls;
1248 1241
1249 GCC_check_connections (); 1242 GCC_check_connections ();
1250 tc = GNUNET_SCHEDULER_get_task_context (); 1243 connection_keepalive (c,
1251 connection_keepalive ((struct CadetConnection *) cls, 1244 GNUNET_NO);
1252 GNUNET_NO,
1253 tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN);
1254 GCC_check_connections (); 1245 GCC_check_connections ();
1255} 1246}
1256 1247
@@ -1461,16 +1452,9 @@ connection_poll (void *cls)
1461 struct GNUNET_CADET_Poll msg; 1452 struct GNUNET_CADET_Poll msg;
1462 struct CadetConnection *c; 1453 struct CadetConnection *c;
1463 int fwd; 1454 int fwd;
1464 const struct GNUNET_SCHEDULER_TaskContext *tc;
1465 1455
1466 fc->poll_task = NULL; 1456 fc->poll_task = NULL;
1467 GCC_check_connections (); 1457 GCC_check_connections ();
1468 tc = GNUNET_SCHEDULER_get_task_context ();
1469 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1470 {
1471 return;
1472 }
1473
1474 c = fc->c; 1458 c = fc->c;
1475 fwd = fc == &c->fwd_fc; 1459 fwd = fc == &c->fwd_fc;
1476 LOG (GNUNET_ERROR_TYPE_DEBUG, "Polling connection %s %s\n", 1460 LOG (GNUNET_ERROR_TYPE_DEBUG, "Polling connection %s %s\n",
@@ -1592,12 +1576,8 @@ static void
1592connection_fwd_timeout (void *cls) 1576connection_fwd_timeout (void *cls)
1593{ 1577{
1594 struct CadetConnection *c = cls; 1578 struct CadetConnection *c = cls;
1595 const struct GNUNET_SCHEDULER_TaskContext *tc;
1596 1579
1597 c->fwd_maintenance_task = NULL; 1580 c->fwd_maintenance_task = NULL;
1598 tc = GNUNET_SCHEDULER_get_task_context ();
1599 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1600 return;
1601 GCC_check_connections (); 1581 GCC_check_connections ();
1602 connection_timeout (c, GNUNET_YES); 1582 connection_timeout (c, GNUNET_YES);
1603 GCC_check_connections (); 1583 GCC_check_connections ();
@@ -1614,12 +1594,8 @@ static void
1614connection_bck_timeout (void *cls) 1594connection_bck_timeout (void *cls)
1615{ 1595{
1616 struct CadetConnection *c = cls; 1596 struct CadetConnection *c = cls;
1617 const struct GNUNET_SCHEDULER_TaskContext *tc;
1618 1597
1619 c->bck_maintenance_task = NULL; 1598 c->bck_maintenance_task = NULL;
1620 tc = GNUNET_SCHEDULER_get_task_context ();
1621 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1622 return;
1623 GCC_check_connections (); 1599 GCC_check_connections ();
1624 connection_timeout (c, GNUNET_NO); 1600 connection_timeout (c, GNUNET_NO);
1625 GCC_check_connections (); 1601 GCC_check_connections ();
@@ -1767,13 +1743,8 @@ static void
1767check_duplicates (void *cls) 1743check_duplicates (void *cls)
1768{ 1744{
1769 struct CadetConnection *c = cls; 1745 struct CadetConnection *c = cls;
1770 const struct GNUNET_SCHEDULER_TaskContext *tc;
1771 1746
1772 c->check_duplicates_task = NULL; 1747 c->check_duplicates_task = NULL;
1773 tc = GNUNET_SCHEDULER_get_task_context ();
1774 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1775 return;
1776
1777 if (GNUNET_YES == does_connection_exist (c)) 1748 if (GNUNET_YES == does_connection_exist (c))
1778 { 1749 {
1779 GCT_debug (c->t, GNUNET_ERROR_TYPE_DEBUG); 1750 GCT_debug (c->t, GNUNET_ERROR_TYPE_DEBUG);
@@ -1783,7 +1754,6 @@ check_duplicates (void *cls)
1783} 1754}
1784 1755
1785 1756
1786
1787/** 1757/**
1788 * Wait for enough time to let any dead connections time out and check for 1758 * Wait for enough time to let any dead connections time out and check for
1789 * any remaining duplicates. 1759 * any remaining duplicates.
@@ -1797,7 +1767,6 @@ schedule_check_duplicates (struct CadetConnection *c)
1797 1767
1798 if (NULL != c->check_duplicates_task) 1768 if (NULL != c->check_duplicates_task)
1799 return; 1769 return;
1800
1801 delay = GNUNET_TIME_relative_multiply (refresh_connection_time, 5); 1770 delay = GNUNET_TIME_relative_multiply (refresh_connection_time, 5);
1802 c->check_duplicates_task = GNUNET_SCHEDULER_add_delayed (delay, 1771 c->check_duplicates_task = GNUNET_SCHEDULER_add_delayed (delay,
1803 &check_duplicates, 1772 &check_duplicates,
@@ -1805,7 +1774,6 @@ schedule_check_duplicates (struct CadetConnection *c)
1805} 1774}
1806 1775
1807 1776
1808
1809/** 1777/**
1810 * Add the connection to the list of both neighbors. 1778 * Add the connection to the list of both neighbors.
1811 * 1779 *
@@ -1903,7 +1871,8 @@ unregister_neighbors (struct CadetConnection *c)
1903 * @param disconnected Peer that disconnected. 1871 * @param disconnected Peer that disconnected.
1904 */ 1872 */
1905static void 1873static void
1906invalidate_paths (struct CadetConnection *c, struct CadetPeer *disconnected) 1874invalidate_paths (struct CadetConnection *c,
1875 struct CadetPeer *disconnected)
1907{ 1876{
1908 struct CadetPeer *peer; 1877 struct CadetPeer *peer;
1909 unsigned int i; 1878 unsigned int i;
diff --git a/src/cadet/gnunet-service-cadet_dht.c b/src/cadet/gnunet-service-cadet_dht.c
index 088d40eac..88a601b52 100644
--- a/src/cadet/gnunet-service-cadet_dht.c
+++ b/src/cadet/gnunet-service-cadet_dht.c
@@ -215,14 +215,8 @@ announce_id (void *cls)
215 size_t size; 215 size_t size;
216 struct GNUNET_TIME_Absolute expiration; 216 struct GNUNET_TIME_Absolute expiration;
217 struct GNUNET_TIME_Relative retry_time; 217 struct GNUNET_TIME_Relative retry_time;
218 const struct GNUNET_SCHEDULER_TaskContext *tc;
219 218
220 tc = GNUNET_SCHEDULER_get_task_context (); 219 announce_id_task = NULL;
221 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
222 {
223 announce_id_task = NULL;
224 return;
225 }
226 LOG (GNUNET_ERROR_TYPE_DEBUG, "Announce ID\n"); 220 LOG (GNUNET_ERROR_TYPE_DEBUG, "Announce ID\n");
227 /* TODO 221 /* TODO
228 * - Set data expiration in function of X 222 * - Set data expiration in function of X
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c
index 51af04527..46961250b 100644
--- a/src/cadet/gnunet-service-cadet_peer.c
+++ b/src/cadet/gnunet-service-cadet_peer.c
@@ -387,7 +387,6 @@ notify_broken (void *cls,
387 * Remove the direct path to the peer. 387 * Remove the direct path to the peer.
388 * 388 *
389 * @param peer Peer to remove the direct path from. 389 * @param peer Peer to remove the direct path from.
390 *
391 */ 390 */
392static struct CadetPeerPath * 391static struct CadetPeerPath *
393pop_direct_path (struct CadetPeer *peer) 392pop_direct_path (struct CadetPeer *peer)
@@ -398,7 +397,9 @@ pop_direct_path (struct CadetPeer *peer)
398 { 397 {
399 if (2 >= iter->length) 398 if (2 >= iter->length)
400 { 399 {
401 GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, iter); 400 GNUNET_CONTAINER_DLL_remove (peer->path_head,
401 peer->path_tail,
402 iter);
402 return iter; 403 return iter;
403 } 404 }
404 } 405 }
@@ -750,7 +751,8 @@ peer_destroy (struct CadetPeer *peer)
750 "destroying peer %s\n", 751 "destroying peer %s\n",
751 GNUNET_i2s (&id)); 752 GNUNET_i2s (&id));
752 753
753 if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_remove (peers, &id, peer)) 754 if (GNUNET_YES !=
755 GNUNET_CONTAINER_multipeermap_remove (peers, &id, peer))
754 { 756 {
755 GNUNET_break (0); 757 GNUNET_break (0);
756 LOG (GNUNET_ERROR_TYPE_WARNING, " peer not in peermap!!\n"); 758 LOG (GNUNET_ERROR_TYPE_WARNING, " peer not in peermap!!\n");
@@ -846,12 +848,8 @@ static void
846delayed_search (void *cls) 848delayed_search (void *cls)
847{ 849{
848 struct CadetPeer *peer = cls; 850 struct CadetPeer *peer = cls;
849 const struct GNUNET_SCHEDULER_TaskContext *tc;
850 851
851 peer->search_delayed = NULL; 852 peer->search_delayed = NULL;
852 tc = GNUNET_SCHEDULER_get_task_context ();
853 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
854 return;
855 GCC_check_connections (); 853 GCC_check_connections ();
856 GCP_start_search (peer); 854 GCP_start_search (peer);
857 GCC_check_connections (); 855 GCC_check_connections ();
@@ -1934,8 +1932,9 @@ GCP_get (const struct GNUNET_PeerIdentity *peer_id, int create)
1934 1932
1935 1933
1936/** 1934/**
1937 * Retrieve the CadetPeer stucture associated with the peer. Optionally create 1935 * Retrieve the CadetPeer stucture associated with the
1938 * one and insert it in the appropriate structures if the peer is not known yet. 1936 * peer. Optionally create one and insert it in the appropriate
1937 * structures if the peer is not known yet.
1939 * 1938 *
1940 * @param peer Short identity of the peer. 1939 * @param peer Short identity of the peer.
1941 * @param create #GNUNET_YES if a new peer should be created if unknown. 1940 * @param create #GNUNET_YES if a new peer should be created if unknown.
@@ -2223,7 +2222,8 @@ GCP_add_path (struct CadetPeer *peer,
2223 } 2222 }
2224 } 2223 }
2225 } 2224 }
2226 GNUNET_CONTAINER_DLL_insert_tail (peer->path_head, peer->path_tail, 2225 GNUNET_CONTAINER_DLL_insert_tail (peer->path_head,
2226 peer->path_tail,
2227 path); 2227 path);
2228 LOG (GNUNET_ERROR_TYPE_DEBUG, " added last\n"); 2228 LOG (GNUNET_ERROR_TYPE_DEBUG, " added last\n");
2229 2229
@@ -2300,7 +2300,8 @@ GCP_add_path_to_all (const struct CadetPeerPath *p, int confirmed)
2300 * @param path Path to remove. Is always destroyed . 2300 * @param path Path to remove. Is always destroyed .
2301 */ 2301 */
2302void 2302void
2303GCP_remove_path (struct CadetPeer *peer, struct CadetPeerPath *path) 2303GCP_remove_path (struct CadetPeer *peer,
2304 struct CadetPeerPath *path)
2304{ 2305{
2305 struct CadetPeerPath *iter; 2306 struct CadetPeerPath *iter;
2306 struct CadetPeerPath *next; 2307 struct CadetPeerPath *next;
@@ -2309,7 +2310,8 @@ GCP_remove_path (struct CadetPeer *peer, struct CadetPeerPath *path)
2309 GNUNET_assert (myid == path->peers[0]); 2310 GNUNET_assert (myid == path->peers[0]);
2310 GNUNET_assert (peer->id == path->peers[path->length - 1]); 2311 GNUNET_assert (peer->id == path->peers[path->length - 1]);
2311 2312
2312 LOG (GNUNET_ERROR_TYPE_INFO, "Removing path %p (%u) from %s\n", 2313 LOG (GNUNET_ERROR_TYPE_INFO,
2314 "Removing path %p (%u) from %s\n",
2313 path, path->length, GCP_2s (peer)); 2315 path, path->length, GCP_2s (peer));
2314 2316
2315 for (iter = peer->path_head; NULL != iter; iter = next) 2317 for (iter = peer->path_head; NULL != iter; iter = next)
@@ -2317,7 +2319,9 @@ GCP_remove_path (struct CadetPeer *peer, struct CadetPeerPath *path)
2317 next = iter->next; 2319 next = iter->next;
2318 if (0 == path_cmp (path, iter)) 2320 if (0 == path_cmp (path, iter))
2319 { 2321 {
2320 GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, iter); 2322 GNUNET_CONTAINER_DLL_remove (peer->path_head,
2323 peer->path_tail,
2324 iter);
2321 if (iter != path) 2325 if (iter != path)
2322 path_destroy (iter); 2326 path_destroy (iter);
2323 } 2327 }
@@ -2512,7 +2516,8 @@ GCP_get_tunnel (const struct CadetPeer *peer)
2512 * @param hello Hello message. 2516 * @param hello Hello message.
2513 */ 2517 */
2514void 2518void
2515GCP_set_hello (struct CadetPeer *peer, const struct GNUNET_HELLO_Message *hello) 2519GCP_set_hello (struct CadetPeer *peer,
2520 const struct GNUNET_HELLO_Message *hello)
2516{ 2521{
2517 struct GNUNET_HELLO_Message *old; 2522 struct GNUNET_HELLO_Message *old;
2518 size_t size; 2523 size_t size;
diff --git a/src/cadet/gnunet-service-cadet_tunnel.c b/src/cadet/gnunet-service-cadet_tunnel.c
index 73bd28643..b9f0e1fa2 100644
--- a/src/cadet/gnunet-service-cadet_tunnel.c
+++ b/src/cadet/gnunet-service-cadet_tunnel.c
@@ -1735,16 +1735,8 @@ static void
1735finish_kx (void *cls) 1735finish_kx (void *cls)
1736{ 1736{
1737 struct CadetTunnel *t = cls; 1737 struct CadetTunnel *t = cls;
1738 const struct GNUNET_SCHEDULER_TaskContext *tc;
1739 1738
1740 LOG (GNUNET_ERROR_TYPE_INFO, "finish KX for %s\n", GCT_2s (t)); 1739 LOG (GNUNET_ERROR_TYPE_INFO, "finish KX for %s\n", GCT_2s (t));
1741 tc = GNUNET_SCHEDULER_get_task_context ();
1742 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1743 {
1744 LOG (GNUNET_ERROR_TYPE_INFO, " shutdown\n");
1745 return;
1746 }
1747
1748 GNUNET_free (t->kx_ctx); 1740 GNUNET_free (t->kx_ctx);
1749 t->kx_ctx = NULL; 1741 t->kx_ctx = NULL;
1750} 1742}
@@ -1767,14 +1759,15 @@ destroy_kx_ctx (struct CadetTunnel *t)
1767 1759
1768 if (is_key_null (&t->kx_ctx->e_key_old)) 1760 if (is_key_null (&t->kx_ctx->e_key_old))
1769 { 1761 {
1770 t->kx_ctx->finish_task = GNUNET_SCHEDULER_add_now (finish_kx, t); 1762 t->kx_ctx->finish_task = GNUNET_SCHEDULER_add_now (&finish_kx, t);
1771 return; 1763 return;
1772 } 1764 }
1773 1765
1774 delay = GNUNET_TIME_relative_divide (rekey_period, 4); 1766 delay = GNUNET_TIME_relative_divide (rekey_period, 4);
1775 delay = GNUNET_TIME_relative_min (delay, GNUNET_TIME_UNIT_MINUTES); 1767 delay = GNUNET_TIME_relative_min (delay, GNUNET_TIME_UNIT_MINUTES);
1776 1768
1777 t->kx_ctx->finish_task = GNUNET_SCHEDULER_add_delayed (delay, finish_kx, t); 1769 t->kx_ctx->finish_task = GNUNET_SCHEDULER_add_delayed (delay,
1770 &finish_kx, t);
1778} 1771}
1779 1772
1780 1773
@@ -2103,13 +2096,8 @@ static void
2103ax_kx_resend (void *cls) 2096ax_kx_resend (void *cls)
2104{ 2097{
2105 struct CadetTunnel *t = cls; 2098 struct CadetTunnel *t = cls;
2106 const struct GNUNET_SCHEDULER_TaskContext *tc;
2107 2099
2108 t->rekey_task = NULL; 2100 t->rekey_task = NULL;
2109 tc = GNUNET_SCHEDULER_get_task_context ();
2110 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
2111 return;
2112
2113 if (CADET_TUNNEL_KEY_OK == t->estate) 2101 if (CADET_TUNNEL_KEY_OK == t->estate)
2114 { 2102 {
2115 /* Should have been canceled on estate change */ 2103 /* Should have been canceled on estate change */
@@ -2333,14 +2321,9 @@ static void
2333rekey_tunnel (void *cls) 2321rekey_tunnel (void *cls)
2334{ 2322{
2335 struct CadetTunnel *t = cls; 2323 struct CadetTunnel *t = cls;
2336 const struct GNUNET_SCHEDULER_TaskContext *tc;
2337 2324
2338 t->rekey_task = NULL; 2325 t->rekey_task = NULL;
2339 LOG (GNUNET_ERROR_TYPE_INFO, "Re-key Tunnel %s\n", GCT_2s (t)); 2326 LOG (GNUNET_ERROR_TYPE_INFO, "Re-key Tunnel %s\n", GCT_2s (t));
2340 tc = GNUNET_SCHEDULER_get_task_context ();
2341 if (NULL != tc && 0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
2342 return;
2343
2344 GNUNET_assert (NULL != t->kx_ctx); 2327 GNUNET_assert (NULL != t->kx_ctx);
2345 struct GNUNET_TIME_Relative duration; 2328 struct GNUNET_TIME_Relative duration;
2346 2329
@@ -2453,13 +2436,8 @@ global_otr_rekey (void *cls)
2453{ 2436{
2454 struct GNUNET_TIME_Absolute time; 2437 struct GNUNET_TIME_Absolute time;
2455 long n; 2438 long n;
2456 const struct GNUNET_SCHEDULER_TaskContext *tc;
2457 2439
2458 rekey_task = NULL; 2440 rekey_task = NULL;
2459 tc = GNUNET_SCHEDULER_get_task_context ();
2460 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
2461 return;
2462
2463 GNUNET_free_non_null (otr_ephemeral_key); 2441 GNUNET_free_non_null (otr_ephemeral_key);
2464 otr_ephemeral_key = GNUNET_CRYPTO_ecdhe_key_create (); 2442 otr_ephemeral_key = GNUNET_CRYPTO_ecdhe_key_create ();
2465 2443
@@ -2501,7 +2479,8 @@ destroy_iterator (void *cls,
2501{ 2479{
2502 struct CadetTunnel *t = value; 2480 struct CadetTunnel *t = value;
2503 2481
2504 LOG (GNUNET_ERROR_TYPE_DEBUG, "GCT_shutdown destroying tunnel at %p\n", t); 2482 LOG (GNUNET_ERROR_TYPE_DEBUG,
2483 "GCT_shutdown destroying tunnel at %p\n", t);
2505 GCT_destroy (t); 2484 GCT_destroy (t);
2506 return GNUNET_YES; 2485 return GNUNET_YES;
2507} 2486}
@@ -3472,13 +3451,8 @@ static void
3472trim_connections (void *cls) 3451trim_connections (void *cls)
3473{ 3452{
3474 struct CadetTunnel *t = cls; 3453 struct CadetTunnel *t = cls;
3475 const struct GNUNET_SCHEDULER_TaskContext *tc;
3476 3454
3477 t->trim_connections_task = NULL; 3455 t->trim_connections_task = NULL;
3478 tc = GNUNET_SCHEDULER_get_task_context ();
3479 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
3480 return;
3481
3482 if (GCT_count_connections (t) > 2 * CONNECTIONS_PER_TUNNEL) 3456 if (GCT_count_connections (t) > 2 * CONNECTIONS_PER_TUNNEL)
3483 { 3457 {
3484 struct CadetTConnection *iter; 3458 struct CadetTConnection *iter;
@@ -3624,8 +3598,11 @@ GCT_add_channel (struct CadetTunnel *t, struct CadetChannel *ch)
3624 3598
3625 aux = GNUNET_new (struct CadetTChannel); 3599 aux = GNUNET_new (struct CadetTChannel);
3626 aux->ch = ch; 3600 aux->ch = ch;
3627 LOG (GNUNET_ERROR_TYPE_DEBUG, " adding %p to %p\n", aux, t->channel_head); 3601 LOG (GNUNET_ERROR_TYPE_DEBUG,
3628 GNUNET_CONTAINER_DLL_insert_tail (t->channel_head, t->channel_tail, aux); 3602 " adding %p to %p\n", aux, t->channel_head);
3603 GNUNET_CONTAINER_DLL_insert_tail (t->channel_head,
3604 t->channel_tail,
3605 aux);
3629 3606
3630 if (NULL != t->destroy_task) 3607 if (NULL != t->destroy_task)
3631 { 3608 {
@@ -3653,7 +3630,9 @@ GCT_remove_channel (struct CadetTunnel *t, struct CadetChannel *ch)
3653 if (aux->ch == ch) 3630 if (aux->ch == ch)
3654 { 3631 {
3655 LOG (GNUNET_ERROR_TYPE_DEBUG, " found! %s\n", GCCH_2s (ch)); 3632 LOG (GNUNET_ERROR_TYPE_DEBUG, " found! %s\n", GCCH_2s (ch));
3656 GNUNET_CONTAINER_DLL_remove (t->channel_head, t->channel_tail, aux); 3633 GNUNET_CONTAINER_DLL_remove (t->channel_head,
3634 t->channel_tail,
3635 aux);
3657 GNUNET_free (aux); 3636 GNUNET_free (aux);
3658 return; 3637 return;
3659 } 3638 }
@@ -3701,20 +3680,12 @@ delayed_destroy (void *cls)
3701{ 3680{
3702 struct CadetTunnel *t = cls; 3681 struct CadetTunnel *t = cls;
3703 struct CadetTConnection *iter; 3682 struct CadetTConnection *iter;
3704 const struct GNUNET_SCHEDULER_TaskContext *tc;
3705 3683
3706 LOG (GNUNET_ERROR_TYPE_DEBUG, "delayed destroying tunnel %p\n", t);
3707 tc = GNUNET_SCHEDULER_get_task_context ();
3708 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
3709 {
3710 LOG (GNUNET_ERROR_TYPE_WARNING,
3711 "Not destroying tunnel, due to shutdown. "
3712 "Tunnel at %p should have been freed by GCT_shutdown\n", t);
3713 return;
3714 }
3715 t->destroy_task = NULL; 3684 t->destroy_task = NULL;
3685 LOG (GNUNET_ERROR_TYPE_DEBUG,
3686 "delayed destroying tunnel %p\n",
3687 t);
3716 t->cstate = CADET_TUNNEL_SHUTDOWN; 3688 t->cstate = CADET_TUNNEL_SHUTDOWN;
3717
3718 for (iter = t->connection_head; NULL != iter; iter = iter->next) 3689 for (iter = t->connection_head; NULL != iter; iter = iter->next)
3719 { 3690 {
3720 GCC_send_destroy (iter->c); 3691 GCC_send_destroy (iter->c);
@@ -3800,8 +3771,9 @@ GCT_destroy (struct CadetTunnel *t)
3800 if (NULL == t) 3771 if (NULL == t)
3801 return; 3772 return;
3802 3773
3803 LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying tunnel %s\n", GCP_2s (t->peer)); 3774 LOG (GNUNET_ERROR_TYPE_DEBUG,
3804 3775 "destroying tunnel %s\n",
3776 GCP_2s (t->peer));
3805 GNUNET_break (GNUNET_YES == 3777 GNUNET_break (GNUNET_YES ==
3806 GNUNET_CONTAINER_multipeermap_remove (tunnels, 3778 GNUNET_CONTAINER_multipeermap_remove (tunnels,
3807 GCP_get_id (t->peer), t)); 3779 GCP_get_id (t->peer), t));
@@ -3850,7 +3822,9 @@ GCT_destroy (struct CadetTunnel *t)
3850 3822
3851 if (NULL != t->destroy_task) 3823 if (NULL != t->destroy_task)
3852 { 3824 {
3853 LOG (GNUNET_ERROR_TYPE_DEBUG, "cancelling dest: %p\n", t->destroy_task); 3825 LOG (GNUNET_ERROR_TYPE_DEBUG,
3826 "cancelling dest: %p\n",
3827 t->destroy_task);
3854 GNUNET_SCHEDULER_cancel (t->destroy_task); 3828 GNUNET_SCHEDULER_cancel (t->destroy_task);
3855 t->destroy_task = NULL; 3829 t->destroy_task = NULL;
3856 } 3830 }
diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c
index 39bfc5fed..b3ded1bdf 100644
--- a/src/cadet/test_cadet.c
+++ b/src/cadet/test_cadet.c
@@ -144,17 +144,17 @@ struct GNUNET_CADET_TEST_Context *test_ctx;
144/** 144/**
145 * Task called to disconnect peers. 145 * Task called to disconnect peers.
146 */ 146 */
147static struct GNUNET_SCHEDULER_Task * disconnect_task; 147static struct GNUNET_SCHEDULER_Task *disconnect_task;
148 148
149/** 149/**
150 * Task To perform tests 150 * Task To perform tests
151 */ 151 */
152static struct GNUNET_SCHEDULER_Task * test_task; 152static struct GNUNET_SCHEDULER_Task *test_task;
153 153
154/** 154/**
155 * Task called to shutdown test. 155 * Task runnining #data_task().
156 */ 156 */
157static struct GNUNET_SCHEDULER_Task * shutdown_handle; 157static struct GNUNET_SCHEDULER_Task *data_job;
158 158
159/** 159/**
160 * Cadet handle for the root peer 160 * Cadet handle for the root peer
@@ -230,6 +230,7 @@ get_expected_target ()
230 return peers_requested - 1; 230 return peers_requested - 1;
231} 231}
232 232
233
233/** 234/**
234 * Show the results of the test (banwidth acheived) and log them to GAUGER 235 * Show the results of the test (banwidth acheived) and log them to GAUGER
235 */ 236 */
@@ -256,20 +257,6 @@ show_end_data (void)
256 257
257 258
258/** 259/**
259 * Shut down peergroup, clean up.
260 *
261 * @param cls Closure (unused).
262 * @param tc Task Context.
263 */
264static void
265shutdown_task (void *cls)
266{
267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n");
268 shutdown_handle = NULL;
269}
270
271
272/**
273 * Disconnect from cadet services af all peers, call shutdown. 260 * Disconnect from cadet services af all peers, call shutdown.
274 * 261 *
275 * @param cls Closure (line number from which termination was requested). 262 * @param cls Closure (line number from which termination was requested).
@@ -280,18 +267,11 @@ disconnect_cadet_peers (void *cls)
280{ 267{
281 long line = (long) cls; 268 long line = (long) cls;
282 unsigned int i; 269 unsigned int i;
283 const struct GNUNET_SCHEDULER_TaskContext *tc;
284 270
285 tc = GNUNET_SCHEDULER_get_task_context ();
286 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
287 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
288 "disconnecting cadet peers due to SHUTDOWN! called from %ld\n",
289 line);
290 else
291 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
292 "disconnecting cadet service of peers, called from line %ld\n",
293 line);
294 disconnect_task = NULL; 271 disconnect_task = NULL;
272 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
273 "disconnecting cadet service of peers, called from line %ld\n",
274 line);
295 for (i = 0; i < 2; i++) 275 for (i = 0; i < 2; i++)
296 { 276 {
297 GNUNET_TESTBED_operation_done (t_op[i]); 277 GNUNET_TESTBED_operation_done (t_op[i]);
@@ -317,15 +297,39 @@ disconnect_cadet_peers (void *cls)
317 incoming_ch = NULL; 297 incoming_ch = NULL;
318 } 298 }
319 GNUNET_CADET_TEST_cleanup (test_ctx); 299 GNUNET_CADET_TEST_cleanup (test_ctx);
320 if (NULL != shutdown_handle) 300 GNUNET_SCHEDULER_shutdown ();
301}
302
303
304/**
305 * Shut down peergroup, clean up.
306 *
307 * @param cls Closure (unused).
308 * @param tc Task Context.
309 */
310static void
311shutdown_task (void *cls)
312{
313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n");
314 if (NULL != data_job)
321 { 315 {
322 GNUNET_SCHEDULER_cancel (shutdown_handle); 316 GNUNET_SCHEDULER_cancel (data_job);
317 data_job = NULL;
318 }
319 if (NULL != test_task)
320 {
321 GNUNET_SCHEDULER_cancel (test_task);
322 test_task = NULL;
323 }
324 if (NULL != disconnect_task)
325 {
326 GNUNET_SCHEDULER_cancel (disconnect_task);
327 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
328 (void *) __LINE__);
323 } 329 }
324 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
325} 330}
326 331
327 332
328
329/** 333/**
330 * Stats callback. Finish the stats testbed operation and when all stats have 334 * Stats callback. Finish the stats testbed operation and when all stats have
331 * been iterated, shutdown the test. 335 * been iterated, shutdown the test.
@@ -346,8 +350,8 @@ stats_cont (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
346 350
347 if (NULL != disconnect_task) 351 if (NULL != disconnect_task)
348 GNUNET_SCHEDULER_cancel (disconnect_task); 352 GNUNET_SCHEDULER_cancel (disconnect_task);
349 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, cls); 353 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
350 354 cls);
351} 355}
352 356
353 357
@@ -393,19 +397,11 @@ static void
393gather_stats_and_exit (void *cls) 397gather_stats_and_exit (void *cls)
394{ 398{
395 long l = (long) cls; 399 long l = (long) cls;
396 const struct GNUNET_SCHEDULER_TaskContext *tc;
397 400
398 disconnect_task = NULL; 401 disconnect_task = NULL;
399 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "gathering statistics from line %d\n", l); 402 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
400 tc = GNUNET_SCHEDULER_get_task_context (); 403 "gathering statistics from line %d\n",
401 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0) 404 l);
402 {
403 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
404 (void *) __LINE__);
405 return;
406 }
407
408
409 if (NULL != ch) 405 if (NULL != ch)
410 { 406 {
411 if (NULL != th) 407 if (NULL != th)
@@ -463,14 +459,10 @@ data_task (void *cls)
463{ 459{
464 struct GNUNET_CADET_Channel *channel; 460 struct GNUNET_CADET_Channel *channel;
465 static struct GNUNET_CADET_TransmitHandle **pth; 461 static struct GNUNET_CADET_TransmitHandle **pth;
466 const struct GNUNET_SCHEDULER_TaskContext *tc;
467 long src; 462 long src;
468 463
464 data_job = NULL;
469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Data task\n"); 465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Data task\n");
470 tc = GNUNET_SCHEDULER_get_task_context ();
471 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
472 return;
473
474 if (GNUNET_YES == test_backwards) 466 if (GNUNET_YES == test_backwards)
475 { 467 {
476 channel = incoming_ch; 468 channel = incoming_ch;
@@ -499,17 +491,16 @@ data_task (void *cls)
499 if (0 == i) 491 if (0 == i)
500 { 492 {
501 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, " in 1 ms\n"); 493 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, " in 1 ms\n");
502 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, 494 data_job = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
503 &data_task, (void *) 1L); 495 &data_task, (void *) 1L);
504 } 496 }
505 else 497 else
506 { 498 {
507 i++; 499 i++;
508 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "in %u ms\n", i); 500 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "in %u ms\n", i);
509 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply ( 501 data_job = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
510 GNUNET_TIME_UNIT_MILLISECONDS, 502 i),
511 i), 503 &data_task, (void *) i);
512 &data_task, (void *) i);
513 } 504 }
514 } 505 }
515} 506}
@@ -574,7 +565,7 @@ tmt_rdy (void *cls, size_t size, void *buf)
574 { 565 {
575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Scheduling message %d\n", 566 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Scheduling message %d\n",
576 counter + 1); 567 counter + 1);
577 GNUNET_SCHEDULER_add_now (&data_task, NULL); 568 data_job = GNUNET_SCHEDULER_add_now (&data_task, NULL);
578 } 569 }
579 } 570 }
580 571
@@ -661,7 +652,7 @@ data_callback (void *cls, struct GNUNET_CADET_Channel *channel,
661 if (SPEED == test) 652 if (SPEED == test)
662 { 653 {
663 GNUNET_assert (peers_requested - 1 == client); 654 GNUNET_assert (peers_requested - 1 == client);
664 GNUNET_SCHEDULER_add_now (&data_task, NULL); 655 data_job = GNUNET_SCHEDULER_add_now (&data_task, NULL);
665 return GNUNET_OK; 656 return GNUNET_OK;
666 } 657 }
667 } 658 }
@@ -842,17 +833,14 @@ static void
842do_test (void *cls) 833do_test (void *cls)
843{ 834{
844 enum GNUNET_CADET_ChannelOption flags; 835 enum GNUNET_CADET_ChannelOption flags;
845 const struct GNUNET_SCHEDULER_TaskContext *tc;
846
847 tc = GNUNET_SCHEDULER_get_task_context ();
848 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
849 return;
850 836
837 test_task = NULL;
851 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "do_test\n"); 838 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "do_test\n");
852 839
853 if (NULL != disconnect_task) 840 if (NULL != disconnect_task)
854 { 841 {
855 GNUNET_SCHEDULER_cancel (disconnect_task); 842 GNUNET_SCHEDULER_cancel (disconnect_task);
843 disconnect_task = NULL;
856 } 844 }
857 845
858 flags = GNUNET_CADET_OPTION_DEFAULT; 846 flags = GNUNET_CADET_OPTION_DEFAULT;
@@ -880,6 +868,7 @@ do_test (void *cls)
880 &tmt_rdy, (void *) 0L); 868 &tmt_rdy, (void *) 0L);
881} 869}
882 870
871
883/** 872/**
884 * Callback to be called when the requested peer information is available 873 * Callback to be called when the requested peer information is available
885 * 874 *
@@ -942,8 +931,7 @@ tmain (void *cls,
942 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, 931 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
943 &disconnect_cadet_peers, 932 &disconnect_cadet_peers,
944 (void *) __LINE__); 933 (void *) __LINE__);
945 shutdown_handle = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 934 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
946 &shutdown_task, NULL);
947 t_op[0] = GNUNET_TESTBED_peer_get_information (peers[0], 935 t_op[0] = GNUNET_TESTBED_peer_get_information (peers[0],
948 GNUNET_TESTBED_PIT_IDENTITY, 936 GNUNET_TESTBED_PIT_IDENTITY,
949 &pi_cb, (void *) 0L); 937 &pi_cb, (void *) 0L);
diff --git a/src/cadet/test_cadet_local.c b/src/cadet/test_cadet_local.c
index 42663b146..a17d8f1ab 100644
--- a/src/cadet/test_cadet_local.c
+++ b/src/cadet/test_cadet_local.c
@@ -42,9 +42,9 @@ static int result = GNUNET_OK;
42 42
43static int got_data = GNUNET_NO; 43static int got_data = GNUNET_NO;
44 44
45static struct GNUNET_SCHEDULER_Task * abort_task; 45static struct GNUNET_SCHEDULER_Task *abort_task;
46 46
47static struct GNUNET_SCHEDULER_Task * shutdown_task; 47static struct GNUNET_SCHEDULER_Task *connect_task;
48 48
49static struct GNUNET_CADET_TransmitHandle *mth; 49static struct GNUNET_CADET_TransmitHandle *mth;
50 50
@@ -68,20 +68,29 @@ do_shutdown (void *cls)
68 if (NULL != abort_task) 68 if (NULL != abort_task)
69 { 69 {
70 GNUNET_SCHEDULER_cancel (abort_task); 70 GNUNET_SCHEDULER_cancel (abort_task);
71 abort_task = NULL;
72 }
73 if (NULL != connect_task)
74 {
75 GNUNET_SCHEDULER_cancel (connect_task);
76 connect_task = NULL;
71 } 77 }
72 if (NULL != ch) 78 if (NULL != ch)
73 { 79 {
74 GNUNET_CADET_channel_destroy (ch); 80 GNUNET_CADET_channel_destroy (ch);
81 ch = NULL;
75 } 82 }
76 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect client 1\n"); 83 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect client 1\n");
77 if (NULL != cadet_peer_1) 84 if (NULL != cadet_peer_1)
78 { 85 {
79 GNUNET_CADET_disconnect (cadet_peer_1); 86 GNUNET_CADET_disconnect (cadet_peer_1);
87 cadet_peer_1 = NULL;
80 } 88 }
81 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect client 2\n"); 89 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect client 2\n");
82 if (NULL != cadet_peer_2) 90 if (NULL != cadet_peer_2)
83 { 91 {
84 GNUNET_CADET_disconnect (cadet_peer_2); 92 GNUNET_CADET_disconnect (cadet_peer_2);
93 cadet_peer_2 = NULL;
85 } 94 }
86} 95}
87 96
@@ -95,12 +104,7 @@ do_abort (void *cls)
95 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ABORT\n"); 104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ABORT\n");
96 result = GNUNET_SYSERR; 105 result = GNUNET_SYSERR;
97 abort_task = NULL; 106 abort_task = NULL;
98 if (NULL != shutdown_task) 107 GNUNET_SCHEDULER_shutdown ();
99 {
100 GNUNET_SCHEDULER_cancel (shutdown_task);
101 shutdown_task = NULL;
102 }
103 do_shutdown (cls);
104} 108}
105 109
106 110
@@ -120,14 +124,10 @@ data_callback (void *cls, struct GNUNET_CADET_Channel *channel,
120 void **channel_ctx, 124 void **channel_ctx,
121 const struct GNUNET_MessageHeader *message) 125 const struct GNUNET_MessageHeader *message)
122{ 126{
123 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Data callback! Shutting down.\n"); 127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
128 "Data callback! Shutting down.\n");
124 got_data = GNUNET_YES; 129 got_data = GNUNET_YES;
125 if (NULL != shutdown_task) 130 GNUNET_SCHEDULER_shutdown ();
126 GNUNET_SCHEDULER_cancel (shutdown_task);
127 shutdown_task =
128 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
129 &do_shutdown,
130 NULL);
131 GNUNET_CADET_receive_done (channel); 131 GNUNET_CADET_receive_done (channel);
132 return GNUNET_OK; 132 return GNUNET_OK;
133} 133}
@@ -254,12 +254,8 @@ static void
254do_connect (void *cls) 254do_connect (void *cls)
255{ 255{
256 struct GNUNET_PeerIdentity id; 256 struct GNUNET_PeerIdentity id;
257 const struct GNUNET_SCHEDULER_TaskContext *tc;
258
259 tc = GNUNET_SCHEDULER_get_task_context ();
260 if (NULL != tc && 0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
261 return;
262 257
258 connect_task = NULL;
263 GNUNET_TESTING_peer_get_identity (me, &id); 259 GNUNET_TESTING_peer_get_identity (me, &id);
264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n"); 260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n");
265 ch = GNUNET_CADET_channel_create (cadet_peer_1, NULL, &id, 1, 261 ch = GNUNET_CADET_channel_create (cadet_peer_1, NULL, &id, 1,
@@ -286,9 +282,11 @@ run (void *cls,
286 static uint32_t ports[] = {1, 0}; 282 static uint32_t ports[] = {1, 0};
287 283
288 me = peer; 284 me = peer;
285 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
289 abort_task = 286 abort_task =
290 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 287 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
291 (GNUNET_TIME_UNIT_SECONDS, 15), &do_abort, 288 (GNUNET_TIME_UNIT_SECONDS, 15),
289 &do_abort,
292 NULL); 290 NULL);
293 cadet_peer_1 = GNUNET_CADET_connect (cfg, /* configuration */ 291 cadet_peer_1 = GNUNET_CADET_connect (cfg, /* configuration */
294 (void *) 1L, /* cls */ 292 (void *) 1L, /* cls */
@@ -305,14 +303,12 @@ run (void *cls,
305 ports); /* ports offered */ 303 ports); /* ports offered */
306 if (NULL == cadet_peer_1 || NULL == cadet_peer_2) 304 if (NULL == cadet_peer_1 || NULL == cadet_peer_2)
307 { 305 {
308 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to cadet :(\n"); 306 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
307 "Couldn't connect to cadet :(\n");
309 result = GNUNET_SYSERR; 308 result = GNUNET_SYSERR;
309 GNUNET_SCHEDULER_shutdown ();
310 return; 310 return;
311 } 311 }
312 else
313 {
314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO CADET :D\n");
315 }
316 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply ( 312 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
317 GNUNET_TIME_UNIT_SECONDS, 313 GNUNET_TIME_UNIT_SECONDS,
318 2), 314 2),
diff --git a/src/cadet/test_cadet_single.c b/src/cadet/test_cadet_single.c
index 93a50c02c..b9ab7e23a 100644
--- a/src/cadet/test_cadet_single.c
+++ b/src/cadet/test_cadet_single.c
@@ -43,9 +43,9 @@ static struct GNUNET_CADET_Channel *ch2;
43 43
44static int result; 44static int result;
45 45
46static struct GNUNET_SCHEDULER_Task * abort_task; 46static struct GNUNET_SCHEDULER_Task *abort_task;
47 47
48static struct GNUNET_SCHEDULER_Task * shutdown_task; 48static struct GNUNET_SCHEDULER_Task *connect_task;
49 49
50static unsigned int repetition; 50static unsigned int repetition;
51 51
@@ -65,10 +65,17 @@ do_shutdown (void *cls)
65 if (NULL != abort_task) 65 if (NULL != abort_task)
66 { 66 {
67 GNUNET_SCHEDULER_cancel (abort_task); 67 GNUNET_SCHEDULER_cancel (abort_task);
68 abort_task = NULL;
69 }
70 if (NULL != connect_task)
71 {
72 GNUNET_SCHEDULER_cancel (connect_task);
73 connect_task = NULL;
68 } 74 }
69 if (NULL != ch1) 75 if (NULL != ch1)
70 { 76 {
71 GNUNET_CADET_channel_destroy (ch1); 77 GNUNET_CADET_channel_destroy (ch1);
78 ch1 = NULL;
72 } 79 }
73 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect client 1\n"); 80 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect client 1\n");
74 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect client 2\n"); 81 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect client 2\n");
@@ -93,22 +100,7 @@ do_abort (void *cls)
93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ABORT\n"); 100 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ABORT\n");
94 result = GNUNET_SYSERR; 101 result = GNUNET_SYSERR;
95 abort_task = NULL; 102 abort_task = NULL;
96 if (NULL != shutdown_task) 103 GNUNET_SCHEDULER_shutdown ();
97 {
98 GNUNET_SCHEDULER_cancel (shutdown_task);
99 shutdown_task = NULL;
100 }
101 do_shutdown (cls);
102}
103
104
105static void
106finish (void)
107{
108 if (NULL != shutdown_task)
109 GNUNET_SCHEDULER_cancel (shutdown_task);
110 shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
111 &do_shutdown, NULL);
112} 104}
113 105
114 106
@@ -202,7 +194,7 @@ channel_end (void *cls, const struct GNUNET_CADET_Channel *channel,
202 ch2 = NULL; 194 ch2 = NULL;
203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "everything fine! finishing!\n"); 195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "everything fine! finishing!\n");
204 result = GNUNET_OK; 196 result = GNUNET_OK;
205 finish (); 197 GNUNET_SCHEDULER_shutdown ();
206 } 198 }
207} 199}
208 200
@@ -253,12 +245,8 @@ do_connect (void *cls)
253{ 245{
254 struct GNUNET_PeerIdentity id; 246 struct GNUNET_PeerIdentity id;
255 size_t size = sizeof (struct GNUNET_MessageHeader) + DATA_SIZE; 247 size_t size = sizeof (struct GNUNET_MessageHeader) + DATA_SIZE;
256 const struct GNUNET_SCHEDULER_TaskContext *tc;
257
258 tc = GNUNET_SCHEDULER_get_task_context ();
259 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
260 return;
261 248
249 connect_task = NULL;
262 GNUNET_TESTING_peer_get_identity (me, &id); 250 GNUNET_TESTING_peer_get_identity (me, &id);
263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n"); 251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n");
264 ch1 = GNUNET_CADET_channel_create (cadet, NULL, &id, 1, 252 ch1 = GNUNET_CADET_channel_create (cadet, NULL, &id, 1,
@@ -284,6 +272,7 @@ run (void *cls,
284 static uint32_t ports[] = {1, 0}; 272 static uint32_t ports[] = {1, 0};
285 273
286 me = peer; 274 me = peer;
275 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
287 abort_task = 276 abort_task =
288 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 277 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
289 (GNUNET_TIME_UNIT_SECONDS, 15), &do_abort, 278 (GNUNET_TIME_UNIT_SECONDS, 15), &do_abort,
@@ -301,11 +290,10 @@ run (void *cls,
301 result = GNUNET_SYSERR; 290 result = GNUNET_SYSERR;
302 return; 291 return;
303 } 292 }
304 else 293 connect_task
305 { 294 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
306 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO CADET :D\n"); 295 &do_connect,
307 } 296 NULL);
308 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_connect, NULL);
309} 297}
310 298
311 299