summaryrefslogtreecommitdiff
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 @@
/*
This file is part of GNUnet.
Copyright (C) 2011 GNUnet e.V.
+
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3, or (at your
option) any later version.
+
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
+
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
-
/**
* @file cadet/cadet_api.c
* @brief cadet api: client implementation of new cadet service
@@ -702,12 +704,8 @@ static void
reconnect_cbk (void *cls)
{
struct GNUNET_CADET_Handle *h = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
h->reconnect_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
do_reconnect (h);
}
@@ -718,7 +716,7 @@ reconnect_cbk (void *cls)
*
* @param h handle to the cadet
*
- * @return GNUNET_YES in case of sucess, GNUNET_NO otherwise (service down...)
+ * @return #GNUNET_YES in case of sucess, #GNUNET_NO otherwise (service down...)
*/
static void
reconnect (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 @@
/**
* @brief Destroy a path after some time has past.
- *
- * If the path is returned from DHT again after a while, try again.
- *
- * Removes the path from the peer (except for direct paths).
+ * Removes the path from the peer (must not be used for direct paths).
*
* @param cls Closure (path to destroy).
*/
@@ -45,28 +42,17 @@ path_destroy_delayed (void *cls)
{
struct CadetPeerPath *path = cls;
struct CadetPeer *peer;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- LOG (GNUNET_ERROR_TYPE_INFO, "Destroy delayed %p (%u)\n", path, path->length);
path->path_delete = NULL;
-
- /* During shutdown, the peers peermap might not exist anymore. */
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) == 0)
- {
- if (2 >= path->length)
- {
- /* This is not the place to destroy direct paths, only core_disconnect
- * should do it and never delay it.
- */
- GNUNET_break (0);
- }
- peer = GCP_get_short (path->peers[path->length - 1], GNUNET_NO);
- if (NULL != peer)
- GCP_remove_path (peer, path);
- }
- else
- path_destroy (path);
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "Destroy delayed %p (%u)\n",
+ path,
+ path->length);
+ GNUNET_assert (2 < path->length);
+ peer = GCP_get_short (path->peers[path->length - 1],
+ GNUNET_NO);
+ GNUNET_assert (NULL != peer);
+ GCP_remove_path (peer, path);
}
@@ -74,7 +60,6 @@ path_destroy_delayed (void *cls)
* Create a new path
*
* @param length How many hops will the path have.
- *
* @return A newly allocated path with a peer array of the specified length.
*/
struct CadetPeerPath *
@@ -125,7 +110,9 @@ path_duplicate (const struct CadetPeerPath *path)
unsigned int i;
aux = path_new (path->length);
- memcpy (aux->peers, path->peers, path->length * sizeof (GNUNET_PEER_Id));
+ memcpy (aux->peers,
+ path->peers,
+ path->length * sizeof (GNUNET_PEER_Id));
for (i = 0; i < aux->length; i++)
GNUNET_PEER_change_rc (aux->peers[i], 1);
return aux;
@@ -167,9 +154,13 @@ path_invalidate (struct CadetPeerPath *p)
if (NULL != p->path_delete)
return;
- LOG (GNUNET_ERROR_TYPE_INFO, "Invalidating path %p (%u)\n", p, p->length);
- p->path_delete = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &path_destroy_delayed, p);
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "Invalidating path %p (%u)\n",
+ p,
+ p->length);
+ p->path_delete
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &path_destroy_delayed, p);
}
@@ -242,8 +233,8 @@ path_build_from_peer_ids (struct GNUNET_PeerIdentity *peers,
* @param p1 First path
* @param p2 Second path
*
- * @return GNUNET_YES if both paths are equivalent
- * GNUNET_NO otherwise
+ * @return #GNUNET_YES if both paths are equivalent
+ * #GNUNET_NO otherwise
*/
int
path_equivalent (const struct CadetPeerPath *p1,
@@ -293,7 +284,7 @@ path_is_valid (const struct CadetPeerPath *path)
*
* @param p the path to destroy
*
- * @return GNUNET_OK on success
+ * @return #GNUNET_OK on success
*/
int
path_destroy (struct CadetPeerPath *p)
@@ -301,7 +292,10 @@ path_destroy (struct CadetPeerPath *p)
if (NULL == p)
return GNUNET_OK;
- LOG (GNUNET_ERROR_TYPE_INFO, "destroying path %p (%u)\n", p, p->length);
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "destroying path %p (%u)\n",
+ p,
+ p->length);
GNUNET_PEER_decrement_rcs (p->peers, p->length);
GNUNET_free_non_null (p->peers);
if (NULL != p->path_delete)
@@ -322,7 +316,8 @@ path_destroy (struct CadetPeerPath *p)
* 0 if they are identical.
*/
int
-path_cmp (const struct CadetPeerPath *p1, const struct CadetPeerPath *p2)
+path_cmp (const struct CadetPeerPath *p1,
+ const struct CadetPeerPath *p2)
{
if (p1->length > p2->length)
return 1;
@@ -330,7 +325,9 @@ path_cmp (const struct CadetPeerPath *p1, const struct CadetPeerPath *p2)
if (p1->length < p2->length)
return -1;
- return memcmp (p1->peers, p2->peers, sizeof (GNUNET_PEER_Id) * p1->length);
+ return memcmp (p1->peers,
+ p2->peers,
+ sizeof (GNUNET_PEER_Id) * p1->length);
}
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
/**
* Task to do the next ping.
*/
- struct GNUNET_SCHEDULER_Task * ping_task;
+ struct GNUNET_SCHEDULER_Task *ping_task;
+
+ /**
+ * NTR operation for the next ping.
+ */
+ struct GNUNET_CADET_TransmitHandle *ping_ntr;
float mean[number_rounds];
float var[number_rounds];
@@ -179,7 +184,7 @@ static struct GNUNET_TESTBED_Operation *stats_op;
/**
* Operation to get peer ids.
*/
-struct CadetPeer *peers;
+static struct CadetPeer *peers;
/**
* Peer ids counter.
@@ -207,19 +212,14 @@ static unsigned long long peers_pinging;
static struct GNUNET_CADET_TEST_Context *test_ctx;
/**
- * Task called to shutdown test.
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_handle;
-
-/**
* Task called to disconnect peers, before shutdown.
*/
-static struct GNUNET_SCHEDULER_Task * disconnect_task;
+static struct GNUNET_SCHEDULER_Task *disconnect_task;
/**
* Task to perform tests
*/
-static struct GNUNET_SCHEDULER_Task * test_task;
+static struct GNUNET_SCHEDULER_Task *test_task;
/**
* Round number.
@@ -241,6 +241,11 @@ static unsigned int peers_warmup;
*/
static int test_finished;
+/**
+ * Task running each round of the benchmark.
+ */
+static struct GNUNET_SCHEDULER_Task *round_task;
+
/**
* START THE TEST ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES.
@@ -310,19 +315,6 @@ show_end_data (void)
/**
- * Shut down peergroup, clean up.
- *
- * @param cls Closure (unused).
- */
-static void
-shutdown_task (void *cls)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Ending test.\n");
- shutdown_handle = NULL;
-}
-
-
-/**
* Disconnect from cadet services af all peers, call shutdown.
*
* @param cls Closure (unused).
@@ -334,7 +326,8 @@ disconnect_cadet_peers (void *cls)
unsigned int i;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "disconnecting cadet service, called from line %ld\n", line);
+ "disconnecting cadet service, called from line %ld\n",
+ line);
disconnect_task = NULL;
for (i = 0; i < peers_total; i++)
{
@@ -346,28 +339,56 @@ disconnect_cadet_peers (void *cls)
if (NULL != peers[i].ch)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u: channel %p\n", i, peers[i].ch);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%u: channel %p\n", i, peers[i].ch);
GNUNET_CADET_channel_destroy (peers[i].ch);
}
if (NULL != peers[i].warmup_ch)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u: warmup channel %p\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%u: warmup channel %p\n",
i, peers[i].warmup_ch);
GNUNET_CADET_channel_destroy (peers[i].warmup_ch);
}
if (NULL != peers[i].incoming_ch)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u: incoming channel %p\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%u: incoming channel %p\n",
i, peers[i].incoming_ch);
GNUNET_CADET_channel_destroy (peers[i].incoming_ch);
}
}
GNUNET_CADET_TEST_cleanup (test_ctx);
- if (NULL != shutdown_handle)
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
+/**
+ * Shut down peergroup, clean up.
+ *
+ * @param cls Closure (unused).
+ */
+static void
+shutdown_task (void *cls)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Ending test.\n");
+ if (NULL != disconnect_task)
{
- GNUNET_SCHEDULER_cancel (shutdown_handle);
+ GNUNET_SCHEDULER_cancel (disconnect_task);
+ disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
+ (void *) __LINE__);
+ }
+ if (NULL != round_task)
+ {
+ GNUNET_SCHEDULER_cancel (round_task);
+ round_task = NULL;
+ }
+ if (NULL != test_task)
+ {
+ GNUNET_SCHEDULER_cancel (test_task);
+ test_task = NULL;
}
- shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
}
@@ -418,13 +439,16 @@ stats_cont (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
* @param subsystem name of subsystem that created the statistic
* @param name the name of the datum
* @param value the current value
- * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
- * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
+ * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
+ * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
*/
static int
-stats_iterator (void *cls, const struct GNUNET_TESTBED_Peer *peer,
- const char *subsystem, const char *name,
- uint64_t value, int is_persistent)
+stats_iterator (void *cls,
+ const struct GNUNET_TESTBED_Peer *peer,
+ const char *subsystem,
+ const char *name,
+ uint64_t value,
+ int is_persistent)
{
uint32_t i;
@@ -444,16 +468,13 @@ stats_iterator (void *cls, const struct GNUNET_TESTBED_Peer *peer,
static void
collect_stats (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- return;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start collecting statistics...\n");
- stats_op = GNUNET_TESTBED_get_statistics (peers_total, testbed_handles,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Start collecting statistics...\n");
+ stats_op = GNUNET_TESTBED_get_statistics (peers_total,
+ testbed_handles,
NULL, NULL,
- stats_iterator, stats_cont, NULL);
+ &stats_iterator,
+ &stats_cont, NULL);
}
@@ -465,17 +486,12 @@ collect_stats (void *cls)
static void
finish_profiler (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- return;
-
test_finished = GNUNET_YES;
- show_end_data();
+ show_end_data ();
GNUNET_SCHEDULER_add_now (&collect_stats, NULL);
}
+
/**
* Set the total number of running peers.
*
@@ -515,9 +531,15 @@ adjust_running_peers (unsigned int target)
run ? "arting" : "opping", r, GNUNET_i2s (&peers[r].id));
if (NULL != peers[r].ping_task)
+ {
GNUNET_SCHEDULER_cancel (peers[r].ping_task);
- peers[r].ping_task = NULL;
-
+ peers[r].ping_task = NULL;
+ }
+ if (NULL != peers[r].ping_ntr)
+ {
+ GNUNET_CADET_notify_transmit_ready_cancel (peers[r].ping_ntr);
+ peers[r].ping_ntr = NULL;
+ }
peers[r].up = run;
if (NULL != peers[r].ch)
@@ -547,12 +569,6 @@ adjust_running_peers (unsigned int target)
static void
next_rnd (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- return;
-
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ROUND %ld\n", current_round);
if (0.0 == rounds[current_round])
{
@@ -563,7 +579,9 @@ next_rnd (void *cls)
adjust_running_peers (rounds[current_round] * peers_total);
current_round++;
- GNUNET_SCHEDULER_add_delayed (round_time, &next_rnd, NULL);
+ round_task = GNUNET_SCHEDULER_add_delayed (round_time,
+ &next_rnd,
+ NULL);
}
@@ -616,21 +634,19 @@ static void
ping (void *cls)
{
struct CadetPeer *peer = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
peer->ping_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)
- || GNUNET_YES == test_finished)
+ if (GNUNET_YES == test_finished)
return;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u -> %u (%u)\n",
- get_index (peer), get_index (peer->dest), peer->data_sent);
-
- GNUNET_CADET_notify_transmit_ready (peer->ch, GNUNET_NO,
- GNUNET_TIME_UNIT_FOREVER_REL,
- sizeof (struct CadetPingMessage),
- &tmt_rdy_ping, peer);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%u -> %u (%u)\n",
+ get_index (peer),
+ get_index (peer->dest),
+ peer->data_sent);
+ peer->ping_ntr = GNUNET_CADET_notify_transmit_ready (peer->ch, GNUNET_NO,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ sizeof (struct CadetPingMessage),
+ &tmt_rdy_ping, peer);
}
/**
@@ -640,12 +656,13 @@ ping (void *cls)
* @param tc Task context.
*/
static void
-pong (struct GNUNET_CADET_Channel *channel, const struct CadetPingMessage *ping)
+pong (struct GNUNET_CADET_Channel *channel,
+ const struct CadetPingMessage *ping)
{
struct CadetPingMessage *copy;
copy = GNUNET_new (struct CadetPingMessage);
- memcpy (copy, ping, sizeof (*ping));
+ *copy = *ping;
GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
GNUNET_TIME_UNIT_FOREVER_REL,
sizeof (struct CadetPingMessage),
@@ -666,7 +683,9 @@ tmt_rdy_ping (void *cls, size_t size, void *buf)
struct CadetPeer *peer = (struct CadetPeer *) cls;
struct CadetPingMessage *msg = buf;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tmt_rdy called, filling buffer\n");
+ peer->ping_ntr = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "tmt_rdy called, filling buffer\n");
if (size < sizeof (struct CadetPingMessage) || NULL == buf)
{
GNUNET_break (GNUNET_YES == test_finished);
@@ -827,7 +846,8 @@ incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel,
* with the channel is stored
*/
static void
-channel_cleaner (void *cls, const struct GNUNET_CADET_Channel *channel,
+channel_cleaner (void *cls,
+ const struct GNUNET_CADET_Channel *channel,
void *channel_ctx)
{
long n = (long) cls;
@@ -874,13 +894,8 @@ start_test (void *cls)
{
enum GNUNET_CADET_ChannelOption flags;
unsigned long i;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
test_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- return;
-
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start profiler\n");
flags = GNUNET_CADET_OPTION_DEFAULT;
@@ -909,7 +924,9 @@ start_test (void *cls)
number_rounds + 1),
&disconnect_cadet_peers,
(void *) __LINE__);
- GNUNET_SCHEDULER_add_delayed (round_time, &next_rnd, NULL);
+ round_task = GNUNET_SCHEDULER_add_delayed (round_time,
+ &next_rnd,
+ NULL);
}
@@ -939,6 +956,7 @@ warmup (void)
}
}
+
/**
* Callback to be called when the requested peer information is available
*
@@ -950,9 +968,9 @@ warmup (void)
*/
static void
peer_id_cb (void *cls,
- struct GNUNET_TESTBED_Operation *op,
- const struct GNUNET_TESTBED_PeerInformation *pinfo,
- const char *emsg)
+ struct GNUNET_TESTBED_Operation *op,
+ const struct GNUNET_TESTBED_PeerInformation *pinfo,
+ const char *emsg)
{
long n = (long) cls;
@@ -991,6 +1009,7 @@ peer_id_cb (void *cls,
&start_test, NULL);
}
+
/**
* test main: start test when all peers are connected
*
@@ -1009,7 +1028,8 @@ tmain (void *cls,
{
unsigned long i;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test main\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "test main\n");
test_ctx = ctx;
GNUNET_assert (peers_total == num_peers);
peers_running = num_peers;
@@ -1017,11 +1037,12 @@ tmain (void *cls,
disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
&disconnect_cadet_peers,
(void *) __LINE__);
- shutdown_handle = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
for (i = 0; i < peers_total; i++)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requesting id %ld\n", i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "requesting id %ld\n",
+ i);
peers[i].up = GNUNET_YES;
peers[i].cadet = cadetes[i];
peers[i].op =
@@ -1047,25 +1068,35 @@ main (int argc, char *argv[])
if (4 > argc)
{
- fprintf (stderr, "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n", argv[0]);
- fprintf (stderr, "example: %s 30s 16 1 Y\n", argv[0]);
+ fprintf (stderr,
+ "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n",
+ argv[0]);
+ fprintf (stderr,
+ "example: %s 30s 16 1 Y\n",
+ argv[0]);
return 1;
}
- if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[1], &round_time))
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_fancy_time_to_relative (argv[1],
+ &round_time))
{
- fprintf (stderr, "%s is not a valid time\n", argv[1]);
+ fprintf (stderr,
+ "%s is not a valid time\n",
+ argv[1]);
return 1;
}
peers_total = atoll (argv[2]);
if (2 > peers_total)
{
- fprintf (stderr, "%s peers is not valid (> 2)\n", argv[1]);
+ fprintf (stderr,
+ "%s peers is not valid (> 2)\n",
+ argv[1]);
return 1;
}
- peers = GNUNET_malloc (sizeof (struct CadetPeer) * peers_total);
-
+ peers = GNUNET_new_array (peers_total,
+ struct CadetPeer);
peers_pinging = atoll (argv[3]);
if (peers_total < 2 * peers_pinging)
@@ -1077,7 +1108,8 @@ main (int argc, char *argv[])
do_warmup = (5 > argc || argv[4][0] != 'N');
- ids = GNUNET_CONTAINER_multipeermap_create (2 * peers_total, GNUNET_YES);
+ ids = GNUNET_CONTAINER_multipeermap_create (2 * peers_total,
+ GNUNET_YES);
GNUNET_assert (NULL != ids);
p_ids = 0;
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;
/**
* Request echo service
*/
-int echo;
+static int echo;
/**
* Request a debug dump
*/
-int dump;
+static int dump;
/**
* Time of last echo request.
*/
-struct GNUNET_TIME_Absolute echo_time;
+static struct GNUNET_TIME_Absolute echo_time;
/**
* Task for next echo request.
*/
-struct GNUNET_SCHEDULER_Task * echo_task;
+static struct GNUNET_SCHEDULER_Task *echo_task;
/**
* Peer to connect to.
@@ -102,8 +102,7 @@ static uint32_t target_port;
/**
* Data pending in netcat mode.
*/
-size_t data_size;
-
+static size_t data_size;
/**
* Cadet handle.
@@ -123,8 +122,17 @@ static struct GNUNET_CADET_TransmitHandle *th;
/**
* Shutdown task handle.
*/
-struct GNUNET_SCHEDULER_Task * sd;
+static struct GNUNET_SCHEDULER_Task *sd;
+/**
+ * Task for reading from stdin.
+ */
+static struct GNUNET_SCHEDULER_Task *rd_task;
+
+/**
+ * Task for main job.
+ */
+static struct GNUNET_SCHEDULER_Task *job;
static void
@@ -195,7 +203,8 @@ conn_2s (uint16_t status)
static void
shutdown_task (void *cls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Shutdown\n");
if (NULL != th)
{
GNUNET_CADET_notify_transmit_ready_cancel (th);
@@ -209,7 +218,22 @@ shutdown_task (void *cls)
if (NULL != mh)
{
GNUNET_CADET_disconnect (mh);
- mh = NULL;
+ mh = NULL;
+ }
+ if (NULL != rd_task)
+ {
+ GNUNET_SCHEDULER_cancel (rd_task);
+ rd_task = NULL;
+ }
+ if (NULL != echo_task)
+ {
+ GNUNET_SCHEDULER_cancel (echo_task);
+ echo_task = NULL;
+ }
+ if (NULL != job)
+ {
+ GNUNET_SCHEDULER_cancel (job);
+ job = NULL;
}
}
@@ -227,7 +251,7 @@ shutdown_task (void *cls)
* @param buf where the callee should write the message
* @return number of bytes written to buf
*/
-size_t
+static size_t
data_ready (void *cls, size_t size, void *buf)
{
struct GNUNET_MessageHeader *msg;
@@ -271,13 +295,6 @@ static void
read_stdio (void *cls)
{
static char buf[60000];
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- return;
- }
data_size = read (0, buf, 60000);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "stdio read %u bytes\n", data_size);
@@ -305,10 +322,10 @@ listen_stdio (void)
rs = GNUNET_NETWORK_fdset_create ();
GNUNET_NETWORK_fdset_set_native (rs, 0);
- GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_TIME_UNIT_FOREVER_REL,
- rs, NULL,
- &read_stdio, NULL);
+ rd_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ rs, NULL,
+ &read_stdio, NULL);
GNUNET_NETWORK_fdset_destroy (rs);
}
@@ -408,12 +425,8 @@ channel_incoming (void *cls,
static void
send_echo (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) || NULL == ch)
+ if (NULL == ch)
return;
-
GNUNET_assert (NULL == th);
th = GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO,
GNUNET_TIME_UNIT_FOREVER_REL,
@@ -432,7 +445,8 @@ request_dump (void *cls)
{
GNUNET_CADET_request_dump (mh);
GNUNET_SCHEDULER_cancel (sd);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &shutdown_task, NULL);
}
@@ -466,7 +480,7 @@ create_channel (void *cls)
if (GNUNET_NO == echo)
listen_stdio ();
else
- GNUNET_SCHEDULER_add_now (send_echo, NULL);
+ echo_task = GNUNET_SCHEDULER_add_now (&send_echo, NULL);
}
@@ -561,8 +575,11 @@ data_callback (void *cls,
* (0 = unknown, 1 = ourselves, 2 = neighbor)
*/
static void
-peers_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
- int tunnel, unsigned int n_paths, unsigned int best_path)
+peers_callback (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ int tunnel,
+ unsigned int n_paths,
+ unsigned int best_path)
{
if (NULL == peer)
{
@@ -589,7 +606,7 @@ peers_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
* Each path starts with the local peer.
* Each path ends with the destination peer (given in @c peer).
*/
-void
+static void
peer_callback (void *cls,
const struct GNUNET_PeerIdentity *peer,
int tunnel,
@@ -629,7 +646,7 @@ peer_callback (void *cls,
* @param estate Encryption state.
* @param cstate Connectivity state.
*/
-void
+static void
tunnels_callback (void *cls,
const struct GNUNET_PeerIdentity *peer,
unsigned int channels,
@@ -665,7 +682,7 @@ tunnels_callback (void *cls,
* @param estate Encryption status.
* @param cstate Connectivity status.
*/
-void
+static void
tunnel_callback (void *cls,
const struct GNUNET_PeerIdentity *peer,
unsigned int n_channels,
@@ -691,7 +708,7 @@ tunnel_callback (void *cls,
}
if (GNUNET_YES != monitor_mode)
{
- GNUNET_SCHEDULER_shutdown();
+ GNUNET_SCHEDULER_shutdown ();
}
return;
}
@@ -705,14 +722,7 @@ tunnel_callback (void *cls,
static void
get_peers (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
- return;
- }
+ job = NULL;
GNUNET_CADET_get_peers (mh, &peers_callback, NULL);
}
@@ -727,6 +737,7 @@ show_peer (void *cls)
{
struct GNUNET_PeerIdentity pid;
+ job = NULL;
if (GNUNET_OK !=
GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
strlen (peer_id),
@@ -741,6 +752,7 @@ show_peer (void *cls)
GNUNET_CADET_get_peer (mh, &pid, peer_callback, NULL);
}
+
/**
* Call CADET's meta API, get all tunnels known to a peer.
*
@@ -749,14 +761,7 @@ show_peer (void *cls)
static void
get_tunnels (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
- return;
- }
+ job = NULL;
GNUNET_CADET_get_tunnels (mh, &tunnels_callback, NULL);
}
@@ -779,7 +784,7 @@ show_tunnel (void *cls)
fprintf (stderr,
_("Invalid tunnel owner `%s'\n"),
tunnel_id);
- GNUNET_SCHEDULER_shutdown();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
GNUNET_CADET_get_tunnel (mh, &pid, tunnel_callback, NULL);
@@ -794,7 +799,8 @@ show_tunnel (void *cls)
static void
show_channel (void *cls)
{
-
+ job = NULL;
+ GNUNET_break (0);
}
@@ -806,7 +812,8 @@ show_channel (void *cls)
static void
show_connection (void *cls)
{
-
+ job = NULL;
+ GNUNET_break (0);
}
@@ -819,7 +826,9 @@ show_connection (void *cls)
* @param cfg configuration
*/
static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_CADET_InboundChannelNotificationHandler *newch = NULL;
@@ -871,32 +880,32 @@ run (void *cls, char *const *args, const char *cfgfile,
else if (NULL != peer_id)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show peer\n");
- GNUNET_SCHEDULER_add_now (&show_peer, NULL);
+ job = GNUNET_SCHEDULER_add_now (&show_peer, NULL);
}
else if (NULL != tunnel_id)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show tunnel\n");
- GNUNET_SCHEDULER_add_now (&show_tunnel, NULL);
+ job = GNUNET_SCHEDULER_add_now (&show_tunnel, NULL);
}
else if (NULL != channel_id)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show channel\n");
- GNUNET_SCHEDULER_add_now (&show_channel, NULL);
+ job = GNUNET_SCHEDULER_add_now (&show_channel, NULL);
}
else if (NULL != conn_id)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show connection\n");
- GNUNET_SCHEDULER_add_now (&show_connection, NULL);
+ job = GNUNET_SCHEDULER_add_now (&show_connection, NULL);
}
else if (GNUNET_YES == request_peers)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all peers\n");
- GNUNET_SCHEDULER_add_now (&get_peers, NULL);
+ job = GNUNET_SCHEDULER_add_now (&get_peers, NULL);
}
else if (GNUNET_YES == request_tunnels)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all tunnels\n");
- GNUNET_SCHEDULER_add_now (&get_tunnels, NULL);
+ job = GNUNET_SCHEDULER_add_now (&get_tunnels, NULL);
}
else
{
@@ -913,11 +922,9 @@ run (void *cls, char *const *args, const char *cfgfile,
ports);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done\n");
if (NULL == mh)
- GNUNET_SCHEDULER_add_now (shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
else
- sd = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- shutdown_task, NULL);
-
+ sd = GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
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,
stats = GNUNET_STATISTICS_create ("cadet", c);
/* Scheduled the task to clean up when shutdown is called */
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "reading key\n");
my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (c);
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)
struct CadetChannel *ch;
struct GNUNET_CADET_Data *payload;
int fwd;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
rel->retry_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
-
ch = rel->ch;
copy = rel->head_sent;
if (NULL == copy)
@@ -765,15 +760,11 @@ static void
channel_recreate (void *cls)
{
struct CadetChannelReliability *rel = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
rel->retry_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
-
LOG (GNUNET_ERROR_TYPE_DEBUG, "RE-CREATE\n");
- GNUNET_STATISTICS_update (stats, "# data retransmitted", 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ "# data retransmitted", 1, GNUNET_NO);
if (rel == rel->ch->root_rel)
{
@@ -787,7 +778,6 @@ channel_recreate (void *cls)
{
GNUNET_break (0);
}
-
}
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)
*
* @param c Connection to keep alive.
* @param fwd Direction.
- * @param shutdown Are we shutting down? (Don't send traffic)
- * Non-zero value for true, not necessarily GNUNET_YES.
*/
static void
-connection_keepalive (struct CadetConnection *c, int fwd, int shutdown)
+connection_keepalive (struct CadetConnection *c,
+ int fwd)
{
GCC_check_connections ();
LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1207,10 +1206,6 @@ connection_keepalive (struct CadetConnection *c, int fwd, int shutdown)
c->fwd_maintenance_task = NULL;
else
c->bck_maintenance_task = NULL;
-
- if (GNUNET_NO != shutdown)
- return;
-
connection_maintain (c, fwd);
GCC_check_connections ();
/* Next execution will be scheduled by message_sent or _maintain*/
@@ -1225,13 +1220,11 @@ connection_keepalive (struct CadetConnection *c, int fwd, int shutdown)
static void
connection_fwd_keepalive (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
+ struct CadetConnection *c = cls;
GCC_check_connections ();
- tc = GNUNET_SCHEDULER_get_task_context ();
- connection_keepalive ((struct CadetConnection *) cls,
- GNUNET_YES,
- tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN);
+ connection_keepalive (c,
+ GNUNET_YES);
GCC_check_connections ();
}
@@ -1244,13 +1237,11 @@ connection_fwd_keepalive (void *cls)
static void
connection_bck_keepalive (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
+ struct CadetConnection *c = cls;
GCC_check_connections ();
- tc = GNUNET_SCHEDULER_get_task_context ();
- connection_keepalive ((struct CadetConnection *) cls,
- GNUNET_NO,
- tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN);
+ connection_keepalive (c,
+ GNUNET_NO);
GCC_check_connections ();
}
@@ -1461,16 +1452,9 @@ connection_poll (void *cls)
struct GNUNET_CADET_Poll msg;
struct CadetConnection *c;
int fwd;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
fc->poll_task = NULL;
GCC_check_connections ();
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- return;
- }
-
c = fc->c;
fwd = fc == &c->fwd_fc;
LOG (GNUNET_ERROR_TYPE_DEBUG, "Polling connection %s %s\n",
@@ -1592,12 +1576,8 @@ static void
connection_fwd_timeout (void *cls)
{
struct CadetConnection *c = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
c->fwd_maintenance_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GCC_check_connections ();
connection_timeout (c, GNUNET_YES);
GCC_check_connections ();
@@ -1614,12 +1594,8 @@ static void
connection_bck_timeout (void *cls)
{
struct CadetConnection *c = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
c->bck_maintenance_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GCC_check_connections ();
connection_timeout (c, GNUNET_NO);
GCC_check_connections ();
@@ -1767,13 +1743,8 @@ static void
check_duplicates (void *cls)
{
struct CadetConnection *c = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
c->check_duplicates_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
-
if (GNUNET_YES == does_connection_exist (c))
{
GCT_debug (c->t, GNUNET_ERROR_TYPE_DEBUG);
@@ -1783,7 +1754,6 @@ check_duplicates (void *cls)
}
-
/**
* Wait for enough time to let any dead connections time out and check for
* any remaining duplicates.
@@ -1797,7 +1767,6 @@ schedule_check_duplicates (struct CadetConnection *c)
if (NULL != c->check_duplicates_task)
return;
-
delay = GNUNET_TIME_relative_multiply (refresh_connection_time, 5);
c->check_duplicates_task = GNUNET_SCHEDULER_add_delayed (delay,
&check_duplicates,
@@ -1805,7 +1774,6 @@ schedule_check_duplicates (struct CadetConnection *c)
}
-
/**
* Add the connection to the list of both neighbors.
*
@@ -1903,7 +1871,8 @@ unregister_neighbors (struct CadetConnection *c)
* @param disconnected Peer that disconnected.
*/
static void
-invalidate_paths (struct CadetConnection *c, struct CadetPeer *disconnected)
+invalidate_paths (struct CadetConnection *c,
+ struct CadetPeer *disconnected)
{
struct CadetPeer *peer;
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)
size_t size;
struct GNUNET_TIME_Absolute expiration;
struct GNUNET_TIME_Relative retry_time;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- announce_id_task = NULL;
- return;
- }
+ announce_id_task = NULL;
LOG (GNUNET_ERROR_TYPE_DEBUG, "Announce ID\n");
/* TODO
* - 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,
* Remove the direct path to the peer.
*
* @param peer Peer to remove the direct path from.
- *
*/
static struct CadetPeerPath *
pop_direct_path (struct CadetPeer *peer)
@@ -398,7 +397,9 @@ pop_direct_path (struct CadetPeer *peer)
{
if (2 >= iter->length)
{
- GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, iter);
+ GNUNET_CONTAINER_DLL_remove (peer->path_head,
+ peer->path_tail,
+ iter);
return iter;
}
}
@@ -750,7 +751,8 @@ peer_destroy (struct CadetPeer *peer)
"destroying peer %s\n",
GNUNET_i2s (&id));
- if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_remove (peers, &id, peer))
+ if (GNUNET_YES !=
+ GNUNET_CONTAINER_multipeermap_remove (peers, &id, peer))
{
GNUNET_break (0);
LOG (GNUNET_ERROR_TYPE_WARNING, " peer not in peermap!!\n");
@@ -846,12 +848,8 @@ static void
delayed_search (void *cls)
{
struct CadetPeer *peer = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
peer->search_delayed = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
GCC_check_connections ();
GCP_start_search (peer);
GCC_check_connections ();
@@ -1934,8 +1932,9 @@ GCP_get (const struct GNUNET_PeerIdentity *peer_id, int create)
/**
- * Retrieve the CadetPeer stucture associated with the peer. Optionally create
- * one and insert it in the appropriate structures if the peer is not known yet.
+ * Retrieve the CadetPeer stucture associated with the
+ * peer. Optionally create one and insert it in the appropriate
+ * structures if the peer is not known yet.
*
* @param peer Short identity of the peer.
* @param create #GNUNET_YES if a new peer should be created if unknown.
@@ -2223,7 +2222,8 @@ GCP_add_path (struct CadetPeer *peer,
}
}
}
- GNUNET_CONTAINER_DLL_insert_tail (peer->path_head, peer->path_tail,
+ GNUNET_CONTAINER_DLL_insert_tail (peer->path_head,
+ peer->path_tail,
path);
LOG (GNUNET_ERROR_TYPE_DEBUG, " added last\n");
@@ -2300,7 +2300,8 @@ GCP_add_path_to_all (const struct CadetPeerPath *p, int confirmed)
* @param path Path to remove. Is always destroyed .
*/
void
-GCP_remove_path (struct CadetPeer *peer, struct CadetPeerPath *path)
+GCP_remove_path (struct CadetPeer *peer,
+ struct CadetPeerPath *path)
{
struct CadetPeerPath *iter;
struct CadetPeerPath *next;
@@ -2309,7 +2310,8 @@ GCP_remove_path (struct CadetPeer *peer, struct CadetPeerPath *path)
GNUNET_assert (myid == path->peers[0]);
GNUNET_assert (peer->id == path->peers[path->length - 1]);
- LOG (GNUNET_ERROR_TYPE_INFO, "Removing path %p (%u) from %s\n",
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "Removing path %p (%u) from %s\n",
path, path->length, GCP_2s (peer));
for (iter = peer->path_head; NULL != iter; iter = next)
@@ -2317,7 +2319,9 @@ GCP_remove_path (struct CadetPeer *peer, struct CadetPeerPath *path)
next = iter->next;
if (0 == path_cmp (path, iter))
{
- GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, iter);
+ GNUNET_CONTAINER_DLL_remove (peer->path_head,
+ peer->path_tail,
+ iter);
if (iter != path)
path_destroy (iter);
}
@@ -2512,7 +2516,8 @@ GCP_get_tunnel (const struct CadetPeer *peer)
* @param hello Hello message.
*/
void
-GCP_set_hello (struct CadetPeer *peer, const struct GNUNET_HELLO_Message *hello)
+GCP_set_hello (struct CadetPeer *peer,
+ const struct GNUNET_HELLO_Message *hello)
{
struct GNUNET_HELLO_Message *old;
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
finish_kx (void *cls)
{
struct CadetTunnel *t = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
LOG (GNUNET_ERROR_TYPE_INFO, "finish KX for %s\n", GCT_2s (t));
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- LOG (GNUNET_ERROR_TYPE_INFO, " shutdown\n");
- return;
- }
-
GNUNET_free (t->kx_ctx);
t->kx_ctx = NULL;
}
@@ -1767,14 +1759,15 @@ destroy_kx_ctx (struct CadetTunnel *t)
if (is_key_null (&t->kx_ctx->e_key_old))
{
- t->kx_ctx->finish_task = GNUNET_SCHEDULER_add_now (finish_kx, t);
+ t->kx_ctx->finish_task = GNUNET_SCHEDULER_add_now (&finish_kx, t);
return;
}
delay = GNUNET_TIME_relative_divide (rekey_period, 4);
delay = GNUNET_TIME_relative_min (delay, GNUNET_TIME_UNIT_MINUTES);
- t->kx_ctx->finish_task = GNUNET_SCHEDULER_add_delayed (delay, finish_kx, t);
+ t->kx_ctx->finish_task = GNUNET_SCHEDULER_add_delayed (delay,
+ &finish_kx, t);
}
@@ -2103,13 +2096,8 @@ static void
ax_kx_resend (void *cls)
{
struct CadetTunnel *t = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
t->rekey_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
-
if (CADET_TUNNEL_KEY_OK == t->estate)
{
/* Should have been canceled on estate change */
@@ -2333,14 +2321,9 @@ static void
rekey_tunnel (void *cls)
{
struct CadetTunnel *t = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
t->rekey_task = NULL;
LOG (GNUNET_ERROR_TYPE_INFO, "Re-key Tunnel %s\n", GCT_2s (t));
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (NULL != tc && 0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
-
GNUNET_assert (NULL != t->kx_ctx);
struct GNUNET_TIME_Relative duration;
@@ -2453,13 +2436,8 @@ global_otr_rekey (void *cls)
{
struct GNUNET_TIME_Absolute time;
long n;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
rekey_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
-
GNUNET_free_non_null (otr_ephemeral_key);
otr_ephemeral_key = GNUNET_CRYPTO_ecdhe_key_create ();
@@ -2501,7 +2479,8 @@ destroy_iterator (void *cls,
{
struct CadetTunnel *t = value;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "GCT_shutdown destroying tunnel at %p\n", t);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "GCT_shutdown destroying tunnel at %p\n", t);
GCT_destroy (t);
return GNUNET_YES;
}
@@ -3472,13 +3451,8 @@ static void
trim_connections (void *cls)
{
struct CadetTunnel *t = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
t->trim_connections_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
-
if (GCT_count_connections (t) > 2 * CONNECTIONS_PER_TUNNEL)
{
struct CadetTConnection *iter;
@@ -3624,8 +3598,11 @@ GCT_add_channel (struct CadetTunnel *t, struct CadetChannel *ch)
aux = GNUNET_new (struct CadetTChannel);
aux->ch = ch;
- LOG (GNUNET_ERROR_TYPE_DEBUG, " adding %p to %p\n", aux, t->channel_head);
- GNUNET_CONTAINER_DLL_insert_tail (t->channel_head, t->channel_tail, aux);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ " adding %p to %p\n", aux, t->channel_head);
+ GNUNET_CONTAINER_DLL_insert_tail (t->channel_head,
+ t->channel_tail,
+ aux);
if (NULL != t->destroy_task)
{
@@ -3653,7 +3630,9 @@ GCT_remove_channel (struct CadetTunnel *t, struct CadetChannel *ch)
if (aux->ch == ch)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, " found! %s\n", GCCH_2s (ch));
- GNUNET_CONTAINER_DLL_remove (t->channel_head, t->channel_tail, aux);
+ GNUNET_CONTAINER_DLL_remove (t->channel_head,
+ t->channel_tail,
+ aux);
GNUNET_free (aux);
return;
}
@@ -3701,20 +3680,12 @@ delayed_destroy (void *cls)
{
struct CadetTunnel *t = cls;
struct CadetTConnection *iter;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "delayed destroying tunnel %p\n", t);
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- "Not destroying tunnel, due to shutdown. "
- "Tunnel at %p should have been freed by GCT_shutdown\n", t);
- return;
- }
t->destroy_task = NULL;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "delayed destroying tunnel %p\n",
+ t);
t->cstate = CADET_TUNNEL_SHUTDOWN;
-
for (iter = t->connection_head; NULL != iter; iter = iter->next)
{
GCC_send_destroy (iter->c);
@@ -3800,8 +3771,9 @@ GCT_destroy (struct CadetTunnel *t)
if (NULL == t)
return;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying tunnel %s\n", GCP_2s (t->peer));
-
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "destroying tunnel %s\n",
+ GCP_2s (t->peer));
GNUNET_break (GNUNET_YES ==
GNUNET_CONTAINER_multipeermap_remove (tunnels,
GCP_get_id (t->peer), t));
@@ -3850,7 +3822,9 @@ GCT_destroy (struct CadetTunnel *t)
if (NULL != t->destroy_task)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "cancelling dest: %p\n", t->destroy_task);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "cancelling dest: %p\n",
+ t->destroy_task);
GNUNET_SCHEDULER_cancel (t->destroy_task);
t->destroy_task = NULL;
}
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;
/**
* Task called to disconnect peers.
*/
-static struct GNUNET_SCHEDULER_Task * disconnect_task;
+static struct GNUNET_SCHEDULER_Task *disconnect_task;
/**
* Task To perform tests
*/
-static struct GNUNET_SCHEDULER_Task * test_task;
+static struct GNUNET_SCHEDULER_Task *test_task;
/**
- * Task called to shutdown test.
+ * Task runnining #data_task().
*/
-static struct GNUNET_SCHEDULER_Task * shutdown_handle;
+static struct GNUNET_SCHEDULER_Task *data_job;
/**
* Cadet handle for the root peer
@@ -230,6 +230,7 @@ get_expected_target ()
return peers_requested - 1;
}
+
/**
* Show the results of the test (banwidth acheived) and log them to GAUGER
*/
@@ -256,20 +257,6 @@ show_end_data (void)
/**
- * Shut down peergroup, clean up.
- *
- * @param cls Closure (unused).
- * @param tc Task Context.
- */
-static void
-shutdown_task (void *cls)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n");
- shutdown_handle = NULL;
-}
-
-
-/**
* Disconnect from cadet services af all peers, call shutdown.
*
* @param cls Closure (line number from which termination was requested).
@@ -280,18 +267,11 @@ disconnect_cadet_peers (void *cls)
{
long line = (long) cls;
unsigned int i;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "disconnecting cadet peers due to SHUTDOWN! called from %ld\n",
- line);
- else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "disconnecting cadet service of peers, called from line %ld\n",
- line);
disconnect_task = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "disconnecting cadet service of peers, called from line %ld\n",
+ line);
for (i = 0; i < 2; i++)
{
GNUNET_TESTBED_operation_done (t_op[i]);
@@ -317,15 +297,39 @@ disconnect_cadet_peers (void *cls)
incoming_ch = NULL;
}
GNUNET_CADET_TEST_cleanup (test_ctx);
- if (NULL != shutdown_handle)
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
+/**
+ * Shut down peergroup, clean up.
+ *
+ * @param cls Closure (unused).
+ * @param tc Task Context.
+ */
+static void
+shutdown_task (void *cls)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n");
+ if (NULL != data_job)
{
- GNUNET_SCHEDULER_cancel (shutdown_handle);
+ GNUNET_SCHEDULER_cancel (data_job);
+ data_job = NULL;
+ }
+ if (NULL != test_task)
+ {
+ GNUNET_SCHEDULER_cancel (test_task);
+ test_task = NULL;
+ }
+ if (NULL != disconnect_task)
+ {
+ GNUNET_SCHEDULER_cancel (disconnect_task);
+ disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
+ (void *) __LINE__);
}
- shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
}
-
/**
* Stats callback. Finish the stats testbed operation and when all stats have
* been iterated, shutdown the test.
@@ -346,8 +350,8 @@ stats_cont (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
if (NULL != disconnect_task)
GNUNET_SCHEDULER_cancel (disconnect_task);
- disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, cls);
-
+ disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
+ cls);
}
@@ -393,19 +397,11 @@ static void
gather_stats_and_exit (void *cls)
{
long l = (long) cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
disconnect_task = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "gathering statistics from line %d\n", l);
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- {
- disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
- (void *) __LINE__);
- return;
- }
-
-
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "gathering statistics from line %d\n",
+ l);
if (NULL != ch)
{
if (NULL != th)
@@ -463,14 +459,10 @@ data_task (void *cls)
{
struct GNUNET_CADET_Channel *channel;
static struct GNUNET_CADET_TransmitHandle **pth;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
long src;
+ data_job = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Data task\n");
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- return;
-
if (GNUNET_YES == test_backwards)
{
channel = incoming_ch;
@@ -499,17 +491,16 @@ data_task (void *cls)
if (0 == i)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, " in 1 ms\n");
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
- &data_task, (void *) 1L);
+ data_job = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
+ &data_task, (void *) 1L);
}
else
{
i++;
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "in %u ms\n", i);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
- GNUNET_TIME_UNIT_MILLISECONDS,
- i),
- &data_task, (void *) i);
+ data_job = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
+ i),
+ &data_task, (void *) i);
}
}
}
@@ -574,7 +565,7 @@ tmt_rdy (void *cls, size_t size, void *buf)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Scheduling message %d\n",
counter + 1);
- GNUNET_SCHEDULER_add_now (&data_task, NULL);
+ data_job = GNUNET_SCHEDULER_add_now (&data_task, NULL);
}
}
@@ -661,7 +652,7 @@ data_callback (void *cls, struct GNUNET_CADET_Channel *channel,
if (SPEED == test)
{
GNUNET_assert (peers_requested - 1 == client);
- GNUNET_SCHEDULER_add_now (&data_task, NULL);
+ data_job = GNUNET_SCHEDULER_add_now (&data_task, NULL);
return GNUNET_OK;
}
}
@@ -842,17 +833,14 @@ static void
do_test (void *cls)
{
enum GNUNET_CADET_ChannelOption flags;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- return;
+ test_task = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "do_test\n");
if (NULL != disconnect_task)
{
GNUNET_SCHEDULER_cancel (disconnect_task);
+ disconnect_task = NULL;
}
flags = GNUNET_CADET_OPTION_DEFAULT;
@@ -880,6 +868,7 @@ do_test (void *cls)
&tmt_rdy, (void *) 0L);
}
+
/**
* Callback to be called when the requested peer information is available
*
@@ -942,8 +931,7 @@ tmain (void *cls,
disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
&disconnect_cadet_peers,
(void *) __LINE__);
- shutdown_handle = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
t_op[0] = GNUNET_TESTBED_peer_get_information (peers[0],
GNUNET_TESTBED_PIT_IDENTITY,
&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;
static int got_data = GNUNET_NO;
-static struct GNUNET_SCHEDULER_Task * abort_task;
+static struct GNUNET_SCHEDULER_Task *abort_task;
-static struct GNUNET_SCHEDULER_Task * shutdown_task;
+static struct GNUNET_SCHEDULER_Task *connect_task;
static struct GNUNET_CADET_TransmitHandle *mth;
@@ -68,20 +68,29 @@ do_shutdown (void *cls)
if (NULL != abort_task)
{
GNUNET_SCHEDULER_cancel (abort_task);
+ abort_task = NULL;
+ }
+ if (NULL != connect_task)
+ {
+ GNUNET_SCHEDULER_cancel (connect_task);
+ connect_task = NULL;
}
if (NULL != ch)
{
GNUNET_CADET_channel_destroy (ch);
+ ch = NULL;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect client 1\n");
if (NULL != cadet_peer_1)
{
GNUNET_CADET_disconnect (cadet_peer_1);
+ cadet_peer_1 = NULL;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect client 2\n");
if (NULL != cadet_peer_2)
{
GNUNET_CADET_disconnect (cadet_peer_2);
+ cadet_peer_2 = NULL;
}
}
@@ -95,12 +104,7 @@ do_abort (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ABORT\n");
result = GNUNET_SYSERR;
abort_task = NULL;
- if (NULL != shutdown_task)
- {
- GNUNET_SCHEDULER_cancel (shutdown_task);
- shutdown_task = NULL;
- }
- do_shutdown (cls);
+ GNUNET_SCHEDULER_shutdown ();
}
@@ -120,14 +124,10 @@ data_callback (void *cls, struct GNUNET_CADET_Channel *channel,
void **channel_ctx,
const struct GNUNET_MessageHeader *message)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Data callback! Shutting down.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Data callback! Shutting down.\n");
got_data = GNUNET_YES;
- if (NULL != shutdown_task)
- GNUNET_SCHEDULER_cancel (shutdown_task);
- shutdown_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_shutdown ();
GNUNET_CADET_receive_done (channel);
return GNUNET_OK;
}
@@ -254,12 +254,8 @@ static void
do_connect (void *cls)
{
struct GNUNET_PeerIdentity id;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (NULL != tc && 0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
+ connect_task = NULL;
GNUNET_TESTING_peer_get_identity (me, &id);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n");
ch = GNUNET_CADET_channel_create (cadet_peer_1, NULL, &id, 1,
@@ -286,9 +282,11 @@ run (void *cls,
static uint32_t ports[] = {1, 0};
me = peer;
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
abort_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 15), &do_abort,
+ (GNUNET_TIME_UNIT_SECONDS, 15),
+ &do_abort,
NULL);
cadet_peer_1 = GNUNET_CADET_connect (cfg, /* configuration */
(void *) 1L, /* cls */
@@ -305,14 +303,12 @@ run (void *cls,
ports); /* ports offered */
if (NULL == cadet_peer_1 || NULL == cadet_peer_2)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to cadet :(\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Couldn't connect to cadet :(\n");
result = GNUNET_SYSERR;
+ GNUNET_SCHEDULER_shutdown ();
return;
}
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO CADET :D\n");
- }
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
GNUNET_TIME_UNIT_SECONDS,
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;
static int result;
-static struct GNUNET_SCHEDULER_Task * abort_task;
+static struct GNUNET_SCHEDULER_Task *abort_task;
-static struct GNUNET_SCHEDULER_Task * shutdown_task;
+static struct GNUNET_SCHEDULER_Task *connect_task;
static unsigned int repetition;
@@ -65,10 +65,17 @@ do_shutdown (void *cls)
if (NULL != abort_task)
{
GNUNET_SCHEDULER_cancel (abort_task);
+ abort_task = NULL;
+ }
+ if (NULL != connect_task)
+ {
+ GNUNET_SCHEDULER_cancel (connect_task);
+ connect_task = NULL;
}
if (NULL != ch1)
{
GNUNET_CADET_channel_destroy (ch1);
+ ch1 = NULL;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect client 1\n");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect client 2\n");
@@ -93,22 +100,7 @@ do_abort (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ABORT\n");
result = GNUNET_SYSERR;
abort_task = NULL;
- if (NULL != shutdown_task)
- {
- GNUNET_SCHEDULER_cancel (shutdown_task);
- shutdown_task = NULL;
- }
- do_shutdown (cls);
-}
-
-
-static void
-finish (void)
-{
- if (NULL != shutdown_task)
- GNUNET_SCHEDULER_cancel (shutdown_task);
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_shutdown ();
}
@@ -202,7 +194,7 @@ channel_end (void *cls, const struct GNUNET_CADET_Channel *channel,
ch2 = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "everything fine! finishing!\n");
result = GNUNET_OK;
- finish ();
+ GNUNET_SCHEDULER_shutdown ();
}
}
@@ -253,12 +245,8 @@ do_connect (void *cls)
{
struct GNUNET_PeerIdentity id;
size_t size = sizeof (struct GNUNET_MessageHeader) + DATA_SIZE;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- return;
+ connect_task = NULL;
GNUNET_TESTING_peer_get_identity (me, &id);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n");
ch1 = GNUNET_CADET_channel_create (cadet, NULL, &id, 1,
@@ -284,6 +272,7 @@ run (void *cls,
static uint32_t ports[] = {1, 0};
me = peer;
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
abort_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 15), &do_abort,
@@ -301,11 +290,10 @@ run (void *cls,
result = GNUNET_SYSERR;
return;
}
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO CADET :D\n");
- }
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_connect, NULL);
+ connect_task
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &do_connect,
+ NULL);
}