summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-04-30 08:17:37 +0000
committerChristian Grothoff <christian@grothoff.org>2016-04-30 08:17:37 +0000
commit95f9076a2139f5fb042b944a0658b6cda2fa35db (patch)
treeb0826a2a1dcf812e6b4450fe6b05d47cd53ae49d
parent7746f68db77b9ca3c4aaca24ab2ce5253461240b (diff)
implementing new scheduler shutdown semantics
-rw-r--r--src/arm/arm_api.c13
-rw-r--r--src/arm/gnunet-arm.c79
-rw-r--r--src/arm/gnunet-service-arm.c89
-rw-r--r--src/arm/test_arm_api.c2
-rw-r--r--src/arm/test_exponential_backoff.c16
-rw-r--r--src/ats-tests/ats-testing-log.c8
-rw-r--r--src/ats-tests/perf_ats_logging.c15
-rw-r--r--src/ats-tool/gnunet-ats.c22
-rw-r--r--src/ats/gnunet-service-ats.c8
-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
-rw-r--r--src/consensus/gnunet-service-consensus.c2
-rw-r--r--src/consensus/test_consensus_api.c14
-rw-r--r--src/conversation/gnunet-conversation-test.c5
-rw-r--r--src/conversation/gnunet-conversation.c4
-rw-r--r--src/conversation/gnunet-service-conversation.c9
-rw-r--r--src/core/gnunet-core.c3
-rw-r--r--src/core/gnunet-service-core.c5
-rw-r--r--src/core/gnunet-service-core_kx.c7
-rw-r--r--src/core/test_core_api_mq.c30
-rw-r--r--src/core/test_core_quota_compliance.c13
-rw-r--r--src/curl/Makefile.am1
-rw-r--r--src/datastore/gnunet-datastore.c3
-rw-r--r--src/datastore/gnunet-service-datastore.c9
-rw-r--r--src/datastore/perf_datastore_api.c4
-rw-r--r--src/datastore/perf_plugin_datastore.c45
-rw-r--r--src/datastore/test_plugin_datastore.c7
-rw-r--r--src/dht/gnunet-dht-get.c30
-rw-r--r--src/dht/gnunet-dht-monitor.c36
-rw-r--r--src/dht/gnunet-dht-put.c7
-rw-r--r--src/dht/gnunet-service-dht.c5
-rw-r--r--src/dht/gnunet-service-dht_clients.c4
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c5
-rw-r--r--src/dht/gnunet-service-wdht.c5
-rw-r--r--src/dht/gnunet-service-wdht_clients.c4
-rw-r--r--src/dht/gnunet-service-xdht.c7
-rw-r--r--src/dht/gnunet-service-xdht_clients.c4
-rw-r--r--src/dht/gnunet_dht_profiler.c99
-rw-r--r--src/dns/dnsstub.c2
-rw-r--r--src/dns/gnunet-dns-monitor.c3
-rw-r--r--src/dns/gnunet-dns-redirector.c3
-rw-r--r--src/dns/gnunet-service-dns.c5
-rw-r--r--src/dv/gnunet-dv.c3
-rw-r--r--src/dv/gnunet-service-dv.c3
-rw-r--r--src/dv/test_transport_dv.c4
-rw-r--r--src/exit/gnunet-daemon-exit.c11
-rw-r--r--src/fs/gnunet-auto-share.c12
-rw-r--r--src/fs/gnunet-daemon-fsprofiler.c12
-rw-r--r--src/fs/gnunet-download.c4
-rw-r--r--src/fs/gnunet-fs-profiler.c29
-rw-r--r--src/fs/gnunet-publish.c5
-rw-r--r--src/fs/gnunet-search.c20
-rw-r--r--src/fs/gnunet-service-fs.c10
-rw-r--r--src/fs/gnunet-service-fs_cp.c43
-rw-r--r--src/fs/gnunet-service-fs_put.c4
-rw-r--r--src/fs/gnunet-unindex.c4
-rw-r--r--src/fs/test_gnunet_service_fs_migration.c17
-rw-r--r--src/gns/gns_api.c7
-rw-r--r--src/gns/gnunet-bcd.c21
-rw-r--r--src/gns/gnunet-dns2gns.c96
-rw-r--r--src/gns/gnunet-gns-helper-service-w32.c4
-rw-r--r--src/gns/gnunet-gns-import.c3
-rw-r--r--src/gns/gnunet-gns-proxy.c7
-rw-r--r--src/gns/gnunet-gns.c32
-rw-r--r--src/gns/gnunet-service-gns.c3
-rw-r--r--src/gns/plugin_rest_gns.c6
-rw-r--r--src/gns/test_gns_proxy.c17
-rw-r--r--src/hostlist/gnunet-daemon-hostlist.c5
-rw-r--r--src/hostlist/gnunet-daemon-hostlist_client.c71
-rw-r--r--src/hostlist/gnunet-daemon-hostlist_server.c19
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist.c29
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_learning.c14
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_reconnect.c18
-rw-r--r--src/identity-provider/gnunet-service-identity-provider.c38
-rw-r--r--src/identity-provider/plugin_rest_identity_provider.c60
-rw-r--r--src/identity/gnunet-identity.c3
-rw-r--r--src/identity/gnunet-service-identity.c4
-rw-r--r--src/identity/plugin_rest_identity.c8
-rw-r--r--src/identity/test_identity.c3
-rw-r--r--src/include/gnunet_common.h2
-rw-r--r--src/include/gnunet_scheduler_lib.h62
-rw-r--r--src/multicast/gnunet-service-multicast.c11
-rw-r--r--src/multicast/test_multicast.c21
-rw-r--r--src/namecache/gnunet-namecache.c6
-rw-r--r--src/namecache/gnunet-service-namecache.c4
-rw-r--r--src/namecache/test_namecache_api_cache_block.c7
-rw-r--r--src/namestore/gnunet-namestore-fcfsd.c3
-rw-r--r--src/namestore/gnunet-namestore.c3
-rw-r--r--src/namestore/gnunet-service-namestore.c4
-rw-r--r--src/namestore/plugin_rest_namestore.c26
-rw-r--r--src/nat/gnunet-nat-server.c4
-rw-r--r--src/nat/nat.c24
-rw-r--r--src/nat/nat_auto.c75
-rw-r--r--src/nat/nat_mini.c16
-rw-r--r--src/nat/nat_test.c34
-rw-r--r--src/nat/test_nat.c3
-rw-r--r--src/nse/gnunet-nse-profiler.c93
-rw-r--r--src/nse/gnunet-nse.c4
-rw-r--r--src/nse/gnunet-service-nse.c24
-rw-r--r--src/nse/nse_api.c6
-rw-r--r--src/nse/test_nse_multipeer.c3
-rw-r--r--src/peerinfo-tool/gnunet-peerinfo.c5
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c68
-rw-r--r--src/peerinfo/peerinfo_api.c4
-rw-r--r--src/peerinfo/peerinfo_api_notify.c5
-rw-r--r--src/peerinfo/test_peerinfo_api_notify_friend_only.c43
-rw-r--r--src/peerstore/gnunet-peerstore.c11
-rw-r--r--src/peerstore/gnunet-service-peerstore.c55
-rw-r--r--src/peerstore/peerstore_api.c6
-rw-r--r--src/psyc/gnunet-service-psyc.c5
-rw-r--r--src/psyc/test_psyc.c117
-rw-r--r--src/psycstore/gnunet-service-psycstore.c12
-rw-r--r--src/psycstore/psycstore_api.c2
-rw-r--r--src/psycstore/test_psycstore.c4
-rw-r--r--src/pt/gnunet-daemon-pt.c4
-rw-r--r--src/pt/test_gnunet_vpn.c3
-rw-r--r--src/regex/gnunet-daemon-regexprofiler.c28
-rw-r--r--src/regex/gnunet-regex-profiler.c122
-rw-r--r--src/regex/gnunet-regex-simulation-profiler.c156
-rw-r--r--src/regex/gnunet-service-regex.c5
-rw-r--r--src/rest/gnunet-rest-server.c19
-rw-r--r--src/revocation/gnunet-revocation.c102
-rw-r--r--src/revocation/gnunet-service-revocation.c5
-rw-r--r--src/rps/gnunet-rps.c15
-rw-r--r--src/rps/gnunet-service-rps.c160
-rw-r--r--src/rps/gnunet-service-rps_sampler.c14
-rw-r--r--src/rps/test_rps.c16
-rw-r--r--src/scalarproduct/gnunet-scalarproduct.c5
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c5
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c5
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct_alice.c5
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct_bob.c5
-rw-r--r--src/secretsharing/gnunet-secretsharing-profiler.c3
-rw-r--r--src/secretsharing/gnunet-service-secretsharing.c4
-rw-r--r--src/secretsharing/test_secretsharing_api.c3
-rw-r--r--src/set/gnunet-service-set.c9
-rw-r--r--src/set/gnunet-set-profiler.c2
-rw-r--r--src/set/set_api.c10
-rw-r--r--src/set/test_set_api.c22
-rw-r--r--src/set/test_set_union_copy.c32
-rw-r--r--src/set/test_set_union_result_symmetric.c5
-rw-r--r--src/social/gnunet-service-social.c31
-rw-r--r--src/social/test_social.c28
-rw-r--r--src/statistics/gnunet-service-statistics.c5
-rw-r--r--src/statistics/gnunet-statistics.c10
-rw-r--r--src/statistics/statistics_api.c3
-rw-r--r--src/statistics/test_statistics_api_watch.c17
-rw-r--r--src/template/gnunet-service-template.c7
-rw-r--r--src/testbed/gnunet-daemon-latency-logger.c13
-rw-r--r--src/testbed/gnunet-daemon-testbed-blacklist.c69
-rw-r--r--src/testbed/gnunet-daemon-testbed-underlay.c9
-rw-r--r--src/testbed/gnunet-helper-testbed.c83
-rw-r--r--src/testbed/gnunet-service-test-barriers.c43
-rw-r--r--src/testbed/gnunet-service-testbed-logger.c66
-rw-r--r--src/testbed/gnunet-service-testbed.c30
-rw-r--r--src/testbed/gnunet-service-testbed_cpustatus.c4
-rw-r--r--src/testbed/gnunet-service-testbed_oc.c4
-rw-r--r--src/testbed/gnunet-testbed-profiler.c22
-rw-r--r--src/testbed/gnunet_testbed_mpi_spawn.c16
-rw-r--r--src/testbed/test_testbed_api_3peers_3controllers.c8
-rw-r--r--src/testbed/test_testbed_api_hosts.c7
-rw-r--r--src/testbed/test_testbed_api_testbed_run.c20
-rw-r--r--src/testbed/test_testbed_logger_api.c30
-rw-r--r--src/testbed/testbed_api_testbed.c15
-rw-r--r--src/testing/gnunet-testing.c15
-rw-r--r--src/topology/gnunet-daemon-topology.c11
-rw-r--r--src/transport/gnunet-service-transport.c5
-rw-r--r--src/transport/gnunet-service-transport_validation.c1
-rw-r--r--src/transport/gnunet-transport-profiler.c14
-rw-r--r--src/transport/gnunet-transport.c34
-rw-r--r--src/transport/plugin_transport_http_client.c21
-rw-r--r--src/transport/plugin_transport_http_server.c56
-rw-r--r--src/transport/plugin_transport_udp.c10
-rw-r--r--src/transport/plugin_transport_unix.c12
-rw-r--r--src/transport/test_transport_api.c5
-rw-r--r--src/transport/test_transport_api_bidirectional_connect.c8
-rw-r--r--src/transport/test_transport_api_blacklisting.c5
-rw-r--r--src/transport/test_transport_api_disconnect.c11
-rw-r--r--src/transport/test_transport_api_http_reverse_peer2.conf1
-rw-r--r--src/transport/test_transport_api_https_peer1.conf1
-rw-r--r--src/transport/test_transport_api_https_peer2.conf1
-rw-r--r--src/transport/test_transport_api_limited_sockets.c6
-rw-r--r--src/transport/test_transport_api_manipulation_cfg.c10
-rw-r--r--src/transport/test_transport_api_manipulation_recv_tcp.c5
-rw-r--r--src/transport/test_transport_api_manipulation_send_tcp.c4
-rw-r--r--src/transport/test_transport_api_monitor_peers.c5
-rw-r--r--src/transport/test_transport_api_monitor_validation.c5
-rw-r--r--src/transport/test_transport_api_restart_1peer.c5
-rw-r--r--src/transport/test_transport_api_restart_2peers.c6
-rw-r--r--src/transport/test_transport_api_timeout.c6
-rw-r--r--src/transport/test_transport_startonly.c13
-rw-r--r--src/transport/transport-testing.c6
-rw-r--r--src/transport/transport_api.c7
-rw-r--r--src/util/bandwidth.c1
-rw-r--r--src/util/client.c37
-rw-r--r--src/util/client_manager.c121
-rw-r--r--src/util/connection.c218
-rw-r--r--src/util/crypto_hash_file.c41
-rw-r--r--src/util/gnunet-scrypt.c88
-rw-r--r--src/util/gnunet-uri.c7
-rw-r--r--src/util/helper.c71
-rw-r--r--src/util/mq.c71
-rw-r--r--src/util/os_installation.c2
-rw-r--r--src/util/os_priority.c190
-rw-r--r--src/util/program.c4
-rw-r--r--src/util/resolver_api.c16
-rw-r--r--src/util/scheduler.c337
-rw-r--r--src/util/server.c30
-rw-r--r--src/util/service.c11
-rw-r--r--src/util/socks.c35
-rw-r--r--src/util/speedup.c29
-rw-r--r--src/util/test_common_logging_runtime_loglevels.c9
-rw-r--r--src/util/test_connection_receive_cancel.c30
-rw-r--r--src/util/test_disk.c72
-rw-r--r--src/util/test_os_start_process.c39
-rw-r--r--src/util/test_scheduler.c34
-rw-r--r--src/util/test_scheduler_delay.c7
-rw-r--r--src/util/test_server_disconnect.c3
-rw-r--r--src/util/test_server_with_client_unix.c15
-rw-r--r--src/util/test_speedup.c17
-rw-r--r--src/vpn/gnunet-service-vpn.c5
-rw-r--r--src/vpn/gnunet-vpn.c7
233 files changed, 3082 insertions, 2939 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c
index c708f9150..5fb2a811a 100644
--- a/src/arm/arm_api.c
+++ b/src/arm/arm_api.c
@@ -241,7 +241,9 @@ reconnect_arm_later (struct GNUNET_ARM_Handle *h)
h->currently_down = GNUNET_YES;
GNUNET_assert (NULL == h->reconnect_task);
h->reconnect_task =
- GNUNET_SCHEDULER_add_delayed (h->retry_backoff, &reconnect_arm_task, h);
+ GNUNET_SCHEDULER_add_delayed (h->retry_backoff,
+ &reconnect_arm_task,
+ h);
/* Don't clear pending messages on disconnection, deliver them later
clear_pending_messages (h, GNUNET_ARM_REQUEST_DISCONNECTED);
GNUNET_assert (NULL == h->control_pending_head);
@@ -635,7 +637,8 @@ reconnect_arm (struct GNUNET_ARM_Handle *h)
*/
struct GNUNET_ARM_Handle *
GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_ARM_ConnectionStatusCallback conn_status, void *cls)
+ GNUNET_ARM_ConnectionStatusCallback conn_status,
+ void *cls)
{
struct GNUNET_ARM_Handle *h;
@@ -942,7 +945,8 @@ change_service (struct GNUNET_ARM_Handle *h, const char *service_name,
h->control_pending_tail, cm);
cm->timeout_task_id =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
- (cm->timeout), &control_message_timeout, cm);
+ (cm->timeout),
+ &control_message_timeout, cm);
trigger_next_request (h, GNUNET_NO);
}
@@ -1106,7 +1110,8 @@ GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h,
h->control_pending_tail, cm);
cm->timeout_task_id =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
- (cm->timeout), &control_message_timeout, cm);
+ (cm->timeout),
+ &control_message_timeout, cm);
trigger_next_request (h, GNUNET_NO);
}
diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c
index af85372d8..4501ed036 100644
--- a/src/arm/gnunet-arm.c
+++ b/src/arm/gnunet-arm.c
@@ -145,6 +145,11 @@ static unsigned int no_stdout;
*/
static unsigned int no_stderr;
+/**
+ * Handle for the task running the #action_loop().
+ */
+static struct GNUNET_SCHEDULER_Task *al_task;
+
/**
* Attempts to delete configuration file and GNUNET_HOME
@@ -183,6 +188,11 @@ delete_files ()
static void
shutdown_task (void *cls)
{
+ if (NULL != al_task)
+ {
+ GNUNET_SCHEDULER_cancel (al_task);
+ al_task = NULL;
+ }
if (NULL != h)
{
GNUNET_ARM_disconnect_and_free (h);
@@ -314,7 +324,8 @@ conn_status (void *cls,
*/
static void
start_callback (void *cls,
- enum GNUNET_ARM_RequestStatus rs, const char *service,
+ enum GNUNET_ARM_RequestStatus rs,
+ const char *service,
enum GNUNET_ARM_Result result)
{
char *msg;
@@ -336,9 +347,10 @@ start_callback (void *cls,
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM service [re]start successful\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ARM service [re]start successful\n");
start = 0;
- GNUNET_SCHEDULER_add_now (action_loop, NULL);
+ al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
}
@@ -356,7 +368,8 @@ start_callback (void *cls,
*/
static void
stop_callback (void *cls,
- enum GNUNET_ARM_RequestStatus rs, const char *service,
+ enum GNUNET_ARM_RequestStatus rs,
+ const char *service,
enum GNUNET_ARM_Result result)
{
char *msg;
@@ -374,7 +387,8 @@ stop_callback (void *cls,
(GNUNET_ARM_RESULT_STOPPED != result) &&
(GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result))
{
- GNUNET_asprintf (&msg, "%s", _("Failed to stop the ARM service: %s\n"));
+ GNUNET_asprintf (&msg, "%s",
+ _("Failed to stop the ARM service: %s\n"));
FPRINTF (stdout, msg, ret_string (result));
GNUNET_free (msg);
GNUNET_SCHEDULER_shutdown ();
@@ -390,7 +404,7 @@ stop_callback (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Initiating an ARM restart\n");
}
- GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+ al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
}
@@ -408,7 +422,8 @@ stop_callback (void *cls,
*/
static void
init_callback (void *cls,
- enum GNUNET_ARM_RequestStatus rs, const char *service,
+ enum GNUNET_ARM_RequestStatus rs,
+ const char *service,
enum GNUNET_ARM_Result result)
{
char *msg;
@@ -438,7 +453,7 @@ init_callback (void *cls,
init);
GNUNET_free (init);
init = NULL;
- GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+ al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
}
@@ -456,7 +471,8 @@ init_callback (void *cls,
*/
static void
term_callback (void *cls,
- enum GNUNET_ARM_RequestStatus rs, const char *service,
+ enum GNUNET_ARM_RequestStatus rs,
+ const char *service,
enum GNUNET_ARM_Result result)
{
char *msg;
@@ -487,7 +503,7 @@ term_callback (void *cls,
term);
GNUNET_free (term);
term = NULL;
- GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+ al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
}
@@ -503,7 +519,8 @@ term_callback (void *cls,
*/
static void
list_callback (void *cls,
- enum GNUNET_ARM_RequestStatus rs, unsigned int count,
+ enum GNUNET_ARM_RequestStatus rs,
+ unsigned int count,
const char *const*list)
{
unsigned int i;
@@ -512,7 +529,8 @@ list_callback (void *cls,
{
char *msg;
- GNUNET_asprintf (&msg, "%s", _("Failed to request a list of services: %s\n"));
+ GNUNET_asprintf (&msg, "%s",
+ _("Failed to request a list of services: %s\n"));
FPRINTF (stdout, msg, req_string (rs));
GNUNET_free (msg);
ret = 3;
@@ -520,7 +538,8 @@ list_callback (void *cls,
}
if (NULL == list)
{
- FPRINTF (stderr, "%s", _("Error communicating with ARM. ARM not running?\n"));
+ FPRINTF (stderr, "%s",
+ _("Error communicating with ARM. ARM not running?\n"));
GNUNET_SCHEDULER_shutdown ();
ret = 3;
return;
@@ -528,7 +547,7 @@ list_callback (void *cls,
FPRINTF (stdout, "%s", _("Running services:\n"));
for (i = 0; i < count; i++)
FPRINTF (stdout, "%s\n", list[i]);
- GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+ al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
}
@@ -541,12 +560,9 @@ list_callback (void *cls,
static void
action_loop (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running requested actions\n");
+ al_task = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Running requested actions\n");
while (1)
{
switch (phase++)
@@ -554,7 +570,8 @@ action_loop (void *cls)
case 0:
if (NULL != term)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Termination action\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Termination action\n");
GNUNET_ARM_request_service_stop (h, term,
(0 == timeout.rel_value_us) ? STOP_TIMEOUT : timeout,
&term_callback, NULL);
@@ -564,7 +581,8 @@ action_loop (void *cls)
case 1:
if (end || restart)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "End action\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "End action\n");
GNUNET_ARM_request_service_stop (h, "arm",
(0 == timeout.rel_value_us) ? STOP_TIMEOUT_ARM : timeout,
&stop_callback, NULL);
@@ -574,7 +592,8 @@ action_loop (void *cls)
case 2:
if (start)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start action\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Start action\n");
GNUNET_ARM_request_service_start (h, "arm",
(no_stdout ? 0 : GNUNET_OS_INHERIT_STD_OUT) |
(no_stderr ? 0 : GNUNET_OS_INHERIT_STD_ERR),
@@ -586,8 +605,10 @@ action_loop (void *cls)
case 3:
if (NULL != init)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initialization action\n");
- GNUNET_ARM_request_service_start (h, init, GNUNET_OS_INHERIT_STD_NONE,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Initialization action\n");
+ GNUNET_ARM_request_service_start (h, init,
+ GNUNET_OS_INHERIT_STD_NONE,
(0 == timeout.rel_value_us) ? STOP_TIMEOUT : timeout,
&init_callback, NULL);
return;
@@ -631,7 +652,8 @@ action_loop (void *cls)
*/
static void
srv_status (void *cls,
- const char *service, enum GNUNET_ARM_ServiceStatus status)
+ const char *service,
+ enum GNUNET_ARM_ServiceStatus status)
{
const char *msg;
@@ -704,9 +726,8 @@ run (void *cls,
return;
if (monitor)
m = GNUNET_ARM_monitor (cfg, &srv_status, NULL);
- GNUNET_SCHEDULER_add_now (&action_loop, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c
index 9feb6e9c1..152a358fc 100644
--- a/src/arm/gnunet-service-arm.c
+++ b/src/arm/gnunet-service-arm.c
@@ -610,13 +610,9 @@ accept_connection (void *cls)
{
struct ServiceListeningInfo *sli = cls;
struct ServiceList *sl = sli->sl;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
sli->accept_task = NULL;
GNUNET_assert (GNUNET_NO == in_shutdown);
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
start_process (sl, NULL, 0);
}
@@ -734,7 +730,9 @@ create_listen_socket (struct sockaddr *sa,
sli->accept_task =
GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, sock,
&accept_connection, sli);
- GNUNET_CONTAINER_DLL_insert (sl->listen_head, sl->listen_tail, sli);
+ GNUNET_CONTAINER_DLL_insert (sl->listen_head,
+ sl->listen_tail,
+ sli);
}
@@ -866,17 +864,24 @@ handle_stop (void *cls,
servicename);
if (0 == strcasecmp (servicename, "arm"))
{
- broadcast_status (servicename, GNUNET_ARM_SERVICE_STOPPING, NULL);
- signal_result (client, servicename, request_id, GNUNET_ARM_RESULT_STOPPING);
+ broadcast_status (servicename,
+ GNUNET_ARM_SERVICE_STOPPING, NULL);
+ signal_result (client,
+ servicename,
+ request_id,
+ GNUNET_ARM_RESULT_STOPPING);
GNUNET_SERVER_client_persist_ (client);
- GNUNET_SCHEDULER_add_now (trigger_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&trigger_shutdown, NULL);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
sl = find_service (servicename);
if (sl == NULL)
{
- signal_result (client, servicename, request_id, GNUNET_ARM_RESULT_IS_NOT_KNOWN);
+ signal_result (client,
+ servicename,
+ request_id,
+ GNUNET_ARM_RESULT_IS_NOT_KNOWN);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
@@ -884,14 +889,19 @@ handle_stop (void *cls,
if (GNUNET_YES == in_shutdown)
{
/* shutdown in progress */
- signal_result (client, servicename, request_id, GNUNET_ARM_RESULT_IN_SHUTDOWN);
+ signal_result (client,
+ servicename,
+ request_id,
+ GNUNET_ARM_RESULT_IN_SHUTDOWN);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
if (NULL != sl->killing_client)
{
/* killing already in progress */
- signal_result (client, servicename, request_id,
+ signal_result (client,
+ servicename,
+ request_id,
GNUNET_ARM_RESULT_IS_STOPPING_ALREADY);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
@@ -899,7 +909,9 @@ handle_stop (void *cls,
if (NULL == sl->proc)
{
/* process is down */
- signal_result (client, servicename, request_id,
+ signal_result (client,
+ servicename,
+ request_id,
GNUNET_ARM_RESULT_IS_STOPPED_ALREADY);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
@@ -907,7 +919,9 @@ handle_stop (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending kill signal to service `%s', waiting for process to die.\n",
servicename);
- broadcast_status (servicename, GNUNET_ARM_SERVICE_STOPPING, NULL);
+ broadcast_status (servicename,
+ GNUNET_ARM_SERVICE_STOPPING,
+ NULL);
/* no signal_start - only when it's STOPPED */
sl->killed_at = GNUNET_TIME_absolute_get ();
if (0 != GNUNET_OS_process_kill (sl->proc, GNUNET_TERM_SIG))
@@ -1055,7 +1069,8 @@ shutdown_task (void *cls)
while (NULL != (sli = pos->listen_head))
{
GNUNET_CONTAINER_DLL_remove (pos->listen_head,
- pos->listen_tail, sli);
+ pos->listen_tail,
+ sli);
if (NULL != sli->accept_task)
{
GNUNET_SCHEDULER_cancel (sli->accept_task);
@@ -1072,7 +1087,7 @@ shutdown_task (void *cls)
while (NULL != (pos = nxt))
{
nxt = pos->next;
- if (pos->proc != NULL)
+ if (NULL != pos->proc)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Stopping service `%s'\n",
@@ -1087,7 +1102,7 @@ shutdown_task (void *cls)
}
}
/* finally, should all service processes be already gone, terminate for real */
- if (running_head == NULL)
+ if (NULL == running_head)
do_shutdown ();
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1105,15 +1120,11 @@ static void
delayed_restart_task (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
struct ServiceList *sl;
struct GNUNET_TIME_Relative lowestRestartDelay;
struct ServiceListeningInfo *sli;
child_restart_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GNUNET_assert (GNUNET_NO == in_shutdown);
lowestRestartDelay = GNUNET_TIME_UNIT_FOREVER_REL;
@@ -1144,7 +1155,8 @@ delayed_restart_task (void *cls)
/* accept was actually paused, so start it again */
sli->accept_task =
GNUNET_SCHEDULER_add_read_net
- (GNUNET_TIME_UNIT_FOREVER_REL, sli->listen_socket,
+ (GNUNET_TIME_UNIT_FOREVER_REL,
+ sli->listen_socket,
&accept_connection, sli);
}
}
@@ -1180,7 +1192,6 @@ delayed_restart_task (void *cls)
static void
maint_child_death (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
struct ServiceList *pos;
struct ServiceList *next;
struct ServiceListeningInfo *sli;
@@ -1192,19 +1203,9 @@ maint_child_death (void *cls)
unsigned long statusCode;
const struct GNUNET_DISK_FileHandle *pr;
- pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
+ pr = GNUNET_DISK_pipe_handle (sigpipe,
+ GNUNET_DISK_PIPE_END_READ);
child_death_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
- {
- /* shutdown scheduled us, ignore! */
- child_death_task =
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- pr,
- &maint_child_death,
- NULL);
- return;
- }
/* consume the signal */
GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c)));
@@ -1353,14 +1354,13 @@ maint_child_death (void *cls)
}
else
{
- if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Service `%s' terminated with status %s/%d, will restart in %s\n"),
- pos->name,
- statstr,
- statcode,
- GNUNET_STRINGS_relative_time_to_string (pos->backoff,
- GNUNET_YES));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Service `%s' terminated with status %s/%d, will restart in %s\n"),
+ pos->name,
+ statstr,
+ statcode,
+ GNUNET_STRINGS_relative_time_to_string (pos->backoff,
+ GNUNET_YES));
/* schedule restart */
pos->restart_at = GNUNET_TIME_relative_to_absolute (pos->backoff);
pos->backoff = GNUNET_TIME_STD_BACKOFF (pos->backoff);
@@ -1601,9 +1601,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *serv,
cfg = c;
server = serv;
GNUNET_assert (NULL != serv);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
child_death_task =
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
GNUNET_DISK_pipe_handle (sigpipe,
diff --git a/src/arm/test_arm_api.c b/src/arm/test_arm_api.c
index 149ec46c4..f5283d714 100644
--- a/src/arm/test_arm_api.c
+++ b/src/arm/test_arm_api.c
@@ -157,7 +157,7 @@ arm_conn (void *cls,
ok = 3;
else if (ok == 1)
ok = 0;
- GNUNET_SCHEDULER_add_now (trigger_disconnect, arm);
+ GNUNET_SCHEDULER_add_now (&trigger_disconnect, arm);
}
}
diff --git a/src/arm/test_exponential_backoff.c b/src/arm/test_exponential_backoff.c
index 1032a9010..3f33c91e6 100644
--- a/src/arm/test_exponential_backoff.c
+++ b/src/arm/test_exponential_backoff.c
@@ -90,7 +90,7 @@ struct ShutdownContext
/**
* Task set up to cancel the shutdown request on timeout.
*/
- struct GNUNET_SCHEDULER_Task * cancel_task;
+ struct GNUNET_SCHEDULER_Task *cancel_task;
/**
* Task to call once shutdown complete
@@ -235,7 +235,7 @@ shutdown_cont (void *cls, int reason)
{
/* Re-try shutdown */
LOG ("do-nothing didn't die, trying again\n");
- GNUNET_SCHEDULER_add_now (kill_task, NULL);
+ GNUNET_SCHEDULER_add_now (&kill_task, NULL);
return;
}
startedWaitingAt = GNUNET_TIME_absolute_get ();
@@ -290,12 +290,15 @@ trigger_disconnect (void *cls)
static void
-arm_stop_cb (void *cls, enum GNUNET_ARM_RequestStatus status, const char *servicename, enum GNUNET_ARM_Result result)
+arm_stop_cb (void *cls,
+ enum GNUNET_ARM_RequestStatus status,
+ const char *servicename,
+ enum GNUNET_ARM_Result result)
{
GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED);
LOG ("ARM service stopped\n");
- GNUNET_SCHEDULER_add_now (trigger_disconnect, NULL);
+ GNUNET_SCHEDULER_add_now (&trigger_disconnect, NULL);
}
@@ -318,7 +321,8 @@ srv_status (void *cls, const char *service, enum GNUNET_ARM_ServiceStatus status
LOG ("do-nothing is starting\n");
phase++;
ok = 1;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &kill_task, NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &kill_task, NULL);
}
else if ((phase == 2) && (strcasecmp (SERVICE, service) == 0))
{
@@ -328,7 +332,7 @@ srv_status (void *cls, const char *service, enum GNUNET_ARM_ServiceStatus status
if (status == GNUNET_ARM_SERVICE_STARTING)
{
LOG ("do-nothing is starting\n");
- GNUNET_SCHEDULER_add_now (kill_task, &ok);
+ GNUNET_SCHEDULER_add_now (&kill_task, &ok);
}
else if ((status == GNUNET_ARM_SERVICE_STOPPED) && (trialCount == 14))
{
diff --git a/src/ats-tests/ats-testing-log.c b/src/ats-tests/ats-testing-log.c
index 650be29f3..5e22d4b47 100644
--- a/src/ats-tests/ats-testing-log.c
+++ b/src/ats-tests/ats-testing-log.c
@@ -804,13 +804,9 @@ static void
collect_log_task (void *cls)
{
struct LoggingHandle *l = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
l->log_task = NULL;
GNUNET_ATS_TEST_logging_now (l);
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
- return;
l->log_task = GNUNET_SCHEDULER_add_delayed (l->frequency,
&collect_log_task,
l);
@@ -829,8 +825,10 @@ GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l)
return;
if (NULL != l->log_task)
+ {
GNUNET_SCHEDULER_cancel (l->log_task);
- l->log_task = NULL;
+ l->log_task = NULL;
+ }
l->running = GNUNET_NO;
GNUNET_log(GNUNET_ERROR_TYPE_INFO,
diff --git a/src/ats-tests/perf_ats_logging.c b/src/ats-tests/perf_ats_logging.c
index 1e4b15432..d4c4f2cd9 100644
--- a/src/ats-tests/perf_ats_logging.c
+++ b/src/ats-tests/perf_ats_logging.c
@@ -639,15 +639,8 @@ collect_log_now (void)
static void
collect_log_task (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
log_task = NULL;
-
- collect_log_now();
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
- return;
-
+ collect_log_now ();
log_task = GNUNET_SCHEDULER_add_delayed (frequency,
&collect_log_task, NULL);
}
@@ -659,12 +652,14 @@ perf_logging_stop ()
int c_m;
struct PeerLoggingTimestep *cur;
- if (GNUNET_YES!= running)
+ if (GNUNET_YES != running)
return;
if (NULL != log_task)
+ {
GNUNET_SCHEDULER_cancel (log_task);
- log_task = NULL;
+ log_task = NULL;
+ }
collect_log_task (NULL);
GNUNET_log(GNUNET_ERROR_TYPE_INFO,
diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c
index a2ef80cef..5fc1d6e92 100644
--- a/src/ats-tool/gnunet-ats.c
+++ b/src/ats-tool/gnunet-ats.c
@@ -363,7 +363,7 @@ transport_addr_to_str_cb (void *cls,
/* All messages received and no resolutions pending*/
if (shutdown_task != NULL)
GNUNET_SCHEDULER_cancel (shutdown_task);
- shutdown_task = GNUNET_SCHEDULER_add_now (end, NULL);
+ shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL);
}
return;
}
@@ -604,7 +604,7 @@ ats_perf_cb (void *cls,
/* All messages received and no resolutions pending*/
if (shutdown_task != NULL)
GNUNET_SCHEDULER_cancel (shutdown_task);
- shutdown_task = GNUNET_SCHEDULER_add_now (end, NULL);
+ shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL);
}
return;
}
@@ -807,9 +807,8 @@ run (void *cls,
shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL);
return;
}
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &end,
- NULL);
+ shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end,
+ NULL);
return;
}
if (opt_list_used)
@@ -834,9 +833,8 @@ run (void *cls,
shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL);
return;
}
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &end,
- NULL);
+ shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end,
+ NULL);
return;
}
if (opt_monitor)
@@ -844,13 +842,15 @@ run (void *cls,
ph = GNUNET_ATS_performance_init (cfg,
&ats_perf_mon_cb,
NULL);
+ shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end,
+ NULL);
if (NULL == ph)
+ {
FPRINTF (stderr,
"%s",
_("Cannot connect to ATS service, exiting...\n"));
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &end,
- NULL);
+ GNUNET_SCHEDULER_shutdown ();
+ }
return;
}
if (opt_set_pref)
diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c
index 7b8dfe222..045a5bb67 100644
--- a/src/ats/gnunet-service-ats.c
+++ b/src/ats/gnunet-service-ats.c
@@ -138,9 +138,6 @@ cleanup_task (void *cls)
GAS_performance_done ();
GAS_preference_done ();
GAS_reservations_done ();
- GNUNET_SERVER_disconnect_notify_cancel (GSA_server,
- &client_disconnect_handler,
- NULL);
if (NULL != GSA_stats)
{
GNUNET_STATISTICS_destroy (GSA_stats, GNUNET_NO);
@@ -221,9 +218,8 @@ run (void *cls,
&client_disconnect_handler,
NULL);
GNUNET_SERVER_add_handlers (server, handlers);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &cleanup_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
+ NULL);
}
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);
}
diff --git a/src/consensus/gnunet-service-consensus.c b/src/consensus/gnunet-service-consensus.c
index 82b05d136..99e7aca97 100644
--- a/src/consensus/gnunet-service-consensus.c
+++ b/src/consensus/gnunet-service-consensus.c
@@ -3231,7 +3231,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
}
statistics = GNUNET_STATISTICS_create ("consensus", cfg);
GNUNET_SERVER_add_handlers (server, server_handlers);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
GNUNET_SERVER_disconnect_notify (server, handle_client_disconnect, NULL);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "consensus running\n");
}
diff --git a/src/consensus/test_consensus_api.c b/src/consensus/test_consensus_api.c
index 0073267f8..85707eed1 100644
--- a/src/consensus/test_consensus_api.c
+++ b/src/consensus/test_consensus_api.c
@@ -92,10 +92,7 @@ run (void *cls,
GNUNET_log_setup ("test_consensus_api",
"INFO",
NULL);
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "testing consensus api\n");
-
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &on_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&on_shutdown, NULL);
GNUNET_CRYPTO_hash (str, strlen (str), &session_id);
consensus = GNUNET_CONSENSUS_create (cfg, 0, NULL, &session_id,
@@ -112,10 +109,7 @@ run (void *cls,
int
main (int argc, char **argv)
{
- int ret;
-
- ret = GNUNET_TESTING_peer_run ("test_consensus_api",
- "test_consensus.conf",
- &run, NULL);
- return ret;
+ return GNUNET_TESTING_peer_run ("test_consensus_api",
+ "test_consensus.conf",
+ &run, NULL);
}
diff --git a/src/conversation/gnunet-conversation-test.c b/src/conversation/gnunet-conversation-test.c
index fe6eae925..815c7ef11 100644
--- a/src/conversation/gnunet-conversation-test.c
+++ b/src/conversation/gnunet-conversation-test.c
@@ -204,9 +204,8 @@ run (void *cls, char *const *args, const char *cfgfile,
switch_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&switch_to_speaker,
NULL);
- st = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown,
- NULL);
+ st = GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
fprintf (stderr,
_("We will now be recording you for %s. After that time, the recording will be played back to you..."),
GNUNET_STRINGS_relative_time_to_string (TIMEOUT, GNUNET_YES));
diff --git a/src/conversation/gnunet-conversation.c b/src/conversation/gnunet-conversation.c
index 9000bcf3f..d899ee5ca 100644
--- a/src/conversation/gnunet-conversation.c
+++ b/src/conversation/gnunet-conversation.c
@@ -1249,8 +1249,8 @@ run (void *cls,
handle_cmd_task =
GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI,
&handle_command, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_stop_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_stop_task,
+ NULL);
}
diff --git a/src/conversation/gnunet-service-conversation.c b/src/conversation/gnunet-service-conversation.c
index fdaa2999c..10f169105 100644
--- a/src/conversation/gnunet-service-conversation.c
+++ b/src/conversation/gnunet-service-conversation.c
@@ -1574,10 +1574,11 @@ run (void *cls,
}
nc = GNUNET_SERVER_notification_context_create (server, 16);
GNUNET_SERVER_add_handlers (server, server_handlers);
- GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown,
- NULL);
+ GNUNET_SERVER_disconnect_notify (server,
+ &handle_client_disconnect,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
}
diff --git a/src/core/gnunet-core.c b/src/core/gnunet-core.c
index 968072e22..d91dc304d 100644
--- a/src/core/gnunet-core.c
+++ b/src/core/gnunet-core.c
@@ -155,8 +155,7 @@ run (void *cls, char *const *args, const char *cfgfile,
_("Failed to connect to CORE service!\n"));
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c
index 1d9de8666..70b83b24c 100644
--- a/src/core/gnunet-service-core.c
+++ b/src/core/gnunet-service-core.c
@@ -106,9 +106,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
return;
}
GSC_stats = GNUNET_STATISTICS_create ("core", GSC_cfg);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
GNUNET_SERVER_suspend (server);
GSC_TYPEMAP_init ();
pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c
index 8250bcc6f..9bb5af100 100644
--- a/src/core/gnunet-service-core_kx.c
+++ b/src/core/gnunet-service-core_kx.c
@@ -745,9 +745,10 @@ GSC_KX_start (const struct GNUNET_PeerIdentity *pid)
{
/* peer with "higher" identity starts a delayed KX, if the "lower" peer
* does not start a KX since he sees no reasons to do so */
- kx->retry_set_key_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &set_key_retry_task,
- kx);
+ kx->retry_set_key_task
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &set_key_retry_task,
+ kx);
}
return kx;
}
diff --git a/src/core/test_core_api_mq.c b/src/core/test_core_api_mq.c
index a82465e74..8ece78e58 100644
--- a/src/core/test_core_api_mq.c
+++ b/src/core/test_core_api_mq.c
@@ -29,15 +29,15 @@
/**
* Has the test been successful?
*/
-int result;
+static int result;
-unsigned int num_received;
+static unsigned int num_received;
-struct GNUNET_CORE_Handle *core;
+static struct GNUNET_CORE_Handle *core;
-struct GNUNET_MQ_Handle *mq;
+static struct GNUNET_MQ_Handle *mq;
-struct GNUNET_PeerIdentity myself;
+static struct GNUNET_PeerIdentity myself;
static void
@@ -55,15 +55,19 @@ init_cb (void *cls,
static void
-connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
+connect_cb (void *cls,
+ const struct GNUNET_PeerIdentity *peer)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %s.\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connected to peer %s.\n",
GNUNET_i2s (peer));
if (0 == memcmp (peer, &myself, sizeof (struct GNUNET_PeerIdentity)))
{
unsigned int i;
struct GNUNET_MQ_Envelope *ev;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing messages.\n");
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Queueing messages.\n");
for (i = 0; i < NUM_MSG; i++)
{
ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_TEST);
@@ -78,7 +82,9 @@ handle_test (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got test message %d\n", num_received);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Got test message %d\n",
+ num_received);
num_received++;
if (NUM_MSG == num_received)
{
@@ -98,7 +104,8 @@ handle_test (void *cls,
static void
shutdown_task (void *cls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Shutting down\n");
GNUNET_MQ_destroy (mq);
GNUNET_CORE_disconnect (core);
}
@@ -129,9 +136,10 @@ run (void *cls,
GNUNET_assert (0);
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
+
int
main (int argc, char *argv1[])
{
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c
index ed895df42..e28f57fa6 100644
--- a/src/core/test_core_quota_compliance.c
+++ b/src/core/test_core_quota_compliance.c
@@ -163,13 +163,9 @@ terminate_task (void *cls)
static void
terminate_task_error (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
err_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Testcase failed!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Testcase failed!\n");
terminate_peer (&p1);
terminate_peer (&p2);
//GNUNET_break (0);
@@ -301,7 +297,6 @@ measurement_stop (void *cls)
*/
GNUNET_SCHEDULER_cancel (err_task);
err_task = GNUNET_SCHEDULER_add_now (&terminate_task, NULL);
-
}
@@ -357,7 +352,6 @@ transmit_ready (void *cls, size_t size, void *buf)
}
-
static void
connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
{
@@ -375,8 +369,7 @@ connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Asking core (1) for transmission to peer `%4s'\n",
GNUNET_i2s (&p2.id));
- if (err_task != NULL)
- GNUNET_SCHEDULER_cancel (err_task);
+ GNUNET_SCHEDULER_cancel (err_task);
err_task =
GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL);
start_time = GNUNET_TIME_absolute_get ();
diff --git a/src/curl/Makefile.am b/src/curl/Makefile.am
index 4bdd03039..9867ba634 100644
--- a/src/curl/Makefile.am
+++ b/src/curl/Makefile.am
@@ -17,6 +17,7 @@ libgnunetcurl_la_SOURCES = \
libgnunetcurl_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la \
-ljansson \
+ -lcurl \
$(XLIB)
#check_PROGRAMS = \
diff --git a/src/datastore/gnunet-datastore.c b/src/datastore/gnunet-datastore.c
index 186889e4c..ddca4ee06 100644
--- a/src/datastore/gnunet-datastore.c
+++ b/src/datastore/gnunet-datastore.c
@@ -224,8 +224,7 @@ run (void *cls, char *const *args, const char *cfgfile,
ret = 1;
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
do_get ();
}
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c
index fdccd925e..6ebfba7fc 100644
--- a/src/datastore/gnunet-service-datastore.c
+++ b/src/datastore/gnunet-service-datastore.c
@@ -391,7 +391,9 @@ static void
delete_expired (void *cls)
{
expired_kill_task = NULL;
- plugin->api->get_expiration (plugin->api->cls, &expired_processor, NULL);
+ plugin->api->get_expiration (plugin->api->cls,
+ &expired_processor,
+ NULL);
}
@@ -1819,9 +1821,8 @@ run (void *cls,
GNUNET_SERVER_disconnect_notify (server,
&cleanup_reservations,
NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &cleaning_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleaning_task,
+ NULL);
}
diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c
index 41cac1283..97774198c 100644
--- a/src/datastore/perf_datastore_api.c
+++ b/src/datastore/perf_datastore_api.c
@@ -351,11 +351,7 @@ run_continuation (void *cls)
static struct GNUNET_HashCode key;
static char data[65536];
char gstr[128];
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- crc->phase = RP_ERROR;
ok = (int) crc->phase;
switch (crc->phase)
{
diff --git a/src/datastore/perf_plugin_datastore.c b/src/datastore/perf_plugin_datastore.c
index 0aeb426ab..cbc01844e 100644
--- a/src/datastore/perf_plugin_datastore.c
+++ b/src/datastore/perf_plugin_datastore.c
@@ -133,6 +133,7 @@ put_continuation (void *cls,
GNUNET_SCHEDULER_add_now (&test, crc);
}
+
static void
do_put (struct CpsRunContext *crc)
{
@@ -195,9 +196,14 @@ do_put (struct CpsRunContext *crc)
static int
-iterate_zeros (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
- const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
- uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
+iterate_zeros (void *cls,
+ const struct GNUNET_HashCode *key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration,
uint64_t uid)
{
struct CpsRunContext *crc = cls;
@@ -246,10 +252,15 @@ iterate_zeros (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
static int
-expiration_get (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
- const void *data, enum GNUNET_BLOCK_Type type,
- uint32_t priority, uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration, uint64_t uid)
+expiration_get (void *cls,
+ const struct GNUNET_HashCode *key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration,
+ uint64_t uid)
{
struct CpsRunContext *crc = cls;
int i;
@@ -293,10 +304,15 @@ expiration_get (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
static int
-replication_get (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
- const void *data, enum GNUNET_BLOCK_Type type,
- uint32_t priority, uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration, uint64_t uid)
+replication_get (void *cls,
+ const struct GNUNET_HashCode *key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration,
+ uint64_t uid)
{
struct CpsRunContext *crc = cls;
int i;
@@ -388,14 +404,7 @@ static void
test (void *cls)
{
struct CpsRunContext *crc = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- GNUNET_break (0);
- crc->phase = RP_ERROR;
- }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"In phase %d, iteration %u\n", crc->phase, crc->cnt);
switch (crc->phase)
diff --git a/src/datastore/test_plugin_datastore.c b/src/datastore/test_plugin_datastore.c
index d7dff1041..9ec0c53a2 100644
--- a/src/datastore/test_plugin_datastore.c
+++ b/src/datastore/test_plugin_datastore.c
@@ -267,14 +267,7 @@ test (void *cls)
{
struct CpsRunContext *crc = cls;
struct GNUNET_HashCode key;
- 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_WARNING, "Test aborted.\n");
- crc->phase = RP_ERROR;
- }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"In phase %d, iteration %u\n", crc->phase, crc->cnt);
switch (crc->phase)
diff --git a/src/dht/gnunet-dht-get.c b/src/dht/gnunet-dht-get.c
index 6846b3af7..8a1b836f6 100644
--- a/src/dht/gnunet-dht-get.c
+++ b/src/dht/gnunet-dht-get.c
@@ -82,9 +82,14 @@ static unsigned int result_count;
*/
static int ret;
+/**
+ * Task scheduled to handle timeout.
+ */
+static struct GNUNET_SCHEDULER_Task *tt;
+
/**
- * Task run to clean up on timeout.
+ * Task run to clean up on shutdown.
*
* @param cls unused
*/
@@ -101,6 +106,24 @@ cleanup_task (void *cls)
GNUNET_DHT_disconnect (dht_handle);
dht_handle = NULL;
}
+ if (NULL != tt)
+ {
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
+ }
+}
+
+
+/**
+ * Task run on timeout. Triggers shutdown.
+ *
+ * @param cls unused
+ */
+static void
+timeout_task (void *cls)
+{
+ tt = NULL;
+ GNUNET_SCHEDULER_shutdown ();
}
@@ -170,8 +193,9 @@ run (void *cls, char *const *args, const char *cfgfile,
GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key);
if (verbose)
FPRINTF (stderr, "%s `%s' \n", _("Issueing DHT GET with key"), GNUNET_h2s_full (&key));
- GNUNET_SCHEDULER_add_delayed (timeout_request,
- &cleanup_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL);
+ tt = GNUNET_SCHEDULER_add_delayed (timeout_request,
+ &timeout_task, NULL);
get_handle =
GNUNET_DHT_get_start (dht_handle, query_type, &key, replication,
(demultixplex_everywhere) ? GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE : GNUNET_DHT_RO_NONE,
diff --git a/src/dht/gnunet-dht-monitor.c b/src/dht/gnunet-dht-monitor.c
index 0502496d7..7f14255d3 100644
--- a/src/dht/gnunet-dht-monitor.c
+++ b/src/dht/gnunet-dht-monitor.c
@@ -71,6 +71,11 @@ static unsigned int result_count;
*/
static int ret;
+/**
+ * Task scheduled to handle timeout.
+ */
+static struct GNUNET_SCHEDULER_Task *tt;
+
/**
* Stop monitoring request and start shutdown
@@ -92,9 +97,28 @@ cleanup_task (void *cls)
GNUNET_DHT_disconnect (dht_handle);
dht_handle = NULL;
}
+ if (NULL != tt)
+ {
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
+ }
+}
+
+
+/**
+ * We hit a timeout. Stop monitoring request and start shutdown
+ *
+ * @param cls closure (unused)
+ */
+static void
+timeout_task (void *cls)
+{
+ tt = NULL;
+ GNUNET_SCHEDULER_shutdown ();
}
+
/**
* Callback called on each GET request going through the DHT.
*
@@ -107,7 +131,7 @@ cleanup_task (void *cls)
* @param desired_replication_level Desired replication level.
* @param key Key of the requested data.
*/
-void
+static void
get_callback (void *cls,
enum GNUNET_DHT_RouteOption options,
enum GNUNET_BLOCK_Type type,
@@ -139,7 +163,7 @@ get_callback (void *cls,
* @param data Pointer to the result data.
* @param size Number of bytes in data.
*/
-void
+static void
get_resp_callback (void *cls,
enum GNUNET_BLOCK_Type type,
const struct GNUNET_PeerIdentity *get_path,
@@ -177,7 +201,7 @@ get_resp_callback (void *cls,
* @param data Pointer to the data carried.
* @param size Number of bytes in data.
*/
-void
+static void
put_callback (void *cls,
enum GNUNET_DHT_RouteOption options,
enum GNUNET_BLOCK_Type type,
@@ -242,7 +266,11 @@ run (void *cls, char *const *args, const char *cfgfile,
FPRINTF (stderr,
"Monitoring for %s\n",
GNUNET_STRINGS_relative_time_to_string (timeout_request, GNUNET_NO));
- GNUNET_SCHEDULER_add_delayed (timeout_request, &cleanup_task, NULL);
+ tt = GNUNET_SCHEDULER_add_delayed (timeout_request,
+ &timeout_task,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
+ NULL);
monitor_handle = GNUNET_DHT_monitor_start (dht_handle,
block_type,
key,
diff --git a/src/dht/gnunet-dht-put.c b/src/dht/gnunet-dht-put.c
index 19e385be1..972369e10 100644
--- a/src/dht/gnunet-dht-put.c
+++ b/src/dht/gnunet-dht-put.c
@@ -98,6 +98,7 @@ shutdown_task (void *cls)
}
}
+
/**
* Signature of the main function of a task.
*
@@ -132,6 +133,7 @@ message_sent_cont (void *cls, int success)
GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
}
+
/**
* Main function that will be run by the scheduler.
*
@@ -141,14 +143,15 @@ message_sent_cont (void *cls, int success)
* @param c 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 *c)
{
struct GNUNET_TIME_Relative timeout;
struct GNUNET_TIME_Absolute expiration;
cfg = c;
-
if ((NULL == query_key) || (NULL == data))
{
FPRINTF (stderr, "%s", _("Must provide KEY and DATA for DHT put!\n"));
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index 1aeca9b85..a44be2dfe 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -161,9 +161,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
shutdown_task (NULL);
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
GDS_transport_handle =
GNUNET_TRANSPORT_connect (GDS_cfg, NULL, NULL, NULL, NULL, NULL);
if (GDS_transport_handle == NULL)
diff --git a/src/dht/gnunet-service-dht_clients.c b/src/dht/gnunet-service-dht_clients.c
index e42069fe0..a5757c25a 100644
--- a/src/dht/gnunet-service-dht_clients.c
+++ b/src/dht/gnunet-service-dht_clients.c
@@ -456,12 +456,8 @@ transmit_next_request_task (void *cls)
{
struct ClientQueryRecord *cqr;
struct GNUNET_TIME_Relative delay;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
retry_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap)))
{
cqr->hnode = NULL;
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index d82effb34..8ab39c9aa 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -712,12 +712,8 @@ send_find_peer_message (void *cls)
struct GNUNET_TIME_Relative next_send_time;
struct BloomConstructorContext bcc;
struct GNUNET_CONTAINER_BloomFilter *peer_bf;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
find_peer_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
if (newly_found_peers > bucket_size)
{
/* If we are finding many peers already, no need to send out our request right now! */
@@ -2443,6 +2439,7 @@ GDS_NEIGHBOURS_done ()
}
}
+
/**
* Get the ID of the local node.
*
diff --git a/src/dht/gnunet-service-wdht.c b/src/dht/gnunet-service-wdht.c
index 0668c9078..b58bb729d 100644
--- a/src/dht/gnunet-service-wdht.c
+++ b/src/dht/gnunet-service-wdht.c
@@ -102,9 +102,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
shutdown_task (NULL);
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
diff --git a/src/dht/gnunet-service-wdht_clients.c b/src/dht/gnunet-service-wdht_clients.c
index c3aff03aa..8eb114660 100644
--- a/src/dht/gnunet-service-wdht_clients.c
+++ b/src/dht/gnunet-service-wdht_clients.c
@@ -880,12 +880,8 @@ transmit_next_request_task (void *cls)
{
struct ClientQueryRecord *cqr;
struct GNUNET_TIME_Relative delay;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
retry_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap)))
{
cqr->hnode = NULL;
diff --git a/src/dht/gnunet-service-xdht.c b/src/dht/gnunet-service-xdht.c
index f6c7c5167..8a60a8d9d 100644
--- a/src/dht/gnunet-service-xdht.c
+++ b/src/dht/gnunet-service-xdht.c
@@ -17,14 +17,12 @@
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
-
/**
* @file dht/gnunet-service-xdht.c
* @brief GNUnet DHT service
* @author Christian Grothoff
* @author Nathan Evans
*/
-
#include "platform.h"
#include "gnunet_block_lib.h"
#include "gnunet_util_lib.h"
@@ -125,9 +123,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
shutdown_task (NULL);
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
diff --git a/src/dht/gnunet-service-xdht_clients.c b/src/dht/gnunet-service-xdht_clients.c
index e08ccf792..3475d00c9 100644
--- a/src/dht/gnunet-service-xdht_clients.c
+++ b/src/dht/gnunet-service-xdht_clients.c
@@ -877,12 +877,8 @@ transmit_next_request_task (void *cls)
{
struct ClientQueryRecord *cqr;
struct GNUNET_TIME_Relative delay;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
retry_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap)))
{
cqr->hnode = NULL;
diff --git a/src/dht/gnunet_dht_profiler.c b/src/dht/gnunet_dht_profiler.c
index f0c4ec7be..03ea62152 100644
--- a/src/dht/gnunet_dht_profiler.c
+++ b/src/dht/gnunet_dht_profiler.c
@@ -461,9 +461,21 @@ do_shutdown (void *cls)
a_ctx = NULL;
}
//FIXME: Should we collect stats only for put/get not for other messages.
- if(NULL != bandwidth_stats_op)
+ if (NULL != bandwidth_stats_op)
+ {
GNUNET_TESTBED_operation_done (bandwidth_stats_op);
- bandwidth_stats_op = NULL;
+ bandwidth_stats_op = NULL;
+ }
+ if (NULL != successor_stats_op)
+ {
+ GNUNET_TESTBED_operation_done (successor_stats_op);
+ successor_stats_op = NULL;
+ }
+ if (NULL != successor_stats_task)
+ {
+ GNUNET_SCHEDULER_cancel (successor_stats_task);
+ successor_stats_task = NULL;
+ }
GNUNET_free_non_null (a_ac);
}
@@ -687,11 +699,7 @@ teardown_dht_connection (void *cls)
{
struct Context *ctx = cls;
struct GNUNET_TESTBED_Operation *op;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
GNUNET_assert (NULL != ctx);
GNUNET_assert (NULL != (op = ctx->op));
ctx->op = NULL;
@@ -1070,7 +1078,7 @@ successor_stats_cont (void *cls,
successor_stats_op = NULL;
if (0 == max_searches)
{
- start_func();
+ start_func ();
return;
}
@@ -1108,39 +1116,27 @@ successor_stats_cont (void *cls,
GNUNET_NO);
if ((start_val == val) && (count == num_peers))
{
- DEBUG("CIRCLE COMPLETED after %u tries", tries);
+ DEBUG ("CIRCLE COMPLETED after %u tries", tries);
if(NULL == successor_stats_task)
{
start_func();
}
return;
}
- else
+ if (max_searches == ++tries)
{
- if (max_searches == ++tries)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Maximum tries %u exceeded while checking successor TOTAL TRIES %u"
- " circle formation. Exiting\n",
- max_searches,tries);
- if (NULL != successor_stats_task)
- {
- successor_stats_task = NULL;
- }
- if(NULL == successor_stats_task)
- {
- start_func();
- }
-
- return;
- }
- else
- {
- flag = 0;
- successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay_stats,
- &collect_stats, cls);
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Maximum tries %u exceeded while checking successor TOTAL TRIES %u"
+ " circle formation. Exiting\n",
+ max_searches,tries);
+ start_func();
+ return;
}
+ flag = 0;
+ successor_stats_task
+ = GNUNET_SCHEDULER_add_delayed (delay_stats,
+ &collect_stats,
+ cls);
}
@@ -1214,26 +1210,21 @@ successor_stats_iterator (void *cls,
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;
-
+ successor_stats_task = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Start collecting statistics...\n");
GNUNET_assert(NULL != testbed_handles);
if (0 != max_searches)
- successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (num_peers,
- GNUNET_NO);
- successor_stats_op =
- GNUNET_TESTBED_get_statistics (num_peers, testbed_handles,
- "dht", NULL,
- successor_stats_iterator,
- successor_stats_cont, cls);
-
- GNUNET_assert(NULL != successor_stats_op);
+ successor_peer_hashmap
+ = GNUNET_CONTAINER_multihashmap_create (num_peers,
+ GNUNET_NO);
+ successor_stats_op
+ = GNUNET_TESTBED_get_statistics (num_peers, testbed_handles,
+ "dht", NULL,
+ successor_stats_iterator,
+ successor_stats_cont, cls);
+ GNUNET_assert (NULL != successor_stats_op);
}
@@ -1265,9 +1256,10 @@ service_started (void *cls,
collect_stat_cls->service_connect_ctx = cls;
collect_stat_cls->op = op;
- successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay_stats,
- &collect_stats,
- collect_stat_cls);
+ successor_stats_task
+ = GNUNET_SCHEDULER_add_delayed (delay_stats,
+ &collect_stats,
+ collect_stat_cls);
}
}
@@ -1393,7 +1385,8 @@ run (void *cls, char *const *args, const char *cfgfile,
if (0 == num_peers)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Exiting as the number of peers is %u\n"),
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Exiting as the number of peers is %u\n"),
num_peers);
return;
}
@@ -1401,8 +1394,8 @@ run (void *cls, char *const *args, const char *cfgfile,
event_mask = 0;
GNUNET_TESTBED_run (hosts_file, cfg, num_peers, event_mask, NULL,
NULL, &test_run, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
}
diff --git a/src/dns/dnsstub.c b/src/dns/dnsstub.c
index 957777cba..c1e7b5f61 100644
--- a/src/dns/dnsstub.c
+++ b/src/dns/dnsstub.c
@@ -476,7 +476,7 @@ read_response (void *cls)
tc = GNUNET_SCHEDULER_get_task_context ();
if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
{
- /* timeout or shutdown */
+ /* timeout */
cleanup_rs (rs);
return;
}
diff --git a/src/dns/gnunet-dns-monitor.c b/src/dns/gnunet-dns-monitor.c
index c9d840325..5e6f90555 100644
--- a/src/dns/gnunet-dns-monitor.c
+++ b/src/dns/gnunet-dns-monitor.c
@@ -339,8 +339,7 @@ run (void *cls, char *const *args, const char *cfgfile,
flags,
&display_request,
NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_disconnect, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_disconnect, NULL);
}
diff --git a/src/dns/gnunet-dns-redirector.c b/src/dns/gnunet-dns-redirector.c
index 8ef69eb91..89929815a 100644
--- a/src/dns/gnunet-dns-redirector.c
+++ b/src/dns/gnunet-dns-redirector.c
@@ -223,8 +223,7 @@ run (void *cls, char *const *args, const char *cfgfile,
GNUNET_DNS_FLAG_POST_RESOLUTION,
&modify_request,
NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_disconnect, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_disconnect, NULL);
}
diff --git a/src/dns/gnunet-service-dns.c b/src/dns/gnunet-service-dns.c
index 972c96f6d..b580f433f 100644
--- a/src/dns/gnunet-service-dns.c
+++ b/src/dns/gnunet-service-dns.c
@@ -1045,9 +1045,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
cfg = cfg_;
stats = GNUNET_STATISTICS_create ("dns", cfg);
nc = GNUNET_SERVER_notification_context_create (server, 1);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &cleanup_task,
- cls);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
+ cls);
dns_exit = NULL;
if ( ( (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
diff --git a/src/dv/gnunet-dv.c b/src/dv/gnunet-dv.c
index d5d95acca..d0917d363 100644
--- a/src/dv/gnunet-dv.c
+++ b/src/dv/gnunet-dv.c
@@ -145,8 +145,7 @@ run (void *cls, char *const *args, const char *cfgfile,
&change_cb,
&disconnect_cb,
&message_cb);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c
index bd0057ab4..df95fd67b 100644
--- a/src/dv/gnunet-service-dv.c
+++ b/src/dv/gnunet-service-dv.c
@@ -2229,8 +2229,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
MAX_QUEUE_SIZE_PLUGIN);
stats = GNUNET_STATISTICS_create ("dv", cfg);
GNUNET_SERVER_add_handlers (server, plugin_handlers);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
diff --git a/src/dv/test_transport_dv.c b/src/dv/test_transport_dv.c
index 1afa30fa9..0a43252a5 100644
--- a/src/dv/test_transport_dv.c
+++ b/src/dv/test_transport_dv.c
@@ -82,8 +82,8 @@ test_connection (void *cls,
unsigned int links_succeeded,
unsigned int links_failed)
{
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ shutdown_task = GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
if (4 != num_peers)
{
ok = 1;
diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c
index 8456018ab..f31e11d83 100644
--- a/src/exit/gnunet-daemon-exit.c
+++ b/src/exit/gnunet-daemon-exit.c
@@ -3149,7 +3149,6 @@ dummy_task (void *cls)
* Function scheduled as very last function, cleans up after us
*
* @param cls NULL
- * @param tc scheduler context
*/
static void
cleanup (void *cls)
@@ -3548,9 +3547,8 @@ run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("`%s' must be installed SUID, EXIT will not work\n"),
"gnunet-helper-exit");
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &dummy_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&dummy_task,
+ NULL);
global_ret = 1;
return;
}
@@ -3639,9 +3637,8 @@ run (void *cls,
app_idx++;
}
GNUNET_free_non_null (dns_exit);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &cleanup,
- cls);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup,
+ NULL);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (cfg, "exit", "MAX_CONNECTIONS",
diff --git a/src/fs/gnunet-auto-share.c b/src/fs/gnunet-auto-share.c
index aef66614c..96f86bf5d 100644
--- a/src/fs/gnunet-auto-share.c
+++ b/src/fs/gnunet-auto-share.c
@@ -95,11 +95,6 @@ static int disable_extractor;
static int do_disable_creation_time;
/**
- * Handle for the 'shutdown' task.
- */
-static struct GNUNET_SCHEDULER_Task *kill_task;
-
-/**
* Handle for the main task that does scanning and working.
*/
static struct GNUNET_SCHEDULER_Task *run_task;
@@ -321,7 +316,6 @@ save_state ()
static void
do_stop_task (void *cls)
{
- kill_task = NULL;
do_shutdown = GNUNET_YES;
if (NULL != publish_proc)
{
@@ -729,10 +723,8 @@ run (void *cls,
run_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
&scan,
NULL);
- kill_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_stop_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_stop_task,
+ NULL);
}
diff --git a/src/fs/gnunet-daemon-fsprofiler.c b/src/fs/gnunet-daemon-fsprofiler.c
index 326178df9..e6bc33e10 100644
--- a/src/fs/gnunet-daemon-fsprofiler.c
+++ b/src/fs/gnunet-daemon-fsprofiler.c
@@ -500,12 +500,8 @@ start_publish (void *cls)
{
struct Pattern *p = cls;
struct GNUNET_FS_FileInformation *fi;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
p->task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
fi = make_file (p->x, p->y, p);
p->start_time = GNUNET_TIME_absolute_get ();
p->ctx = GNUNET_FS_publish_start (fs_handle,
@@ -525,12 +521,8 @@ start_download (void *cls)
{
struct Pattern *p = cls;
struct GNUNET_FS_Uri *keywords;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
p->task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
keywords = make_keywords (p->x);
p->start_time = GNUNET_TIME_absolute_get ();
p->sctx = GNUNET_FS_search_start (fs_handle, keywords,
@@ -558,8 +550,8 @@ run (void *cls, char *const *args GNUNET_UNUSED,
cfg = cfg_;
/* 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);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (cfg,
diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c
index a2b0aa5fc..6d9adb8ab 100644
--- a/src/fs/gnunet-download.c
+++ b/src/fs/gnunet-download.c
@@ -284,8 +284,8 @@ run (void *cls, char *const *args, const char *cfgfile,
ctx = NULL;
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
diff --git a/src/fs/gnunet-fs-profiler.c b/src/fs/gnunet-fs-profiler.c
index 69433346f..cfbe57bbd 100644
--- a/src/fs/gnunet-fs-profiler.c
+++ b/src/fs/gnunet-fs-profiler.c
@@ -105,7 +105,7 @@ process_stats (void *cls,
/**
- * Task run on timeout to terminate. Triggers printing out
+ * Task run on shutdown to terminate. Triggers printing out
* all statistics.
*
* @param cls NULL
@@ -113,7 +113,11 @@ process_stats (void *cls,
static void
terminate_task (void *cls)
{
- terminate_taskid = NULL;
+ if (NULL != terminate_taskid)
+ {
+ GNUNET_SCHEDULER_cancel (terminate_taskid);
+ terminate_taskid = NULL;
+ }
GNUNET_TESTBED_get_statistics (0, NULL,
NULL, NULL,
&process_stats,
@@ -123,6 +127,20 @@ terminate_task (void *cls)
/**
+ * Task run on timeout to terminate. Triggers printing out
+ * all statistics.
+ *
+ * @param cls NULL
+ */
+static void
+timeout_task (void *cls)
+{
+ terminate_taskid = NULL;
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
+/**
* Signature of a main function for a testcase.
*
* @param cls closure
@@ -148,11 +166,10 @@ test_master (void *cls,
if (0 != timeout.rel_value_us)
terminate_taskid = GNUNET_SCHEDULER_add_delayed (timeout,
- &terminate_task, NULL);
- else
- terminate_taskid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &terminate_task,
+ &timeout_task,
NULL);
+ GNUNET_SCHEDULER_add_shutdown (&terminate_task,
+ NULL);
}
diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c
index f058c10b2..a563d7b7a 100644
--- a/src/fs/gnunet-publish.c
+++ b/src/fs/gnunet-publish.c
@@ -872,9 +872,8 @@ run (void *cls,
ret = 1;
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_stop_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_stop_task,
+ NULL);
if (NULL != pseudonym)
identity = GNUNET_IDENTITY_connect (cfg,
&identity_cb,
diff --git a/src/fs/gnunet-search.c b/src/fs/gnunet-search.c
index a15d0d883..0ddcd892e 100644
--- a/src/fs/gnunet-search.c
+++ b/src/fs/gnunet-search.c
@@ -55,6 +55,9 @@ static int verbose;
static int local_only;
+static struct GNUNET_SCHEDULER_Task *tt;
+
+
/**
* Type of a function that libextractor calls for each
* meta data item found.
@@ -220,6 +223,14 @@ shutdown_task (void *cls)
}
+static void
+timeout_task (void *cls)
+{
+ tt = NULL;
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
/**
* Main function that will be run by the scheduler.
*
@@ -272,10 +283,11 @@ run (void *cls, char *const *args, const char *cfgfile,
return;
}
if (0 != timeout.rel_value_us)
- GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_task, NULL);
- else
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ tt = GNUNET_SCHEDULER_add_delayed (timeout,
+ &timeout_task,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c
index 2ba96334c..348bab092 100644
--- a/src/fs/gnunet-service-fs.c
+++ b/src/fs/gnunet-service-fs.c
@@ -191,7 +191,8 @@ age_cover_counters (void *cls)
GSF_cover_content_count = (GSF_cover_content_count * 15) / 16;
GSF_cover_query_count = (GSF_cover_query_count * 15) / 16;
cover_age_task =
- GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, &age_cover_counters,
+ GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY,
+ &age_cover_counters,
NULL);
}
@@ -759,13 +760,14 @@ main_init (struct GNUNET_SERVER_Handle *server,
NULL);
GNUNET_SERVER_add_handlers (server, handlers);
cover_age_task =
- GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, &age_cover_counters,
+ GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY,
+ &age_cover_counters,
NULL);
datastore_get_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE);
GSF_cadet_start_server ();
GSF_cadet_start_client ();
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
return GNUNET_OK;
}
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c
index e916a73a8..53838a542 100644
--- a/src/fs/gnunet-service-fs_cp.c
+++ b/src/fs/gnunet-service-fs_cp.c
@@ -335,6 +335,11 @@ static struct GNUNET_CONTAINER_MultiPeerMap *cp_map;
*/
static struct GNUNET_PEERSTORE_Handle *peerstore;
+/**
+ * Task used to flush respect values to disk.
+ */
+static struct GNUNET_SCHEDULER_Task *fr_task;
+
/**
* Update the latency information kept for the given peer.
@@ -876,19 +881,11 @@ transmit_delayed_now (void *cls)
{
struct GSF_DelayedHandle *dh = cls;
struct GSF_ConnectedPeer *cp = dh->cp;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
GNUNET_CONTAINER_DLL_remove (cp->delayed_head,
cp->delayed_tail,
dh);
cp->delay_queue_size--;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- {
- GNUNET_free (dh->pm);
- GNUNET_free (dh);
- return;
- }
(void) GSF_peer_transmit_ (cp,
GNUNET_NO,
UINT32_MAX,
@@ -1977,18 +1974,13 @@ GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp,
static void
cron_flush_respect (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- if (NULL == cp_map)
- return;
+ fr_task = NULL;
GNUNET_CONTAINER_multipeermap_iterate (cp_map,
- &flush_respect, NULL);
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
- GNUNET_SCHEDULER_add_delayed_with_priority (RESPECT_FLUSH_FREQ,
- GNUNET_SCHEDULER_PRIORITY_HIGH,
- &cron_flush_respect, NULL);
+ &flush_respect,
+ NULL);
+ fr_task = GNUNET_SCHEDULER_add_delayed_with_priority (RESPECT_FLUSH_FREQ,
+ GNUNET_SCHEDULER_PRIORITY_HIGH,
+ &cron_flush_respect, NULL);
}
@@ -2000,8 +1992,8 @@ GSF_connected_peer_init_ ()
{
cp_map = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES);
peerstore = GNUNET_PEERSTORE_connect (GSF_cfg);
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_HIGH,
- &cron_flush_respect, NULL);
+ fr_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_HIGH,
+ &cron_flush_respect, NULL);
}
@@ -2033,10 +2025,15 @@ GSF_connected_peer_done_ ()
&flush_respect,
NULL);
GNUNET_CONTAINER_multipeermap_iterate (cp_map,
- &clean_peer, NULL);
+ &clean_peer,
+ NULL);
+ GNUNET_SCHEDULER_cancel (fr_task);
+ fr_task = NULL;
GNUNET_CONTAINER_multipeermap_destroy (cp_map);
cp_map = NULL;
- GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_YES);
+ GNUNET_PEERSTORE_disconnect (peerstore,
+ GNUNET_YES);
+
}
diff --git a/src/fs/gnunet-service-fs_put.c b/src/fs/gnunet-service-fs_put.c
index fa5aa461d..045b640db 100644
--- a/src/fs/gnunet-service-fs_put.c
+++ b/src/fs/gnunet-service-fs_put.c
@@ -215,12 +215,8 @@ static void
gather_dht_put_blocks (void *cls)
{
struct PutOperator *po = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
po->dht_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
po->dht_qe =
GNUNET_DATASTORE_get_zero_anonymity (GSF_dsh, po->current_offset++, 0,
UINT_MAX,
diff --git a/src/fs/gnunet-unindex.c b/src/fs/gnunet-unindex.c
index cab963e0d..40fa13b62 100644
--- a/src/fs/gnunet-unindex.c
+++ b/src/fs/gnunet-unindex.c
@@ -147,8 +147,8 @@ run (void *cls, char *const *args, const char *cfgfile,
GNUNET_FS_stop (ctx);
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
diff --git a/src/fs/test_gnunet_service_fs_migration.c b/src/fs/test_gnunet_service_fs_migration.c
index f00290b0d..2ff495ac3 100644
--- a/src/fs/test_gnunet_service_fs_migration.c
+++ b/src/fs/test_gnunet_service_fs_migration.c
@@ -142,15 +142,13 @@ static void
stop_source_peer (void *cls)
{
struct DownloadContext *dc = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- /* Do not interact with testbed when shutting down */
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ /* FIXME: We should not interact with testbed when shutting down */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Stopping source peer\n");
- op = GNUNET_TESTBED_peer_stop (NULL, daemons[1], &do_download, dc);
+ op = GNUNET_TESTBED_peer_stop (NULL,
+ daemons[1],
+ &do_download, dc);
GNUNET_assert (NULL != op);
}
@@ -176,7 +174,9 @@ do_wait (void *cls,
dc->uri = GNUNET_FS_uri_dup (uri);
if (NULL != fn)
dc->fn = GNUNET_strdup (fn);
- (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY, &stop_source_peer, dc);
+ (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY,
+ &stop_source_peer,
+ dc);
}
@@ -196,7 +196,8 @@ do_publish (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Publishing %llu bytes\n",
(unsigned long long) FILESIZE);
- GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED,
+ GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, 1, GNUNET_NO,
+ FILESIZE, SEED,
VERBOSE, &do_wait, NULL);
}
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index 6696158c9..a1fe3680a 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.c
@@ -239,9 +239,10 @@ force_reconnect (struct GNUNET_GNS_Handle *handle)
p);
}
handle->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff);
- handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff,
- &reconnect_task,
- handle);
+ handle->reconnect_task
+ = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff,
+ &reconnect_task,
+ handle);
}
diff --git a/src/gns/gnunet-bcd.c b/src/gns/gnunet-bcd.c
index e7be8fd84..284804175 100644
--- a/src/gns/gnunet-bcd.c
+++ b/src/gns/gnunet-bcd.c
@@ -90,10 +90,14 @@ struct Entry
* Main request handler.
*/
static int
-access_handler_callback (void *cls, struct MHD_Connection *connection,
- const char *url, const char *method,
- const char *version, const char *upload_data,
- size_t * upload_data_size, void **con_cls)
+access_handler_callback (void *cls,
+ struct MHD_Connection *connection,
+ const char *url,
+ const char *method,
+ const char *version,
+ const char *upload_data,
+ size_t * upload_data_size,
+ void **con_cls)
{
static int dummy;
static const struct Entry map[] = {
@@ -290,12 +294,8 @@ static void
run_daemon (void *cls)
{
struct MHD_Daemon *daemon_handle = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
http_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
http_task = prepare_daemon (daemon_handle);
}
@@ -499,9 +499,8 @@ run (void *cls,
if (GNUNET_OK !=
server_start ())
return;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &server_stop,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&server_stop,
+ NULL);
}
diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c
index 119bda91a..df3b4e882 100644
--- a/src/gns/gnunet-dns2gns.c
+++ b/src/gns/gnunet-dns2gns.c
@@ -175,9 +175,15 @@ static void
do_shutdown (void *cls)
{
if (NULL != t4)
+ {
GNUNET_SCHEDULER_cancel (t4);
+ t4 = NULL;
+ }
if (NULL != t6)
+ {
GNUNET_SCHEDULER_cancel (t6);
+ t6 = NULL;
+ }
if (NULL != listen_socket4)
{
GNUNET_NETWORK_socket_close (listen_socket4);
@@ -607,57 +613,57 @@ run_dnsd ()
SOCK_DGRAM,
IPPROTO_UDP);
if (NULL != listen_socket4)
- {
- struct sockaddr_in v4;
-
- memset (&v4, 0, sizeof (v4));
- v4.sin_family = AF_INET;
+ {
+ struct sockaddr_in v4;
+
+ memset (&v4, 0, sizeof (v4));
+ v4.sin_family = AF_INET;
#if HAVE_SOCKADDR_IN_SIN_LEN
- v4.sin_len = sizeof (v4);
+ v4.sin_len = sizeof (v4);
#endif
- v4.sin_port = htons (listen_port);
- if (GNUNET_OK !=
- GNUNET_NETWORK_socket_bind (listen_socket4,
- (struct sockaddr *) &v4,
- sizeof (v4)))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
- GNUNET_NETWORK_socket_close (listen_socket4);
- listen_socket4 = NULL;
- }
+ v4.sin_port = htons (listen_port);
+ if (GNUNET_OK !=
+ GNUNET_NETWORK_socket_bind (listen_socket4,
+ (struct sockaddr *) &v4,
+ sizeof (v4)))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
+ GNUNET_NETWORK_socket_close (listen_socket4);
+ listen_socket4 = NULL;
}
+ }
listen_socket6 = GNUNET_NETWORK_socket_create (PF_INET6,
SOCK_DGRAM,
IPPROTO_UDP);
if (NULL != listen_socket6)
- {
- struct sockaddr_in6 v6;
-
- memset (&v6, 0, sizeof (v6));
- v6.sin6_family = AF_INET6;
+ {
+ struct sockaddr_in6 v6;
+
+ memset (&v6, 0, sizeof (v6));
+ v6.sin6_family = AF_INET6;
#if HAVE_SOCKADDR_IN_SIN_LEN
- v6.sin6_len = sizeof (v6);
+ v6.sin6_len = sizeof (v6);
#endif
- v6.sin6_port = htons (listen_port);
- if (GNUNET_OK !=
- GNUNET_NETWORK_socket_bind (listen_socket6,
- (struct sockaddr *) &v6,
- sizeof (v6)))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
- GNUNET_NETWORK_socket_close (listen_socket6);
- listen_socket6 = NULL;
- }
+ v6.sin6_port = htons (listen_port);
+ if (GNUNET_OK !=
+ GNUNET_NETWORK_socket_bind (listen_socket6,
+ (struct sockaddr *) &v6,
+ sizeof (v6)))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
+ GNUNET_NETWORK_socket_close (listen_socket6);
+ listen_socket6 = NULL;
}
+ }
if ( (NULL == listen_socket4) &&
(NULL == listen_socket6) )
- {
- GNUNET_GNS_disconnect (gns);
- gns = NULL;
- GNUNET_DNSSTUB_stop (dns_stub);
- dns_stub = NULL;
- return;
- }
+ {
+ GNUNET_GNS_disconnect (gns);
+ gns = NULL;
+ GNUNET_DNSSTUB_stop (dns_stub);
+ dns_stub = NULL;
+ return;
+ }
if (NULL != listen_socket4)
t4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
listen_socket4,
@@ -668,7 +674,6 @@ run_dnsd ()
listen_socket6,
&read_dns6,
listen_socket6);
-
}
@@ -719,7 +724,9 @@ identity_cb (void *cls,
* @param c 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 *c)
{
cfg = c;
@@ -730,8 +737,7 @@ run (void *cls, char *const *args, const char *cfgfile,
_("No DNS server specified!\n"));
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
if (NULL == gns_zone_str)
{
identity = GNUNET_IDENTITY_connect (cfg,
@@ -745,8 +751,8 @@ run (void *cls, char *const *args, const char *cfgfile,
if ( (NULL == gns_zone_str) ||
(GNUNET_OK !=
GNUNET_CRYPTO_ecdsa_public_key_from_string (gns_zone_str,
- strlen (gns_zone_str),
- &my_zone)) )
+ strlen (gns_zone_str),
+ &my_zone)) )
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("No valid GNS zone specified!\n"));
diff --git a/src/gns/gnunet-gns-helper-service-w32.c b/src/gns/gnunet-gns-helper-service-w32.c
index 112bcd258..c9c9e3fec 100644
--- a/src/gns/gnunet-gns-helper-service-w32.c
+++ b/src/gns/gnunet-gns-helper-service-w32.c
@@ -827,8 +827,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
identity = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
if (NULL == identity)
diff --git a/src/gns/gnunet-gns-import.c b/src/gns/gnunet-gns-import.c
index 5f94e7792..e98babfa8 100644
--- a/src/gns/gnunet-gns-import.c
+++ b/src/gns/gnunet-gns-import.c
@@ -454,8 +454,7 @@ run (void *cls, char *const *args, const char *cfgfile,
ns = GNUNET_NAMESTORE_connect (cfg);
sh = GNUNET_IDENTITY_connect (cfg, &get_ego, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index 9a34c83af..6793d6f5c 100644
--- a/src/gns/gnunet-gns-proxy.c
+++ b/src/gns/gnunet-gns-proxy.c
@@ -2713,15 +2713,11 @@ do_accept (void *cls)
struct GNUNET_NETWORK_Handle *lsock = cls;
struct GNUNET_NETWORK_Handle *s;
struct Socks5Request *s5r;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
if (lsock == lsock4)
ltask4 = NULL;
else
ltask6 = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
if (lsock == lsock4)
ltask4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
lsock,
@@ -3126,8 +3122,7 @@ run (void *cls, char *const *args, const char *cfgfile,
"gns-proxy",
&identity_master_cb,
NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
}
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c
index c8310db46..62cec54cb 100644
--- a/src/gns/gnunet-gns.c
+++ b/src/gns/gnunet-gns.c
@@ -100,6 +100,11 @@ static struct GNUNET_IDENTITY_Handle *identity;
*/
static struct GNUNET_IDENTITY_Operation *id_op;
+/**
+ * Task scheduled to handle timeout.
+ */
+static struct GNUNET_SCHEDULER_Task *tt;
+
/**
* Task run on shutdown. Cleans up everything.
@@ -134,6 +139,24 @@ do_shutdown (void *cls)
GNUNET_GNS_disconnect (gns);
gns = NULL;
}
+ if (NULL != tt)
+ {
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
+ }
+}
+
+
+/**
+ * Task run on timeout. Triggers shutdown.
+ *
+ * @param cls unused
+ */
+static void
+do_timeout (void *cls)
+{
+ tt = NULL;
+ GNUNET_SCHEDULER_shutdown ();
}
@@ -376,7 +399,9 @@ identity_master_cb (void *cls,
* @param c 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 *c)
{
struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
@@ -390,8 +415,9 @@ run (void *cls, char *const *args, const char *cfgfile,
_("Failed to connect to GNS\n"));
return;
}
- GNUNET_SCHEDULER_add_delayed (timeout,
- &do_shutdown, NULL);
+ tt = GNUNET_SCHEDULER_add_delayed (timeout,
+ &do_timeout, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
if (NULL != public_key)
{
if (GNUNET_OK !=
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 87b0fd04e..682d8f5f7 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -1010,8 +1010,7 @@ run (void *cls,
&monitor_sync_event,
NULL);
GNUNET_break (NULL != zmon);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
diff --git a/src/gns/plugin_rest_gns.c b/src/gns/plugin_rest_gns.c
index 8a3f26041..1315e6cda 100644
--- a/src/gns/plugin_rest_gns.c
+++ b/src/gns/plugin_rest_gns.c
@@ -632,9 +632,10 @@ options_cont (struct RestConnectionDataHandle *con_handle,
MHD_add_response_header (resp,
"Access-Control-Allow-Methods",
MHD_HTTP_METHOD_GET);
- handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
+ handle->proc (handle->proc_cls,
+ resp,
+ MHD_HTTP_OK);
cleanup_handle (handle);
- return;
}
@@ -671,7 +672,6 @@ rest_gns_process_request(struct RestConnectionDataHandle *conndata_handle,
}
-
/**
* Entry point for the plugin.
*
diff --git a/src/gns/test_gns_proxy.c b/src/gns/test_gns_proxy.c
index 0afc3ea0b..55ada84d7 100644
--- a/src/gns/test_gns_proxy.c
+++ b/src/gns/test_gns_proxy.c
@@ -245,6 +245,7 @@ curl_main ()
NULL);
}
+
static void
start_curl (void *cls)
{
@@ -289,25 +290,27 @@ disco_ns (void* cls)
* specified target peer; NULL on error
*/
static void
-commence_testing (void *cls, int32_t success, const char *emsg)
+commence_testing (void *cls,
+ int32_t success,
+ const char *emsg)
{
GNUNET_SCHEDULER_add_now (&disco_ns, NULL);
- if ((emsg != NULL) && (GNUNET_YES != success))
+ if ( (emsg != NULL) && (GNUNET_YES != success) )
{
fprintf (stderr,
- "NS failed to create record %s\n", emsg);
+ "NS failed to create record %s\n",
+ emsg);
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), start_curl, NULL);
-
+ curl_task_id =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &start_curl, NULL);
}
-
-
/**
* Function to keep the HTTP server running.
*/
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c
index 6a4689af1..21fab323b 100644
--- a/src/hostlist/gnunet-daemon-hostlist.c
+++ b/src/hostlist/gnunet-daemon-hostlist.c
@@ -299,9 +299,8 @@ run (void *cls,
GNUNET_HOSTLIST_server_start (cfg, stats, core, &server_ch, &server_dh,
advertising);
#endif
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &cleaning_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleaning_task,
+ NULL);
if (NULL == core)
{
diff --git a/src/hostlist/gnunet-daemon-hostlist_client.c b/src/hostlist/gnunet-daemon-hostlist_client.c
index dbf6eaeda..15a82c2d5 100644
--- a/src/hostlist/gnunet-daemon-hostlist_client.c
+++ b/src/hostlist/gnunet-daemon-hostlist_client.c
@@ -210,27 +210,27 @@ static struct GNUNET_TIME_Relative hostlist_delay;
/**
* ID of the task, checking if hostlist download should take plate
*/
-static struct GNUNET_SCHEDULER_Task * ti_check_download;
+static struct GNUNET_SCHEDULER_Task *ti_check_download;
/**
* ID of the task downloading the hostlist
*/
-static struct GNUNET_SCHEDULER_Task * ti_download;
+static struct GNUNET_SCHEDULER_Task *ti_download;
/**
* ID of the task saving the hostlsit in a regular intervall
*/
-static struct GNUNET_SCHEDULER_Task * ti_saving_task;
+static struct GNUNET_SCHEDULER_Task *ti_saving_task;
/**
* ID of the task called to initiate a download
*/
-static struct GNUNET_SCHEDULER_Task * ti_download_dispatcher_task;
+static struct GNUNET_SCHEDULER_Task *ti_download_dispatcher_task;
/**
* ID of the task controlling the locking between two hostlist tests
*/
-static struct GNUNET_SCHEDULER_Task * ti_testing_intervall_task;
+static struct GNUNET_SCHEDULER_Task *ti_testing_intervall_task;
/**
* At what time MUST the current hostlist request be done?
@@ -719,8 +719,9 @@ clean_up ()
{
CURLMcode mret;
- if ((stat_testing_hostlist == GNUNET_YES) &&
- (GNUNET_NO == stat_download_successful) && (NULL != hostlist_to_test))
+ if ( (stat_testing_hostlist == GNUNET_YES) &&
+ (GNUNET_NO == stat_download_successful) &&
+ (NULL != hostlist_to_test) )
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_
@@ -738,7 +739,7 @@ clean_up ()
hostlist_to_test = NULL;
}
- if (multi != NULL)
+ if (NULL != multi)
{
mret = curl_multi_remove_handle (multi, curl);
if (mret != CURLM_OK)
@@ -754,7 +755,7 @@ clean_up ()
curl_multi_strerror (mret));
multi = NULL;
}
- if (curl != NULL)
+ if (NULL != curl)
{
curl_easy_cleanup (curl);
curl = NULL;
@@ -847,19 +848,8 @@ task_download (void *cls)
int running;
struct CURLMsg *msg;
CURLMcode mret;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
ti_download = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Shutdown requested while trying to download hostlist from `%s'\n",
- current_url);
- update_hostlist ();
- clean_up ();
- return;
- }
if (0 == GNUNET_TIME_absolute_get_remaining (end_time).rel_value_us)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -1047,12 +1037,7 @@ download_hostlist ()
static void
task_download_dispatcher (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
ti_download_dispatcher_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n");
if (GNUNET_NO == stat_download_in_progress)
{
@@ -1080,12 +1065,8 @@ task_check (void *cls)
{
static int once;
struct GNUNET_TIME_Relative delay;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
ti_check_download = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
if (stats == NULL)
{
curl_global_cleanup ();
@@ -1120,7 +1101,8 @@ task_check (void *cls)
_("Have %u/%u connections. Will consider downloading hostlist in %s\n"),
stat_connection_count, MIN_CONNECTIONS,
GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
- ti_check_download = GNUNET_SCHEDULER_add_delayed (delay, &task_check, NULL);
+ ti_check_download = GNUNET_SCHEDULER_add_delayed (delay,
+ &task_check, NULL);
}
@@ -1132,12 +1114,7 @@ task_check (void *cls)
static void
task_testing_intervall_reset (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
ti_testing_intervall_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
stat_testing_allowed = GNUNET_OK;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Testing new hostlist advertisements is allowed again\n");
@@ -1152,19 +1129,15 @@ task_testing_intervall_reset (void *cls)
static void
task_hostlist_saving (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
ti_saving_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
save_hostlist_file (GNUNET_NO);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Hostlists will be saved to file again in %s\n",
GNUNET_STRINGS_relative_time_to_string(SAVING_INTERVAL, GNUNET_YES));
ti_saving_task =
- GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, &task_hostlist_saving,
+ GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL,
+ &task_hostlist_saving,
NULL);
}
@@ -1684,7 +1657,8 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
void
GNUNET_HOSTLIST_client_stop ()
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Hostlist client shutdown\n");
if (NULL != sget)
{
GNUNET_STATISTICS_get_cancel (sget);
@@ -1693,28 +1667,29 @@ GNUNET_HOSTLIST_client_stop ()
stats = NULL;
if (GNUNET_YES == stat_learning)
save_hostlist_file (GNUNET_YES);
- if (ti_saving_task != NULL)
+ if (NULL != ti_saving_task)
{
GNUNET_SCHEDULER_cancel (ti_saving_task);
ti_saving_task = NULL;
}
-
- if (ti_download_dispatcher_task != NULL)
+ if (NULL != ti_download_dispatcher_task)
{
GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task);
ti_download_dispatcher_task = NULL;
}
- if (ti_testing_intervall_task != NULL)
+ if (NULL != ti_testing_intervall_task)
{
GNUNET_SCHEDULER_cancel (ti_testing_intervall_task);
ti_testing_intervall_task = NULL;
}
- if (ti_download != NULL)
+ if (NULL != ti_download)
{
GNUNET_SCHEDULER_cancel (ti_download);
ti_download = NULL;
+ update_hostlist ();
+ clean_up ();
}
- if (ti_check_download != NULL)
+ if (NULL != ti_check_download)
{
GNUNET_SCHEDULER_cancel (ti_check_download);
ti_check_download = NULL;
diff --git a/src/hostlist/gnunet-daemon-hostlist_server.c b/src/hostlist/gnunet-daemon-hostlist_server.c
index 6e2cb7ee4..5b45af831 100644
--- a/src/hostlist/gnunet-daemon-hostlist_server.c
+++ b/src/hostlist/gnunet-daemon-hostlist_server.c
@@ -74,12 +74,12 @@ static struct GNUNET_PEERINFO_NotifyContext *notify;
/**
* Our primary task for IPv4.
*/
-static struct GNUNET_SCHEDULER_Task * hostlist_task_v4;
+static struct GNUNET_SCHEDULER_Task *hostlist_task_v4;
/**
* Our primary task for IPv6.
*/
-static struct GNUNET_SCHEDULER_Task * hostlist_task_v6;
+static struct GNUNET_SCHEDULER_Task *hostlist_task_v6;
/**
* Our canonical response.
@@ -632,15 +632,11 @@ static void
run_daemon (void *cls)
{
struct MHD_Daemon *daemon_handle = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
if (daemon_handle == daemon_handle_v4)
hostlist_task_v4 = NULL;
else
hostlist_task_v6 = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
if (daemon_handle == daemon_handle_v4)
hostlist_task_v4 = prepare_daemon (daemon_handle);
@@ -675,7 +671,9 @@ prepare_daemon (struct MHD_Daemon *daemon_handle)
wrs = GNUNET_NETWORK_fdset_create ();
wws = GNUNET_NETWORK_fdset_create ();
max = -1;
- GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max));
+ GNUNET_assert (MHD_YES ==
+ MHD_get_fdset (daemon_handle,
+ &rs, &ws, &es, &max));
haveto = MHD_get_timeout (daemon_handle, &timeout);
if (haveto == MHD_YES)
tv.rel_value_us = (uint64_t) timeout * 1000LL;
@@ -683,10 +681,9 @@ prepare_daemon (struct MHD_Daemon *daemon_handle)
tv = GNUNET_TIME_UNIT_FOREVER_REL;
GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
- ret =
- GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
- tv, wrs, wws,
- &run_daemon, daemon_handle);
+ ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
+ tv, wrs, wws,
+ &run_daemon, daemon_handle);
GNUNET_NETWORK_fdset_destroy (wrs);
GNUNET_NETWORK_fdset_destroy (wws);
return ret;
diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c
index 2f99b887d..5f8ece9b8 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist.c
@@ -35,7 +35,7 @@
static int ok;
-static struct GNUNET_SCHEDULER_Task * timeout_task;
+static struct GNUNET_SCHEDULER_Task *timeout_task;
struct PeerContext
{
@@ -100,11 +100,13 @@ timeout_error (void *cls)
* @param distance in overlay hops, as given by transport plugin
*/
static void
-notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
+notify_connect (void *cls,
+ const struct GNUNET_PeerIdentity *peer)
{
if (peer == NULL)
return;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peers connected, shutting down.\n");
ok = 0;
if (timeout_task != NULL)
{
@@ -116,7 +118,8 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
static void
-process_hello (void *cls, const struct GNUNET_MessageHeader *message)
+process_hello (void *cls,
+ const struct GNUNET_MessageHeader *message)
{
struct PeerContext *p = cls;
@@ -170,8 +173,10 @@ waitpid_task (void *cls)
static void
stop_arm (struct PeerContext *p)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n");
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Asking ARM to stop core service\n");
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &waitpid_task, p);
}
@@ -187,14 +192,18 @@ shutdown_task (void *cls)
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_assert (ok == 1);
ok++;
- timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &timeout_error,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf");
setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf");
}
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c
index a71b8ecae..717311be7 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c
@@ -242,7 +242,9 @@ process_adv_sent_done (void *cls, int success)
static int
-process_adv_sent (void *cls, const char *subsystem, const char *name,
+process_adv_sent (void *cls,
+ const char *subsystem,
+ const char *name,
uint64_t value, int is_persistent)
{
if ((value >= 1) && (adv_sent == GNUNET_NO))
@@ -267,13 +269,10 @@ static void
check_statistics (void *cls)
{
char *stat;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
check_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
- GNUNET_asprintf (&stat, gettext_noop ("# advertised URI `%s' downloaded"),
+ GNUNET_asprintf (&stat,
+ gettext_noop ("# advertised URI `%s' downloaded"),
current_adv_uri);
if (NULL != learn_peer.stats)
{
@@ -313,7 +312,8 @@ check_statistics (void *cls)
* Core handler for p2p hostlist advertisements
*/
static int
-ad_arrive_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
+ad_arrive_handler (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message)
{
char *hostname;
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
index 0af16e065..562eec55b 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
@@ -100,11 +100,13 @@ timeout_error (void *cls)
* @param distance in overlay hops, as given by transport plugin
*/
static void
-notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
+notify_connect (void *cls,
+ const struct GNUNET_PeerIdentity *peer)
{
if (peer == NULL)
return;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peers connected, shutting down.\n");
ok = 0;
if (timeout_task != NULL)
{
@@ -116,7 +118,8 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
static void
-process_hello (void *cls, const struct GNUNET_MessageHeader *message)
+process_hello (void *cls,
+ const struct GNUNET_MessageHeader *message)
{
struct PeerContext *p = cls;
@@ -171,7 +174,8 @@ static void
stop_arm (struct PeerContext *p)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n");
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &waitpid_task, p);
}
@@ -192,8 +196,10 @@ run (void *cls, char *const *args, const char *cfgfile,
{
GNUNET_assert (ok == 1);
ok++;
- timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
+ timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &timeout_error, NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ &shutdown_task,
NULL);
setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf");
setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf");
diff --git a/src/identity-provider/gnunet-service-identity-provider.c b/src/identity-provider/gnunet-service-identity-provider.c
index 59e678b24..0bb400e07 100644
--- a/src/identity-provider/gnunet-service-identity-provider.c
+++ b/src/identity-provider/gnunet-service-identity-provider.c
@@ -105,13 +105,12 @@ static struct GNUNET_NAMESTORE_ZoneIterator *ns_it;
/**
* Timeout task
*/
-static struct GNUNET_SCHEDULER_Task * timeout_task;
-
+static struct GNUNET_SCHEDULER_Task *timeout_task;
/**
* Update task
*/
-static struct GNUNET_SCHEDULER_Task * update_task;
+static struct GNUNET_SCHEDULER_Task *update_task;
/**
* Timeout for next update pass
@@ -494,9 +493,11 @@ handle_token_update (void *cls)
scopes = NULL;
}
+
static void
update_identities(void *cls);
+
/**
*
* Cleanup attr_map
@@ -504,7 +505,7 @@ update_identities(void *cls);
* @param cls NULL
* @param key the key
* @param value the json_t attribute value
- * @return GNUNET_YES
+ * @return #GNUNET_YES
*/
static int
clear_ego_attrs (void *cls,
@@ -530,6 +531,7 @@ clear_ego_attrs (void *cls,
return GNUNET_YES;
}
+
/**
*
* Update all ID_TOKEN records for an identity and store them
@@ -539,7 +541,6 @@ clear_ego_attrs (void *cls,
* @param lbl the name of the record
* @param rd_count number of records
* @param rd record data
- *
*/
static void
token_collect (void *cls,
@@ -579,7 +580,9 @@ token_collect (void *cls,
{
token_metadata_record = &rd[0];
token_record = &rd[1];
- } else {
+ }
+ else
+ {
token_record = &rd[0];
token_metadata_record = &rd[1];
}
@@ -607,7 +610,8 @@ token_collect (void *cls,
label = GNUNET_strdup (lbl);
rd_exp = token_record->expiration_time;
- GNUNET_SCHEDULER_add_now (&handle_token_update, ego_entry);
+ GNUNET_SCHEDULER_add_now (&handle_token_update,
+ ego_entry);
}
@@ -642,7 +646,8 @@ attribute_collect (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
">>> Updating Attributes finished\n");
ego_entry->attributes_dirty = GNUNET_NO;
- update_task = GNUNET_SCHEDULER_add_now (&update_identities, ego_entry);
+ update_task = GNUNET_SCHEDULER_add_now (&update_identities,
+ ego_entry);
return;
}
@@ -752,7 +757,6 @@ update_identities(void *cls)
}
-
/**
* Function called initially to start update task
*/
@@ -761,9 +765,11 @@ init_cont ()
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO, ">>> Starting Service\n");
//Initially iterate all itenties and refresh all tokens
- update_task = GNUNET_SCHEDULER_add_now (&update_identities, ego_head);
+ update_task = GNUNET_SCHEDULER_add_now (&update_identities,
+ ego_head);
}
+
/**
* Initial ego collection function.
*
@@ -934,6 +940,7 @@ store_token_issue_cont (void *cls,
struct GNUNET_IDENTITY_PROVIDER_IssueResultMessage *irm;
char *ticket_str;
char *token_str;
+
handle->ns_qe = NULL;
if (GNUNET_SYSERR == success)
{
@@ -964,7 +971,9 @@ store_token_issue_cont (void *cls,
GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
return;
}
- irm = create_issue_result_message (handle->label, ticket_str, token_str);
+ irm = create_issue_result_message (handle->label,
+ ticket_str,
+ token_str);
GNUNET_SERVER_notification_context_unicast (nc,
handle->client,
&irm->header,
@@ -1528,19 +1537,16 @@ run (void *cls,
token_expiration_interval = DEFAULT_TOKEN_EXPIRATION_INTERVAL;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
}
/**
- *
* The main function
*
* @param argc number of arguments from the cli
* @param argv command line arguments
* @return 0 ok, 1 on error
- *
*/
int
main (int argc, char *const *argv)
@@ -1551,4 +1557,4 @@ main (int argc, char *const *argv)
&run, NULL)) ? 0 : 1;
}
-/* end of gnunet-rest-server.c */
+/* end of gnunet-service-identity-provider.c */
diff --git a/src/identity-provider/plugin_rest_identity_provider.c b/src/identity-provider/plugin_rest_identity_provider.c
index b104950ba..376110a6d 100644
--- a/src/identity-provider/plugin_rest_identity_provider.c
+++ b/src/identity-provider/plugin_rest_identity_provider.c
@@ -248,7 +248,7 @@ struct RequestHandle
/**
* ID of a task associated with the resolution process.
*/
- struct GNUNET_SCHEDULER_Task * timeout_task;
+ struct GNUNET_SCHEDULER_Task *timeout_task;
/**
* The plugin result processor
@@ -321,9 +321,9 @@ cleanup_handle (struct RequestHandle *handle)
/**
- * Task run on shutdown. Cleans up everything.
+ * Task run on error, sends error message. Cleans up everything.
*
- * @param cls unused
+ * @param cls the `struct RequestHandle`
*/
static void
do_error (void *cls)
@@ -342,6 +342,21 @@ do_error (void *cls)
}
/**
+ * Task run on timeout, sends error message. Cleans up everything.
+ *
+ * @param cls the `struct RequestHandle`
+ */
+static void
+do_timeout (void *cls)
+{
+ struct RequestHandle *handle = cls;
+
+ handle->timeout_task = NULL;
+ do_error (handle);
+}
+
+
+/**
* Task run on shutdown. Cleans up everything.
*
* @param cls unused
@@ -350,7 +365,8 @@ static void
do_cleanup_handle_delayed (void *cls)
{
struct RequestHandle *handle = cls;
- cleanup_handle(handle);
+
+ cleanup_handle (handle);
}
@@ -406,10 +422,9 @@ token_creat_cont (void *cls,
handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
GNUNET_free (result_str);
GNUNET_SCHEDULER_add_now (&do_cleanup_handle_delayed, handle);
-
-
}
+
/**
* Continueationf for token issue request
*
@@ -459,7 +474,8 @@ issue_token_cont (struct RestConnectionDataHandle *con,
GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map,
&key) )
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Issuer not found\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Issuer not found\n");
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
@@ -468,7 +484,9 @@ issue_token_cont (struct RestConnectionDataHandle *con,
if (NULL == ego_val)
{
GNUNET_SCHEDULER_add_now (&do_error, handle);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Ego invalid: %s\n", ego_val);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Ego invalid: %s\n",
+ ego_val);
return;
}
for (ego_entry = handle->ego_head;
@@ -480,13 +498,18 @@ issue_token_cont (struct RestConnectionDataHandle *con,
egoname = ego_entry->identifier;
break;
}
- if (NULL == egoname || NULL == ego_entry)
+ if ( (NULL == egoname) ||
+ (NULL == ego_entry) )
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Ego not found: %s\n", ego_val);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Ego not found: %s\n",
+ ego_val);
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego to issue token for: %s\n", egoname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Ego to issue token for: %s\n",
+ egoname);
//Meta info
@@ -516,13 +539,16 @@ issue_token_cont (struct RestConnectionDataHandle *con,
GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map,
&key) )
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Audience missing!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Audience missing!\n");
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
audience = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map,
&key);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Audience to issue token for: %s\n", audience);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Audience to issue token for: %s\n",
+ audience);
priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego,
@@ -547,7 +573,9 @@ issue_token_cont (struct RestConnectionDataHandle *con,
}
nonce_str = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map,
&key);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Request nonce: %s\n", nonce_str);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Request nonce: %s\n",
+ nonce_str);
sscanf (nonce_str, "%"SCNu64, &nonce);
//Get expiration for token from URL parameter
@@ -1048,10 +1076,8 @@ rest_identity_process_request(struct RestConnectionDataHandle *conndata_handle,
handle);
handle->timeout_task =
GNUNET_SCHEDULER_add_delayed (handle->timeout,
- &do_error,
+ &do_timeout,
handle);
-
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Connected\n");
}
diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c
index dc9174d21..23c20d91f 100644
--- a/src/identity/gnunet-identity.c
+++ b/src/identity/gnunet-identity.c
@@ -302,8 +302,7 @@ run (void *cls, char *const *args, const char *cfgfile,
create_ego,
&create_finished,
&create_op);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
test_finished ();
}
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c
index d36319a99..9185aac64 100644
--- a/src/identity/gnunet-service-identity.c
+++ b/src/identity/gnunet-service-identity.c
@@ -916,8 +916,8 @@ run (void *cls,
GNUNET_DISK_directory_scan (ego_directory,
&process_ego_file,
NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c
index 22ade6a0e..5bed8af55 100644
--- a/src/identity/plugin_rest_identity.c
+++ b/src/identity/plugin_rest_identity.c
@@ -257,9 +257,9 @@ cleanup_handle (struct RequestHandle *handle)
/**
- * Task run on shutdown. Cleans up everything.
+ * Task run on errors. Reports an error and cleans up everything.
*
- * @param cls unused
+ * @param cls the `struct RequestHandle`
*/
static void
do_error (void *cls)
@@ -273,7 +273,9 @@ do_error (void *cls)
&handle->emsg);
resp = GNUNET_REST_create_json_response (json_error);
- handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST);
+ handle->proc (handle->proc_cls,
+ resp,
+ MHD_HTTP_BAD_REQUEST);
cleanup_handle (handle);
GNUNET_free (json_error);
}
diff --git a/src/identity/test_identity.c b/src/identity/test_identity.c
index 6eaa86e91..37065ce08 100644
--- a/src/identity/test_identity.c
+++ b/src/identity/test_identity.c
@@ -110,8 +110,7 @@ end ()
GNUNET_SCHEDULER_cancel (endbadly_task);
endbadly_task = NULL;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
- &end_normally, NULL);
+ GNUNET_SCHEDULER_add_now (&end_normally, NULL);
}
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index 3d7dede17..89b692789 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -66,7 +66,7 @@ extern "C"
/**
* Version of the API (for entire gnunetutil.so library).
*/
-#define GNUNET_UTIL_VERSION 0x000A0100
+#define GNUNET_UTIL_VERSION 0x000A0101
/**
diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h
index d9b63775a..87cb3b6f1 100644
--- a/src/include/gnunet_scheduler_lib.h
+++ b/src/include/gnunet_scheduler_lib.h
@@ -65,8 +65,7 @@ enum GNUNET_SCHEDULER_Reason
GNUNET_SCHEDULER_REASON_STARTUP = 1,
/**
- * We are shutting down and are running all shutdown-related tasks
- * (regardless of timeout, etc.).
+ * We are shutting down and are running all shutdown-related tasks.
*/
GNUNET_SCHEDULER_REASON_SHUTDOWN = 2,
@@ -158,7 +157,7 @@ typedef int
* tasks have completed. On systems with signals, receiving a SIGTERM
* (and other similar signals) will cause #GNUNET_SCHEDULER_shutdown
* to be run after the active task is complete. As a result, SIGTERM
- * causes all active tasks to be scheduled with reason
+ * causes all shutdown tasks to be scheduled with reason
* #GNUNET_SCHEDULER_REASON_SHUTDOWN. (However, tasks added
* afterwards will execute normally!). Note that any particular
* signal will only shut down one scheduler; applications should
@@ -173,11 +172,10 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task,
/**
- * Request the shutdown of the scheduler. Marks all currently
- * pending tasks as ready because of shutdown. This will
- * cause all tasks to run (as soon as possible, respecting
- * priorities and prerequisite tasks). Note that tasks
- * scheduled AFTER this call may still be delayed arbitrarily.
+ * Request the shutdown of a scheduler. Marks all tasks
+ * awaiting shutdown as ready. Note that tasks
+ * scheduled with #GNUNET_SCHEDULER_add_shutdown() AFTER this call
+ * will be delayed until the next shutdown signal.
*/
void
GNUNET_SCHEDULER_shutdown (void);
@@ -272,6 +270,21 @@ GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_TaskCallback task,
/**
+ * Schedule a new task to be run on shutdown, that is when a CTRL-C
+ * signal is received, or when #GNUNET_SCHEDULER_shutdown() is being
+ * invoked.
+ *
+ * @param task main function of the task
+ * @param task_cls closure of @a task
+ * @return unique task identifier for the job
+ * only valid until @a task is started!
+ */
+struct GNUNET_SCHEDULER_Task *
+GNUNET_SCHEDULER_add_shutdown (GNUNET_SCHEDULER_TaskCallback task,
+ void *task_cls);
+
+
+/**
* Schedule a new task to be run as soon as possible with the
* (transitive) ignore-shutdown flag either explicitly set or
* explicitly enabled. This task (and all tasks created from it,
@@ -296,8 +309,7 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
* will be scheduled for execution once the delay has expired. It
* will be run with the DEFAULT priority.
*
- * * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param task main function of the task
* @param task_cls closure of @a task
* @return unique task identifier for the job
@@ -313,8 +325,7 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
* Schedule a new task to be run with a specified delay. The task
* will be scheduled for execution once the delay has expired.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param priority priority to use for the task
* @param task main function of the task
* @param task_cls closure of @a task
@@ -335,8 +346,7 @@ GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
* scheduled for execution once either the delay has expired or the
* socket operation is ready. It will be run with the DEFAULT priority.
*
- * * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * * @param delay when should this operation time out?
* @param rfd read file-descriptor
* @param task main function of the task
* @param task_cls closure of @a task
@@ -358,8 +368,7 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay,
* either the delay has expired or the socket operation is ready. It
* will be run with the DEFAULT priority.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param priority priority to use for the task
* @param rfd read file-descriptor
* @param task main function of the task
@@ -382,8 +391,7 @@ GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay,
* scheduled for execution once either the delay has expired or the
* socket operation is ready. It will be run with the DEFAULT priority.
*
- * * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * * @param delay when should this operation time out?
* @param wfd write file-descriptor
* @param task main function of the task
* @param task_cls closure of @a task
@@ -404,8 +412,7 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
* scheduled for execution once either the delay has expired or the
* socket operation is ready.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param priority priority of the task
* @param fd file-descriptor
* @param on_read whether to poll the file-descriptor for readability
@@ -431,8 +438,7 @@ GNUNET_SCHEDULER_add_net_with_priority (struct GNUNET_TIME_Relative delay,
* scheduled for execution once either the delay has expired or the
* socket operation is ready. It will be run with the DEFAULT priority.
*
- * * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * * @param delay when should this operation time out?
* @param rfd read file-descriptor
* @param task main function of the task
* @param task_cls closure of @a task
@@ -453,8 +459,7 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
* scheduled for execution once either the delay has expired or the
* socket operation is ready. It will be run with the DEFAULT priority.
*
- * * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * * @param delay when should this operation time out?
* @param wfd write file-descriptor
* @param task main function of the task
* @param task_cls closure of @a task
@@ -475,8 +480,7 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
* scheduled for execution once either the delay has expired or the
* socket operation is ready.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param priority priority of the task
* @param fd file-descriptor
* @param on_read whether to poll the file-descriptor for readability
@@ -508,13 +512,11 @@ GNUNET_SCHEDULER_add_file_with_priority (struct GNUNET_TIME_Relative delay,
* (prerequisite-run)
* && (delay-ready
* || any-rs-ready
- * || any-ws-ready
- * || shutdown-active)
+ * || any-ws-ready)
* </code>
*
* @param prio how important is this task?
- * @param delay how long should we wait? Use #GNUNET_TIME_UNIT_FOREVER_REL for "forever",
- * which means that the task will only be run after we receive SIGTERM
+ * @param delay how long should we wait?
* @param rs set of file descriptors we want to read (can be NULL)
* @param ws set of file descriptors we want to write (can be NULL)
* @param task main function of the task
diff --git a/src/multicast/gnunet-service-multicast.c b/src/multicast/gnunet-service-multicast.c
index 8041119b0..f157041bc 100644
--- a/src/multicast/gnunet-service-multicast.c
+++ b/src/multicast/gnunet-service-multicast.c
@@ -1837,10 +1837,10 @@ core_connected_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity)
nc = GNUNET_SERVER_notification_context_create (server, 1);
GNUNET_SERVER_add_handlers (server, server_handlers);
- GNUNET_SERVER_disconnect_notify (server, &client_notify_disconnect, NULL);
-
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SERVER_disconnect_notify (server,
+ &client_notify_disconnect, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
@@ -1852,7 +1852,8 @@ core_connected_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity)
* @param cfg configuration to use
*/
static void
-run (void *cls, struct GNUNET_SERVER_Handle *srv,
+run (void *cls,
+ struct GNUNET_SERVER_Handle *srv,
const struct GNUNET_CONFIGURATION_Handle *c)
{
cfg = c;
diff --git a/src/multicast/test_multicast.c b/src/multicast/test_multicast.c
index 9550b8894..9e042d61b 100644
--- a/src/multicast/test_multicast.c
+++ b/src/multicast/test_multicast.c
@@ -276,7 +276,7 @@ member_parted (void *cls)
break;
case TEST_MEMBER_PART:
- GNUNET_SCHEDULER_add_now (schedule_origin_stop, NULL);
+ GNUNET_SCHEDULER_add_now (&schedule_origin_stop, NULL);
break;
default:
@@ -302,7 +302,7 @@ member_part ()
test = TEST_MEMBER_PART;
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Test #%u: member_part()\n", test);
- GNUNET_SCHEDULER_add_now (schedule_member_part, NULL);
+ GNUNET_SCHEDULER_add_now (&schedule_member_part, NULL);
}
@@ -569,7 +569,7 @@ member_recv_join_decision (void *cls,
{
case TEST_MEMBER_JOIN_REFUSE:
GNUNET_assert (0 == relay_count);
- GNUNET_SCHEDULER_add_now (schedule_member_part, NULL);
+ GNUNET_SCHEDULER_add_now (&schedule_member_part, NULL);
break;
case TEST_MEMBER_JOIN_ADMIT:
@@ -695,7 +695,9 @@ core_connected (void *cls, const struct GNUNET_PeerIdentity *my_identity)
*/
static void
#if DEBUG_TEST_MULTICAST
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c)
#else
run (void *cls,
@@ -704,10 +706,13 @@ run (void *cls,
#endif
{
cfg = c;
- end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
-
- core = GNUNET_CORE_connect (cfg, NULL, &core_connected, NULL, NULL,
- NULL, GNUNET_NO, NULL, GNUNET_NO, NULL);
+ end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &end_badly, NULL);
+ core = GNUNET_CORE_connect (cfg, NULL,
+ &core_connected, NULL, NULL,
+ NULL, GNUNET_NO,
+ NULL, GNUNET_NO,
+ NULL);
}
diff --git a/src/namecache/gnunet-namecache.c b/src/namecache/gnunet-namecache.c
index 6abcb7b92..490197b1e 100644
--- a/src/namecache/gnunet-namecache.c
+++ b/src/namecache/gnunet-namecache.c
@@ -202,10 +202,8 @@ run (void *cls, char *const *args, const char *cfgfile,
return;
}
-
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
ns = GNUNET_NAMECACHE_connect (cfg);
GNUNET_GNSRECORD_query_from_public_key (&pubkey,
name,
diff --git a/src/namecache/gnunet-service-namecache.c b/src/namecache/gnunet-service-namecache.c
index 81b1cce9b..e01dfcdf3 100644
--- a/src/namecache/gnunet-service-namecache.c
+++ b/src/namecache/gnunet-service-namecache.c
@@ -404,8 +404,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
GNUNET_SERVER_disconnect_notify (server,
&client_disconnect_notification,
NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
+ NULL);
}
diff --git a/src/namecache/test_namecache_api_cache_block.c b/src/namecache/test_namecache_api_cache_block.c
index 5522b207d..7b0e6e318 100644
--- a/src/namecache/test_namecache_api_cache_block.c
+++ b/src/namecache/test_namecache_api_cache_block.c
@@ -108,10 +108,11 @@ rd_decrypt_cb (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Block was decrypted successfully \n");
-
- GNUNET_SCHEDULER_add_now (&end, NULL);
+
+ GNUNET_SCHEDULER_add_now (&end, NULL);
}
+
static void
name_lookup_proc (void *cls,
const struct GNUNET_GNSRECORD_Block *block)
@@ -131,7 +132,7 @@ name_lookup_proc (void *cls,
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Namecache returned no block\n"));
- if (endbadly_task != NULL)
+ if (NULL != endbadly_task)
GNUNET_SCHEDULER_cancel (endbadly_task);
endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
return;
diff --git a/src/namestore/gnunet-namestore-fcfsd.c b/src/namestore/gnunet-namestore-fcfsd.c
index 82d73f6de..c2f506f6d 100644
--- a/src/namestore/gnunet-namestore-fcfsd.c
+++ b/src/namestore/gnunet-namestore-fcfsd.c
@@ -988,8 +988,7 @@ run (void *cls, char *const *args, const char *cfgfile,
}
id_op = GNUNET_IDENTITY_get (identity, "fcfsd",
&identity_cb, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
}
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c
index 0965d8cbe..90214e9d6 100644
--- a/src/namestore/gnunet-namestore.c
+++ b/src/namestore/gnunet-namestore.c
@@ -1006,8 +1006,7 @@ testservice_id_task (void *cls, int result)
ret = -1;
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, (void *) cfg);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, (void *) cfg);
if (NULL == ego_name)
{
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index 0bfd002f5..4be55cf9b 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -1689,8 +1689,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
GNUNET_SERVER_disconnect_notify (server,
&client_disconnect_notification,
NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
+ NULL);
}
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c
index cfebd63a7..4612528c6 100644
--- a/src/namestore/plugin_rest_namestore.c
+++ b/src/namestore/plugin_rest_namestore.c
@@ -242,6 +242,7 @@ struct RequestHandle
/**
* Cleanup lookup handle
+ *
* @param handle Handle to clean up
*/
static void
@@ -250,6 +251,7 @@ cleanup_handle (struct RequestHandle *handle)
struct RecordEntry *record_entry;
struct RecordEntry *record_tmp;
int i;
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Cleaning up\n");
if (NULL != handle->resp_object)
@@ -295,6 +297,7 @@ cleanup_handle (struct RequestHandle *handle)
GNUNET_free (handle);
}
+
/**
* Create json representation of a GNSRECORD
*
@@ -350,9 +353,9 @@ gnsrecord_to_json (const struct GNUNET_GNSRECORD_Data *rd)
/**
- * Task run on shutdown. Cleans up everything.
+ * Task run on error. Generates error response and cleans up.
*
- * @param cls unused
+ * @param cls the request to generate an error response for
*/
static void
do_error (void *cls)
@@ -365,6 +368,21 @@ do_error (void *cls)
}
+/**
+ * Task run on timeout.
+ *
+ * @param cls the request to time out
+ */
+static void
+do_timeout (void *cls)
+{
+ struct RequestHandle *handle = cls;
+
+ handle->timeout_task = NULL;
+ do_error (handle);
+}
+
+
static void
cleanup_handle_delayed (void *cls)
{
@@ -1138,10 +1156,8 @@ rest_identity_process_request(struct RestConnectionDataHandle *conndata_handle,
&testservice_id_task,
handle);
handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout,
- &do_error,
+ &do_timeout,
handle);
-
-
}
/**
diff --git a/src/nat/gnunet-nat-server.c b/src/nat/gnunet-nat-server.c
index 0069303ca..db51ef89a 100644
--- a/src/nat/gnunet-nat-server.c
+++ b/src/nat/gnunet-nat-server.c
@@ -294,8 +294,8 @@ run (void *cls, char *const *args, const char *cfgfile,
GNUNET_SERVER_create (NULL, NULL, (struct sockaddr * const *) sa, slen,
GNUNET_TIME_UNIT_SECONDS, GNUNET_YES);
GNUNET_SERVER_add_handlers (server, handlers);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
diff --git a/src/nat/nat.c b/src/nat/nat.c
index 1c60e4e0d..042a0f686 100644
--- a/src/nat/nat.c
+++ b/src/nat/nat.c
@@ -603,7 +603,8 @@ add_to_address_list (struct GNUNET_NAT_Handle *h,
*/
static void
add_ip_to_address_list (struct GNUNET_NAT_Handle *h,
- enum LocalAddressSource src, const void *addr,
+ enum LocalAddressSource src,
+ const void *addr,
socklen_t addrlen)
{
struct sockaddr_in s4;
@@ -913,10 +914,12 @@ process_interfaces (void *cls,
GNUNET_break (0);
return GNUNET_OK;
}
- if ((h->internal_address == NULL) && (h->server_proc == NULL) &&
- (h->server_read_task == NULL) &&
- (GNUNET_YES == isDefault) && ((addr->sa_family == AF_INET) ||
- (addr->sa_family == AF_INET6)))
+ if ( (h->internal_address == NULL) &&
+ (h->server_proc == NULL) &&
+ (h->server_read_task == NULL) &&
+ (GNUNET_YES == isDefault) &&
+ ( (addr->sa_family == AF_INET) ||
+ (addr->sa_family == AF_INET6) ) )
{
/* no internal address configured, but we found a "default"
* interface, try using that as our 'internal' address */
@@ -938,12 +941,8 @@ static void
restart_nat_server (void *cls)
{
struct GNUNET_NAT_Handle *h = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
h->server_read_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
start_gnunet_nat_server (h);
}
@@ -965,12 +964,8 @@ nat_server_read (void *cls)
int port;
const char *port_start;
struct sockaddr_in sin_addr;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
h->server_read_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
memset (mybuf, 0, sizeof (mybuf));
bytes =
GNUNET_DISK_file_read (h->server_stdout_handle, mybuf, sizeof (mybuf));
@@ -1036,7 +1031,8 @@ nat_server_read (void *cls)
sizeof (sin_addr));
h->server_read_task =
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->server_stdout_handle, &nat_server_read,
+ h->server_stdout_handle,
+ &nat_server_read,
h);
}
diff --git a/src/nat/nat_auto.c b/src/nat/nat_auto.c
index 82e067f73..4611edc62 100644
--- a/src/nat/nat_auto.c
+++ b/src/nat/nat_auto.c
@@ -273,7 +273,9 @@ do_udp_read (void *cls)
(GNUNET_NETWORK_fdset_isset (tc->read_ready,
lsock4)))
{
- rlen = GNUNET_NETWORK_socket_recv (lsock4, reply_buf, sizeof (reply_buf));
+ rlen = GNUNET_NETWORK_socket_recv (lsock4,
+ reply_buf,
+ sizeof (reply_buf));
//Lets handle the packet
memset(&answer, 0, sizeof(struct sockaddr_in));
@@ -288,7 +290,8 @@ do_udp_read (void *cls)
}
else
{
- if (GNUNET_OK == GNUNET_NAT_stun_handle_packet (reply_buf, rlen, &answer))
+ if (GNUNET_OK ==
+ GNUNET_NAT_stun_handle_packet (reply_buf, rlen, &answer))
{
//Process the answer
process_stun_reply (&answer, ah);
@@ -310,9 +313,6 @@ do_udp_read (void *cls)
next_phase (ah);
}
-
-
-
}
@@ -352,10 +352,9 @@ bind_v4 ()
}
-
-
-static void request_callback (void *cls,
- enum GNUNET_NAT_StatusCode result)
+static void
+request_callback (void *cls,
+ enum GNUNET_NAT_StatusCode result)
{
// struct GNUNET_NAT_AutoHandle *ah = cls;
@@ -363,10 +362,7 @@ static void request_callback (void *cls,
stop_stun ();
// next_phase (ah); FIXME this always will be NULL, as called in test_stun()
-};
-
-
-
+}
/**
@@ -518,17 +514,20 @@ test_stun (struct GNUNET_NAT_AutoHandle *ah)
{
//Lets call our function now when it accepts
ltask4 = GNUNET_SCHEDULER_add_read_net (NAT_SERVER_TIMEOUT,
- lsock4, &do_udp_read, ah);
-
+ lsock4,
+ &do_udp_read,
+ ah);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"STUN service listens on port %u\n",
port);
- if (GNUNET_NO == GNUNET_NAT_stun_make_request (stun_server, stun_port,
- lsock4, &request_callback,
- NULL))
+ if (GNUNET_NO ==
+ GNUNET_NAT_stun_make_request (stun_server, stun_port,
+ lsock4,
+ &request_callback,
+ NULL))
{
/*An error happened*/
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "STUN error, stopping\n");
@@ -538,7 +537,6 @@ test_stun (struct GNUNET_NAT_AutoHandle *ah)
}
-
/**
* Process list of local IP addresses. Find and set the
* one of the default interface.
@@ -550,16 +548,16 @@ test_stun (struct GNUNET_NAT_AutoHandle *ah)
* @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned)
* @param netmask the network mask (can be NULL for unknown or unassigned))
* @param addrlen length of the @a addr and @a broadcast_addr
- * @return GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
+ * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
*/
static int
process_if (void *cls,
- const char *name,
- int isDefault,
- const struct sockaddr *addr,
- const struct sockaddr *broadcast_addr,
- const struct sockaddr *netmask,
- socklen_t addrlen)
+ const char *name,
+ int isDefault,
+ const struct sockaddr *addr,
+ const struct sockaddr *broadcast_addr,
+ const struct sockaddr *netmask,
+ socklen_t addrlen)
{
struct GNUNET_NAT_AutoHandle *ah = cls;
const struct sockaddr_in *in;
@@ -640,11 +638,9 @@ test_local_ip (struct GNUNET_NAT_AutoHandle *ah)
static void
test_nat_punched (struct GNUNET_NAT_AutoHandle *ah)
{
-
struct GNUNET_CLIENT_Connection *client;
struct GNUNET_NAT_TestMessage msg;
-
if (ah->stun_ip)
{
LOG (GNUNET_ERROR_TYPE_INFO,
@@ -676,9 +672,10 @@ test_nat_punched (struct GNUNET_NAT_AutoHandle *ah)
{
GNUNET_SCHEDULER_cancel (ltask4);
ltask4 = GNUNET_SCHEDULER_add_read_net (NAT_SERVER_TIMEOUT,
- lsock4, &do_udp_read, ah);
+ lsock4,
+ &do_udp_read,
+ ah);
}
-
}
else
{
@@ -686,13 +683,9 @@ test_nat_punched (struct GNUNET_NAT_AutoHandle *ah)
"We don't have a STUN IP");
next_phase(ah);
}
-
-
}
-
-
/**
* Test if UPnPC works.
*
@@ -772,7 +765,6 @@ err:
ah->task = GNUNET_SCHEDULER_add_now (&reversal_test, ah);
else
next_phase (ah);
-
}
@@ -784,8 +776,6 @@ err:
static void
test_icmp_client (struct GNUNET_NAT_AutoHandle *ah)
{
-
-
char *tmp;
char *helper;
@@ -802,7 +792,8 @@ test_icmp_client (struct GNUNET_NAT_AutoHandle *ah)
if (GNUNET_YES !=
GNUNET_CONFIGURATION_get_value_yesno (ah->cfg, "nat", "BEHIND_NAT")){
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("test_icmp_server not possible, as we are not behind NAT\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("test_icmp_server not possible, as we are not behind NAT\n"));
}
else
goto err;
@@ -810,14 +801,14 @@ test_icmp_client (struct GNUNET_NAT_AutoHandle *ah)
if (GNUNET_YES ==
GNUNET_OS_check_helper_binary (helper, GNUNET_YES, "-d 127.0.0.1 127.0.0.2 42")){
// none of these parameters are actually used in privilege testing mode
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("No working gnunet-helper-nat-server found\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("No working gnunet-helper-nat-server found\n"));
}
err:
GNUNET_free_non_null (tmp);
GNUNET_free (helper);
next_phase (ah);
-
}
@@ -940,11 +931,7 @@ next_phase (struct GNUNET_NAT_AutoHandle *ah)
GNUNET_CONFIGURATION_destroy (diff);
GNUNET_NAT_autoconfig_cancel (ah);
return;
-
}
-
-
-
}
diff --git a/src/nat/nat_mini.c b/src/nat/nat_mini.c
index d310b3e14..915bcbdb6 100644
--- a/src/nat/nat_mini.c
+++ b/src/nat/nat_mini.c
@@ -121,11 +121,15 @@ read_external_ipv4 (void *cls)
eh->task = NULL;
tc = GNUNET_SCHEDULER_get_task_context ();
- if (GNUNET_YES == GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, eh->r))
+ if (GNUNET_YES ==
+ GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, eh->r))
+ {
ret =
GNUNET_DISK_file_read (eh->r, &eh->buf[eh->off],
sizeof (eh->buf) - eh->off);
- else {
+ }
+ else
+ {
eh->ret = GNUNET_NAT_ERROR_IPC_FAILURE;
ret = -1; /* error reading, timeout, etc. */
}
@@ -541,7 +545,9 @@ process_map_output (void *cls,
GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED);
if (NULL == mini->refresh_task)
mini->refresh_task =
- GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, &do_refresh, mini);
+ GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ,
+ &do_refresh,
+ mini);
return;
}
/*
@@ -617,7 +623,9 @@ GNUNET_NAT_mini_map_start (uint16_t port,
ret->is_tcp = is_tcp;
ret->port = port;
ret->refresh_task =
- GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, &do_refresh, ret);
+ GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ,
+ &do_refresh,
+ ret);
run_upnpc_r (ret);
return ret;
}
diff --git a/src/nat/nat_test.c b/src/nat/nat_test.c
index 33f81d800..b2f22781e 100644
--- a/src/nat/nat_test.c
+++ b/src/nat/nat_test.c
@@ -252,7 +252,9 @@ do_read (void *cls)
tc = GNUNET_SCHEDULER_get_task_context ();
na->rtask = NULL;
tst = na->h;
- GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, na);
+ GNUNET_CONTAINER_DLL_remove (tst->na_head,
+ tst->na_tail,
+ na);
if ((NULL != tc->write_ready) &&
(GNUNET_NETWORK_fdset_isset (tc->read_ready, na->sock)) &&
(sizeof (data) ==
@@ -284,14 +286,10 @@ do_accept (void *cls)
struct GNUNET_NAT_Test *tst = cls;
struct GNUNET_NETWORK_Handle *s;
struct NatActivity *wl;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tst->ltask = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
tst->ltask =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, tst->lsock,
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ tst->lsock,
&do_accept, tst);
s = GNUNET_NETWORK_socket_accept (tst->lsock, NULL, NULL);
if (NULL == s)
@@ -308,7 +306,9 @@ do_accept (void *cls)
GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
wl->sock,
&do_read, wl);
- GNUNET_CONTAINER_DLL_insert (tst->na_head, tst->na_tail, wl);
+ GNUNET_CONTAINER_DLL_insert (tst->na_head,
+ tst->na_tail,
+ wl);
}
@@ -474,13 +474,15 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_listen (nh->lsock, 5));
nh->ltask =
GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- nh->lsock, &do_accept, nh);
+ nh->lsock,
+ &do_accept, nh);
}
else
{
nh->ltask =
GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- nh->lsock, &do_udp_read, nh);
+ nh->lsock,
+ &do_udp_read, nh);
}
LOG (GNUNET_ERROR_TYPE_INFO,
"NAT test listens on port %u (%s)\n",
@@ -508,7 +510,9 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
return nh;
}
}
- nh->ttask = GNUNET_SCHEDULER_add_delayed (timeout, &do_timeout, nh);
+ nh->ttask = GNUNET_SCHEDULER_add_delayed (timeout,
+ &do_timeout,
+ nh);
return nh;
}
@@ -528,13 +532,17 @@ GNUNET_NAT_test_stop (struct GNUNET_NAT_Test *tst)
"Stopping NAT test\n");
while (NULL != (cpos = tst->ca_head))
{
- GNUNET_CONTAINER_DLL_remove (tst->ca_head, tst->ca_tail, cpos);
+ GNUNET_CONTAINER_DLL_remove (tst->ca_head,
+ tst->ca_tail,
+ cpos);
GNUNET_CLIENT_disconnect (cpos->client);
GNUNET_free (cpos);
}
while (NULL != (pos = tst->na_head))
{
- GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, pos);
+ GNUNET_CONTAINER_DLL_remove (tst->na_head,
+ tst->na_tail,
+ pos);
GNUNET_SCHEDULER_cancel (pos->rtask);
GNUNET_NETWORK_socket_close (pos->sock);
GNUNET_free (pos);
diff --git a/src/nat/test_nat.c b/src/nat/test_nat.c
index a840f3ef9..fd67473ee 100644
--- a/src/nat/test_nat.c
+++ b/src/nat/test_nat.c
@@ -69,7 +69,8 @@ stop (void *cls)
{
struct GNUNET_NAT_Handle *nat = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping NAT and quitting...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Stopping NAT and quitting...\n");
GNUNET_NAT_unregister (nat);
}
diff --git a/src/nse/gnunet-nse-profiler.c b/src/nse/gnunet-nse-profiler.c
index 5b893ae47..48afd9298 100644
--- a/src/nse/gnunet-nse-profiler.c
+++ b/src/nse/gnunet-nse-profiler.c
@@ -177,11 +177,6 @@ static struct GNUNET_TESTBED_Peer **daemons;
static struct GNUNET_CONFIGURATION_Handle *testing_cfg;
/**
- * The shutdown task
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_task_id;
-
-/**
* Maximum number of connections to NSE services.
*/
static unsigned int connection_limit;
@@ -228,9 +223,9 @@ static struct OpListEntry *oplist_head;
static struct OpListEntry *oplist_tail;
/**
- * Are we shutting down
+ * Task running each round of the experiment.
*/
-static int shutting_down;
+static struct GNUNET_SCHEDULER_Task *round_task;
/**
@@ -269,12 +264,13 @@ close_monitor_connections ()
static void
shutdown_task (void *cls)
{
- shutdown_task_id = NULL;
- if (GNUNET_YES == shutting_down)
- return;
- shutting_down = GNUNET_YES;
LOG_DEBUG ("Ending test.\n");
close_monitor_connections ();
+ if (NULL != round_task)
+ {
+ GNUNET_SCHEDULER_cancel (round_task);
+ round_task = NULL;
+ }
if (NULL != data_file)
{
GNUNET_DISK_file_close (data_file);
@@ -286,20 +282,10 @@ shutdown_task (void *cls)
output_file = NULL;
}
if (NULL != testing_cfg)
+ {
GNUNET_CONFIGURATION_destroy (testing_cfg);
- testing_cfg = NULL;
-}
-
-
-/**
- * Schedules shutdown task to be run now
- */
-static void
-shutdown_now ()
-{
- if (NULL != shutdown_task_id)
- GNUNET_SCHEDULER_cancel (shutdown_task_id);
- shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ testing_cfg = NULL;
+ }
}
@@ -556,14 +542,11 @@ next_round (void *cls);
static void
finish_round (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
- LOG (GNUNET_ERROR_TYPE_INFO, "Have %u connections\n", total_connections);
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "Have %u connections\n",
+ total_connections);
close_monitor_connections ();
- GNUNET_SCHEDULER_add_now (&next_round, NULL);
+ round_task = GNUNET_SCHEDULER_add_now (&next_round, NULL);
}
@@ -575,7 +558,8 @@ finish_round (void *cls)
static void
run_round ()
{
- LOG_DEBUG ("Running round %u\n", current_round);
+ LOG_DEBUG ("Running round %u\n",
+ current_round);
connect_nse_service ();
GNUNET_SCHEDULER_add_delayed (wait_time,
&finish_round,
@@ -592,7 +576,9 @@ make_oplist_entry ()
struct OpListEntry *entry;
entry = GNUNET_new (struct OpListEntry);
- GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry);
+ GNUNET_CONTAINER_DLL_insert_tail (oplist_head,
+ oplist_tail,
+ entry);
return entry;
}
@@ -605,7 +591,8 @@ make_oplist_entry ()
* @param emsg NULL on success; otherwise an error description
*/
static void
-manage_service_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
+manage_service_cb (void *cls,
+ struct GNUNET_TESTBED_Operation *op,
const char *emsg)
{
struct OpListEntry *entry = cls;
@@ -619,7 +606,9 @@ manage_service_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
}
GNUNET_assert (0 != entry->delta);
peers_running += entry->delta;
- GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
+ GNUNET_CONTAINER_DLL_remove (oplist_head,
+ oplist_tail,
+ entry);
GNUNET_free (entry);
if (num_peers_in_round[current_round] == peers_running)
run_round ();
@@ -672,26 +661,22 @@ adjust_running_peers ()
static void
next_round (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
+ round_task = NULL;
LOG_DEBUG ("Disconnecting nse service of peers\n");
current_round++;
if (current_round == num_rounds)
- {
- /* this was the last round, terminate */
- ok = 0;
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
+ {
+ /* this was the last round, terminate */
+ ok = 0;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
if (num_peers_in_round[current_round] == peers_running)
- {
- /* no need to churn, just run next round */
- run_round ();
- return;
- }
+ {
+ /* no need to churn, just run next round */
+ run_round ();
+ return;
+ }
adjust_running_peers ();
}
@@ -744,7 +729,7 @@ test_master (void *cls,
{
if (NULL == peers)
{
- shutdown_now ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
daemons = peers;
@@ -838,9 +823,7 @@ run (void *cls, char *const *args, const char *cfgfile,
NULL, /* master_controller_cb cls */
&test_master,
NULL); /* test_master cls */
- shutdown_task_id =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
diff --git a/src/nse/gnunet-nse.c b/src/nse/gnunet-nse.c
index 97c3da29b..840b8e64d 100644
--- a/src/nse/gnunet-nse.c
+++ b/src/nse/gnunet-nse.c
@@ -143,8 +143,8 @@ run (void *cls, char *const *args, const char *cfgfile,
GNUNET_TIME_UNIT_SECONDS,
nse_test_result,
NULL);
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ shutdown_task = GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
}
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c
index 608274ae1..d4098d1bc 100644
--- a/src/nse/gnunet-service-nse.c
+++ b/src/nse/gnunet-service-nse.c
@@ -784,7 +784,9 @@ schedule_current_round (void *cls,
delay =
get_transmit_delay ((peer_entry->previous_round == GNUNET_NO) ? -1 : 0);
peer_entry->transmit_task =
- GNUNET_SCHEDULER_add_delayed (delay, &transmit_task_cb, peer_entry);
+ GNUNET_SCHEDULER_add_delayed (delay,
+ &transmit_task_cb,
+ peer_entry);
return GNUNET_OK;
}
@@ -799,18 +801,15 @@ update_flood_message (void *cls)
{
struct GNUNET_TIME_Relative offset;
unsigned int i;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
flood_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
offset = GNUNET_TIME_absolute_get_remaining (next_timestamp);
if (0 != offset.rel_value_us)
{
/* somehow run early, delay more */
flood_task =
- GNUNET_SCHEDULER_add_delayed (offset, &update_flood_message, NULL);
+ GNUNET_SCHEDULER_add_delayed (offset,
+ &update_flood_message, NULL);
return;
}
estimate_index = (estimate_index + 1) % HISTORY_SIZE;
@@ -841,7 +840,8 @@ update_flood_message (void *cls)
NULL);
flood_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
- (next_timestamp), &update_flood_message,
+ (next_timestamp),
+ &update_flood_message,
NULL);
}
@@ -1043,7 +1043,8 @@ update_flood_times (void *cls,
}
delay = get_transmit_delay (0);
peer_entry->transmit_task =
- GNUNET_SCHEDULER_add_delayed (delay, &transmit_task_cb, peer_entry);
+ GNUNET_SCHEDULER_add_delayed (delay,
+ &transmit_task_cb, peer_entry);
return GNUNET_OK;
}
@@ -1439,7 +1440,8 @@ core_init (void *cls,
}
flood_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
- (next_timestamp), &update_flood_message,
+ (next_timestamp),
+ &update_flood_message,
NULL);
}
@@ -1560,8 +1562,8 @@ run (void *cls,
}
#endif
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
pk = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
GNUNET_assert (NULL != pk);
my_private_key = pk;
diff --git a/src/nse/nse_api.c b/src/nse/nse_api.c
index a42dcb369..1c260d537 100644
--- a/src/nse/nse_api.c
+++ b/src/nse/nse_api.c
@@ -94,7 +94,8 @@ reconnect (void *cls);
* @param msg message received, NULL on timeout or fatal error
*/
static void
-message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
+message_handler (void *cls,
+ const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_NSE_Handle *h = cls;
const struct GNUNET_NSE_ClientMessage *client_msg;
@@ -150,7 +151,8 @@ reschedule_connect (struct GNUNET_NSE_Handle *h)
GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay,
GNUNET_YES));
h->reconnect_task =
- GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
+ GNUNET_SCHEDULER_add_delayed (h->reconnect_delay,
+ &reconnect, h);
h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
}
diff --git a/src/nse/test_nse_multipeer.c b/src/nse/test_nse_multipeer.c
index 5e6c31e6c..d6d63778e 100644
--- a/src/nse/test_nse_multipeer.c
+++ b/src/nse/test_nse_multipeer.c
@@ -207,7 +207,8 @@ run (void *cls,
&nse_connect_adapter,
&nse_disconnect_adapter,
&nse_peers[i]);
- GNUNET_SCHEDULER_add_delayed (TIMEOUT, &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &shutdown_task, NULL);
}
diff --git a/src/peerinfo-tool/gnunet-peerinfo.c b/src/peerinfo-tool/gnunet-peerinfo.c
index 8cfb67a73..5f28fd484 100644
--- a/src/peerinfo-tool/gnunet-peerinfo.c
+++ b/src/peerinfo-tool/gnunet-peerinfo.c
@@ -757,9 +757,8 @@ testservice_task (void *cls,
{
tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c
index a0defb8cc..66082e8f7 100644
--- a/src/peerinfo/gnunet-service-peerinfo.c
+++ b/src/peerinfo/gnunet-service-peerinfo.c
@@ -161,6 +161,16 @@ static struct NotificationContext *nc_head;
*/
static struct NotificationContext *nc_tail;
+/**
+ * Handle for task to run #cron_clean_data_hosts()
+ */
+static struct GNUNET_SCHEDULER_Task *cron_clean;
+
+/**
+ * Handle for task to run #cron_scan_directory_hosts()
+ */
+static struct GNUNET_SCHEDULER_Task *cron_scan;
+
/**
* Notify all clients in the notify list about the
@@ -657,16 +667,14 @@ cron_scan_directory_data_hosts (void *cls)
{
static unsigned int retries;
struct DirScanContext dsc;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
- if (GNUNET_SYSERR == GNUNET_DISK_directory_create (networkIdDirectory))
+ cron_scan = NULL;
+ if (GNUNET_SYSERR ==
+ GNUNET_DISK_directory_create (networkIdDirectory))
{
- GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- &cron_scan_directory_data_hosts, NULL);
+ cron_scan = GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &cron_scan_directory_data_hosts, NULL);
return;
}
dsc.matched = 0;
@@ -680,10 +688,10 @@ cron_scan_directory_data_hosts (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
_("Still no peers found in `%s'!\n"),
networkIdDirectory);
- GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- &cron_scan_directory_data_hosts,
- NULL);
+ cron_scan = GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &cron_scan_directory_data_hosts,
+ NULL);
}
@@ -1046,11 +1054,8 @@ static void
cron_clean_data_hosts (void *cls)
{
struct GNUNET_TIME_Absolute now;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ cron_clean = NULL;
now = GNUNET_TIME_absolute_get ();
GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
_("Cleaning up directory `%s'\n"),
@@ -1058,9 +1063,9 @@ cron_clean_data_hosts (void *cls)
GNUNET_DISK_directory_scan (networkIdDirectory,
&discard_hosts_helper,
&now);
- GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ,
- &cron_clean_data_hosts,
- NULL);
+ cron_clean = GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ,
+ &cron_clean_data_hosts,
+ NULL);
}
@@ -1302,6 +1307,16 @@ shutdown_task (void *cls)
GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
stats = NULL;
}
+ if (NULL != cron_clean)
+ {
+ GNUNET_SCHEDULER_cancel (cron_clean);
+ cron_clean = NULL;
+ }
+ if (NULL != cron_scan)
+ {
+ GNUNET_SCHEDULER_cancel (cron_scan);
+ cron_scan = NULL;
+ }
}
@@ -1342,9 +1357,8 @@ run (void *cls,
"USE_INCLUDED_HELLOS");
if (GNUNET_SYSERR == use_included)
use_included = GNUNET_NO;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
if (GNUNET_YES != noio)
{
GNUNET_assert (GNUNET_OK ==
@@ -1358,11 +1372,13 @@ run (void *cls,
return;
}
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &cron_scan_directory_data_hosts, NULL);
+ cron_scan = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &cron_scan_directory_data_hosts,
+ NULL);
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &cron_clean_data_hosts, NULL);
+ cron_clean = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &cron_clean_data_hosts,
+ NULL);
if (GNUNET_YES == use_included)
{
ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
diff --git a/src/peerinfo/peerinfo_api.c b/src/peerinfo/peerinfo_api.c
index ad4576fc2..0637eda72 100644
--- a/src/peerinfo/peerinfo_api.c
+++ b/src/peerinfo/peerinfo_api.c
@@ -786,7 +786,9 @@ GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
GNUNET_SCHEDULER_add_delayed (timeout, &signal_timeout, ic);
ac->cont = &iterator_start_receive;
ac->cont_cls = ic;
- GNUNET_CONTAINER_DLL_insert_tail (h->ac_head, h->ac_tail, ac);
+ GNUNET_CONTAINER_DLL_insert_tail (h->ac_head,
+ h->ac_tail,
+ ac);
GNUNET_CONTAINER_DLL_insert_tail (h->ic_head,
h->ic_tail,
ic);
diff --git a/src/peerinfo/peerinfo_api_notify.c b/src/peerinfo/peerinfo_api_notify.c
index 16331548d..2a80c6c1a 100644
--- a/src/peerinfo/peerinfo_api_notify.c
+++ b/src/peerinfo/peerinfo_api_notify.c
@@ -66,7 +66,7 @@ struct GNUNET_PEERINFO_NotifyContext
/**
* Tasked used for delayed re-connection attempt.
*/
- struct GNUNET_SCHEDULER_Task * task;
+ struct GNUNET_SCHEDULER_Task *task;
/**
* Include friend only HELLOs in callbacks
@@ -112,7 +112,8 @@ reconnect (void *cls)
{
/* ugh */
nc->task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect, nc);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &reconnect, nc);
return;
}
request_notifications (nc);
diff --git a/src/peerinfo/test_peerinfo_api_notify_friend_only.c b/src/peerinfo/test_peerinfo_api_notify_friend_only.c
index d0322713c..403ed4b71 100644
--- a/src/peerinfo/test_peerinfo_api_notify_friend_only.c
+++ b/src/peerinfo/test_peerinfo_api_notify_friend_only.c
@@ -127,15 +127,18 @@ address_generator (void *cls, size_t max, void *buf)
return ret;
}
+
static void
-process_w_fo (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Message *hello, const char *err_msg)
+process_w_fo (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_HELLO_Message *hello,
+ const char *err_msg)
{
- if (err_msg != NULL )
+ if (err_msg != NULL)
{
GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
_("Error in communication with PEERINFO service\n"));
- GNUNET_SCHEDULER_add_now (&done, NULL );
+ GNUNET_SCHEDULER_add_now (&done, NULL);
return;
}
@@ -160,7 +163,7 @@ process_w_fo (void *cls, const struct GNUNET_PeerIdentity *peer,
if (0 == memcmp (&pid, peer, sizeof(pid)))
{
res_cb_w_fo = GNUNET_YES;
- GNUNET_SCHEDULER_add_now (&done, NULL );
+ GNUNET_SCHEDULER_add_now (&done, NULL);
}
return;
}
@@ -170,11 +173,11 @@ static void
process_wo_fo (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_HELLO_Message *hello, const char *err_msg)
{
- if (err_msg != NULL )
+ if (err_msg != NULL)
{
GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
_("Error in communication with PEERINFO service\n"));
- GNUNET_SCHEDULER_add_now (&done, NULL );
+ GNUNET_SCHEDULER_add_now (&done, NULL);
return;
}
@@ -204,6 +207,7 @@ process_wo_fo (void *cls, const struct GNUNET_PeerIdentity *peer,
}
}
+
static void
add_peer_done (void *cls, const char *emsg)
{
@@ -215,10 +219,11 @@ add_peer_done (void *cls, const char *emsg)
{
GNUNET_break(0);
GNUNET_SCHEDULER_cancel (timeout_task);
- timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL );
+ timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
}
}
+
static void
add_peer ()
{
@@ -229,33 +234,37 @@ add_peer ()
memset (&pid, 32, sizeof(pid));
h2 = GNUNET_HELLO_create (&pid.public_key, &address_generator, &agc,
GNUNET_YES);
- GNUNET_PEERINFO_add_peer (h, h2, &add_peer_done, NULL );
+ GNUNET_PEERINFO_add_peer (h, h2, &add_peer_done, NULL);
GNUNET_free(h2);
}
+
static void
-run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Peer *peer)
+run (void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Peer *peer)
{
- timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL );
+ timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
mycfg = cfg;
- pnc_w_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_YES, &process_w_fo, NULL );
- pnc_wo_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_NO, &process_wo_fo, NULL );
+ pnc_w_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_YES, &process_w_fo, NULL);
+ pnc_wo_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_NO, &process_wo_fo, NULL);
h = GNUNET_PEERINFO_connect (cfg);
GNUNET_assert(NULL != h);
add_peer ();
}
+
int
main (int argc, char *argv[])
{
res_cb_w_fo = GNUNET_NO;
res_cb_wo_fo = GNUNET_NO;
global_ret = 3;
- if (0
- != GNUNET_TESTING_service_run ("test-peerinfo-api-friend-only",
- "peerinfo", "test_peerinfo_api_data.conf", &run, NULL ))
+ if (0 != GNUNET_TESTING_service_run ("test-peerinfo-api-friend-only",
+ "peerinfo",
+ "test_peerinfo_api_data.conf",
+ &run, NULL))
return 1;
return global_ret;
}
diff --git a/src/peerstore/gnunet-peerstore.c b/src/peerstore/gnunet-peerstore.c
index 68ae1746f..25a4f0ff4 100644
--- a/src/peerstore/gnunet-peerstore.c
+++ b/src/peerstore/gnunet-peerstore.c
@@ -60,16 +60,15 @@ shutdown_task (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)
{
-
- peerstore_handle = NULL;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
peerstore_handle = GNUNET_PEERSTORE_connect (cfg);
GNUNET_assert (NULL != peerstore_handle);
-
ret = 0;
}
diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c
index 3a2d928e3..048201c77 100644
--- a/src/peerstore/gnunet-service-peerstore.c
+++ b/src/peerstore/gnunet-service-peerstore.c
@@ -91,6 +91,11 @@ static struct ClientEntry *client_head;
static struct ClientEntry *client_tail;
/**
+ * Task run to clean up expired records.
+ */
+static struct GNUNET_SCHEDULER_Task *expire_task;
+
+/**
* Are we in the process of shutting down the service? #GNUNET_YES / #GNUNET_NO
*/
static int in_shutdown;
@@ -117,6 +122,11 @@ do_shutdown ()
GNUNET_CONTAINER_multihashmap_destroy (watchers);
watchers = NULL;
}
+ if (NULL != expire_task)
+ {
+ GNUNET_SCHEDULER_cancel (expire_task);
+ expire_task = NULL;
+ }
GNUNET_SCHEDULER_shutdown ();
}
@@ -147,21 +157,18 @@ static void
cleanup_expired_records (void *cls)
{
int ret;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ expire_task = NULL;
GNUNET_assert (NULL != db);
- ret =
- db->expire_records (db->cls, GNUNET_TIME_absolute_get (),
- expire_records_continuation, NULL);
+ ret = db->expire_records (db->cls, GNUNET_TIME_absolute_get (),
+ &expire_records_continuation, NULL);
if (GNUNET_OK != ret)
{
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS,
- EXPIRED_RECORDS_CLEANUP_INTERVAL),
- &cleanup_expired_records, NULL);
+ GNUNET_assert (NULL == expire_task);
+ expire_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ EXPIRED_RECORDS_CLEANUP_INTERVAL),
+ &cleanup_expired_records, NULL);
}
}
@@ -173,14 +180,18 @@ cleanup_expired_records (void *cls)
* @param success count of records deleted or #GNUNET_SYSERR
*/
static void
-expire_records_continuation (void *cls, int success)
+expire_records_continuation (void *cls,
+ int success)
{
if (success > 0)
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", success);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS,
- EXPIRED_RECORDS_CLEANUP_INTERVAL),
- &cleanup_expired_records, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%d records expired.\n",
+ success);
+ GNUNET_assert (NULL == expire_task);
+ expire_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ EXPIRED_RECORDS_CLEANUP_INTERVAL),
+ &cleanup_expired_records, NULL);
}
@@ -565,18 +576,20 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
if (NULL == db)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not load database backend `%s'\n"), db_lib_name);
+ _("Could not load database backend `%s'\n"),
+ db_lib_name);
GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
return;
}
nc = GNUNET_SERVER_notification_context_create (server, 16);
watchers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
- GNUNET_SCHEDULER_add_now (&cleanup_expired_records, NULL);
+ expire_task = GNUNET_SCHEDULER_add_now (&cleanup_expired_records,
+ NULL);
GNUNET_SERVER_add_handlers (server, handlers);
GNUNET_SERVER_connect_notify (server, &handle_client_connect, NULL);
GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c
index 14117a333..f1c5ccd32 100644
--- a/src/peerstore/peerstore_api.c
+++ b/src/peerstore/peerstore_api.c
@@ -213,7 +213,7 @@ struct GNUNET_PEERSTORE_IterateContext
* Task identifier for the function called
* on iterate request timeout
*/
- struct GNUNET_SCHEDULER_Task * timeout_task;
+ struct GNUNET_SCHEDULER_Task *timeout_task;
};
@@ -340,7 +340,9 @@ handle_client_error (void *cls, enum GNUNET_MQ_Error error)
* @return #GNUNET_YES (continue to iterate)
*/
static int
-rewatch_it (void *cls, const struct GNUNET_HashCode *key, void *value)
+rewatch_it (void *cls,
+ const struct GNUNET_HashCode *key,
+ void *value)
{
struct GNUNET_PEERSTORE_Handle *h = cls;
struct GNUNET_PEERSTORE_WatchContext *wc = value;
diff --git a/src/psyc/gnunet-service-psyc.c b/src/psyc/gnunet-service-psyc.c
index 2b436aa21..0f2216428 100644
--- a/src/psyc/gnunet-service-psyc.c
+++ b/src/psyc/gnunet-service-psyc.c
@@ -2007,7 +2007,7 @@ transmit_notify (void *cls, size_t *data_size, void *data)
if (NULL != chn->tmit_head)
{
- GNUNET_SCHEDULER_add_now (schedule_transmit_message, chn);
+ GNUNET_SCHEDULER_add_now (&schedule_transmit_message, chn);
}
else if (GNUNET_YES == chn->is_disconnected
&& tmit_msg->last_ptype < GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END)
@@ -2645,8 +2645,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
nc = GNUNET_SERVER_notification_context_create (server, 1);
GNUNET_SERVER_add_handlers (server, server_handlers);
GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
diff --git a/src/psyc/test_psyc.c b/src/psyc/test_psyc.c
index 1169b49d5..5ea83dd63 100644
--- a/src/psyc/test_psyc.c
+++ b/src/psyc/test_psyc.c
@@ -41,28 +41,28 @@
/**
* Return value from 'main'.
*/
-int res;
+static int res;
-const struct GNUNET_CONFIGURATION_Handle *cfg;
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
-struct GNUNET_CORE_Handle *core;
-struct GNUNET_PeerIdentity this_peer;
+static struct GNUNET_CORE_Handle *core;
+static struct GNUNET_PeerIdentity this_peer;
/**
* Handle for task for timeout termination.
*/
-struct GNUNET_SCHEDULER_Task * end_badly_task;
+static struct GNUNET_SCHEDULER_Task * end_badly_task;
-struct GNUNET_PSYC_Master *mst;
-struct GNUNET_PSYC_Slave *slv;
+static struct GNUNET_PSYC_Master *mst;
+static struct GNUNET_PSYC_Slave *slv;
-struct GNUNET_PSYC_Channel *mst_chn, *slv_chn;
+static struct GNUNET_PSYC_Channel *mst_chn, *slv_chn;
-struct GNUNET_CRYPTO_EddsaPrivateKey *channel_key;
-struct GNUNET_CRYPTO_EcdsaPrivateKey *slave_key;
+static struct GNUNET_CRYPTO_EddsaPrivateKey *channel_key;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey *slave_key;
-struct GNUNET_CRYPTO_EddsaPublicKey channel_pub_key;
-struct GNUNET_CRYPTO_EcdsaPublicKey slave_pub_key;
+static struct GNUNET_CRYPTO_EddsaPublicKey channel_pub_key;
+static struct GNUNET_CRYPTO_EcdsaPublicKey slave_pub_key;
struct TransmitClosure
{
@@ -79,9 +79,9 @@ struct TransmitClosure
uint8_t n;
};
-struct TransmitClosure *tmit;
+static struct TransmitClosure *tmit;
-uint8_t join_req_count, end_count;
+static uint8_t join_req_count, end_count;
enum
{
@@ -104,14 +104,15 @@ enum
} test;
-void
+static void
master_transmit ();
-void
+static void
master_history_replay_latest ();
-void master_stopped (void *cls)
+static void
+master_stopped (void *cls)
{
if (NULL != tmit)
{
@@ -122,7 +123,9 @@ void master_stopped (void *cls)
GNUNET_SCHEDULER_shutdown ();
}
-void slave_parted (void *cls)
+
+static void
+slave_parted (void *cls)
{
if (NULL != mst)
{
@@ -133,10 +136,11 @@ void slave_parted (void *cls)
master_stopped (NULL);
}
+
/**
* Clean up all resources used.
*/
-void
+static void
cleanup ()
{
if (NULL != core)
@@ -185,7 +189,7 @@ end_normally (void *cls)
/**
* Finish the test case (successfully).
*/
-void
+static void
end ()
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending tests.\n");
@@ -200,7 +204,7 @@ end ()
}
-void
+static void
master_message_cb (void *cls, const struct GNUNET_PSYC_MessageHeader *msg)
{
GNUNET_assert (NULL != msg);
@@ -213,7 +217,7 @@ master_message_cb (void *cls, const struct GNUNET_PSYC_MessageHeader *msg)
}
-void
+static void
master_message_part_cb (void *cls, const struct GNUNET_PSYC_MessageHeader *msg,
const struct GNUNET_MessageHeader *pmsg)
{
@@ -270,7 +274,7 @@ master_message_part_cb (void *cls, const struct GNUNET_PSYC_MessageHeader *msg,
}
-void
+static void
slave_message_cb (void *cls, const struct GNUNET_PSYC_MessageHeader *msg)
{
GNUNET_assert (NULL != msg);
@@ -283,7 +287,7 @@ slave_message_cb (void *cls, const struct GNUNET_PSYC_MessageHeader *msg)
}
-void
+static void
slave_message_part_cb (void *cls,
const struct GNUNET_PSYC_MessageHeader *msg,
const struct GNUNET_MessageHeader *pmsg)
@@ -326,7 +330,7 @@ slave_message_part_cb (void *cls,
}
-void
+static void
state_get_var (void *cls, const struct GNUNET_MessageHeader *mod,
const char *name, const void *value,
uint32_t value_size, uint32_t full_value_size)
@@ -338,7 +342,7 @@ state_get_var (void *cls, const struct GNUNET_MessageHeader *mod,
/*** Slave state_get_prefix() ***/
-void
+static void
slave_state_get_prefix_result (void *cls, int64_t result,
const void *err_msg, uint16_t err_msg_size)
{
@@ -350,7 +354,7 @@ slave_state_get_prefix_result (void *cls, int64_t result,
}
-void
+static void
slave_state_get_prefix ()
{
test = TEST_SLAVE_STATE_GET_PREFIX;
@@ -362,7 +366,7 @@ slave_state_get_prefix ()
/*** Master state_get_prefix() ***/
-void
+static void
master_state_get_prefix_result (void *cls, int64_t result,
const void *err_msg, uint16_t err_msg_size)
{
@@ -373,7 +377,7 @@ master_state_get_prefix_result (void *cls, int64_t result,
}
-void
+static void
master_state_get_prefix ()
{
test = TEST_MASTER_STATE_GET_PREFIX;
@@ -385,7 +389,7 @@ master_state_get_prefix ()
/*** Slave state_get() ***/
-void
+static void
slave_state_get_result (void *cls, int64_t result,
const void *err_msg, uint16_t err_msg_size)
{
@@ -397,7 +401,7 @@ slave_state_get_result (void *cls, int64_t result,
}
-void
+static void
slave_state_get ()
{
test = TEST_SLAVE_STATE_GET;
@@ -409,7 +413,7 @@ slave_state_get ()
/*** Master state_get() ***/
-void
+static void
master_state_get_result (void *cls, int64_t result,
const void *err_msg, uint16_t err_msg_size)
{
@@ -421,7 +425,7 @@ master_state_get_result (void *cls, int64_t result,
}
-void
+static void
master_state_get ()
{
test = TEST_MASTER_STATE_GET;
@@ -432,7 +436,7 @@ master_state_get ()
/*** Slave history_replay() ***/
-void
+static void
slave_history_replay_result (void *cls, int64_t result,
const void *err_msg, uint16_t err_msg_size)
{
@@ -445,7 +449,7 @@ slave_history_replay_result (void *cls, int64_t result,
}
-void
+static void
slave_history_replay ()
{
test = TEST_SLAVE_HISTORY_REPLAY;
@@ -460,7 +464,7 @@ slave_history_replay ()
/*** Master history_replay() ***/
-void
+static void
master_history_replay_result (void *cls, int64_t result,
const void *err_msg, uint16_t err_msg_size)
{
@@ -473,7 +477,7 @@ master_history_replay_result (void *cls, int64_t result,
}
-void
+static void
master_history_replay ()
{
test = TEST_MASTER_HISTORY_REPLAY;
@@ -488,7 +492,7 @@ master_history_replay ()
/*** Slave history_replay_latest() ***/
-void
+static void
slave_history_replay_latest_result (void *cls, int64_t result,
const void *err_msg, uint16_t err_msg_size)
{
@@ -501,7 +505,7 @@ slave_history_replay_latest_result (void *cls, int64_t result,
}
-void
+static void
slave_history_replay_latest ()
{
test = TEST_SLAVE_HISTORY_REPLAY_LATEST;
@@ -517,7 +521,7 @@ slave_history_replay_latest ()
/*** Master history_replay_latest() ***/
-void
+static void
master_history_replay_latest_result (void *cls, int64_t result,
const void *err_msg, uint16_t err_msg_size)
{
@@ -530,7 +534,7 @@ master_history_replay_latest_result (void *cls, int64_t result,
}
-void
+static void
master_history_replay_latest ()
{
test = TEST_MASTER_HISTORY_REPLAY_LATEST;
@@ -555,7 +559,7 @@ transmit_resume (void *cls)
}
-int
+static int
tmit_notify_data (void *cls, uint16_t *data_size, void *data)
{
struct TransmitClosure *tmit = cls;
@@ -598,7 +602,7 @@ tmit_notify_data (void *cls, uint16_t *data_size, void *data)
}
-int
+static int
tmit_notify_mod (void *cls, uint16_t *data_size, void *data, uint8_t *oper,
uint32_t *full_value_size)
{
@@ -678,7 +682,7 @@ static void
slave_join ();
-void
+static void
slave_transmit ()
{
test = TEST_SLAVE_TRANSMIT;
@@ -702,7 +706,7 @@ slave_transmit ()
}
-void
+static void
slave_remove_cb (void *cls, int64_t result,
const void *err_msg, uint16_t err_msg_size)
{
@@ -714,7 +718,7 @@ slave_remove_cb (void *cls, int64_t result,
}
-void
+static void
slave_remove ()
{
test = TEST_SLAVE_REMOVE;
@@ -724,7 +728,7 @@ slave_remove ()
}
-void
+static void
slave_add_cb (void *cls, int64_t result,
const void *err_msg, uint16_t err_msg_size)
{
@@ -735,7 +739,7 @@ slave_add_cb (void *cls, int64_t result,
}
-void
+static void
slave_add ()
{
test = TEST_SLAVE_ADD;
@@ -744,7 +748,8 @@ slave_add ()
}
-void first_slave_parted (void *cls)
+static void
+first_slave_parted (void *cls)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "First slave parted.\n");
slave_join (TEST_SLAVE_JOIN_ACCEPT);
@@ -754,7 +759,7 @@ void first_slave_parted (void *cls)
static void
schedule_slave_part (void *cls)
{
- GNUNET_PSYC_slave_part (slv, GNUNET_NO, first_slave_parted, NULL);
+ GNUNET_PSYC_slave_part (slv, GNUNET_NO, &first_slave_parted, NULL);
}
@@ -772,7 +777,7 @@ join_decision_cb (void *cls,
case TEST_SLAVE_JOIN_REJECT:
GNUNET_assert (0 == is_admitted);
GNUNET_assert (1 == join_req_count);
- GNUNET_SCHEDULER_add_now (schedule_slave_part, NULL);
+ GNUNET_SCHEDULER_add_now (&schedule_slave_part, NULL);
break;
case TEST_SLAVE_JOIN_ACCEPT:
@@ -844,7 +849,7 @@ slave_join (int t)
}
-void
+static void
master_transmit ()
{
test = TEST_MASTER_TRANSMIT;
@@ -899,7 +904,7 @@ master_transmit ()
}
-void
+static void
master_start_cb (void *cls, int result, uint64_t max_message_id)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -911,7 +916,7 @@ master_start_cb (void *cls, int result, uint64_t max_message_id)
}
-void
+static void
master_start ()
{
test = TEST_MASTER_START;
@@ -931,7 +936,7 @@ schedule_master_start (void *cls)
}
-void
+static void
core_connected (void *cls, const struct GNUNET_PeerIdentity *my_identity)
{
this_peer = *my_identity;
@@ -953,7 +958,7 @@ core_connected (void *cls, const struct GNUNET_PeerIdentity *my_identity)
* @param cfg configuration we use (also to connect to PSYC service)
* @param peer handle to access more of the peer (not used)
*/
-void
+static void
#if DEBUG_TEST_PSYC
run (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c)
diff --git a/src/psycstore/gnunet-service-psycstore.c b/src/psycstore/gnunet-service-psycstore.c
index 737cff422..e02f77714 100644
--- a/src/psycstore/gnunet-service-psycstore.c
+++ b/src/psycstore/gnunet-service-psycstore.c
@@ -946,11 +946,15 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
GNUNET_CONFIGURATION_get_value_string (cfg, "psycstore", "database",
&database))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "psycstore",
+ "database");
}
else
{
- GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_psycstore_%s", database);
+ GNUNET_asprintf (&db_lib_name,
+ "libgnunet_plugin_psycstore_%s",
+ database);
db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg);
GNUNET_free (database);
}
@@ -966,8 +970,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
stats = GNUNET_STATISTICS_create ("psycstore", cfg);
GNUNET_SERVER_add_handlers (server, handlers);
nc = GNUNET_SERVER_notification_context_create (server, 1);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
diff --git a/src/psycstore/psycstore_api.c b/src/psycstore/psycstore_api.c
index b8f00a41c..234218fba 100644
--- a/src/psycstore/psycstore_api.c
+++ b/src/psycstore/psycstore_api.c
@@ -131,7 +131,7 @@ struct GNUNET_PSYCSTORE_Handle
/**
* Task doing exponential back-off trying to reconnect.
*/
- struct GNUNET_SCHEDULER_Task * reconnect_task;
+ struct GNUNET_SCHEDULER_Task *reconnect_task;
/**
* Time for next connect retry.
diff --git a/src/psycstore/test_psycstore.c b/src/psycstore/test_psycstore.c
index 266ee5c1d..2582cbf3f 100644
--- a/src/psycstore/test_psycstore.c
+++ b/src/psycstore/test_psycstore.c
@@ -54,7 +54,7 @@ static struct GNUNET_PSYCSTORE_OperationHandle *op;
/**
* Handle for task for timeout termination.
*/
-static struct GNUNET_SCHEDULER_Task * end_badly_task;
+static struct GNUNET_SCHEDULER_Task *end_badly_task;
static struct GNUNET_CRYPTO_EddsaPrivateKey *channel_key;
static struct GNUNET_CRYPTO_EcdsaPrivateKey *slave_key;
@@ -141,7 +141,7 @@ end_normally (void *cls)
static void
end ()
{
- if (end_badly_task != NULL)
+ if (NULL != end_badly_task)
{
GNUNET_SCHEDULER_cancel (end_badly_task);
end_badly_task = NULL;
diff --git a/src/pt/gnunet-daemon-pt.c b/src/pt/gnunet-daemon-pt.c
index a86cbd316..02c0df3cc 100644
--- a/src/pt/gnunet-daemon-pt.c
+++ b/src/pt/gnunet-daemon-pt.c
@@ -228,7 +228,7 @@ struct RequestContext
/**
* Task used to abort this operation with timeout.
*/
- struct GNUNET_SCHEDULER_Task * timeout_task;
+ struct GNUNET_SCHEDULER_Task *timeout_task;
/**
* Length of the request message that follows this struct.
@@ -1244,7 +1244,7 @@ run (void *cls, char *const *args GNUNET_UNUSED,
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup, cls);
if (ipv4_pt || ipv6_pt)
{
dns_post_handle
diff --git a/src/pt/test_gnunet_vpn.c b/src/pt/test_gnunet_vpn.c
index 85b28fbf8..df87da30a 100644
--- a/src/pt/test_gnunet_vpn.c
+++ b/src/pt/test_gnunet_vpn.c
@@ -354,7 +354,8 @@ mhd_main ()
static void
-run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
+run (void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
struct in_addr v4;
diff --git a/src/regex/gnunet-daemon-regexprofiler.c b/src/regex/gnunet-daemon-regexprofiler.c
index 1ff3b55e3..42fc8ace0 100644
--- a/src/regex/gnunet-daemon-regexprofiler.c
+++ b/src/regex/gnunet-daemon-regexprofiler.c
@@ -117,7 +117,11 @@ shutdown_task (void *cls)
REGEX_INTERNAL_announce_cancel (announce_handle);
announce_handle = NULL;
}
-
+ if (NULL != reannounce_task)
+ {
+ GNUNET_free (GNUNET_SCHEDULER_cancel (reannounce_task));
+ reannounce_task = NULL;
+ }
if (NULL != dht_handle)
{
GNUNET_DHT_disconnect (dht_handle);
@@ -142,16 +146,8 @@ reannounce_regex (void *cls)
{
char *regex = cls;
struct GNUNET_TIME_Relative random_delay;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
reannounce_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- GNUNET_free (regex);
- return;
- }
-
if (0 == rounds--)
{
global_ret = 0;
@@ -195,7 +191,7 @@ reannounce_regex (void *cls)
* @param regex regular expression to announce on this peer's cadet.
*/
static void
-announce_regex (const char * regex)
+announce_regex (const char *regex)
{
char *copy;
@@ -210,7 +206,8 @@ announce_regex (const char * regex)
policy_filename);
GNUNET_assert (NULL == reannounce_task);
copy = GNUNET_strdup (regex);
- reannounce_task = GNUNET_SCHEDULER_add_now (reannounce_regex, (void *) copy);
+ reannounce_task = GNUNET_SCHEDULER_add_now (&reannounce_regex,
+ (void *) copy);
}
@@ -347,14 +344,17 @@ run (void *cls, char *const *args GNUNET_UNUSED,
REGEX_TEST_free_from_file (components);
/* Announcing regexes from policy_filename */
- GNUNET_asprintf (&rx_with_pfx, "%s(%s)(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f)*", regex_prefix, regex);
+ GNUNET_asprintf (&rx_with_pfx,
+ "%s(%s)(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f)*",
+ regex_prefix,
+ regex);
announce_regex (rx_with_pfx);
GNUNET_free (regex);
GNUNET_free (rx_with_pfx);
/* 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);
}
diff --git a/src/regex/gnunet-regex-profiler.c b/src/regex/gnunet-regex-profiler.c
index 5938c99b1..db5432845 100644
--- a/src/regex/gnunet-regex-profiler.c
+++ b/src/regex/gnunet-regex-profiler.c
@@ -214,11 +214,6 @@ static struct GNUNET_CONFIGURATION_Handle *cfg;
static struct GNUNET_SCHEDULER_Task * abort_task;
/**
- * Shutdown task identifier
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_task;
-
-/**
* Host registration task identifier
*/
static struct GNUNET_SCHEDULER_Task * register_hosts_task;
@@ -408,12 +403,16 @@ do_shutdown (void *cls)
char output_buffer[512];
size_t size;
- shutdown_task = NULL;
if (NULL != abort_task)
+ {
GNUNET_SCHEDULER_cancel (abort_task);
+ abort_task = NULL;
+ }
if (NULL != register_hosts_task)
+ {
GNUNET_SCHEDULER_cancel (register_hosts_task);
-
+ register_hosts_task = NULL;
+ }
for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
{
peer = &peers[peer_cnt];
@@ -441,8 +440,10 @@ do_shutdown (void *cls)
}
if (NULL != data_file)
+ {
GNUNET_DISK_file_close (data_file);
-
+ data_file = NULL;
+ }
for (search_str_cnt = 0;
search_str_cnt < num_peers && NULL != search_strings;
search_str_cnt++)
@@ -450,18 +451,28 @@ do_shutdown (void *cls)
GNUNET_free_non_null (search_strings[search_str_cnt]);
}
GNUNET_free_non_null (search_strings);
+ search_strings = NULL;
if (NULL != reg_handle)
+ {
GNUNET_TESTBED_cancel_registration (reg_handle);
-
+ reg_handle = NULL;
+ }
if (NULL != mc)
+ {
GNUNET_TESTBED_controller_disconnect (mc);
+ mc = NULL;
+ }
if (NULL != mc_proc)
+ {
GNUNET_TESTBED_controller_stop (mc_proc);
+ mc_proc = NULL;
+ }
if (NULL != cfg)
+ {
GNUNET_CONFIGURATION_destroy (cfg);
-
- GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */
+ cfg = NULL;
+ }
}
@@ -475,12 +486,11 @@ do_abort (void *cls)
{
unsigned long i = (unsigned long) cls;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting from line %lu...\n", i);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Aborting from line %lu...\n", i);
abort_task = NULL;
result = GNUNET_SYSERR;
- if (NULL != shutdown_task)
- GNUNET_SCHEDULER_cancel (shutdown_task);
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
}
@@ -499,7 +509,8 @@ do_abort (void *cls)
* @return service handle to return in 'op_result', NULL on error
*/
static void *
-stats_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
+stats_ca (void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
return GNUNET_STATISTICS_create ("<driver>", cfg);
}
@@ -532,10 +543,12 @@ stats_da (void *cls, void *op_result)
* @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
+ * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
*/
static int
-stats_iterator (void *cls, const char *subsystem, const char *name,
+stats_iterator (void *cls,
+ const char *subsystem,
+ const char *name,
uint64_t value, int is_persistent)
{
struct RegexPeer *peer = cls;
@@ -596,9 +609,9 @@ stats_cb (void *cls,
fprintf (stderr, "s");
if (peer_cnt == num_peers)
{
- struct GNUNET_TIME_Relative delay = { 100 };
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\nCollecting stats finished. Shutting down.\n");
- shutdown_task = GNUNET_SCHEDULER_add_delayed (delay, &do_shutdown, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "\nCollecting stats finished. Shutting down.\n");
+ GNUNET_SCHEDULER_shutdown ();
result = GNUNET_OK;
}
else
@@ -845,12 +858,8 @@ static void
find_timed_out (void *cls)
{
struct RegexPeer *p = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
p->timeout = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Searching for string \"%s\" on peer %d timed out.\n",
p->search_str,
@@ -869,12 +878,9 @@ static void
find_string (void *cls)
{
unsigned int search_peer = (unsigned int) (long) cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) ||
- search_peer >= num_peers ||
- GNUNET_YES == in_shutdown)
+ if ( (search_peer >= num_peers) ||
+ (GNUNET_YES == in_shutdown) )
return;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -893,14 +899,13 @@ find_string (void *cls)
&dht_da,
&peers[search_peer]);
GNUNET_assert (NULL != peers[search_peer].op_handle);
- peers[search_peer].timeout = GNUNET_SCHEDULER_add_delayed (FIND_TIMEOUT,
- &find_timed_out,
- &peers[search_peer]);
+ peers[search_peer].timeout
+ = GNUNET_SCHEDULER_add_delayed (FIND_TIMEOUT,
+ &find_timed_out,
+ &peers[search_peer]);
}
-
-
/**
* Callback called when testbed has started the daemon we asked for.
*
@@ -909,7 +914,8 @@ find_string (void *cls)
* @param emsg NULL on success; otherwise an error description
*/
static void
-daemon_started (void *cls, struct GNUNET_TESTBED_Operation *op,
+daemon_started (void *cls,
+ struct GNUNET_TESTBED_Operation *op,
const char *emsg)
{
struct RegexPeer *peer = (struct RegexPeer *) cls;
@@ -961,8 +967,10 @@ do_announce (void *cls)
{
unsigned int i;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting announce.\n");
-
+ if (GNUNET_YES == in_shutdown)
+ return;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Starting announce.\n");
for (i = 0; i < init_parallel_searches; i++)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -982,10 +990,8 @@ static void
announce_next_regex (void *cls)
{
struct RegexPeer *peer;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ if (GNUNET_YES == in_shutdown)
return;
if (next_search >= num_peers)
{
@@ -1015,6 +1021,7 @@ announce_next_regex (void *cls)
parallel_searches++;
}
+
/**
* DHT connect callback. Called when we are connected to the dht service for
* the peer in 'cls'. If successfull we connect to the stats service of this
@@ -1026,8 +1033,10 @@ announce_next_regex (void *cls)
* @param emsg error message.
*/
static void
-dht_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
- void *ca_result, const char *emsg)
+dht_connect_cb (void *cls,
+ struct GNUNET_TESTBED_Operation *op,
+ void *ca_result,
+ const char *emsg)
{
struct RegexPeer *peer = (struct RegexPeer *) cls;
@@ -1194,10 +1203,12 @@ master_controller_cb (void *cls,
* @param strings set of strings loaded from file. Caller needs to free this
* if number returned is greater than zero.
* @param limit upper limit on the number of strings read from the file
- * @return number of strings found in the file. GNUNET_SYSERR on error.
+ * @return number of strings found in the file. #GNUNET_SYSERR on error.
*/
static int
-load_search_strings (const char *filename, char ***strings, unsigned int limit)
+load_search_strings (const char *filename,
+ char ***strings,
+ unsigned int limit)
{
char *data;
char *buf;
@@ -1268,7 +1279,9 @@ load_search_strings (const char *filename, char ***strings, unsigned int limit)
* @param config 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 *config)
{
unsigned int nsearchstrs;
@@ -1282,7 +1295,7 @@ run (void *cls, char *const *args, const char *cfgfile,
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("No configuration file given. Exiting\n"));
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
return;
}
cfg = GNUNET_CONFIGURATION_dup (config);
@@ -1291,9 +1304,10 @@ run (void *cls, char *const *args, const char *cfgfile,
"REGEX_PREFIX",
&regex_prefix))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Configuration option \"regex_prefix\" missing. Exiting\n"));
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "regexprofiler",
+ "regex_prefix");
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
return;
}
if (GNUNET_OK !=
@@ -1328,7 +1342,7 @@ run (void *cls, char *const *args, const char *cfgfile,
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Specified policies directory does not exist. Exiting.\n"));
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
return;
}
if (0 >= (int) (num_peers = GNUNET_DISK_directory_scan (policy_dir, NULL, NULL)))
@@ -1344,7 +1358,7 @@ run (void *cls, char *const *args, const char *cfgfile,
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("No search strings file given. Exiting.\n"));
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
return;
}
nsearchstrs = load_search_strings (strings_file,
@@ -1357,14 +1371,14 @@ run (void *cls, char *const *args, const char *cfgfile,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"File (%s) does not contain enough strings (%u/%u).\n",
strings_file, nsearchstrs, num_peers);
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
return;
}
if ( (0 == num_peers) || (NULL == search_strings))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Error loading search strings. Exiting.\n"));
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
return;
}
for (i = 0; i < num_peers; i++)
diff --git a/src/regex/gnunet-regex-simulation-profiler.c b/src/regex/gnunet-regex-simulation-profiler.c
index 27dfa773d..0f955f7b5 100644
--- a/src/regex/gnunet-regex-simulation-profiler.c
+++ b/src/regex/gnunet-regex-simulation-profiler.c
@@ -89,19 +89,9 @@ struct ProgressMeter
static struct ProgressMeter *meter;
/**
- * Abort task identifier.
- */
-static struct GNUNET_SCHEDULER_Task * abort_task;
-
-/**
- * Shutdown task identifier.
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_task;
-
-/**
* Scan task identifier;
*/
-static struct GNUNET_SCHEDULER_Task * scan_task;
+static struct GNUNET_SCHEDULER_Task *scan_task;
/**
* Global testing status.
@@ -240,8 +230,8 @@ update_meter (struct ProgressMeter *meter)
*
* @param meter the meter to reset
*
- * @return GNUNET_YES if meter reset,
- * GNUNET_SYSERR on error
+ * @return #GNUNET_YES if meter reset,
+ * #GNUNET_SYSERR on error
*/
static int
reset_meter (struct ProgressMeter *meter)
@@ -274,21 +264,28 @@ free_meter (struct ProgressMeter *meter)
*/
static void
do_shutdown (void *cls)
-{
- shutdown_task = NULL;
- if (NULL != abort_task)
- GNUNET_SCHEDULER_cancel (abort_task);
+{
if (NULL != mysql_ctx)
+ {
GNUNET_MYSQL_context_destroy (mysql_ctx);
+ mysql_ctx = NULL;
+ }
if (NULL != meter)
+ {
free_meter (meter);
-
- GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */
+ meter = NULL;
+ }
}
/**
- * abort task to run on test timed out
+ * Abort task to run on test timed out.
+ *
+ * FIXME: this doesn't actually work, it used to cancel
+ * the already running 'scan_task', but now that should
+ * always be NULL and do nothing. We instead need to set
+ * a global variable and abort scan_task internally, not
+ * via scheduler.
*
* @param cls NULL
*/
@@ -296,25 +293,29 @@ static void
do_abort (void *cls)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
- abort_task = NULL;
- GNUNET_SCHEDULER_cancel (scan_task);
- scan_task = NULL;
+ if (NULL != scan_task)
+ {
+ GNUNET_SCHEDULER_cancel (scan_task);
+ scan_task = NULL;
+ }
result = GNUNET_SYSERR;
- GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_shutdown ();
}
/**
- * Dummy function for prepared select. Always return GNUNET_OK.
+ * Dummy function for prepared select. Always returns #GNUNET_OK.
*
* @param cls closure
* @param num_values number of values.
* @param values returned values from select stmt.
*
- * @return GNUNET_OK
+ * @return #GNUNET_OK
*/
static int
-return_ok (void *cls, unsigned int num_values, MYSQL_BIND * values)
+return_ok (void *cls,
+ unsigned int num_values,
+ MYSQL_BIND * values)
{
return GNUNET_OK;
}
@@ -326,13 +327,16 @@ return_ok (void *cls, unsigned int num_values, MYSQL_BIND * values)
* @param cls closure.
* @param key hash for current state.
* @param proof proof for current state.
- * @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not.
+ * @param accepting #GNUNET_YES if this is an accepting state, #GNUNET_NO if not.
* @param num_edges number of edges leaving current state.
* @param edges edges leaving current state.
*/
static void
-regex_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof,
- int accepting, unsigned int num_edges,
+regex_iterator (void *cls,
+ const struct GNUNET_HashCode *key,
+ const char *proof,
+ int accepting,
+ unsigned int num_edges,
const struct REGEX_BLOCK_Edge *edges)
{
unsigned int i;
@@ -453,7 +457,7 @@ regex_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof,
* each state into a MySQL database.
*
* @param regex regular expression.
- * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure.
*/
static int
announce_regex (const char *regex)
@@ -461,18 +465,20 @@ announce_regex (const char *regex)
struct REGEX_INTERNAL_Automaton *dfa;
dfa =
- REGEX_INTERNAL_construct_dfa (regex, strlen (regex), max_path_compression);
+ REGEX_INTERNAL_construct_dfa (regex,
+ strlen (regex),
+ max_path_compression);
if (NULL == dfa)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create DFA for regex %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to create DFA for regex %s\n",
regex);
- abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
+ GNUNET_SCHEDULER_add_now (&do_abort, NULL);
return GNUNET_SYSERR;
}
-
- REGEX_INTERNAL_iterate_all_edges (dfa, &regex_iterator, NULL);
-
+ REGEX_INTERNAL_iterate_all_edges (dfa,
+ &regex_iterator, NULL);
REGEX_INTERNAL_automaton_destroy (dfa);
return GNUNET_OK;
@@ -484,8 +490,8 @@ announce_regex (const char *regex)
*
* @param cls closure
* @param filename complete filename (absolute path)
- * @return GNUNET_OK to continue to iterate,
- * GNUNET_SYSERR to abort iteration with error!
+ * @return #GNUNET_OK to continue to iterate,
+ * #GNUNET_SYSERR to abort iteration with error!
*/
static int
policy_filename_cb (void *cls, const char *filename)
@@ -498,17 +504,20 @@ policy_filename_cb (void *cls, const char *filename)
GNUNET_assert (NULL != filename);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Announcing regexes from file %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Announcing regexes from file %s\n",
filename);
if (GNUNET_YES != GNUNET_DISK_file_test (filename))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not find policy file %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Could not find policy file %s\n",
filename);
return GNUNET_OK;
}
if (GNUNET_OK !=
- GNUNET_DISK_file_size (filename, &filesize, GNUNET_YES, GNUNET_YES))
+ GNUNET_DISK_file_size (filename, &filesize,
+ GNUNET_YES, GNUNET_YES))
filesize = 0;
if (0 == filesize)
{
@@ -520,7 +529,8 @@ policy_filename_cb (void *cls, const char *filename)
if (filesize != GNUNET_DISK_fn_read (filename, data, filesize))
{
GNUNET_free (data);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not read policy file %s.\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Could not read policy file %s.\n",
filename);
return GNUNET_OK;
}
@@ -545,11 +555,13 @@ policy_filename_cb (void *cls, const char *filename)
data[offset] = '\0';
GNUNET_asprintf (&regex, "%s(%s)", regex_prefix, data);
GNUNET_assert (NULL != regex);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Announcing regex: %s\n", regex);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Announcing regex: %s\n", regex);
if (GNUNET_OK != announce_regex (regex))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not announce regex %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not announce regex %s\n",
regex);
}
GNUNET_free (regex);
@@ -571,6 +583,7 @@ do_directory_scan (void *cls)
char *stmt;
/* Create an MySQL prepared statement for the inserts */
+ scan_task = NULL;
GNUNET_asprintf (&stmt, INSERT_EDGE_STMT, table_name);
stmt_handle = GNUNET_MYSQL_statement_prepare (mysql_ctx, stmt);
GNUNET_free (stmt);
@@ -581,10 +594,13 @@ do_directory_scan (void *cls)
GNUNET_assert (NULL != stmt_handle);
- meter =
- create_meter (num_policy_files, "Announcing policy files\n", GNUNET_YES);
+ meter = create_meter (num_policy_files,
+ "Announcing policy files\n",
+ GNUNET_YES);
start_time = GNUNET_TIME_absolute_get ();
- GNUNET_DISK_directory_scan (policy_dir, &policy_filename_cb, stmt_handle);
+ GNUNET_DISK_directory_scan (policy_dir,
+ &policy_filename_cb,
+ stmt_handle);
duration = GNUNET_TIME_absolute_get_duration (start_time);
reset_meter (meter);
free_meter (meter);
@@ -592,12 +608,13 @@ do_directory_scan (void *cls)
printf ("Announced %u files containing %u policies in %s\n"
"Duplicate transitions: %llu\nMerged states: %llu\n",
- num_policy_files, num_policies,
+ num_policy_files,
+ num_policies,
GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_NO),
- num_merged_transitions, num_merged_states);
-
+ num_merged_transitions,
+ num_merged_states);
result = GNUNET_OK;
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_shutdown ();
}
@@ -610,7 +627,9 @@ do_directory_scan (void *cls)
* @param config 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 *config)
{
if (NULL == args[0])
@@ -620,7 +639,8 @@ run (void *cls, char *const *args, const char *cfgfile,
result = GNUNET_SYSERR;
return;
}
- if (GNUNET_YES != GNUNET_DISK_directory_test (args[0], GNUNET_YES))
+ if (GNUNET_YES !=
+ GNUNET_DISK_directory_test (args[0], GNUNET_YES))
{
fprintf (stderr,
_("Specified policies directory does not exist. Exiting.\n"));
@@ -629,7 +649,8 @@ run (void *cls, char *const *args, const char *cfgfile,
}
policy_dir = args[0];
- num_policy_files = GNUNET_DISK_directory_scan (policy_dir, NULL, NULL);
+ num_policy_files = GNUNET_DISK_directory_scan (policy_dir,
+ NULL, NULL);
meter = NULL;
if (NULL == table_name)
@@ -642,32 +663,29 @@ run (void *cls, char *const *args, const char *cfgfile,
mysql_ctx = GNUNET_MYSQL_context_create (config, "regex-mysql");
if (NULL == mysql_ctx)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create mysql context\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to create mysql context\n");
result = GNUNET_SYSERR;
return;
}
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (config, "regex-mysql",
- "REGEX_PREFIX", &regex_prefix))
+ GNUNET_CONFIGURATION_get_value_string (config,
+ "regex-mysql",
+ "REGEX_PREFIX",
+ &regex_prefix))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("%s service is lacking key configuration settings (%s). Exiting.\n"),
- "regexprofiler", "regex_prefix");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "regex-mysql",
+ "REGEX_PREFIX");
result = GNUNET_SYSERR;
return;
}
-
result = GNUNET_OK;
-
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
scan_task = GNUNET_SCHEDULER_add_now (&do_directory_scan, NULL);
-
- /* Scheduled the task to clean up when shutdown is called */
- shutdown_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown,
- NULL);
}
diff --git a/src/regex/gnunet-service-regex.c b/src/regex/gnunet-service-regex.c
index a70876534..530e4f358 100644
--- a/src/regex/gnunet-service-regex.c
+++ b/src/regex/gnunet-service-regex.c
@@ -384,9 +384,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &cleanup_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
+ NULL);
nc = GNUNET_SERVER_notification_context_create (server, 1);
stats = GNUNET_STATISTICS_create ("regex", cfg);
GNUNET_SERVER_add_handlers (server, handlers);
diff --git a/src/rest/gnunet-rest-server.c b/src/rest/gnunet-rest-server.c
index 705fcbeb3..ffd65228a 100644
--- a/src/rest/gnunet-rest-server.c
+++ b/src/rest/gnunet-rest-server.c
@@ -61,7 +61,7 @@
/**
* The task ID
*/
-static struct GNUNET_SCHEDULER_Task * httpd_task;
+static struct GNUNET_SCHEDULER_Task *httpd_task;
/**
* The port the service is running on (default 7776)
@@ -396,6 +396,16 @@ kill_httpd ()
GNUNET_SCHEDULER_cancel (httpd_task);
httpd_task = NULL;
}
+ if (NULL != ltask4)
+ {
+ GNUNET_SCHEDULER_cancel (ltask4);
+ ltask4 = NULL;
+ }
+ if (NULL != ltask6)
+ {
+ GNUNET_SCHEDULER_cancel (ltask6);
+ ltask6 = NULL;
+ }
}
@@ -498,7 +508,6 @@ static void
do_accept (void *cls)
{
struct GNUNET_NETWORK_Handle *lsock = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
struct GNUNET_NETWORK_Handle *s;
int fd;
const struct sockaddr *addr;
@@ -508,9 +517,6 @@ do_accept (void *cls)
ltask4 = NULL;
else
ltask6 = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
if (lsock == lsock4)
ltask4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
lsock,
@@ -770,8 +776,7 @@ run (void *cls,
(void *) cfg,
&load_plugin,
NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
}
diff --git a/src/revocation/gnunet-revocation.c b/src/revocation/gnunet-revocation.c
index f68c18aa4..5e983a079 100644
--- a/src/revocation/gnunet-revocation.c
+++ b/src/revocation/gnunet-revocation.c
@@ -79,6 +79,11 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
*/
static unsigned long long matching_bits;
+/**
+ * Task used for proof-of-work calculation.
+ */
+static struct GNUNET_SCHEDULER_Task *pow_task;
+
/**
* Function run if the user aborts with CTRL-C.
@@ -226,32 +231,60 @@ perform_revocation (const struct RevocationData *rd)
/**
+ * Write the current state of the revocation data
+ * to disk.
+ *
+ * @param rd data to sync
+ */
+static void
+sync_rd (const struct RevocationData *rd)
+{
+ if ( (NULL != filename) &&
+ (sizeof (struct RevocationData) ==
+ GNUNET_DISK_fn_write (filename,
+ &rd,
+ sizeof (rd),
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE)) )
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "write",
+ filename);
+}
+
+
+/**
* Perform the proof-of-work calculation.
*
* @param cls the `struct RevocationData`
*/
static void
-calculate_pow (void *cls)
+calculate_pow_shutdown (void *cls)
{
struct RevocationData *rd = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- /* store temporary results */
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ( (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) ||
- (0 == (rd->pow % 128) ) )
+ if (NULL != pow_task)
{
- if ( (NULL != filename) &&
- (sizeof (struct RevocationData) ==
- GNUNET_DISK_fn_write (filename,
- &rd,
- sizeof (rd),
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE)) )
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "write",
- filename);
+ GNUNET_SCHEDULER_cancel (pow_task);
+ pow_task = NULL;
}
+ sync_rd (rd);
+ GNUNET_free (rd);
+}
+
+
+/**
+ * Perform the proof-of-work calculation.
+ *
+ * @param cls the `struct RevocationData`
+ */
+static void
+calculate_pow (void *cls)
+{
+ struct RevocationData *rd = cls;
+
+ /* store temporary results */
+ if (0 == (rd->pow % 128))
+ sync_rd (rd);
/* display progress estimate */
if ( (0 == ((1 << matching_bits) / 100 / 50)) ||
(0 == (rd->pow % ((1 << matching_bits) / 100 / 50))) )
@@ -261,11 +294,6 @@ calculate_pow (void *cls)
(0 == (rd->pow % ((1 << matching_bits) / 100))) ) )
FPRINTF (stderr, " - @ %3u%% (estimate)\n",
(unsigned int) (rd->pow * 100) / (1 << matching_bits));
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- {
- GNUNET_free (rd);
- return;
- }
/* actually do POW calculation */
rd->pow++;
if (GNUNET_OK ==
@@ -297,8 +325,8 @@ calculate_pow (void *cls)
GNUNET_free (rd);
return;
}
- GNUNET_SCHEDULER_add_now (&calculate_pow,
- rd);
+ pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow,
+ rd);
}
@@ -371,8 +399,10 @@ ego_callback (void *cls,
FPRINTF (stderr,
"%s",
_("Revocation certificate not ready, calculating proof of work\n"));
- GNUNET_SCHEDULER_add_now (&calculate_pow,
- rd);
+ pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow,
+ rd);
+ GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown,
+ rd);
}
@@ -406,9 +436,8 @@ run (void *cls,
test_ego);
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
q = GNUNET_REVOCATION_query (cfg,
&pk,
&print_query_result,
@@ -444,9 +473,8 @@ run (void *cls,
revoke_ego,
&ego_callback,
NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
return;
}
if ( (NULL != filename) &&
@@ -462,9 +490,8 @@ run (void *cls,
filename);
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
if (GNUNET_YES !=
GNUNET_REVOCATION_check_pow (&rd.key,
rd.pow,
@@ -473,10 +500,11 @@ run (void *cls,
struct RevocationData *cp = GNUNET_new (struct RevocationData);
*cp = rd;
- GNUNET_SCHEDULER_add_now (&calculate_pow,
- cp);
+ pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow,
+ cp);
+ GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown,
+ cp);
return;
-
}
perform_revocation (&rd);
return;
diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c
index e41195d55..9f3162690 100644
--- a/src/revocation/gnunet-service-revocation.c
+++ b/src/revocation/gnunet-service-revocation.c
@@ -901,9 +901,8 @@ run (void *cls,
}
GNUNET_free (fn);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
peers = GNUNET_CONTAINER_multipeermap_create (128,
GNUNET_YES);
GNUNET_SERVER_add_handlers (srv, handlers);
diff --git a/src/rps/gnunet-rps.c b/src/rps/gnunet-rps.c
index 01be2aeb3..705c2c9b0 100644
--- a/src/rps/gnunet-rps.c
+++ b/src/rps/gnunet-rps.c
@@ -46,12 +46,6 @@ static struct GNUNET_PeerIdentity *peer_id;
/**
- * Shutdown task
- */
-static struct GNUNET_SCHEDULER_Task *shutdown_task;
-
-
-/**
* Set an option of type 'struct GNUNET_PeerIdentity *' from the command line.
* A pointer to this function should be passed as part of the
* 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options
@@ -96,7 +90,6 @@ GNUNET_GETOPT_set_peerid (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
static void
do_shutdown (void *cls)
{
- shutdown_task = NULL;
if (NULL != req_handle)
GNUNET_RPS_request_cancel (req_handle);
GNUNET_RPS_disconnect (rps_handle);
@@ -126,8 +119,7 @@ reply_handle (void *cls,
}
ret = 0;
- GNUNET_SCHEDULER_cancel (shutdown_task);
- GNUNET_SCHEDULER_add_now (do_shutdown, NULL);
+ GNUNET_SCHEDULER_shutdown ();
}
@@ -156,15 +148,14 @@ run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Requesting %u PeerIDs\n", num_peers);
req_handle = GNUNET_RPS_request_peers (rps_handle, num_peers, reply_handle, NULL);
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
}
else
{ /* Seed PeerID */
GNUNET_RPS_seed_ids (rps_handle, 1, peer_id);
FPRINTF (stdout, "Seeded PeerID %s\n", GNUNET_i2s_full (peer_id));
ret = 0;
- GNUNET_SCHEDULER_add_now (do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
}
}
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index af06cf1bd..91d4840bb 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C)
+ Copyright (C) 2013-2015 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
@@ -149,16 +149,14 @@ static struct RPS_Sampler *prot_sampler;
*/
static struct RPS_Sampler *client_sampler;
-
/**
* Name to log view to
*/
static char *file_name_view_log;
-
/**
- * The size of sampler we need to be able to satisfy the client's need of
- * random peers.
+ * The size of sampler we need to be able to satisfy the client's need
+ * of random peers.
*/
static unsigned int sampler_size_client_need;
@@ -170,7 +168,6 @@ static unsigned int sampler_size_client_need;
*/
static unsigned int sampler_size_est_need;
-
/**
* Percentage of total peer number in the view
* to send random PUSHes to
@@ -184,12 +181,6 @@ static float alpha;
static float beta;
/**
- * The percentage gamma of history updates.
- * Simply 1 - alpha - beta
- */
-
-
-/**
* Identifier for the main task that runs periodically.
*/
static struct GNUNET_SCHEDULER_Task *do_round_task;
@@ -199,8 +190,6 @@ static struct GNUNET_SCHEDULER_Task *do_round_task;
*/
static struct GNUNET_TIME_Relative round_interval;
-
-
/**
* List to store peers received through pushes temporary.
*/
@@ -211,7 +200,6 @@ static struct CustomPeerMap *push_map;
*/
static struct CustomPeerMap *pull_map;
-
/**
* Handler to NSE.
*/
@@ -230,8 +218,7 @@ static struct GNUNET_PEERINFO_Handle *peerinfo_handle;
/**
* Handle for cancellation of iteration over peers.
*/
-struct GNUNET_PEERINFO_NotifyContext *peerinfo_notify_handle;
-
+static struct GNUNET_PEERINFO_NotifyContext *peerinfo_notify_handle;
/**
* Request counter.
@@ -263,13 +250,12 @@ static struct GNUNET_TIME_Relative request_deltas[REQUEST_DELTAS_SIZE];
/**
* The prediction of the rate of requests
*/
-static struct GNUNET_TIME_Relative request_rate;
-
+static struct GNUNET_TIME_Relative request_rate;
/**
* Number of history update tasks.
*/
-uint32_t num_hist_update_tasks;
+static uint32_t num_hist_update_tasks;
#ifdef ENABLE_MALICIOUS
@@ -281,18 +267,18 @@ uint32_t num_hist_update_tasks;
* 2 Try to partition the network
* 3 Combined attack
*/
-uint32_t mal_type = 0;
+static uint32_t mal_type;
/**
* Other malicious peers
*/
-static struct GNUNET_PeerIdentity *mal_peers = NULL;
+static struct GNUNET_PeerIdentity *mal_peers;
/**
* Hashmap of malicious peers used as set.
* Used to more efficiently check whether we know that peer.
*/
-static struct GNUNET_CONTAINER_MultiPeerMap *mal_peer_set = NULL;
+static struct GNUNET_CONTAINER_MultiPeerMap *mal_peer_set;
/**
* Number of other malicious peers
@@ -320,26 +306,25 @@ struct AttackedPeer
/**
* If type is 2 this is the DLL of attacked peers
*/
-static struct AttackedPeer *att_peers_head = NULL;
-static struct AttackedPeer *att_peers_tail = NULL;
+static struct AttackedPeer *att_peers_head;
+static struct AttackedPeer *att_peers_tail;
/**
* This index is used to point to an attacked peer to
* implement the round-robin-ish way to select attacked peers.
*/
-static struct AttackedPeer *att_peer_index = NULL;
+static struct AttackedPeer *att_peer_index;
/**
* Hashmap of attacked peers used as set.
* Used to more efficiently check whether we know that peer.
*/
-static struct GNUNET_CONTAINER_MultiPeerMap *att_peer_set = NULL;
+static struct GNUNET_CONTAINER_MultiPeerMap *att_peer_set;
/**
* Number of attacked peers
*/
-static uint32_t num_attacked_peers = 0;
-
+static uint32_t num_attacked_peers;
/**
* If type is 1 this is the attacked peer
@@ -362,10 +347,6 @@ static uint32_t push_limit = 10000;
***********************************************************************/
-
-
-
-
/***********************************************************************
* Util functions
***********************************************************************/
@@ -374,8 +355,9 @@ static uint32_t push_limit = 10000;
/**
* Print peerlist to log.
*/
-void
-print_peer_list (struct GNUNET_PeerIdentity *list, unsigned int len)
+static void
+print_peer_list (struct GNUNET_PeerIdentity *list,
+ unsigned int len)
{
unsigned int i;
@@ -395,7 +377,7 @@ print_peer_list (struct GNUNET_PeerIdentity *list, unsigned int len)
/**
* Remove peer from list.
*/
- void
+static void
rem_from_list (struct GNUNET_PeerIdentity **peer_list,
unsigned int *list_size,
const struct GNUNET_PeerIdentity *peer)
@@ -429,9 +411,10 @@ rem_from_list (struct GNUNET_PeerIdentity **peer_list,
/**
* Sum all time relatives of an array.
- */
- struct GNUNET_TIME_Relative
-T_relative_sum (const struct GNUNET_TIME_Relative *rel_array, uint32_t arr_size)
+ */
+static struct GNUNET_TIME_Relative
+T_relative_sum (const struct GNUNET_TIME_Relative *rel_array,
+ uint32_t arr_size)
{
struct GNUNET_TIME_Relative sum;
uint32_t i;
@@ -448,18 +431,23 @@ T_relative_sum (const struct GNUNET_TIME_Relative *rel_array, uint32_t arr_size)
/**
* Compute the average of given time relatives.
*/
- struct GNUNET_TIME_Relative
-T_relative_avg (const struct GNUNET_TIME_Relative *rel_array, uint32_t arr_size)
+static struct GNUNET_TIME_Relative
+T_relative_avg (const struct GNUNET_TIME_Relative *rel_array,
+ uint32_t arr_size)
{
- return GNUNET_TIME_relative_divide (T_relative_sum (rel_array, arr_size), arr_size);
+ return GNUNET_TIME_relative_divide (T_relative_sum (rel_array,
+ arr_size),
+ arr_size);
}
/**
* Put random peer from sampler into the view as history update.
*/
- void
-hist_update (void *cls, struct GNUNET_PeerIdentity *ids, uint32_t num_peers)
+static void
+hist_update (void *cls,
+ struct GNUNET_PeerIdentity *ids,
+ uint32_t num_peers)
{
unsigned int i;
@@ -475,7 +463,6 @@ hist_update (void *cls, struct GNUNET_PeerIdentity *ids, uint32_t num_peers)
}
-
/**
* Wrapper around #RPS_sampler_resize()
*
@@ -526,7 +513,7 @@ client_resize_wrapper ()
*
* Called every time we receive a request from the client.
*/
- void
+static void
est_request_rate()
{
struct GNUNET_TIME_Relative max_round_duration;
@@ -647,28 +634,33 @@ send_pull_reply (const struct GNUNET_PeerIdentity *peer_id,
*
* Called once we know a peer is live.
*/
- void
-insert_in_pull_map (void *cls, const struct GNUNET_PeerIdentity *peer)
+static void
+insert_in_pull_map (void *cls,
+ const struct GNUNET_PeerIdentity *peer)
{
CustomPeerMap_put (pull_map, peer);
}
+
/**
* Insert PeerID in #view
*
* Called once we know a peer is live.
*/
- void
-insert_in_view (void *cls, const struct GNUNET_PeerIdentity *peer)
+static void
+insert_in_view (void *cls,
+ const struct GNUNET_PeerIdentity *peer)
{
View_put (peer);
}
+
/**
* Update sampler with given PeerID.
*/
- void
-insert_in_sampler (void *cls, const struct GNUNET_PeerIdentity *peer)
+static void
+insert_in_sampler (void *cls,
+ const struct GNUNET_PeerIdentity *peer)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Updating samplers with peer %s from insert_in_sampler()\n",
@@ -875,6 +867,7 @@ destroy_reply_cls (struct ReplyCls *rep_cls)
GNUNET_free (rep_cls);
}
+
static void
destroy_cli_ctx (struct ClientContext *cli_ctx)
{
@@ -899,8 +892,9 @@ destroy_cli_ctx (struct ClientContext *cli_ctx)
* Updates sizes of sampler list and view and adapt those lists
* accordingly.
*/
- void
-nse_callback (void *cls, struct GNUNET_TIME_Absolute timestamp,
+static void
+nse_callback (void *cls,
+ struct GNUNET_TIME_Absolute timestamp,
double logestimate, double std_dev)
{
double estimate;
@@ -933,7 +927,7 @@ nse_callback (void *cls, struct GNUNET_TIME_Absolute timestamp,
*
* Sends those to the requesting client.
*/
-void
+static void
client_respond (void *cls,
struct GNUNET_PeerIdentity *peer_ids,
uint32_t num_peers)
@@ -1080,7 +1074,7 @@ handle_client_request_cancel (void *cls,
* @param client identification of the client
* @param message the actual message
*/
- static void
+static void
handle_client_seed (void *cls,
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
@@ -1136,7 +1130,7 @@ handle_client_seed (void *cls,
////GNUNET_free (peers);
GNUNET_SERVER_receive_done (client,
- GNUNET_OK);
+ GNUNET_OK);
}
@@ -1153,9 +1147,9 @@ handle_client_seed (void *cls,
*/
static int
handle_peer_push (void *cls,
- struct GNUNET_CADET_Channel *channel,
- void **channel_ctx,
- const struct GNUNET_MessageHeader *msg)
+ struct GNUNET_CADET_Channel *channel,
+ void **channel_ctx,
+ const struct GNUNET_MessageHeader *msg)
{
const struct GNUNET_PeerIdentity *peer;
@@ -1165,9 +1159,11 @@ handle_peer_push (void *cls,
GNUNET_CADET_channel_get_info (channel, GNUNET_CADET_OPTION_PEER);
// FIXME wait for cadet to change this function
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PUSH (%s)\n", GNUNET_i2s (peer));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received PUSH (%s)\n",
+ GNUNET_i2s (peer));
- #ifdef ENABLE_MALICIOUS
+#ifdef ENABLE_MALICIOUS
struct AttackedPeer *tmp_att_peer;
tmp_att_peer = GNUNET_new (struct AttackedPeer);
@@ -1220,9 +1216,9 @@ handle_peer_push (void *cls,
*/
static int
handle_peer_pull_request (void *cls,
- struct GNUNET_CADET_Channel *channel,
- void **channel_ctx,
- const struct GNUNET_MessageHeader *msg)
+ struct GNUNET_CADET_Channel *channel,
+ void **channel_ctx,
+ const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_PeerIdentity *peer;
const struct GNUNET_PeerIdentity *view_array;
@@ -1272,7 +1268,7 @@ handle_peer_pull_request (void *cls,
* @param channel_ctx The context associated with this channel
* @param msg The message header
*/
- static int
+static int
handle_peer_pull_reply (void *cls,
struct GNUNET_CADET_Channel *channel,
void **channel_ctx,
@@ -1404,7 +1400,8 @@ handle_peer_pull_reply (void *cls,
* @param spread the inverse amount of deviation from the mean
*/
static struct GNUNET_TIME_Relative
-compute_rand_delay (struct GNUNET_TIME_Relative mean, unsigned int spread)
+compute_rand_delay (struct GNUNET_TIME_Relative mean,
+ unsigned int spread)
{
struct GNUNET_TIME_Relative half_interval;
struct GNUNET_TIME_Relative ret;
@@ -1496,7 +1493,7 @@ do_mal_round (void *cls);
* @param client The client that sent the message
* @param msg The message header
*/
- static void
+static void
handle_client_act_malicious (void *cls,
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *msg)
@@ -1613,8 +1610,8 @@ handle_client_act_malicious (void *cls,
{
GNUNET_break (0);
}
-
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_OK);
}
@@ -1631,7 +1628,8 @@ do_mal_round (void *cls)
struct GNUNET_TIME_Relative time_next_round;
struct AttackedPeer *tmp_att_peer;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to execute next round maliciously type %" PRIu32 ".\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Going to execute next round maliciously type %" PRIu32 ".\n",
mal_type);
do_round_task = NULL;
GNUNET_assert (mal_type <= 3);
@@ -1744,7 +1742,8 @@ do_mal_round (void *cls)
//do_round_task = GNUNET_SCHEDULER_add_delayed (round_interval, &do_mal_round,
//NULL);
GNUNET_assert (NULL == do_round_task);
- do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round, &do_mal_round, NULL);
+ do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round,
+ &do_mal_round, NULL);
LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n");
}
#endif /* ENABLE_MALICIOUS */
@@ -1758,8 +1757,6 @@ do_mal_round (void *cls)
static void
do_round (void *cls)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to execute next round.\n");
-
uint32_t i;
const struct GNUNET_PeerIdentity *view_array;
unsigned int *permut;
@@ -1770,6 +1767,8 @@ do_round (void *cls)
struct GNUNET_PeerIdentity peer;
struct GNUNET_PeerIdentity *update_peer;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Going to execute next round.\n");
do_round_task = NULL;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Printing view:\n");
@@ -1967,7 +1966,8 @@ do_round (void *cls)
time_next_round = compute_rand_delay (round_interval, 2);
/* Schedule next round */
- do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round, &do_round, NULL);
+ do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round,
+ &do_round, NULL);
LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n");
}
@@ -2036,9 +2036,8 @@ process_peerinfo_peers (void *cls,
static void
shutdown_task (void *cls)
{
-
- LOG (GNUNET_ERROR_TYPE_DEBUG, "RPS is going down\n");
-
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "RPS is going down\n");
GNUNET_PEERINFO_notify_cancel (peerinfo_notify_handle);
GNUNET_PEERINFO_disconnect (peerinfo_handle);
@@ -2153,9 +2152,8 @@ rps_start (struct GNUNET_SERVER_Handle *server)
do_round_task = GNUNET_SCHEDULER_add_now (&do_round, NULL);
LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduled first round\n");
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c
index e5f6595bb..2ac6054f4 100644
--- a/src/rps/gnunet-service-rps_sampler.c
+++ b/src/rps/gnunet-service-rps_sampler.c
@@ -533,12 +533,8 @@ sampler_get_rand_peer (void *cls)
struct GetPeerCls *gpc = cls;
uint32_t r_index;
struct RPS_Sampler *sampler;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
gpc->get_peer_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
sampler = gpc->req_handle->sampler;
/**;
@@ -588,12 +584,8 @@ sampler_mod_get_rand_peer (void *cls)
struct RPS_SamplerElement *s_elem;
struct GNUNET_TIME_Relative last_request_diff;
struct RPS_Sampler *sampler;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
gpc->get_peer_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
sampler = gpc->req_handle->sampler;
LOG (GNUNET_ERROR_TYPE_DEBUG, "Single peer was requested\n");
@@ -607,7 +599,8 @@ sampler_mod_get_rand_peer (void *cls)
if (EMPTY == s_elem->is_empty)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Sampler_mod element empty, rescheduling.\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sampler_mod element empty, rescheduling.\n");
GNUNET_assert (NULL == gpc->get_peer_task);
gpc->get_peer_task =
GNUNET_SCHEDULER_add_delayed (sampler->max_round_interval,
@@ -708,7 +701,8 @@ RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler,
req_handle->gpc_tail,
gpc);
// maybe add a little delay
- gpc->get_peer_task = GNUNET_SCHEDULER_add_now (sampler->get_peers, gpc);
+ gpc->get_peer_task = GNUNET_SCHEDULER_add_now (sampler->get_peers,
+ gpc);
}
return req_handle;
}
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c
index aca58d55e..128a81f21 100644
--- a/src/rps/test_rps.c
+++ b/src/rps/test_rps.c
@@ -38,7 +38,7 @@
/**
* How many peers do we start?
*/
-uint32_t num_peers;
+static uint32_t num_peers;
/**
* How long do we run the test?
@@ -256,19 +256,12 @@ static unsigned int num_peers_online;
*/
static int ok;
-
/**
* Identifier for the churn task that runs periodically
*/
static struct GNUNET_SCHEDULER_Task *churn_task;
/**
- * Identifier for the churn task that runs periodically
- */
-static struct GNUNET_SCHEDULER_Task *shutdown_task;
-
-
-/**
* Called to initialise the given RPSPeer
*/
typedef void (*InitPeer) (struct RPSPeer *rps_peer);
@@ -362,7 +355,7 @@ static int in_shutdown;
* Append arguments to file
*/
static void
-tofile_ (const char *file_name, char *line)
+tofile_ (const char *file_name, const char *line)
{
struct GNUNET_DISK_FileHandle *f;
/* char output_buffer[512]; */
@@ -754,8 +747,7 @@ default_reply_handle (void *cls,
if (0 == evaluate ())
{
- GNUNET_SCHEDULER_cancel (shutdown_task);
- shutdown_task = GNUNET_SCHEDULER_add_now (&shutdown_op, NULL);
+ GNUNET_SCHEDULER_shutdown ();
}
}
@@ -1388,7 +1380,7 @@ run (void *cls,
if (NULL != churn_task)
GNUNET_SCHEDULER_cancel (churn_task);
- shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL);
+ GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL);
}
diff --git a/src/scalarproduct/gnunet-scalarproduct.c b/src/scalarproduct/gnunet-scalarproduct.c
index 5811ee57b..aa894b61d 100644
--- a/src/scalarproduct/gnunet-scalarproduct.c
+++ b/src/scalarproduct/gnunet-scalarproduct.c
@@ -327,9 +327,8 @@ run (void *cls,
return;
}
GNUNET_free (elements);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
ret = 0;
}
diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c
index c22b4e09e..7485d5de1 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c
@@ -1193,9 +1193,8 @@ run (void *cls,
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c
index 41cf7d1a8..3162d1252 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c
@@ -1251,9 +1251,8 @@ run (void *cls,
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_alice.c b/src/scalarproduct/gnunet-service-scalarproduct_alice.c
index 0b7ba00d5..7eb2d006c 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct_alice.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct_alice.c
@@ -1418,9 +1418,8 @@ run (void *cls,
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_bob.c b/src/scalarproduct/gnunet-service-scalarproduct_bob.c
index c9db1e9ae..8d97ea1b6 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct_bob.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct_bob.c
@@ -1548,9 +1548,8 @@ run (void *cls,
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
diff --git a/src/secretsharing/gnunet-secretsharing-profiler.c b/src/secretsharing/gnunet-secretsharing-profiler.c
index 917431df4..34f959d1a 100644
--- a/src/secretsharing/gnunet-secretsharing-profiler.c
+++ b/src/secretsharing/gnunet-secretsharing-profiler.c
@@ -530,8 +530,7 @@ test_master (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "test master\n");
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &handle_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&handle_shutdown, NULL);
peers = started_peers;
diff --git a/src/secretsharing/gnunet-service-secretsharing.c b/src/secretsharing/gnunet-service-secretsharing.c
index 6babe209a..a264bfdd5 100644
--- a/src/secretsharing/gnunet-service-secretsharing.c
+++ b/src/secretsharing/gnunet-service-secretsharing.c
@@ -2255,8 +2255,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
}
GNUNET_SERVER_add_handlers (server, handlers);
GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
+ NULL);
}
diff --git a/src/secretsharing/test_secretsharing_api.c b/src/secretsharing/test_secretsharing_api.c
index 5057d5c33..341a33b84 100644
--- a/src/secretsharing/test_secretsharing_api.c
+++ b/src/secretsharing/test_secretsharing_api.c
@@ -68,8 +68,7 @@ run (void *cls,
struct GNUNET_TIME_Absolute start;
struct GNUNET_TIME_Absolute deadline;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- handle_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&handle_shutdown, NULL);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "testing secretsharing api\n");
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c
index e9555928a..2aad60309 100644
--- a/src/set/gnunet-service-set.c
+++ b/src/set/gnunet-service-set.c
@@ -1710,7 +1710,6 @@ handle_client_accept (void *cls,
* Called to clean up, after a shutdown has been requested.
*
* @param cls closure
- * @param tc context information (why was this task triggered now)
*/
static void
shutdown_task (void *cls)
@@ -1740,7 +1739,6 @@ shutdown_task (void *cls)
* - we suggested an operation to our listener,
* but did not receive a response in time
* - we got the channel from a peer but no #GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST
- * - shutdown (obviously)
*
* @param cls channel context
* @param tc context information (why was this task triggered now)
@@ -1749,13 +1747,9 @@ static void
incoming_timeout_cb (void *cls)
{
struct Operation *incoming = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
incoming->timeout_task = NULL;
GNUNET_assert (GNUNET_YES == incoming->is_incoming);
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Remote peer's incoming request timed out\n");
incoming_destroy (incoming);
@@ -1997,8 +1991,7 @@ run (void *cls,
static const uint32_t cadet_ports[] = {GNUNET_APPLICATION_TYPE_SET, 0};
configuration = cfg;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
GNUNET_SERVER_disconnect_notify (server,
&handle_client_disconnect, NULL);
GNUNET_SERVER_add_handlers (server,
diff --git a/src/set/gnunet-set-profiler.c b/src/set/gnunet-set-profiler.c
index ff76b27ce..186a2763e 100644
--- a/src/set/gnunet-set-profiler.c
+++ b/src/set/gnunet-set-profiler.c
@@ -299,7 +299,7 @@ run (void *cls,
statistics = GNUNET_STATISTICS_create ("set-profiler", cfg);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, handle_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&handle_shutdown, NULL);
info1.id = "a";
info2.id = "b";
diff --git a/src/set/set_api.c b/src/set/set_api.c
index 772140269..794ae57b7 100644
--- a/src/set/set_api.c
+++ b/src/set/set_api.c
@@ -230,7 +230,7 @@ struct GNUNET_SET_ListenHandle
/**
* Task for reconnecting when the listener fails.
*/
- struct GNUNET_SCHEDULER_Task * reconnect_task;
+ struct GNUNET_SCHEDULER_Task *reconnect_task;
/**
* Operation we listen for.
@@ -891,15 +891,7 @@ listen_connect (void *cls)
struct GNUNET_SET_ListenHandle *lh = cls;
struct GNUNET_MQ_Envelope *mqm;
struct GNUNET_SET_ListenMessage *msg;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Listener not reconnecting due to shutdown\n");
- return;
- }
lh->reconnect_task = NULL;
GNUNET_assert (NULL == lh->client);
lh->client = GNUNET_CLIENT_connect ("set", lh->cfg);
diff --git a/src/set/test_set_api.c b/src/set/test_set_api.c
index b5c21f8a3..d04877b39 100644
--- a/src/set/test_set_api.c
+++ b/src/set/test_set_api.c
@@ -44,6 +44,8 @@ static unsigned int iter_count;
static int ret;
+static struct GNUNET_SCHEDULER_Task *tt;
+
static void
result_cb_set1 (void *cls,
@@ -61,6 +63,8 @@ result_cb_set1 (void *cls,
fprintf (stderr,
"set 1: received failure status!\n");
ret = 1;
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
GNUNET_SCHEDULER_shutdown ();
break;
case GNUNET_SET_STATUS_DONE:
@@ -69,7 +73,11 @@ result_cb_set1 (void *cls,
GNUNET_SET_destroy (set1);
set1 = NULL;
if (NULL == set2)
+ {
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
GNUNET_SCHEDULER_shutdown ();
+ }
break;
default:
GNUNET_assert (0);
@@ -100,7 +108,11 @@ result_cb_set2 (void *cls,
GNUNET_SET_destroy (set2);
set2 = NULL;
if (NULL == set1)
+ {
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
GNUNET_SCHEDULER_shutdown ();
+ }
break;
default:
GNUNET_assert (0);
@@ -250,11 +262,7 @@ test_iter ()
static void
timeout_fail (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ tt = NULL;
GNUNET_SCHEDULER_shutdown ();
ret = 1;
}
@@ -276,8 +284,8 @@ run (void *cls,
struct GNUNET_SET_OperationHandle *my_oh;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
- &timeout_fail, NULL);
+ tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
+ &timeout_fail, NULL);
config = cfg;
GNUNET_CRYPTO_get_peer_identity (cfg, &local_id);
diff --git a/src/set/test_set_union_copy.c b/src/set/test_set_union_copy.c
index fdf6bf9df..7fedf426b 100644
--- a/src/set/test_set_union_copy.c
+++ b/src/set/test_set_union_copy.c
@@ -42,6 +42,8 @@ static struct GNUNET_SET_Handle *set2;
static const struct GNUNET_CONFIGURATION_Handle *config;
+static struct GNUNET_SCHEDULER_Task *tt;
+
static void
add_element_str (struct GNUNET_SET_Handle *set, char *str)
@@ -77,11 +79,7 @@ remove_element_str (struct GNUNET_SET_Handle *set, char *str)
static void
timeout_fail (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ tt = NULL;
GNUNET_SCHEDULER_shutdown ();
ret = 1;
}
@@ -125,8 +123,7 @@ check_count_iter (void *cls,
}
-
-void
+static void
check_count (struct GNUNET_SET_Handle *set,
char *what,
unsigned int expected_count,
@@ -145,24 +142,28 @@ check_count (struct GNUNET_SET_Handle *set,
}
-void test_done (void *cls)
+static void
+test_done (void *cls)
{
if (NULL != set1)
GNUNET_SET_destroy (set1);
if (NULL != set2)
GNUNET_SET_destroy (set2);
-
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
GNUNET_SCHEDULER_shutdown ();
}
-void check_new_set_count (void *cls)
+static void
+check_new_set_count (void *cls)
{
check_count (set2, "new set", 4, &test_done, NULL);
}
-void copy_done (void *cls, struct GNUNET_SET_Handle *new_set)
+static void
+copy_done (void *cls, struct GNUNET_SET_Handle *new_set)
{
printf ("copy done\n");
set2 = new_set;
@@ -177,7 +178,8 @@ void copy_done (void *cls, struct GNUNET_SET_Handle *new_set)
}
-void test_copy (void *cls)
+static void
+test_copy (void *cls)
{
printf ("about to copy\n");
GNUNET_SET_copy_lazy (set1, copy_done, NULL);
@@ -198,9 +200,9 @@ run (void *cls,
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
- &timeout_fail,
- NULL);
+ tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
+ &timeout_fail,
+ NULL);
config = cfg;
GNUNET_TESTING_peer_get_identity (peer,
diff --git a/src/set/test_set_union_result_symmetric.c b/src/set/test_set_union_result_symmetric.c
index b312bcb4c..77fec71c6 100644
--- a/src/set/test_set_union_result_symmetric.c
+++ b/src/set/test_set_union_result_symmetric.c
@@ -297,11 +297,6 @@ test_iter ()
static void
timeout_fail (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GNUNET_SCHEDULER_shutdown ();
ret = 1;
}
diff --git a/src/social/gnunet-service-social.c b/src/social/gnunet-service-social.c
index 1746a82ca..03a113d7e 100644
--- a/src/social/gnunet-service-social.c
+++ b/src/social/gnunet-service-social.c
@@ -408,8 +408,13 @@ static int
psyc_transmit_message (struct Place *plc);
+/**
+ * Clean up place data structures after a client disconnected.
+ *
+ * @param cls the `struct Place` to clean up
+ */
static void
-cleanup_place (struct Place *plc);
+cleanup_place (void *cls);
static struct MessageTransmitQueue *
@@ -426,7 +431,9 @@ place_entry_cleanup (void *cls,
const struct GNUNET_HashCode *key,
void *value)
{
- cleanup_place (value);
+ struct Place *plc = value;
+
+ cleanup_place (plc);
return GNUNET_YES;
}
@@ -524,10 +531,14 @@ cleanup_guest (struct Guest *gst)
/**
* Clean up place data structures after a client disconnected.
+ *
+ * @param cls the `struct Place` to clean up
*/
static void
-cleanup_place (struct Place *plc)
+cleanup_place (void *cls)
{
+ struct Place *plc = cls;
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%p Cleaning up place %s\n",
plc, GNUNET_h2s (&plc->pub_key_hash));
@@ -541,13 +552,6 @@ cleanup_place (struct Place *plc)
}
-static void
-schedule_cleanup_place (void *cls)
-{
- cleanup_place (cls);
-}
-
-
/**
* Called whenever a client is disconnected.
* Frees our resources associated with that client.
@@ -2329,7 +2333,7 @@ psyc_transmit_notify_data (void *cls, uint16_t *data_size, void *data)
tmit_msg = psyc_transmit_queue_next_msg (plc, tmit_msg);
plc->is_disconnected = GNUNET_YES;
GNUNET_SERVER_client_disconnect (tmit_frag->client);
- GNUNET_SCHEDULER_add_now (&schedule_cleanup_place, plc);
+ GNUNET_SCHEDULER_add_now (&cleanup_place, plc);
return ret;
}
else
@@ -2489,7 +2493,7 @@ psyc_transmit_notify_mod (void *cls, uint16_t *data_size, void *data,
tmit_msg = psyc_transmit_queue_next_msg (plc, tmit_msg);
plc->is_disconnected = GNUNET_YES;
GNUNET_SERVER_client_disconnect (tmit_frag->client);
- GNUNET_SCHEDULER_add_now (&schedule_cleanup_place, plc);
+ GNUNET_SCHEDULER_add_now (&cleanup_place, plc);
}
else
{
@@ -3480,8 +3484,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
nc = GNUNET_SERVER_notification_context_create (server, 1);
GNUNET_SERVER_add_handlers (server, handlers);
GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
diff --git a/src/social/test_social.c b/src/social/test_social.c
index 5eeb20196..e2639f4d6 100644
--- a/src/social/test_social.c
+++ b/src/social/test_social.c
@@ -267,16 +267,17 @@ end ()
GNUNET_SCHEDULER_cancel (end_badly_task);
end_badly_task = NULL;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
- &end_normally, NULL);
+ GNUNET_SCHEDULER_add_now (&end_normally, NULL);
}
static void
transmit_resume (void *cls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission resumed.\n");
struct TransmitClosure *tmit = cls;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission resumed.\n");
if (NULL != tmit->host_ann)
GNUNET_SOCIAL_host_announce_resume (tmit->host_ann);
else
@@ -357,14 +358,14 @@ host_farewell2 (void *cls,
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Nym left the place again.\n");
- GNUNET_SCHEDULER_add_now (schedule_host_leave, NULL);
+ GNUNET_SCHEDULER_add_now (&schedule_host_leave, NULL);
}
static void
host_reconnected (void *cls, int result,
- const struct GNUNET_CRYPTO_EddsaPublicKey *home_pub_key,
- uint64_t max_message_id)
+ const struct GNUNET_CRYPTO_EddsaPublicKey *home_pub_key,
+ uint64_t max_message_id)
{
place_pub_key = *home_pub_key;
GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash);
@@ -375,7 +376,7 @@ host_reconnected (void *cls, int result,
is_host_reconnected = GNUNET_YES;
if (GNUNET_YES == is_guest_reconnected)
{
- GNUNET_SCHEDULER_add_now (schedule_guest_leave, NULL);
+ GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
}
}
@@ -393,7 +394,7 @@ guest_reconnected (void *cls, int result,
is_guest_reconnected = GNUNET_YES;
if (GNUNET_YES == is_host_reconnected)
{
- GNUNET_SCHEDULER_add_now (schedule_guest_leave, NULL);
+ GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
}
}
@@ -583,8 +584,10 @@ schedule_guest_leave (void *cls)
static void
-guest_look_for_result (void *cls, int64_t result_code,
- const void *data, uint16_t data_size)
+guest_look_for_result (void *cls,
+ int64_t result_code,
+ const void *data,
+ uint16_t data_size)
{
struct ResultClosure *rcls = cls;
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -1047,7 +1050,7 @@ guest_recv_entry_decision (void *cls,
break;
case TEST_GUEST_ENTER_BY_NAME:
- GNUNET_SCHEDULER_add_now (schedule_reconnect, NULL);
+ GNUNET_SCHEDULER_add_now (&schedule_reconnect, NULL);
break;
default:
@@ -1313,7 +1316,8 @@ run (void *cls,
#endif
{
cfg = c;
- end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
+ end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &end_badly, NULL);
core = GNUNET_CORE_connect (cfg, NULL, &core_connected, NULL, NULL,
NULL, GNUNET_NO, NULL, GNUNET_NO, NULL);
diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c
index 0126f149b..adec5a96d 100644
--- a/src/statistics/gnunet-service-statistics.c
+++ b/src/statistics/gnunet-service-statistics.c
@@ -1053,9 +1053,8 @@ run (void *cls,
&handle_client_disconnect,
NULL);
load (server);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
diff --git a/src/statistics/gnunet-statistics.c b/src/statistics/gnunet-statistics.c
index 2bf5959e3..f21da6059 100644
--- a/src/statistics/gnunet-statistics.c
+++ b/src/statistics/gnunet-statistics.c
@@ -180,7 +180,6 @@ shutdown_task (void *cls)
* Main task that does the actual work.
*
* @param cls closure with our configuration
- * @param tc schedueler context
*/
static void
main_task (void *cls)
@@ -221,7 +220,8 @@ main_task (void *cls)
if (GNUNET_NO == watch)
{
if (NULL ==
- GNUNET_STATISTICS_get (h, subsystem, name, GET_TIMEOUT, &cleanup,
+ GNUNET_STATISTICS_get (h, subsystem, name, GET_TIMEOUT,
+ &cleanup,
&printer, h))
cleanup (h, GNUNET_SYSERR);
}
@@ -235,15 +235,15 @@ main_task (void *cls)
ret = 1;
return;
}
- if (GNUNET_OK != GNUNET_STATISTICS_watch (h, subsystem, name, &printer, h))
+ if (GNUNET_OK != GNUNET_STATISTICS_watch (h, subsystem, name,
+ &printer, h))
{
fprintf (stderr, _("Failed to initialize watch routine\n"));
GNUNET_SCHEDULER_add_now (&shutdown_task, h);
return;
}
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, h);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, h);
}
diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c
index 2b491df72..32b973eec 100644
--- a/src/statistics/statistics_api.c
+++ b/src/statistics/statistics_api.c
@@ -1217,7 +1217,8 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
ai->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
&run_get_timeout,
ai);
- GNUNET_CONTAINER_DLL_insert_tail (handle->action_head, handle->action_tail,
+ GNUNET_CONTAINER_DLL_insert_tail (handle->action_head,
+ handle->action_tail,
ai);
schedule_action (handle);
return ai;
diff --git a/src/statistics/test_statistics_api_watch.c b/src/statistics/test_statistics_api_watch.c
index c7fe54b1f..9b004d1d5 100644
--- a/src/statistics/test_statistics_api_watch.c
+++ b/src/statistics/test_statistics_api_watch.c
@@ -55,7 +55,10 @@ normal_shutdown (void *cls)
static int
-watch_1 (void *cls, const char *subsystem, const char *name, uint64_t value,
+watch_1 (void *cls,
+ const char *subsystem,
+ const char *name,
+ uint64_t value,
int is_persistent)
{
GNUNET_assert (value == 42);
@@ -71,7 +74,10 @@ watch_1 (void *cls, const char *subsystem, const char *name, uint64_t value,
static int
-watch_2 (void *cls, const char *subsystem, const char *name, uint64_t value,
+watch_2 (void *cls,
+ const char *subsystem,
+ const char *name,
+ uint64_t value,
int is_persistent)
{
GNUNET_assert (value == 43);
@@ -87,7 +93,9 @@ watch_2 (void *cls, const char *subsystem, const char *name, uint64_t value,
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)
{
h = GNUNET_STATISTICS_create ("dummy", cfg);
@@ -101,7 +109,8 @@ run (void *cls, char *const *args, const char *cfgfile,
GNUNET_STATISTICS_set (h2, "test-1", 42, GNUNET_NO);
GNUNET_STATISTICS_set (h2, "test-2", 43, GNUNET_NO);
shutdown_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &force_shutdown,
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &force_shutdown,
NULL);
}
diff --git a/src/template/gnunet-service-template.c b/src/template/gnunet-service-template.c
index 556d44bd8..6ff63c073 100644
--- a/src/template/gnunet-service-template.c
+++ b/src/template/gnunet-service-template.c
@@ -47,7 +47,8 @@ cleanup_task (void *cls)
* @param cfg configuration to use
*/
static void
-run (void *cls, struct GNUNET_SERVER_Handle *server,
+run (void *cls,
+ struct GNUNET_SERVER_Handle *server,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
static const struct GNUNET_SERVER_MessageHandler handlers[] = {
@@ -56,8 +57,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
};
/* FIXME: do setup here */
GNUNET_SERVER_add_handlers (server, handlers);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
+ NULL);
}
diff --git a/src/testbed/gnunet-daemon-latency-logger.c b/src/testbed/gnunet-daemon-latency-logger.c
index 9652721a1..b2c7b1043 100644
--- a/src/testbed/gnunet-daemon-latency-logger.c
+++ b/src/testbed/gnunet-daemon-latency-logger.c
@@ -89,17 +89,12 @@ static struct sqlite3 *db;
/**
* Handle to the ATS performance subsystem
*/
-struct GNUNET_ATS_PerformanceHandle *ats;
+static struct GNUNET_ATS_PerformanceHandle *ats;
/**
* Prepared statement for inserting values into the database table
*/
-struct sqlite3_stmt *stmt_insert;
-
-/**
- * Shutdown task identifier
- */
-struct GNUNET_SCHEDULER_Task * shutdown_task;
+static struct sqlite3_stmt *stmt_insert;
/**
@@ -136,7 +131,6 @@ free_iterator (void *cls,
static void
do_shutdown (void *cls)
{
- shutdown_task = NULL;
GNUNET_ATS_performance_done (ats);
ats = NULL;
if (NULL != stmt_insert)
@@ -298,8 +292,7 @@ run (void *cls, char *const *args, const char *cfgfile,
dbfile = NULL;
ats = GNUNET_ATS_performance_init (c, &addr_info_cb, NULL);
map = GNUNET_CONTAINER_multipeermap_create (30, GNUNET_YES);
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
}
diff --git a/src/testbed/gnunet-daemon-testbed-blacklist.c b/src/testbed/gnunet-daemon-testbed-blacklist.c
index 0e0c7ebd5..0cb83aacf 100644
--- a/src/testbed/gnunet-daemon-testbed-blacklist.c
+++ b/src/testbed/gnunet-daemon-testbed-blacklist.c
@@ -67,12 +67,7 @@ static struct GNUNET_PeerIdentity *ilist;
* The blacklist handle we obtain from transport when we register ourselves for
* access control
*/
-struct GNUNET_TRANSPORT_Blacklist *bh;
-
-/**
- * Task for shutdown
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_task;
+static struct GNUNET_TRANSPORT_Blacklist *bh;
/**
* Are we allowing or denying access from peers
@@ -81,26 +76,6 @@ static int mode;
/**
- * @ingroup hashmap
- * Iterator over hash map entries.
- *
- * @param cls closure
- * @param key current key code
- * @param value value in the hash map
- * @return #GNUNET_YES if we should continue to
- * iterate,
- * #GNUNET_NO if not.
- */
-static int
-iterator (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
-{
- GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (map, key,
- value));
- return GNUNET_YES;
-}
-
-
-/**
* Cleaup and destroy the map
*/
static void
@@ -108,9 +83,6 @@ cleanup_map ()
{
if (NULL != map)
{
- GNUNET_assert (GNUNET_SYSERR != GNUNET_CONTAINER_multipeermap_iterate (map,
- &iterator,
- NULL));
GNUNET_CONTAINER_multipeermap_destroy (map);
map = NULL;
}
@@ -161,14 +133,16 @@ check_access (void *cls, const struct GNUNET_PeerIdentity * pid)
* @param cfg the configuration for connecting to the peer's transport service
*/
static void
-setup_ac (const char *fname, const struct GNUNET_CONFIGURATION_Handle *cfg)
+setup_ac (const char *fname,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
uint64_t fsize;
unsigned int npeers;
unsigned int cnt;
- GNUNET_assert (GNUNET_OK != GNUNET_DISK_file_size (fname, &fsize, GNUNET_NO,
- GNUNET_YES));
+ GNUNET_assert (GNUNET_OK !=
+ GNUNET_DISK_file_size (fname, &fsize, GNUNET_NO,
+ GNUNET_YES));
if (0 != (fsize % sizeof (struct GNUNET_PeerIdentity)))
{
GNUNET_break (0);
@@ -183,17 +157,17 @@ setup_ac (const char *fname, const struct GNUNET_CONFIGURATION_Handle *cfg)
}
for (cnt = 0; cnt < npeers; cnt++)
{
- if (GNUNET_SYSERR == GNUNET_CONTAINER_multipeermap_put (map, &ilist[cnt],
- &ilist[cnt],
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+ if (GNUNET_SYSERR ==
+ GNUNET_CONTAINER_multipeermap_put (map, &ilist[cnt],
+ &ilist[cnt],
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
{
cleanup_map ();
GNUNET_free (ilist);
return;
}
}
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
bh = GNUNET_TRANSPORT_blacklist (cfg, &check_access, NULL);
}
@@ -207,15 +181,18 @@ setup_ac (const char *fname, const struct GNUNET_CONFIGURATION_Handle *cfg)
* @param c 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 *c)
{
char *shome;
char *fname;
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "PATHS",
- "GNUNET_HOME",
- &shome))
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (c, "PATHS",
+ "GNUNET_HOME",
+ &shome))
{
GNUNET_break (0);
return;
@@ -260,13 +237,15 @@ main (int argc, char *const *argv)
};
int ret;
- if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_get_utf8_args (argc, argv,
+ &argc, &argv))
return 2;
ret =
(GNUNET_OK ==
- GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-testbed-blacklist",
- _
- ("Daemon to restrict incoming transport layer connections during testbed deployments"),
+ GNUNET_PROGRAM_run (argc, argv,
+ "gnunet-daemon-testbed-blacklist",
+ _("Daemon to restrict incoming transport layer connections during testbed deployments"),
options, &run, NULL)) ? 0 : 1;
GNUNET_free ((void*) argv);
return ret;
diff --git a/src/testbed/gnunet-daemon-testbed-underlay.c b/src/testbed/gnunet-daemon-testbed-underlay.c
index ce0cc46d9..663ab2d08 100644
--- a/src/testbed/gnunet-daemon-testbed-underlay.c
+++ b/src/testbed/gnunet-daemon-testbed-underlay.c
@@ -101,11 +101,6 @@ static struct GNUNET_TRANSPORT_Handle *transport;
*/
static unsigned int num_hostkeys;
-/**
- * Task for shutdown
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_task;
-
/**
* @ingroup hashmap
@@ -439,12 +434,10 @@ run (void *cls, char *const *args, const char *cfgfile,
GNUNET_free (wl_entry);
}
bh = GNUNET_TRANSPORT_blacklist (c, &check_access, NULL);
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
close_db:
GNUNET_break (SQLITE_OK == sqlite3_close (db));
- return;
}
diff --git a/src/testbed/gnunet-helper-testbed.c b/src/testbed/gnunet-helper-testbed.c
index b43f10983..e27e21588 100644
--- a/src/testbed/gnunet-helper-testbed.c
+++ b/src/testbed/gnunet-helper-testbed.c
@@ -124,12 +124,12 @@ static struct GNUNET_DISK_PipeHandle *sigpipe;
/**
* Task identifier for the read task
*/
-static struct GNUNET_SCHEDULER_Task * read_task_id;
+static struct GNUNET_SCHEDULER_Task *read_task_id;
/**
* Task identifier for the write task
*/
-static struct GNUNET_SCHEDULER_Task * write_task_id;
+static struct GNUNET_SCHEDULER_Task *write_task_id;
/**
* Task to kill the child
@@ -137,11 +137,6 @@ static struct GNUNET_SCHEDULER_Task * write_task_id;
static struct GNUNET_SCHEDULER_Task * child_death_task_id;
/**
- * shutdown task id
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_task_id;
-
-/**
* Are we done reading messages from stdin?
*/
static int done_reading;
@@ -161,7 +156,6 @@ static void
shutdown_task (void *cls)
{
LOG_DEBUG ("Shutting down\n");
- shutdown_task_id = NULL;
if (NULL != testbed)
{
LOG_DEBUG ("Killing testbed\n");
@@ -174,8 +168,12 @@ shutdown_task (void *cls)
}
if (NULL != write_task_id)
{
- GNUNET_SCHEDULER_cancel (write_task_id);
+ struct WriteContext *wc;
+
+ wc = GNUNET_SCHEDULER_cancel (write_task_id);
write_task_id = NULL;
+ GNUNET_free (wc->data);
+ GNUNET_free (wc);
}
if (NULL != child_death_task_id)
{
@@ -203,18 +201,6 @@ shutdown_task (void *cls)
/**
- * Scheduler shutdown task to be run now.
- */
-static void
-shutdown_now (void)
-{
- if (NULL != shutdown_task_id)
- GNUNET_SCHEDULER_cancel (shutdown_task_id);
- shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
-}
-
-
-/**
* Task to write to the standard out
*
* @param cls the WriteContext
@@ -224,23 +210,16 @@ write_task (void *cls)
{
struct WriteContext *wc = cls;
ssize_t bytes_wrote;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
GNUNET_assert (NULL != wc);
write_task_id = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- {
- GNUNET_free (wc->data);
- GNUNET_free (wc);
- return;
- }
bytes_wrote =
GNUNET_DISK_file_write (stdout_fd, wc->data + wc->pos,
wc->length - wc->pos);
if (GNUNET_SYSERR == bytes_wrote)
{
- LOG (GNUNET_ERROR_TYPE_WARNING, "Cannot reply back configuration\n");
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Cannot reply back configuration\n");
GNUNET_free (wc->data);
GNUNET_free (wc);
return;
@@ -253,7 +232,8 @@ write_task (void *cls)
return;
}
write_task_id =
- GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, stdout_fd,
+ GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ stdout_fd,
&write_task, wc);
}
@@ -272,18 +252,9 @@ child_death_task (void *cls)
enum GNUNET_OS_ProcessStatusType type;
unsigned long code;
int ret;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
child_death_task_id = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
- {
- child_death_task_id =
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- pr, &child_death_task, NULL);
- return;
- }
/* consume the signal */
GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c)));
LOG_DEBUG ("Got SIGCHLD\n");
@@ -302,7 +273,7 @@ child_death_task (void *cls)
if (0 != PLIBC_KILL (0, GNUNET_TERM_SIG))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "signal");
- shutdown_now (); /* Couldn't send the signal, we shutdown frowning */
+ GNUNET_SCHEDULER_shutdown (); /* Couldn't send the signal, we shutdown frowning */
}
return;
}
@@ -499,7 +470,8 @@ tokenizer_cb (void *cls, void *client,
reply->config_size = htons ((uint16_t) config_size);
wc->data = reply;
write_task_id =
- GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, stdout_fd,
+ GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ stdout_fd,
&write_task, wc);
child_death_task_id =
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
@@ -510,7 +482,7 @@ tokenizer_cb (void *cls, void *client,
error:
status = GNUNET_SYSERR;
- shutdown_now ();
+ GNUNET_SCHEDULER_shutdown ();
return GNUNET_SYSERR;
}
@@ -525,24 +497,20 @@ read_task (void *cls)
{
char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE];
ssize_t sread;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
read_task_id = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
sread = GNUNET_DISK_file_read (stdin_fd, buf, sizeof (buf));
if ((GNUNET_SYSERR == sread) || (0 == sread))
{
LOG_DEBUG ("STDIN closed\n");
- shutdown_now ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
if (GNUNET_YES == done_reading)
{
/* didn't expect any more data! */
GNUNET_break_op (0);
- shutdown_now ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
LOG_DEBUG ("Read %u bytes\n", sread);
@@ -551,11 +519,12 @@ read_task (void *cls)
GNUNET_NO))
{
GNUNET_break (0);
- shutdown_now ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
read_task_id = /* No timeout while reading */
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, stdin_fd,
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ stdin_fd,
&read_task, NULL);
}
@@ -569,7 +538,9 @@ read_task (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)
{
LOG_DEBUG ("Starting testbed helper...\n");
@@ -577,11 +548,11 @@ run (void *cls, char *const *args, const char *cfgfile,
stdin_fd = GNUNET_DISK_get_handle_from_native (stdin);
stdout_fd = GNUNET_DISK_get_handle_from_native (stdout);
read_task_id =
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, stdin_fd,
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ stdin_fd,
&read_task, NULL);
- shutdown_task_id =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
diff --git a/src/testbed/gnunet-service-test-barriers.c b/src/testbed/gnunet-service-test-barriers.c
index 281172cbf..ce5249696 100644
--- a/src/testbed/gnunet-service-test-barriers.c
+++ b/src/testbed/gnunet-service-test-barriers.c
@@ -39,7 +39,9 @@
/**
* Our barrier wait handle
*/
-struct GNUNET_TESTBED_BarrierWaitHandle *wh;
+static struct GNUNET_TESTBED_BarrierWaitHandle *wh;
+
+static struct GNUNET_SCHEDULER_Task *tt;
/**
@@ -51,8 +53,15 @@ static void
do_shutdown (void *cls)
{
if (NULL != wh)
+ {
GNUNET_TESTBED_barrier_wait_cancel (wh);
- wh = NULL;
+ wh = NULL;
+ }
+ if (NULL != tt)
+ {
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
+ }
}
@@ -63,8 +72,8 @@ do_shutdown (void *cls)
*
* @param cls NULL
* @param name the barrier name
- * @param status GNUNET_SYSERR in case of error while waiting for the barrier;
- * GNUNET_OK if the barrier is crossed
+ * @param status #GNUNET_SYSERR in case of error while waiting for the barrier;
+ * #GNUNET_OK if the barrier is crossed
*/
static void
barrier_wait_cb (void *cls, const char *name, int status)
@@ -84,12 +93,10 @@ barrier_wait_cb (void *cls, const char *name, int status)
static void
do_wait (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
- wh = GNUNET_TESTBED_barrier_wait (TEST_BARRIER_NAME, &barrier_wait_cb, NULL);
+ tt = NULL;
+ wh = GNUNET_TESTBED_barrier_wait (TEST_BARRIER_NAME,
+ &barrier_wait_cb,
+ NULL);
GNUNET_break (NULL != wh);
}
@@ -103,17 +110,18 @@ do_wait (void *cls)
* @param config the configuration file handle
*/
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 *config)
{
unsigned int rsec;
rsec = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 10);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, rsec),
- &do_wait, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, rsec),
+ &do_wait, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
}
@@ -121,7 +129,8 @@ run (void *cls, char *const *args, const char *cfgfile,
/**
* Main
*/
-int main (int argc, char **argv)
+int
+main (int argc, char **argv)
{
struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_OPTION_END
diff --git a/src/testbed/gnunet-service-testbed-logger.c b/src/testbed/gnunet-service-testbed-logger.c
index ab5b17460..0f9fab01b 100644
--- a/src/testbed/gnunet-service-testbed-logger.c
+++ b/src/testbed/gnunet-service-testbed-logger.c
@@ -81,11 +81,6 @@ static struct MessageQueue *mq_tail;
struct GNUNET_BIO_WriteHandle *bio;
/**
- * The shutdown task handle
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_task_id;
-
-/**
* The number of connections we have
*/
static unsigned int nconn;
@@ -95,15 +90,17 @@ static unsigned int nconn;
*/
static int in_shutdown;
+
/**
- * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
+ * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
*
* @param cls NULL
* @param client identification of the client
* @param msg the actual message
*/
static void
-handle_log_msg (void *cls, struct GNUNET_SERVER_Client *client,
+handle_log_msg (void *cls,
+ struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *msg)
{
uint16_t ms;
@@ -125,21 +122,20 @@ shutdown_task (void *cls)
{
struct MessageQueue *mq_entry;
- shutdown_task_id = NULL;
in_shutdown = GNUNET_YES;
if (0 != nconn)
{
/* Delay shutdown if there are active connections */
- shutdown_task_id = GNUNET_SCHEDULER_add_delayed
- (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
return;
}
while (NULL != (mq_entry = mq_head))
{
GNUNET_free (mq_entry->msg);
GNUNET_SERVER_client_drop (mq_entry->client);
- GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry);
+ GNUNET_CONTAINER_DLL_remove (mq_head,
+ mq_tail,
+ mq_entry);
GNUNET_free (mq_entry);
}
GNUNET_break (GNUNET_OK == GNUNET_BIO_write_close (bio));
@@ -147,7 +143,7 @@ shutdown_task (void *cls)
/**
- * Functions with this signature are called whenever a client
+x * Functions with this signature are called whenever a client
* is disconnected on the network level.
*
* @param cls closure
@@ -155,7 +151,8 @@ shutdown_task (void *cls)
* for the last call when the server is destroyed
*/
static void
-client_disconnected (void *cls, struct GNUNET_SERVER_Client *client)
+client_disconnected (void *cls,
+ struct GNUNET_SERVER_Client *client)
{
if (NULL == client)
{
@@ -163,11 +160,8 @@ client_disconnected (void *cls, struct GNUNET_SERVER_Client *client)
return;
}
nconn--;
- if (GNUNET_YES != in_shutdown)
- return;
- GNUNET_assert (NULL != shutdown_task_id);
- GNUNET_SCHEDULER_cancel (shutdown_task_id);
- shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ if (GNUNET_YES == in_shutdown)
+ GNUNET_SCHEDULER_shutdown ();
}
@@ -179,7 +173,8 @@ client_disconnected (void *cls, struct GNUNET_SERVER_Client *client)
* @param client identification of the client
*/
static void
-client_connected (void *cls, struct GNUNET_SERVER_Client *client)
+client_connected (void *cls,
+ struct GNUNET_SERVER_Client *client)
{
if (NULL == client)
{
@@ -199,8 +194,9 @@ client_connected (void *cls, struct GNUNET_SERVER_Client *client)
* @param cfg configuration to use
*/
static void
-logger_run (void *cls, struct GNUNET_SERVER_Handle *server,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+logger_run (void *cls,
+ struct GNUNET_SERVER_Handle *server,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
static const struct GNUNET_SERVER_MessageHandler message_handlers[] = {
{&handle_log_msg, NULL, GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG, 0},
@@ -213,10 +209,14 @@ logger_run (void *cls, struct GNUNET_SERVER_Handle *server,
pid_t pid;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg, "TESTBED-LOGGER", "DIR",
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "TESTBED-LOGGER",
+ "DIR",
&dir))
{
- LOG (GNUNET_ERROR_TYPE_ERROR, "Not logging directory definied. Exiting\n");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "TESTBED-LOGGER",
+ "DIR");
GNUNET_SCHEDULER_shutdown ();
return;
}
@@ -225,14 +225,19 @@ logger_run (void *cls, struct GNUNET_SERVER_Handle *server,
hname = GNUNET_malloc (hname_len);
if (0 != gethostname (hname, hname_len))
{
- LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot get hostname. Exiting\n");
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Cannot get hostname. Exiting\n");
GNUNET_free (hname);
GNUNET_free (dir);
GNUNET_SCHEDULER_shutdown ();
return;
}
- (void) GNUNET_asprintf (&fn, "%s/%.*s_%jd.dat", dir, hname_len, hname,
- (intmax_t) pid);
+ GNUNET_asprintf (&fn,
+ "%s/%.*s_%jd.dat",
+ dir,
+ hname_len,
+ hname,
+ (intmax_t) pid);
GNUNET_free (hname);
GNUNET_free (dir);
if (NULL == (bio = GNUNET_BIO_write_open (fn)))
@@ -245,9 +250,7 @@ logger_run (void *cls, struct GNUNET_SERVER_Handle *server,
GNUNET_SERVER_add_handlers (server, message_handlers);
GNUNET_SERVER_connect_notify (server, &client_connected, NULL);
GNUNET_SERVER_disconnect_notify (server, &client_disconnected, NULL);
- shutdown_task_id =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
LOG_DEBUG ("TESTBED-LOGGER startup complete\n");
}
@@ -258,11 +261,10 @@ logger_run (void *cls, struct GNUNET_SERVER_Handle *server,
int
main (int argc, char *const *argv)
{
- //sleep (15); /* Debugging */
return (GNUNET_OK ==
GNUNET_SERVICE_run (argc, argv, "testbed-logger",
GNUNET_SERVICE_OPTION_NONE,
&logger_run, NULL)) ? 0 : 1;
}
-/* end of gnunet-service-testbed.c */
+/* end of gnunet-service-testbed-logger.c */
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index e4fe87fcd..8a286742c 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -130,12 +130,6 @@ static struct MessageQueue *mq_tail;
/**
- * The shutdown task handle
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_task_id;
-
-
-/**
* Function called to notify a client about the connection begin ready to queue
* more data. "buf" will be NULL and "size" zero if the connection was closed
* for writing in the meantime.
@@ -480,7 +474,8 @@ parse_shared_services (char *ss_str, struct GNUNET_CONFIGURATION_Handle *cfg)
* @param message the actual message
*/
static void
-handle_init (void *cls, struct GNUNET_SERVER_Client *client,
+handle_init (void *cls,
+ struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
const struct GNUNET_TESTBED_InitMessage *msg;
@@ -553,14 +548,15 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client,
/**
- * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
+ * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
*
* @param cls NULL
* @param client identification of the client
* @param message the actual message
*/
static void
-handle_add_host (void *cls, struct GNUNET_SERVER_Client *client,
+handle_add_host (void *cls,
+ struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
struct GNUNET_TESTBED_Host *host;
@@ -669,14 +665,15 @@ handle_add_host (void *cls, struct GNUNET_SERVER_Client *client,
/**
- * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages
+ * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages
*
* @param cls NULL
* @param client identification of the client
* @param message the actual message
*/
static void
-handle_slave_get_config (void *cls, struct GNUNET_SERVER_Client *client,
+handle_slave_get_config (void *cls,
+ struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg;
@@ -781,7 +778,6 @@ shutdown_task (void *cls)
struct MessageQueue *mq_entry;
uint32_t id;
- shutdown_task_id = NULL;
LOG_DEBUG ("Shutting down testbed service\n");
/* cleanup any remaining forwarded operations */
GST_clear_fopcq ();
@@ -939,10 +935,7 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
GST_config = GNUNET_CONFIGURATION_dup (cfg);
GNUNET_SERVER_add_handlers (server, message_handlers);
GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL);
- shutdown_task_id =
- GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
LOG_DEBUG ("Testbed startup complete\n");
GST_stats_init (GST_config);
GST_barriers_init (GST_config);
@@ -955,9 +948,10 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
int
main (int argc, char *const *argv)
{
- //sleep (15); /* Debugging */
return (GNUNET_OK ==
- GNUNET_SERVICE_run (argc, argv, "testbed", GNUNET_SERVICE_OPTION_NONE,
+ GNUNET_SERVICE_run (argc, argv,
+ "testbed",
+ GNUNET_SERVICE_OPTION_NONE,
&testbed_run, NULL)) ? 0 : 1;
}
diff --git a/src/testbed/gnunet-service-testbed_cpustatus.c b/src/testbed/gnunet-service-testbed_cpustatus.c
index cda669caa..ae49e31f9 100644
--- a/src/testbed/gnunet-service-testbed_cpustatus.c
+++ b/src/testbed/gnunet-service-testbed_cpustatus.c
@@ -655,12 +655,8 @@ sample_load_task (void *cls)
int ld_disk;
unsigned int mem_usage;
unsigned int nproc;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
sample_load_task_id = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
ld_cpu = cpu_get_load ();
ld_disk = disk_get_load ();
if ( (-1 == ld_cpu) || (-1 == ld_disk) )
diff --git a/src/testbed/gnunet-service-testbed_oc.c b/src/testbed/gnunet-service-testbed_oc.c
index 34bf8e047..55dd5cad9 100644
--- a/src/testbed/gnunet-service-testbed_oc.c
+++ b/src/testbed/gnunet-service-testbed_oc.c
@@ -879,13 +879,9 @@ send_hello (void *cls)
struct OverlayConnectContext *occ = cls;
struct LocalPeer2Context *lp2c;
char *other_peer_str;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
occ->send_hello_task = NULL;
GNUNET_assert (NULL != occ->timeout_task);
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GNUNET_assert (NULL != occ->hello);
if (OCC_TYPE_LOCAL != occ->type)
{
diff --git a/src/testbed/gnunet-testbed-profiler.c b/src/testbed/gnunet-testbed-profiler.c
index 308ec0386..9468b3c91 100644
--- a/src/testbed/gnunet-testbed-profiler.c
+++ b/src/testbed/gnunet-testbed-profiler.c
@@ -55,12 +55,7 @@ static char *hosts_file;
/**
* Abort task identifier
*/
-static struct GNUNET_SCHEDULER_Task * abort_task;
-
-/**
- * Shutdown task identifier
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_task;
+static struct GNUNET_SCHEDULER_Task *abort_task;
/**
* Global event mask for all testbed events
@@ -111,7 +106,6 @@ static int noninteractive;
static void
do_shutdown (void *cls)
{
- shutdown_task = NULL;
if (NULL != abort_task)
{
GNUNET_SCHEDULER_cancel (abort_task);
@@ -122,7 +116,6 @@ do_shutdown (void *cls)
GNUNET_CONFIGURATION_destroy (cfg);
cfg = NULL;
}
- GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */
}
@@ -134,12 +127,11 @@ do_shutdown (void *cls)
static void
do_abort (void *cls)
{
- LOG (GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
abort_task = NULL;
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Aborting\n");
result = GNUNET_SYSERR;
- if (NULL != shutdown_task)
- GNUNET_SCHEDULER_cancel (shutdown_task);
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_shutdown ();
}
@@ -228,12 +220,11 @@ test_run (void *cls,
result = GNUNET_OK;
fprintf (stdout, "\n");
print_overlay_links_summary ();
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
if (noninteractive)
{
GNUNET_SCHEDULER_cancel (abort_task);
abort_task = NULL;
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
return;
}
#if (!ENABLE_SUPERMUC)
@@ -243,8 +234,7 @@ test_run (void *cls,
#endif
fprintf (stdout, "Shutting down. Please wait\n");
fflush (stdout);
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
- return;
+ GNUNET_SCHEDULER_shutdown ();
}
diff --git a/src/testbed/gnunet_testbed_mpi_spawn.c b/src/testbed/gnunet_testbed_mpi_spawn.c
index 191f658b7..d69812cd2 100644
--- a/src/testbed/gnunet_testbed_mpi_spawn.c
+++ b/src/testbed/gnunet_testbed_mpi_spawn.c
@@ -56,11 +56,6 @@ static unsigned long child_exit_code;
static enum GNUNET_OS_ProcessStatusType child_status;
/**
- * The shutdown task
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_task_id;
-
-/**
* Task to kill the child
*/
static struct GNUNET_SCHEDULER_Task * terminate_task_id;
@@ -76,7 +71,6 @@ static struct GNUNET_SCHEDULER_Task * child_death_task_id;
static void
shutdown_task (void *cls)
{
- shutdown_task_id = NULL;
if (0 != child_exit_code)
{
LOG (GNUNET_ERROR_TYPE_WARNING, "Child exited with error code: %lu\n",
@@ -102,8 +96,7 @@ terminate_task (void *cls)
GNUNET_assert (NULL != child);
terminate_task_id =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &terminate_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&terminate_task, NULL);
if (0 != hard_kill)
{
switch (hard_kill)
@@ -159,7 +152,7 @@ child_death_task (void *cls)
&child_exit_code));
GNUNET_OS_process_destroy (child);
child = NULL;
- shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
}
@@ -253,13 +246,12 @@ run (void *cls)
{
GNUNET_break (0);
ret = GNUNET_SYSERR;
- shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
return;
}
ret = GNUNET_OK;
terminate_task_id =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &terminate_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&terminate_task, NULL);
child_death_task_id =
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
GNUNET_DISK_pipe_handle (sigpipe,
diff --git a/src/testbed/test_testbed_api_3peers_3controllers.c b/src/testbed/test_testbed_api_3peers_3controllers.c
index a728048f3..0ee1fc566 100644
--- a/src/testbed/test_testbed_api_3peers_3controllers.c
+++ b/src/testbed/test_testbed_api_3peers_3controllers.c
@@ -301,6 +301,7 @@ do_abort (void *cls)
do_shutdown (cls);
}
+
static void
abort_test ()
{
@@ -842,10 +843,11 @@ status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config,
* @param cls NULL
* @param host the host whose status is being reported; will be NULL if the host
* given to GNUNET_TESTBED_is_host_habitable() is NULL
- * @param status GNUNET_YES if it is habitable; GNUNET_NO if not
+ * @param status #GNUNET_YES if it is habitable; #GNUNET_NO if not
*/
static void
-host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *_host,
+host_habitable_cb (void *cls,
+ const struct GNUNET_TESTBED_Host *_host,
int status)
{
hc_handle = NULL;
@@ -857,7 +859,7 @@ host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *_host,
"Skipping test\n");
GNUNET_SCHEDULER_cancel (abort_task);
abort_task = NULL;
- (void) GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
result = SKIP;
return;
}
diff --git a/src/testbed/test_testbed_api_hosts.c b/src/testbed/test_testbed_api_hosts.c
index 2141dc46f..0999020a8 100644
--- a/src/testbed/test_testbed_api_hosts.c
+++ b/src/testbed/test_testbed_api_hosts.c
@@ -58,10 +58,6 @@ static unsigned int num_hosts;
*/
static int status;
-/**
- * Shutdown task identifier
- */
-struct GNUNET_SCHEDULER_Task * shutdown_id;
/**
* The shutdown task
@@ -159,8 +155,7 @@ run (void *cls, char *const *args, const char *cfgfile,
}
}
status = GNUNET_YES;
- shutdown_id =
- GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (0), &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
}
diff --git a/src/testbed/test_testbed_api_testbed_run.c b/src/testbed/test_testbed_api_testbed_run.c
index 10beebc1f..45c9f5adf 100644
--- a/src/testbed/test_testbed_api_testbed_run.c
+++ b/src/testbed/test_testbed_api_testbed_run.c
@@ -86,9 +86,10 @@ do_shutdown (void *cls)
static void
do_abort (void *cls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
abort_task = NULL;
- (void) GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Test timed out -- Aborting\n");
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
}
@@ -119,8 +120,7 @@ test_master (void *cls,
return; /* abort already scheduled */
GNUNET_SCHEDULER_cancel (abort_task);
abort_task = NULL;
- (void) GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
return;
}
GNUNET_assert (NULL != peers[0]);
@@ -168,7 +168,9 @@ controller_event_cb (void *cls,
* @param cfg the configuration file handle
*/
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 *config)
{
uint64_t event_mask;
@@ -176,11 +178,13 @@ run (void *cls, char *const *args, const char *cfgfile,
event_mask = 0;
event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
- GNUNET_TESTBED_run (NULL, config, NUM_PEERS, event_mask, &controller_event_cb,
- NULL, &test_master, NULL);
+ GNUNET_TESTBED_run (NULL, config, NUM_PEERS, event_mask,
+ &controller_event_cb, NULL,
+ &test_master, NULL);
abort_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 300), &do_abort,
+ (GNUNET_TIME_UNIT_SECONDS, 300),
+ &do_abort,
NULL);
}
diff --git a/src/testbed/test_testbed_logger_api.c b/src/testbed/test_testbed_logger_api.c
index 30740c94d..f140dfbad 100644
--- a/src/testbed/test_testbed_logger_api.c
+++ b/src/testbed/test_testbed_logger_api.c
@@ -113,39 +113,39 @@ do_abort (void *cls)
*
* @param cls closure
* @param filename complete filename (absolute path)
+ * @return #GNUNET_OK to continue to iterate,
+ * #GNUNET_NO to stop iteration with no error,
+ * #GNUNET_SYSERR to abort iteration with error!
*/
-static void
+static int
iterator_cb (void *cls,
const char *filename)
{
const char *fn;
size_t len;
uint64_t fs;
- int cancel;
- cancel = GNUNET_NO;
- if (NULL == filename)
- return;
len = strlen (filename);
if (len < 5) /* log file: `pid'.dat */
- return;
+ return GNUNET_OK;
+
fn = filename + len;
if (0 != strcasecmp (".dat", fn - 4))
- return;
- if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fs,
- GNUNET_NO, GNUNET_YES))
- return;
+ return GNUNET_OK;
+ if (GNUNET_OK !=
+ GNUNET_DISK_file_size (filename, &fs,
+ GNUNET_NO, GNUNET_YES))
+ return GNUNET_SYSERR;
if ((BSIZE * 2) != fs) /* The file size should be equal to what we
have written */
- return;
- cancel = GNUNET_YES;
- result = GNUNET_OK;
+ return GNUNET_SYSERR;
+ return GNUNET_OK;
}
/**
- * Functions of this type are called to notify a successful transmission of the
- * message to the logger service
+ * Functions of this type are called to notify a successful
+ * transmission of the message to the logger service
*
* @param cls the closure given to GNUNET_TESTBED_LOGGER_send()
* @param size the amount of data sent
diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c
index de99fb5a3..b3b2c3987 100644
--- a/src/testbed/testbed_api_testbed.c
+++ b/src/testbed/testbed_api_testbed.c
@@ -263,7 +263,7 @@ struct GNUNET_TESTBED_RunHandle
/**
* Task run upon shutdown interrupts
*/
- struct GNUNET_SCHEDULER_Task * interrupt_task;
+ struct GNUNET_SCHEDULER_Task *interrupt_task;
/**
* The event mask for the controller
@@ -620,8 +620,7 @@ interrupt (void *cls)
unsigned int size;
/* reschedule */
- rc->interrupt_task = GNUNET_SCHEDULER_add_delayed
- (GNUNET_TIME_UNIT_FOREVER_REL, &interrupt, rc);
+ rc->interrupt_task = GNUNET_SCHEDULER_add_shutdown (&interrupt, rc);
rc_cleanup_operations (rc);
if ( (GNUNET_NO == rc->shutdown) &&
(NULL != c) &&
@@ -988,7 +987,8 @@ host_registration_completion (void *cls, const char *emsg)
GNUNET_SCHEDULER_shutdown ();
return;
}
- rc->register_hosts_task = GNUNET_SCHEDULER_add_now (&register_hosts, rc);
+ rc->register_hosts_task = GNUNET_SCHEDULER_add_now (&register_hosts,
+ rc);
}
@@ -1415,10 +1415,11 @@ GNUNET_TESTBED_run (const char *host_filename,
}
rc->rcop_map = GNUNET_CONTAINER_multihashmap32_create (256);
rc->timeout_task =
- GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task, rc);
+ GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task, rc);
+ GNUNET_assert (NULL == rc->interrupt_task);
rc->interrupt_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &interrupt,
- rc);
+ GNUNET_SCHEDULER_add_shutdown (&interrupt,
+ rc);
return;
error_cleanup:
diff --git a/src/testing/gnunet-testing.c b/src/testing/gnunet-testing.c
index 92dd17d98..07f1560cb 100644
--- a/src/testing/gnunet-testing.c
+++ b/src/testing/gnunet-testing.c
@@ -76,7 +76,7 @@ static char *tmpfilename;
/**
* Task identifier of the task that waits for stdin.
*/
-static struct GNUNET_SCHEDULER_Task * tid;
+static struct GNUNET_SCHEDULER_Task *tid;
/**
* Peer started for '-r'.
@@ -228,13 +228,8 @@ static void
stdin_cb (void *cls)
{
int c;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
tid = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
- GNUNET_assert (0 != (GNUNET_SCHEDULER_REASON_READ_READY & tc->reason));
c = getchar ();
switch (c)
{
@@ -258,7 +253,8 @@ stdin_cb (void *cls)
fprintf (stderr, _("Unknown command, use 'q' to quit or 'r' to restart peer\n"));
break;
}
- tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, fh,
+ tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ fh,
&stdin_cb, NULL);
}
@@ -291,9 +287,10 @@ testing_main (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
}
printf("ok\n%s\n", tmpfilename);
fflush(stdout);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL);
fh = GNUNET_DISK_get_handle_from_native (stdin);
- tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, fh,
+ tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ fh,
&stdin_cb, NULL);
}
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c
index 1a6c163ee..eddac8c8a 100644
--- a/src/topology/gnunet-daemon-topology.c
+++ b/src/topology/gnunet-daemon-topology.c
@@ -514,13 +514,9 @@ schedule_next_hello (void *cls)
struct FindAdvHelloContext fah;
size_t next_want;
struct GNUNET_TIME_Relative delay;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
pl->hello_delay_task = NULL;
GNUNET_assert (GNUNET_YES == pl->is_connected);
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return; /* we're out of here */
if (pl->hello_req != NULL)
return; /* did not finish sending the previous one */
/* find applicable HELLOs */
@@ -535,7 +531,7 @@ schedule_next_hello (void *cls)
GNUNET_SCHEDULER_add_delayed (fah.next_adv,
&schedule_next_hello,
pl);
- if (fah.result == NULL)
+ if (NULL == fah.result)
return;
next_want = GNUNET_HELLO_size (fah.result->hello);
delay = GNUNET_TIME_absolute_get_remaining (pl->next_hello_allowed);
@@ -1241,9 +1237,8 @@ run (void *cls,
NULL, GNUNET_NO,
NULL, GNUNET_NO,
handlers);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &cleaning_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleaning_task,
+ NULL);
if (NULL == transport)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index 9fde3d83e..119e5e564 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -848,9 +848,8 @@ run (void *cls,
"My identity is `%4s'\n",
GNUNET_i2s_full (&GST_my_identity));
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
if (NULL == GST_peerinfo)
{
GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index 836aa418c..6ea5394bf 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -873,7 +873,6 @@ add_valid_address (void *cls,
validation_entry_changed (ve,
GNUNET_TRANSPORT_VS_UPDATE);
memset (&prop, 0, sizeof (prop));
- GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != ve->network);
prop.scope = ve->network;
prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2);
if (GNUNET_YES != ve->known_to_ats)
diff --git a/src/transport/gnunet-transport-profiler.c b/src/transport/gnunet-transport-profiler.c
index 624d1a16c..af47c5c56 100644
--- a/src/transport/gnunet-transport-profiler.c
+++ b/src/transport/gnunet-transport-profiler.c
@@ -146,11 +146,6 @@ static struct GNUNET_TRANSPORT_Blacklist *bl_handle;
static struct GNUNET_PeerIdentity pid;
/**
- * Task scheduled for cleanup / termination of the process.
- */
-static struct GNUNET_SCHEDULER_Task * end;
-
-/**
* Selected level of verbosity.
*/
static int verbosity;
@@ -380,9 +375,7 @@ iteration_done ()
if (it_count == benchmark_iterations)
{
benchmark_running = GNUNET_NO;
- if (NULL != end)
- GNUNET_SCHEDULER_cancel (end);
- end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ GNUNET_SCHEDULER_shutdown ();
return;
}
else
@@ -570,9 +563,8 @@ testservice_task (void *cls, int result)
ats_sh = GNUNET_ATS_connectivity_suggest (ats,
&pid,
1);
- end = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index bed9bdc85..cbddee905 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -607,9 +607,7 @@ operation_timeout (void *cls)
FPRINTF (stdout,
_("Failed to connect to `%s'\n"),
GNUNET_i2s_full (&pid));
- if (NULL != end)
- GNUNET_SCHEDULER_cancel (end);
- end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ GNUNET_SCHEDULER_shutdown ();
ret = 1;
return;
}
@@ -633,9 +631,7 @@ operation_timeout (void *cls)
FPRINTF (stdout,
"%s",
_("Failed to list connections, timeout occured\n"));
- if (NULL != end)
- GNUNET_SCHEDULER_cancel (end);
- end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ GNUNET_SCHEDULER_shutdown ();
ret = 1;
return;
}
@@ -851,18 +847,13 @@ process_validation_string (void *cls,
GNUNET_free (vc);
if ((0 == address_resolutions) && (iterate_validation))
{
- if (NULL != end)
- {
- GNUNET_SCHEDULER_cancel (end);
- end = NULL;
- }
if (NULL != op_timeout)
{
GNUNET_SCHEDULER_cancel (op_timeout);
op_timeout = NULL;
}
ret = 0;
- end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ GNUNET_SCHEDULER_shutdown ();
}
}
@@ -937,9 +928,7 @@ process_validation_cb (void *cls,
return;
}
vic = NULL;
- if (NULL != end)
- GNUNET_SCHEDULER_cancel (end);
- end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ GNUNET_SCHEDULER_shutdown ();
return;
}
resolve_validation_address (address,
@@ -1364,19 +1353,13 @@ process_peer_string (void *cls,
GNUNET_free (rc);
if ((0 == address_resolutions) && (iterate_connections))
{
- if (NULL != end)
- {
- GNUNET_SCHEDULER_cancel (end);
- end = NULL;
- }
if (NULL != op_timeout)
{
GNUNET_SCHEDULER_cancel (op_timeout);
op_timeout = NULL;
}
ret = 0;
- end = GNUNET_SCHEDULER_add_now (&shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_shutdown ();
}
}
@@ -1950,10 +1933,9 @@ testservice_task (void *cls,
GNUNET_break(0);
return;
}
-
- end = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c
index 2b0b8939e..132406799 100644
--- a/src/transport/plugin_transport_http_client.c
+++ b/src/transport/plugin_transport_http_client.c
@@ -226,17 +226,17 @@ struct GNUNET_ATS_Session
/**
* Session timeout task
*/
- struct GNUNET_SCHEDULER_Task * put_disconnect_task;
+ struct GNUNET_SCHEDULER_Task *put_disconnect_task;
/**
* Session timeout task
*/
- struct GNUNET_SCHEDULER_Task * timeout_task;
+ struct GNUNET_SCHEDULER_Task *timeout_task;
/**
* Task to wake up client receive handle when receiving is allowed again
*/
- struct GNUNET_SCHEDULER_Task * recv_wakeup_task;
+ struct GNUNET_SCHEDULER_Task *recv_wakeup_task;
/**
* Absolute time when to receive data again.
@@ -1130,12 +1130,8 @@ static void
client_wake_up (void *cls)
{
struct GNUNET_ATS_Session *s = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
s->recv_wakeup_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Session %p/request %p: Waking up GET handle\n",
s, s->get.easyhandle);
@@ -1301,13 +1297,8 @@ client_run (void *cls)
CURLMsg *msg;
int put_request; /* GNUNET_YES if easy handle is put, GNUNET_NO for get */
int msgs_left;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
plugin->client_perform_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
-
/* While data are available or timeouts occured */
do
{
@@ -2379,8 +2370,10 @@ http_client_plugin_update_inbound_delay (void *cls,
if (s->recv_wakeup_task != NULL)
{
GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
- s->recv_wakeup_task = GNUNET_SCHEDULER_add_delayed (delay,
- &client_wake_up, s);
+ s->recv_wakeup_task
+ = GNUNET_SCHEDULER_add_delayed (delay,
+ &client_wake_up,
+ s);
}
}
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c
index dfd0294e5..c43124c2e 100644
--- a/src/transport/plugin_transport_http_server.c
+++ b/src/transport/plugin_transport_http_server.c
@@ -374,17 +374,17 @@ struct HTTP_Server_Plugin
/**
* MHD IPv4 task
*/
- struct GNUNET_SCHEDULER_Task * server_v4_task;
+ struct GNUNET_SCHEDULER_Task *server_v4_task;
/**
* MHD IPv6 task
*/
- struct GNUNET_SCHEDULER_Task * server_v6_task;
+ struct GNUNET_SCHEDULER_Task *server_v6_task;
/**
* Task calling transport service about external address
*/
- struct GNUNET_SCHEDULER_Task * notify_ext_task;
+ struct GNUNET_SCHEDULER_Task *notify_ext_task;
/**
* Notify transport only about external address
@@ -496,12 +496,8 @@ static void
server_wake_up (void *cls)
{
struct GNUNET_ATS_Session *s = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
s->recv_wakeup_task = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Session %p: Waking up PUT handle\n",
s);
@@ -913,12 +909,8 @@ static void
server_v4_run (void *cls)
{
struct HTTP_Server_Plugin *plugin = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
plugin->server_v4_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
plugin->server_v4_immediately = GNUNET_NO;
GNUNET_assert (MHD_YES == MHD_run (plugin->server_v4));
server_reschedule (plugin, plugin->server_v4, GNUNET_NO);
@@ -935,12 +927,8 @@ static void
server_v6_run (void *cls)
{
struct HTTP_Server_Plugin *plugin = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
plugin->server_v6_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
plugin->server_v6_immediately = GNUNET_NO;
GNUNET_assert (MHD_YES == MHD_run (plugin->server_v6));
server_reschedule (plugin, plugin->server_v6, GNUNET_NO);
@@ -1869,8 +1857,10 @@ server_access_cb (void *cls,
GNUNET_assert(s->server_recv->mhd_conn == mhd_connection);
MHD_suspend_connection (s->server_recv->mhd_conn);
if (NULL == s->recv_wakeup_task)
- s->recv_wakeup_task = GNUNET_SCHEDULER_add_delayed (delay,
- &server_wake_up, s);
+ s->recv_wakeup_task
+ = GNUNET_SCHEDULER_add_delayed (delay,
+ &server_wake_up,
+ s);
}
return MHD_YES;
}
@@ -2851,18 +2841,12 @@ server_notify_external_hostname (void *cls)
size_t ext_addr_len;
unsigned int urlen;
char *url;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
plugin->notify_ext_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
-
- GNUNET_asprintf(&url,
- "%s://%s",
- plugin->protocol,
- plugin->external_hostname);
-
+ GNUNET_asprintf (&url,
+ "%s://%s",
+ plugin->protocol,
+ plugin->external_hostname);
urlen = strlen (url) + 1;
ext_addr = GNUNET_malloc (sizeof (struct HttpAddress) + urlen);
ext_addr->options = htonl (plugin->options);
@@ -2881,13 +2865,23 @@ server_notify_external_hostname (void *cls)
"Enabling SSL verification for external hostname address `%s'\n",
plugin->external_hostname);
plugin->ext_addr = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
- "https_client", ext_addr, ext_addr_len, GNUNET_HELLO_ADDRESS_INFO_NONE );
- plugin->env->notify_address (plugin->env->cls, GNUNET_YES, plugin->ext_addr);
+ "https_client",
+ ext_addr,
+ ext_addr_len,
+ GNUNET_HELLO_ADDRESS_INFO_NONE);
+ plugin->env->notify_address (plugin->env->cls,
+ GNUNET_YES,
+ plugin->ext_addr);
GNUNET_free (ext_addr);
#else
plugin->ext_addr = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
- "http_client", ext_addr, ext_addr_len, GNUNET_HELLO_ADDRESS_INFO_NONE );
- plugin->env->notify_address (plugin->env->cls, GNUNET_YES, plugin->ext_addr);
+ "http_client",
+ ext_addr,
+ ext_addr_len,
+ GNUNET_HELLO_ADDRESS_INFO_NONE);
+ plugin->env->notify_address (plugin->env->cls,
+ GNUNET_YES,
+ plugin->ext_addr);
GNUNET_free (ext_addr);
#endif
}
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index 89feb8f5c..b5706f024 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -3516,13 +3516,11 @@ udp_plugin_select_v4 (void *cls)
{
struct Plugin *plugin = cls;
const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
+
plugin->select_task_v4 = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
if (NULL == plugin->sockv4)
return;
+ tc = GNUNET_SCHEDULER_get_task_context ();
if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
(GNUNET_NETWORK_fdset_isset (tc->read_ready,
plugin->sockv4)))
@@ -3547,12 +3545,10 @@ udp_plugin_select_v6 (void *cls)
struct Plugin *plugin = cls;
const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
plugin->select_task_v6 = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
if (NULL == plugin->sockv6)
return;
+ tc = GNUNET_SCHEDULER_get_task_context ();
if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
(GNUNET_NETWORK_fdset_isset (tc->read_ready,
plugin->sockv6)) )
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c
index e320785d4..d0566c2d3 100644
--- a/src/transport/plugin_transport_unix.c
+++ b/src/transport/plugin_transport_unix.c
@@ -1229,11 +1229,9 @@ unix_plugin_select_read (void *cls)
{
struct Plugin *plugin = cls;
const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
+
plugin->read_task = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ tc = GNUNET_SCHEDULER_get_task_context ();
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
unix_plugin_do_read (plugin);
plugin->read_task =
@@ -1254,11 +1252,9 @@ unix_plugin_select_write (void *cls)
{
struct Plugin *plugin = cls;
const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
+
plugin->write_task = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ tc = GNUNET_SCHEDULER_get_task_context ();
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))
unix_plugin_do_write (plugin);
if (NULL == plugin->msg_head)
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c
index 13333b371..528b8f2bf 100644
--- a/src/transport/test_transport_api.c
+++ b/src/transport/test_transport_api.c
@@ -228,12 +228,7 @@ notify_ready (void *cls, size_t size, void *buf)
static void
sendtask (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
diff --git a/src/transport/test_transport_api_bidirectional_connect.c b/src/transport/test_transport_api_bidirectional_connect.c
index 1e00e982d..a5d6b6b71 100644
--- a/src/transport/test_transport_api_bidirectional_connect.c
+++ b/src/transport/test_transport_api_bidirectional_connect.c
@@ -210,14 +210,10 @@ notify_ready (void *cls, size_t size, void *buf)
static void
sendtask (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
+ char *receiver_s;
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
- char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
-
+ receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending message from peer %u (`%4s') -> peer %u (`%s') !\n",
p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s);
diff --git a/src/transport/test_transport_api_blacklisting.c b/src/transport/test_transport_api_blacklisting.c
index f65fb74f9..963d3b045 100644
--- a/src/transport/test_transport_api_blacklisting.c
+++ b/src/transport/test_transport_api_blacklisting.c
@@ -262,12 +262,7 @@ notify_ready (void *cls, size_t size, void *buf)
static void
sendtask (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/transport/test_transport_api_disconnect.c b/src/transport/test_transport_api_disconnect.c
index 36497ece5..f52634bde 100644
--- a/src/transport/test_transport_api_disconnect.c
+++ b/src/transport/test_transport_api_disconnect.c
@@ -165,12 +165,6 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
static void
stop_peer (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
-
struct PeerContext *p = cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down peer %u (`%s')\n", p->no,
@@ -254,12 +248,7 @@ notify_ready (void *cls, size_t size, void *buf)
static void
sendtask (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/transport/test_transport_api_http_reverse_peer2.conf b/src/transport/test_transport_api_http_reverse_peer2.conf
index 7117895ef..136c09008 100644
--- a/src/transport/test_transport_api_http_reverse_peer2.conf
+++ b/src/transport/test_transport_api_http_reverse_peer2.conf
@@ -10,4 +10,3 @@ EXTERNAL_HOSTNAME_ONLY = YES
[transport]
PLUGINS = http_server
-
diff --git a/src/transport/test_transport_api_https_peer1.conf b/src/transport/test_transport_api_https_peer1.conf
index 8fc2edf2e..c6a083f37 100644
--- a/src/transport/test_transport_api_https_peer1.conf
+++ b/src/transport/test_transport_api_https_peer1.conf
@@ -21,5 +21,6 @@ UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-peerinfo.sock
PORT = 12101
PLUGINS = https_client
UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-transport.sock
+#PREFIX = valgrind
diff --git a/src/transport/test_transport_api_https_peer2.conf b/src/transport/test_transport_api_https_peer2.conf
index d2bf20011..49210651c 100644
--- a/src/transport/test_transport_api_https_peer2.conf
+++ b/src/transport/test_transport_api_https_peer2.conf
@@ -27,5 +27,6 @@ UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-peerinfo.sock
PORT = 12111
PLUGINS = https_server
UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-transport.sock
+#PREFIX = valgrind
diff --git a/src/transport/test_transport_api_limited_sockets.c b/src/transport/test_transport_api_limited_sockets.c
index 8d875ed52..0ae807077 100644
--- a/src/transport/test_transport_api_limited_sockets.c
+++ b/src/transport/test_transport_api_limited_sockets.c
@@ -198,13 +198,7 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
static void
sendtask (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
-
th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th, &p2->id, 256, TIMEOUT,
&notify_ready, &p1);
}
diff --git a/src/transport/test_transport_api_manipulation_cfg.c b/src/transport/test_transport_api_manipulation_cfg.c
index 915b79719..fe3d31f7b 100644
--- a/src/transport/test_transport_api_manipulation_cfg.c
+++ b/src/transport/test_transport_api_manipulation_cfg.c
@@ -206,12 +206,7 @@ notify_request_ready (void *cls, size_t size, void *buf)
static void
sendtask_request_task (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p2->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -272,12 +267,7 @@ notify_response_ready (void *cls, size_t size, void *buf)
static void
sendtask_response_task (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
{
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
diff --git a/src/transport/test_transport_api_manipulation_recv_tcp.c b/src/transport/test_transport_api_manipulation_recv_tcp.c
index 7b82236f9..02c9408a6 100644
--- a/src/transport/test_transport_api_manipulation_recv_tcp.c
+++ b/src/transport/test_transport_api_manipulation_recv_tcp.c
@@ -292,12 +292,7 @@ notify_ready (void *cls, size_t size, void *buf)
static void
sendtask (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/transport/test_transport_api_manipulation_send_tcp.c b/src/transport/test_transport_api_manipulation_send_tcp.c
index 22b420c27..e031b7111 100644
--- a/src/transport/test_transport_api_manipulation_send_tcp.c
+++ b/src/transport/test_transport_api_manipulation_send_tcp.c
@@ -288,12 +288,8 @@ sendtask (void *cls)
{
struct GNUNET_TIME_Relative delay;
struct GNUNET_ATS_Properties prop;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/transport/test_transport_api_monitor_peers.c b/src/transport/test_transport_api_monitor_peers.c
index 79b39325c..549394944 100644
--- a/src/transport/test_transport_api_monitor_peers.c
+++ b/src/transport/test_transport_api_monitor_peers.c
@@ -262,12 +262,7 @@ notify_ready (void *cls, size_t size, void *buf)
static void
sendtask (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
diff --git a/src/transport/test_transport_api_monitor_validation.c b/src/transport/test_transport_api_monitor_validation.c
index 37b8494f1..49550e011 100644
--- a/src/transport/test_transport_api_monitor_validation.c
+++ b/src/transport/test_transport_api_monitor_validation.c
@@ -275,12 +275,7 @@ notify_ready (void *cls,
static void
sendtask (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
diff --git a/src/transport/test_transport_api_restart_1peer.c b/src/transport/test_transport_api_restart_1peer.c
index adec15f4f..50f9ebb9c 100644
--- a/src/transport/test_transport_api_restart_1peer.c
+++ b/src/transport/test_transport_api_restart_1peer.c
@@ -260,12 +260,7 @@ notify_ready (void *cls, size_t size, void *buf)
static void
sendtask (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/transport/test_transport_api_restart_2peers.c b/src/transport/test_transport_api_restart_2peers.c
index 2a669c9a0..18cc87c78 100644
--- a/src/transport/test_transport_api_restart_2peers.c
+++ b/src/transport/test_transport_api_restart_2peers.c
@@ -266,13 +266,7 @@ notify_ready (void *cls,
static void
sendtask (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
-
{
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
diff --git a/src/transport/test_transport_api_timeout.c b/src/transport/test_transport_api_timeout.c
index aa9884a2e..89fabdefd 100644
--- a/src/transport/test_transport_api_timeout.c
+++ b/src/transport/test_transport_api_timeout.c
@@ -185,13 +185,8 @@ static void
timer (void *cls)
{
static int percentage;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
timer_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
-
percentage += 10;
time_running =
GNUNET_TIME_relative_add (time_running,
@@ -213,6 +208,7 @@ timer (void *cls)
}
}
+
static void
testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
{
diff --git a/src/transport/test_transport_startonly.c b/src/transport/test_transport_startonly.c
index d49e3a8c0..7dd4984e2 100644
--- a/src/transport/test_transport_startonly.c
+++ b/src/transport/test_transport_startonly.c
@@ -67,15 +67,9 @@ end ()
static void
end_badly (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
-
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Fail! Stopping peers\n");
timeout_task = NULL;
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
-
if (p1 != NULL)
GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
if (NULL != tth)
@@ -83,6 +77,7 @@ end_badly (void *cls)
ret = GNUNET_SYSERR;
}
+
static void
notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
@@ -91,6 +86,7 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
connected++;
}
+
static void
notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
@@ -98,6 +94,7 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
GNUNET_i2s (peer));
}
+
static void
notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message)
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c
index 652a4e08f..4a514ea72 100644
--- a/src/transport/transport-testing.c
+++ b/src/transport/transport-testing.c
@@ -220,7 +220,7 @@ hello_offered (void *cls)
/**
* Offer the current HELLO of P2 to P1.
*
- * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequest `
+ * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequest`
*/
static void
offer_hello (void *cls)
@@ -228,12 +228,8 @@ offer_hello (void *cls)
struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = cls;
struct PeerContext *p1 = cc->p1;
struct PeerContext *p2 = cc->p2;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
cc->tct = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
{
char *p2_s = GNUNET_strdup (GNUNET_i2s (&p2->id));
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c
index 6fc538f25..59f249686 100644
--- a/src/transport/transport_api.c
+++ b/src/transport/transport_api.c
@@ -1196,15 +1196,8 @@ static void
reconnect (void *cls)
{
struct GNUNET_TRANSPORT_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))
- {
- /* shutdown, just give up */
- return;
- }
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Connecting to transport service.\n");
GNUNET_assert (NULL == h->client);
diff --git a/src/util/bandwidth.c b/src/util/bandwidth.c
index 2df2a9449..364c46977 100644
--- a/src/util/bandwidth.c
+++ b/src/util/bandwidth.c
@@ -149,7 +149,6 @@ excess_trigger (void *cls)
struct GNUNET_BANDWIDTH_Tracker *av = cls;
av->excess_task = NULL;
-
if (NULL != av->excess_cb)
av->excess_cb (av->excess_cb_cls);
}
diff --git a/src/util/client.c b/src/util/client.c
index f93fd1d10..d00e8bbd0 100644
--- a/src/util/client.c
+++ b/src/util/client.c
@@ -578,7 +578,7 @@ receive_helper (void *cls,
/**
* Continuation to call the receive callback.
*
- * @param cls our handle to the client connection
+ * @param cls our handle to the client connection
*/
static void
receive_task (void *cls)
@@ -611,7 +611,8 @@ receive_task (void *cls)
GNUNET_assert (GNUNET_YES == client->msg_complete);
GNUNET_assert (client->received_pos >= msize);
memcpy (msg, cmsg, msize);
- memmove (client->received_buf, &client->received_buf[msize],
+ memmove (client->received_buf,
+ &client->received_buf[msize],
client->received_pos - msize);
client->received_pos -= msize;
client->msg_complete = GNUNET_NO;
@@ -655,7 +656,8 @@ GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *client,
(GNUNET_SYSERR == client->in_receive) )
{
GNUNET_assert (NULL == client->receive_task);
- client->receive_task = GNUNET_SCHEDULER_add_now (&receive_task, client);
+ client->receive_task = GNUNET_SCHEDULER_add_now (&receive_task,
+ client);
return;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -703,7 +705,7 @@ struct GNUNET_CLIENT_TestHandle
/**
* ID of task used for asynchronous operations.
*/
- struct GNUNET_SCHEDULER_Task * task;
+ struct GNUNET_SCHEDULER_Task *task;
/**
* Final result to report back (once known).
@@ -1081,19 +1083,9 @@ static void
client_delayed_retry (void *cls)
{
struct GNUNET_CLIENT_TransmitHandle *th = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
struct GNUNET_TIME_Relative delay;
th->reconnect_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- /* give up, was shutdown */
- th->client->th = NULL;
- th->notify (th->notify_cls, 0, NULL);
- GNUNET_free (th);
- return;
- }
th->client->connection =
do_connect (th->client->service_name,
th->client->cfg,
@@ -1112,13 +1104,16 @@ client_delayed_retry (void *cls)
GNUNET_assert (NULL == th->th);
GNUNET_assert (NULL == th->reconnect_task);
th->reconnect_task =
- GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th);
+ GNUNET_SCHEDULER_add_delayed (delay,
+ &client_delayed_retry,
+ th);
return;
}
th->th =
GNUNET_CONNECTION_notify_transmit_ready (th->client->connection, th->size,
GNUNET_TIME_absolute_get_remaining
- (th->timeout), &client_notify,
+ (th->timeout),
+ &client_notify,
th);
if (NULL == th->th)
{
@@ -1149,22 +1144,18 @@ client_notify (void *cls,
struct GNUNET_CLIENT_Connection *client = th->client;
size_t ret;
struct GNUNET_TIME_Relative delay;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
LOG (GNUNET_ERROR_TYPE_DEBUG,
"client_notify is running\n");
th->th = NULL;
client->th = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
if (NULL == buf)
{
delay = GNUNET_TIME_absolute_get_remaining (th->timeout);
delay.rel_value_us /= 2;
if ( (GNUNET_YES != th->auto_retry) ||
(0 == --th->attempts_left) ||
- (delay.rel_value_us < 1)||
- (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)))
+ (delay.rel_value_us < 1) )
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Transmission failed %u times, giving up.\n",
@@ -1198,7 +1189,9 @@ client_notify (void *cls,
GNUNET_assert (NULL == th->reconnect_task);
GNUNET_assert (NULL == th->th);
th->reconnect_task =
- GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th);
+ GNUNET_SCHEDULER_add_delayed (delay,
+ &client_delayed_retry,
+ th);
return 0;
}
GNUNET_assert (size >= th->size);
diff --git a/src/util/client_manager.c b/src/util/client_manager.c
index f334bb5b6..026837841 100644
--- a/src/util/client_manager.c
+++ b/src/util/client_manager.c
@@ -243,8 +243,10 @@ static void
schedule_disconnect (void *cls)
{
struct GNUNET_CLIENT_MANAGER_Connection *mgr = cls;
+
GNUNET_CLIENT_MANAGER_disconnect (mgr, GNUNET_NO,
- mgr->disconnect_cb, mgr->disconnect_cls);
+ mgr->disconnect_cb,
+ mgr->disconnect_cls);
}
@@ -263,9 +265,10 @@ schedule_disconnect (void *cls)
static size_t
send_next_message (void *cls, size_t buf_size, void *buf)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "send_next_message()\n");
struct GNUNET_CLIENT_MANAGER_Connection *mgr = cls;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "send_next_message()\n");
if (NULL == buf)
{
/* disconnected */
@@ -282,7 +285,9 @@ send_next_message (void *cls, size_t buf_size, void *buf)
GNUNET_assert (size <= buf_size);
memcpy (buf, mqi->msg, size);
- GNUNET_CONTAINER_DLL_remove (mgr->tmit_head, mgr->tmit_tail, mqi);
+ GNUNET_CONTAINER_DLL_remove (mgr->tmit_head,
+ mgr->tmit_tail,
+ mqi);
GNUNET_free (mqi->msg);
GNUNET_free (mqi);
@@ -292,7 +297,7 @@ send_next_message (void *cls, size_t buf_size, void *buf)
}
else if (GNUNET_YES == mgr->is_disconnecting)
{
- GNUNET_SCHEDULER_add_now (&schedule_disconnect, mgr);
+ (void) GNUNET_SCHEDULER_add_now (&schedule_disconnect, mgr);
return size;
}
@@ -322,7 +327,8 @@ transmit_next (struct GNUNET_CLIENT_MANAGER_Connection *mgr)
{
if (GNUNET_YES == mgr->is_disconnecting)
GNUNET_CLIENT_MANAGER_disconnect (mgr, GNUNET_NO,
- mgr->disconnect_cb, mgr->disconnect_cls);
+ mgr->disconnect_cb,
+ mgr->disconnect_cls);
return;
}
@@ -346,14 +352,15 @@ static void
schedule_reconnect (void *cls)
{
struct GNUNET_CLIENT_MANAGER_Connection *mgr = cls;
- mgr->reconnect_task = NULL;
+ mgr->reconnect_task = NULL;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting to %s service.\n", mgr->service_name);
+ "Connecting to %s service.\n",
+ mgr->service_name);
GNUNET_assert (NULL == mgr->client);
- mgr->client = GNUNET_CLIENT_connect (mgr->service_name, mgr->cfg);
+ mgr->client = GNUNET_CLIENT_connect (mgr->service_name,
+ mgr->cfg);
GNUNET_assert (NULL != mgr->client);
-
transmit_next (mgr);
}
@@ -373,16 +380,17 @@ schedule_reconnect (void *cls)
struct GNUNET_CLIENT_MANAGER_Connection *
GNUNET_CLIENT_MANAGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
const char *service_name,
- const struct
- GNUNET_CLIENT_MANAGER_MessageHandler *handlers)
+ const struct GNUNET_CLIENT_MANAGER_MessageHandler *handlers)
{
- struct GNUNET_CLIENT_MANAGER_Connection *
- mgr = GNUNET_malloc (sizeof (*mgr));
+ struct GNUNET_CLIENT_MANAGER_Connection *mgr;
+
+ mgr = GNUNET_new (struct GNUNET_CLIENT_MANAGER_Connection);
mgr->cfg = cfg;
mgr->service_name = service_name;
mgr->handlers = handlers;
mgr->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
- mgr->reconnect_task = GNUNET_SCHEDULER_add_now (&schedule_reconnect, mgr);
+ mgr->reconnect_task = GNUNET_SCHEDULER_add_now (&schedule_reconnect,
+ mgr);
return mgr;
}
@@ -405,7 +413,9 @@ GNUNET_CLIENT_MANAGER_disconnect (struct GNUNET_CLIENT_MANAGER_Connection *mgr,
GNUNET_ContinuationCallback disconnect_cb,
void *cls)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting (%d)\n", transmit_queue);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Disconnecting (%d)\n",
+ transmit_queue);
mgr->disconnect_cb = disconnect_cb;
mgr->disconnect_cls = cls;
if (NULL != mgr->tmit_head)
@@ -424,7 +434,7 @@ GNUNET_CLIENT_MANAGER_disconnect (struct GNUNET_CLIENT_MANAGER_Connection *mgr,
GNUNET_CLIENT_MANAGER_drop_queue (mgr);
}
}
- if (mgr->reconnect_task != NULL)
+ if (NULL != mgr->reconnect_task)
{
GNUNET_SCHEDULER_cancel (mgr->reconnect_task);
mgr->reconnect_task = NULL;
@@ -473,7 +483,9 @@ GNUNET_CLIENT_MANAGER_reconnect (struct GNUNET_CLIENT_MANAGER_Connection *mgr)
"Scheduling task to reconnect to service in %s.\n",
GNUNET_STRINGS_relative_time_to_string (mgr->reconnect_delay, GNUNET_YES));
mgr->reconnect_task =
- GNUNET_SCHEDULER_add_delayed (mgr->reconnect_delay, &schedule_reconnect, mgr);
+ GNUNET_SCHEDULER_add_delayed (mgr->reconnect_delay,
+ &schedule_reconnect,
+ mgr);
mgr->reconnect_delay = GNUNET_TIME_STD_BACKOFF (mgr->reconnect_delay);
}
@@ -491,9 +503,13 @@ void
GNUNET_CLIENT_MANAGER_transmit (struct GNUNET_CLIENT_MANAGER_Connection *mgr,
struct GNUNET_MessageHeader *msg)
{
- struct MessageQueueItem *mqi = GNUNET_malloc (sizeof (*mqi));
+ struct MessageQueueItem *mqi;
+
+ mqi = GNUNET_new (struct MessageQueueItem);
mqi->msg = GNUNET_copy_message (msg);
- GNUNET_CONTAINER_DLL_insert_tail (mgr->tmit_head, mgr->tmit_tail, mqi);
+ GNUNET_CONTAINER_DLL_insert_tail (mgr->tmit_head,
+ mgr->tmit_tail,
+ mqi);
transmit_next (mgr);
}
@@ -511,9 +527,13 @@ void
GNUNET_CLIENT_MANAGER_transmit_now (struct GNUNET_CLIENT_MANAGER_Connection *mgr,
struct GNUNET_MessageHeader *msg)
{
- struct MessageQueueItem *mqi = GNUNET_malloc (sizeof (*mqi));
+ struct MessageQueueItem *mqi;
+
+ mqi = GNUNET_new (struct MessageQueueItem);
mqi->msg = GNUNET_copy_message (msg);
- GNUNET_CONTAINER_DLL_insert (mgr->tmit_head, mgr->tmit_tail, mqi);
+ GNUNET_CONTAINER_DLL_insert (mgr->tmit_head,
+ mgr->tmit_tail,
+ mqi);
transmit_next (mgr);
}
@@ -527,7 +547,10 @@ GNUNET_CLIENT_MANAGER_transmit_now (struct GNUNET_CLIENT_MANAGER_Connection *mgr
void
GNUNET_CLIENT_MANAGER_drop_queue (struct GNUNET_CLIENT_MANAGER_Connection *mgr)
{
- struct MessageQueueItem *cur, *next = mgr->tmit_head;
+ struct MessageQueueItem *cur;
+ struct MessageQueueItem *next;
+
+ next = mgr->tmit_head;
while (NULL != next)
{
cur = next;
@@ -629,15 +652,14 @@ GNUNET_CLIENT_MANAGER_op_get_next_id (struct GNUNET_CLIENT_MANAGER_Connection *m
* @return Operation, or NULL if not found.
*/
static struct OperationListItem *
-op_find (struct GNUNET_CLIENT_MANAGER_Connection *mgr, uint64_t op_id)
+op_find (struct GNUNET_CLIENT_MANAGER_Connection *mgr,
+ uint64_t op_id)
{
- struct OperationListItem *op = mgr->op_head;
- while (NULL != op)
- {
+ struct OperationListItem *op;
+
+ for (op = mgr->op_head; NULL != op; op = op->next)
if (op->op_id == op_id)
return op;
- op = op->next;
- }
return NULL;
}
@@ -691,17 +713,21 @@ GNUNET_CLIENT_MANAGER_op_add (struct GNUNET_CLIENT_MANAGER_Connection *mgr,
GNUNET_ResultCallback result_cb,
void *cls)
{
+ struct OperationListItem *op;
+
if (NULL == result_cb)
return 0;
-
- struct OperationListItem *op = GNUNET_malloc (sizeof (*op));
+ op = GNUNET_new (struct OperationListItem);
op->op_id = GNUNET_CLIENT_MANAGER_op_get_next_id (mgr);
op->result_cb = result_cb;
op->cls = cls;
- GNUNET_CONTAINER_DLL_insert_tail (mgr->op_head, mgr->op_tail, op);
-
+ GNUNET_CONTAINER_DLL_insert_tail (mgr->op_head,
+ mgr->op_tail,
+ op);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "%p Added operation #%" PRIu64 "\n", mgr, op->op_id);
+ "%p Added operation #%" PRIu64 "\n",
+ mgr,
+ op->op_id);
return op->op_id;
}
@@ -730,8 +756,11 @@ GNUNET_CLIENT_MANAGER_op_add (struct GNUNET_CLIENT_MANAGER_Connection *mgr,
*/
static int
op_result (struct GNUNET_CLIENT_MANAGER_Connection *mgr,
- uint64_t op_id, int64_t result_code,
- const void *data, uint16_t data_size, uint8_t cancel)
+ uint64_t op_id,
+ int64_t result_code,
+ const void *data,
+ uint16_t data_size,
+ uint8_t cancel)
{
if (0 == op_id)
return GNUNET_NO;
@@ -744,11 +773,15 @@ op_result (struct GNUNET_CLIENT_MANAGER_Connection *mgr,
return GNUNET_NO;
}
- GNUNET_CONTAINER_DLL_remove (mgr->op_head, mgr->op_tail, op);
-
- if (GNUNET_YES != cancel && NULL != op->result_cb)
- op->result_cb (op->cls, result_code, data, data_size);
+ GNUNET_CONTAINER_DLL_remove (mgr->op_head,
+ mgr->op_tail,
+ op);
+ if ( (GNUNET_YES != cancel) &&
+ (NULL != op->result_cb) )
+ op->result_cb (op->cls,
+ result_code, data,
+ data_size);
GNUNET_free (op);
return GNUNET_YES;
}
@@ -773,8 +806,10 @@ op_result (struct GNUNET_CLIENT_MANAGER_Connection *mgr,
*/
int
GNUNET_CLIENT_MANAGER_op_result (struct GNUNET_CLIENT_MANAGER_Connection *mgr,
- uint64_t op_id, int64_t result_code,
- const void *data, uint16_t data_size)
+ uint64_t op_id,
+ int64_t result_code,
+ const void *data,
+ uint16_t data_size)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"%p Received result for operation #%" PRIu64 ": %" PRId64 " (size: %u)\n",
@@ -799,6 +834,8 @@ GNUNET_CLIENT_MANAGER_op_cancel (struct GNUNET_CLIENT_MANAGER_Connection *mgr,
uint64_t op_id)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "%p Cancelling operation #%" PRIu64 "\n", mgr, op_id);
+ "%p Cancelling operation #%" PRIu64 "\n",
+ mgr,
+ op_id);
return op_result (mgr, op_id, 0, NULL, 0, GNUNET_YES);
}
diff --git a/src/util/connection.c b/src/util/connection.c
index b3ea3b5af..95fbb13f8 100644
--- a/src/util/connection.c
+++ b/src/util/connection.c
@@ -217,7 +217,7 @@ struct GNUNET_CONNECTION_Handle
struct GNUNET_RESOLVER_RequestHandle *dns_active;
/**
- * The handle we return for GNUNET_CONNECTION_notify_transmit_ready.
+ * The handle we return for #GNUNET_CONNECTION_notify_transmit_ready().
*/
struct GNUNET_CONNECTION_TransmitHandle nth;
@@ -344,7 +344,9 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
addrlen = sizeof (addr);
sock =
- GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen);
+ GNUNET_NETWORK_socket_accept (lsock,
+ (struct sockaddr *) &addr,
+ &addrlen);
if (NULL == sock)
{
if (EAGAIN != errno)
@@ -360,7 +362,8 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
sa = (struct sockaddr *) addr;
v6 = (struct sockaddr_in6 *) addr;
- if ((AF_INET6 == sa->sa_family) && (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr)))
+ if ( (AF_INET6 == sa->sa_family) &&
+ (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr)) )
{
/* convert to V4 address */
v4 = GNUNET_new (struct sockaddr_in);
@@ -389,15 +392,21 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
{
#if HAVE_GETPEEREID
/* most BSDs */
- if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid))
+ if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock),
+ &gc.uid,
+ &gc.gid))
gcp = &gc;
#else
#ifdef SO_PEERCRED
/* largely traditional GNU/Linux */
olen = sizeof (uc);
- if ((0 ==
- getsockopt (GNUNET_NETWORK_get_fd (sock), SOL_SOCKET, SO_PEERCRED, &uc,
- &olen)) && (olen == sizeof (uc)))
+ if ( (0 ==
+ getsockopt (GNUNET_NETWORK_get_fd (sock),
+ SOL_SOCKET,
+ SO_PEERCRED,
+ &uc,
+ &olen)) &&
+ (olen == sizeof (uc)) )
{
gc.uid = uc.uid;
gc.gid = uc.gid;
@@ -421,8 +430,11 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
#endif
}
- if ((NULL != access_cb) &&
- (GNUNET_YES != (aret = access_cb (access_cb_cls, gcp, uaddr, addrlen))))
+ if ( (NULL != access_cb) &&
+ (GNUNET_YES != (aret = access_cb (access_cb_cls,
+ gcp,
+ uaddr,
+ addrlen))) )
{
if (GNUNET_NO == aret)
LOG (GNUNET_ERROR_TYPE_INFO,
@@ -444,7 +456,9 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
connection->sock = sock;
LOG (GNUNET_ERROR_TYPE_INFO,
_("Accepting connection from `%s': %p\n"),
- GNUNET_a2s (uaddr, addrlen), connection);
+ GNUNET_a2s (uaddr,
+ addrlen),
+ connection);
return connection;
}
@@ -554,7 +568,9 @@ signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection,
return; /* nobody to tell about it */
notify = connection->nth.notify_ready;
connection->nth.notify_ready = NULL;
- notify (connection->nth.notify_ready_cls, 0, NULL);
+ notify (connection->nth.notify_ready_cls,
+ 0,
+ NULL);
}
@@ -631,7 +647,8 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Connection to `%s' succeeded! (%p)\n",
- GNUNET_a2s (connection->addr, connection->addrlen),
+ GNUNET_a2s (connection->addr,
+ connection->addrlen),
connection);
/* trigger jobs that waited for the connection */
if (NULL != connection->receiver)
@@ -642,7 +659,8 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection)
GNUNET_assert (NULL == connection->read_task);
connection->read_task =
GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining
- (connection->receive_timeout), connection->sock,
+ (connection->receive_timeout),
+ connection->sock,
&receive_ready, connection);
}
if (NULL != connection->nth.notify_ready)
@@ -679,21 +697,28 @@ connect_probe_continuation (void *cls)
socklen_t len;
GNUNET_assert (NULL != ap->sock);
- GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, ap);
+ GNUNET_CONTAINER_DLL_remove (connection->ap_head,
+ connection->ap_tail,
+ ap);
len = sizeof (error);
errno = 0;
error = 0;
tc = GNUNET_SCHEDULER_get_task_context ();
- if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ||
- (GNUNET_OK !=
- GNUNET_NETWORK_socket_getsockopt (ap->sock, SOL_SOCKET, SO_ERROR, &error,
- &len)) || (0 != error))
+ if ( (0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ||
+ (GNUNET_OK !=
+ GNUNET_NETWORK_socket_getsockopt (ap->sock,
+ SOL_SOCKET,
+ SO_ERROR,
+ &error,
+ &len)) ||
+ (0 != error) )
{
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_NETWORK_socket_close (ap->sock));
GNUNET_free (ap);
- if ((NULL == connection->ap_head) &&
- (GNUNET_NO == connection->dns_active) &&
- (NULL == connection->proxy_handshake))
+ if ( (NULL == connection->ap_head) &&
+ (GNUNET_NO == connection->dns_active) &&
+ (NULL == connection->proxy_handshake) )
connect_fail_continuation (connection);
return;
}
@@ -709,7 +734,9 @@ connect_probe_continuation (void *cls)
{
GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock));
GNUNET_SCHEDULER_cancel (pos->task);
- GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos);
+ GNUNET_CONTAINER_DLL_remove (connection->ap_head,
+ connection->ap_tail,
+ pos);
GNUNET_free (pos);
}
connect_success_continuation (connection);
@@ -771,7 +798,8 @@ try_connect_using_address (void *cls,
GNUNET_free (ap);
return; /* not supported by us */
}
- ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0);
+ ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family,
+ SOCK_STREAM, 0);
if (NULL == ap->sock)
{
GNUNET_free (ap);
@@ -782,7 +810,9 @@ try_connect_using_address (void *cls,
GNUNET_a2s (ap->addr, ap->addrlen),
connection);
if ((GNUNET_OK !=
- GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) &&
+ GNUNET_NETWORK_socket_connect (ap->sock,
+ ap->addr,
+ ap->addrlen)) &&
(EINPROGRESS != errno))
{
/* maybe refused / unsupported address, try next */
@@ -794,17 +824,15 @@ try_connect_using_address (void *cls,
GNUNET_CONTAINER_DLL_insert (connection->ap_head, connection->ap_tail, ap);
delay = GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT;
if (NULL != connection->nth.notify_ready)
- delay =
- GNUNET_TIME_relative_min (delay,
- GNUNET_TIME_absolute_get_remaining (connection->nth.transmit_timeout));
+ delay = GNUNET_TIME_relative_min (delay,
+ GNUNET_TIME_absolute_get_remaining (connection->nth.transmit_timeout));
if (NULL != connection->receiver)
- delay =
- GNUNET_TIME_relative_min (delay,
- GNUNET_TIME_absolute_get_remaining
- (connection->receive_timeout));
- ap->task =
- GNUNET_SCHEDULER_add_write_net (delay, ap->sock,
- &connect_probe_continuation, ap);
+ delay = GNUNET_TIME_relative_min (delay,
+ GNUNET_TIME_absolute_get_remaining (connection->receive_timeout));
+ ap->task = GNUNET_SCHEDULER_add_write_net (delay,
+ ap->sock,
+ &connect_probe_continuation,
+ ap);
}
@@ -833,9 +861,11 @@ GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle
connection->port = port;
connection->hostname = GNUNET_strdup (hostname);
connection->dns_active =
- GNUNET_RESOLVER_ip_get (connection->hostname, AF_UNSPEC,
+ GNUNET_RESOLVER_ip_get (connection->hostname,
+ AF_UNSPEC,
GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT,
- &try_connect_using_address, connection);
+ &try_connect_using_address,
+ connection);
return connection;
}
@@ -865,7 +895,8 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA
{
int abstract;
- abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, "TESTING",
+ abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ "TESTING",
"USE_ABSTRACT_SOCKETS");
if (GNUNET_YES == abstract)
un->sun_path[0] = '\0';
@@ -882,7 +913,9 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA
connection->hostname = NULL;
connection->addr = (struct sockaddr *) un;
connection->addrlen = sizeof (struct sockaddr_un);
- connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
+ connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX,
+ SOCK_STREAM,
+ 0);
if (NULL == connection->sock)
{
GNUNET_free (connection->addr);
@@ -891,11 +924,14 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA
return NULL;
}
if ( (GNUNET_OK !=
- GNUNET_NETWORK_socket_connect (connection->sock, connection->addr, connection->addrlen)) &&
+ GNUNET_NETWORK_socket_connect (connection->sock,
+ connection->addr,
+ connection->addrlen)) &&
(EINPROGRESS != errno) )
{
/* Just return; we expect everything to work eventually so don't fail HARD */
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_NETWORK_socket_close (connection->sock));
connection->sock = NULL;
return connection;
}
@@ -971,10 +1007,13 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family,
s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0);
if (NULL == s)
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "socket");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
+ "socket");
return NULL;
}
- return GNUNET_CONNECTION_connect_socket (s, serv_addr, addrlen);
+ return GNUNET_CONNECTION_connect_socket (s,
+ serv_addr,
+ addrlen);
}
@@ -1054,7 +1093,9 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection)
{
GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock));
GNUNET_SCHEDULER_cancel (pos->task);
- GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos);
+ GNUNET_CONTAINER_DLL_remove (connection->ap_head,
+ connection->ap_tail,
+ pos);
GNUNET_free (pos);
}
if ( (NULL != connection->sock) &&
@@ -1105,21 +1146,14 @@ receive_ready (void *cls)
connection->read_task = NULL;
tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- /* ignore shutdown request, go again immediately */
- connection->read_task =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining
- (connection->receive_timeout), connection->sock,
- &receive_ready, connection);
- return;
- }
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Receive from `%s' encounters error: timeout (%s, %p)\n",
- GNUNET_a2s (connection->addr, connection->addrlen),
- GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (connection->receive_timeout), GNUNET_YES),
+ GNUNET_a2s (connection->addr,
+ connection->addrlen),
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (connection->receive_timeout),
+ GNUNET_YES),
connection);
signal_receive_timeout (connection);
return;
@@ -1130,7 +1164,8 @@ receive_ready (void *cls)
signal_receive_error (connection, ECONNREFUSED);
return;
}
- GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, connection->sock));
+ GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready,
+ connection->sock));
RETRY:
ret = GNUNET_NETWORK_socket_recv (connection->sock,
buffer,
@@ -1161,8 +1196,8 @@ RETRY:
/**
- * Receive data from the given connection. Note that this function will
- * call @a receiver asynchronously using the scheduler. It will
+ * Receive data from the given connection. Note that this function
+ * will call @a receiver asynchronously using the scheduler. It will
* "immediately" return. Note that there MUST only be one active
* receive call per connection at any given point in time (so do not
* call receive again until the receiver callback has been invoked).
@@ -1202,7 +1237,10 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection,
(NULL == connection->proxy_handshake))
{
connection->receiver = NULL;
- receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT);
+ receiver (receiver_cls,
+ NULL, 0,
+ NULL, 0,
+ ETIMEDOUT);
return;
}
}
@@ -1312,7 +1350,9 @@ transmit_timeout (void *cls)
notify = connection->nth.notify_ready;
GNUNET_assert (NULL != notify);
connection->nth.notify_ready = NULL;
- notify (connection->nth.notify_ready_cls, 0, NULL);
+ notify (connection->nth.notify_ready_cls,
+ 0,
+ NULL);
}
@@ -1339,7 +1379,9 @@ connect_error (void *cls)
connection->write_task = NULL;
notify = connection->nth.notify_ready;
connection->nth.notify_ready = NULL;
- notify (connection->nth.notify_ready_cls, 0, NULL);
+ notify (connection->nth.notify_ready_cls,
+ 0,
+ NULL);
}
@@ -1364,21 +1406,6 @@ transmit_ready (void *cls)
connection->write_task = NULL;
GNUNET_assert (NULL == connection->nth.timeout_task);
tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- if (NULL != connection->sock)
- goto SCHEDULE_WRITE; /* ignore shutdown, go again immediately */
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Transmit to `%s' fails, shutdown happened (%p).\n",
- GNUNET_a2s (connection->addr, connection->addrlen), connection);
- notify = connection->nth.notify_ready;
- if (NULL != notify)
- {
- connection->nth.notify_ready = NULL;
- notify (connection->nth.notify_ready_cls, 0, NULL);
- }
- return;
- }
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1400,7 +1427,8 @@ transmit_ready (void *cls)
* Hence retry. */
goto SCHEDULE_WRITE;
}
- if (!GNUNET_NETWORK_fdset_isset (tc->write_ready, connection->sock))
+ if (! GNUNET_NETWORK_fdset_isset (tc->write_ready,
+ connection->sock))
{
GNUNET_assert (NULL == connection->write_task);
/* special circumstances (in particular, shutdown): not yet ready
@@ -1444,7 +1472,11 @@ RETRY:
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Connection transmitted %u/%u bytes to `%s' (%p)\n",
- (unsigned int) ret, have, GNUNET_a2s (connection->addr, connection->addrlen), connection);
+ (unsigned int) ret,
+ have,
+ GNUNET_a2s (connection->addr,
+ connection->addrlen),
+ connection);
connection->write_buffer_pos += ret;
if (connection->write_buffer_pos == connection->write_buffer_off)
{
@@ -1452,21 +1484,25 @@ RETRY:
connection->write_buffer_pos = 0;
connection->write_buffer_off = 0;
}
- if ((0 == connection->write_buffer_off) && (NULL == connection->nth.notify_ready))
+ if ( (0 == connection->write_buffer_off) &&
+ (NULL == connection->nth.notify_ready) )
return; /* all data sent! */
/* not done writing, schedule more */
SCHEDULE_WRITE:
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Re-scheduling transmit_ready (more to do) (%p).\n", connection);
+ "Re-scheduling transmit_ready (more to do) (%p).\n",
+ connection);
have = connection->write_buffer_off - connection->write_buffer_pos;
- GNUNET_assert ((NULL != connection->nth.notify_ready) || (have > 0));
+ GNUNET_assert ( (NULL != connection->nth.notify_ready) ||
+ (have > 0) );
if (NULL == connection->write_task)
connection->write_task =
GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready ==
NULL) ? GNUNET_TIME_UNIT_FOREVER_REL :
GNUNET_TIME_absolute_get_remaining
(connection->nth.transmit_timeout),
- connection->sock, &transmit_ready, connection);
+ connection->sock,
+ &transmit_ready, connection);
}
@@ -1488,8 +1524,8 @@ struct GNUNET_CONNECTION_TransmitHandle *
GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connection,
size_t size,
struct GNUNET_TIME_Relative timeout,
- GNUNET_CONNECTION_TransmitReadyNotify
- notify, void *notify_cls)
+ GNUNET_CONNECTION_TransmitReadyNotify notify,
+ void *notify_cls)
{
if (NULL != connection->nth.notify_ready)
{
@@ -1529,7 +1565,8 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec
connection->write_task =
GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining
(connection->nth.transmit_timeout),
- connection->sock, &transmit_ready, connection);
+ connection->sock,
+ &transmit_ready, connection);
return &connection->nth;
}
/* not yet connected, wait for connection */
@@ -1538,7 +1575,8 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec
connection);
connection->nth.timeout_task =
GNUNET_SCHEDULER_add_delayed (timeout,
- &transmit_timeout, connection);
+ &transmit_timeout,
+ connection);
return &connection->nth;
}
@@ -1575,7 +1613,8 @@ GNUNET_CONNECTION_notify_transmit_ready_cancel (struct GNUNET_CONNECTION_Transmi
struct GNUNET_CONNECTION_Handle *
GNUNET_CONNECTION_create_proxied_from_handshake (struct GNUNET_CONNECTION_Handle *cph)
{
- struct GNUNET_CONNECTION_Handle * proxied = GNUNET_CONNECTION_create_from_existing(NULL);
+ struct GNUNET_CONNECTION_Handle *proxied = GNUNET_CONNECTION_create_from_existing (NULL);
+
proxied->proxy_handshake = cph;
return proxied;
}
@@ -1592,11 +1631,12 @@ void
GNUNET_CONNECTION_acivate_proxied (struct GNUNET_CONNECTION_Handle *proxied)
{
struct GNUNET_CONNECTION_Handle *cph = proxied->proxy_handshake;
+
GNUNET_assert (NULL != cph);
GNUNET_assert (NULL == proxied->sock);
GNUNET_assert (NULL != cph->sock);
- proxied->sock=cph->sock;
- cph->sock=NULL;
+ proxied->sock = cph->sock;
+ cph->sock = NULL;
GNUNET_CONNECTION_destroy (cph);
connect_success_continuation (proxied);
}
diff --git a/src/util/crypto_hash_file.c b/src/util/crypto_hash_file.c
index f2d49d164..ace5212c9 100644
--- a/src/util/crypto_hash_file.c
+++ b/src/util/crypto_hash_file.c
@@ -130,9 +130,13 @@ file_hash_task (void *cls)
delta = fhc->bsize;
if (fhc->fsize - fhc->offset < delta)
delta = fhc->fsize - fhc->offset;
- if (delta != GNUNET_DISK_file_read (fhc->fh, fhc->buffer, delta))
+ if (delta != GNUNET_DISK_file_read (fhc->fh,
+ fhc->buffer,
+ delta))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", fhc->filename);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
+ "read",
+ fhc->filename);
file_hash_finish (fhc, NULL);
return;
}
@@ -140,12 +144,14 @@ file_hash_task (void *cls)
fhc->offset += delta;
if (fhc->offset == fhc->fsize)
{
- res = (struct GNUNET_HashCode *) gcry_md_read (fhc->md, GCRY_MD_SHA512);
+ res = (struct GNUNET_HashCode *) gcry_md_read (fhc->md,
+ GCRY_MD_SHA512);
file_hash_finish (fhc, res);
return;
}
fhc->task = GNUNET_SCHEDULER_add_with_priority (fhc->priority,
- &file_hash_task, fhc);
+ &file_hash_task,
+ fhc);
}
@@ -156,12 +162,13 @@ file_hash_task (void *cls)
* @param filename name of file to hash
* @param blocksize number of bytes to process in one task
* @param callback function to call upon completion
- * @param callback_cls closure for callback
+ * @param callback_cls closure for @a callback
* @return NULL on (immediate) errror
*/
struct GNUNET_CRYPTO_FileHashContext *
GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority,
- const char *filename, size_t blocksize,
+ const char *filename,
+ size_t blocksize,
GNUNET_CRYPTO_HashCompletedCallback callback,
void *callback_cls)
{
@@ -181,24 +188,29 @@ GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority,
return NULL;
}
fhc->bsize = blocksize;
- if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fhc->fsize, GNUNET_NO, GNUNET_YES))
+ if (GNUNET_OK !=
+ GNUNET_DISK_file_size (filename,
+ &fhc->fsize,
+ GNUNET_NO,
+ GNUNET_YES))
{
GNUNET_free (fhc->filename);
GNUNET_free (fhc);
return NULL;
}
- fhc->fh =
- GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
- if (!fhc->fh)
+ fhc->fh = GNUNET_DISK_file_open (filename,
+ GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_NONE);
+ if (! fhc->fh)
{
GNUNET_free (fhc->filename);
GNUNET_free (fhc);
return NULL;
}
fhc->priority = priority;
- fhc->task =
- GNUNET_SCHEDULER_add_with_priority (priority, &file_hash_task, fhc);
+ fhc->task = GNUNET_SCHEDULER_add_with_priority (priority,
+ &file_hash_task,
+ fhc);
return fhc;
}
@@ -213,7 +225,8 @@ GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc)
{
GNUNET_SCHEDULER_cancel (fhc->task);
GNUNET_free (fhc->filename);
- GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fhc->fh));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_DISK_file_close (fhc->fh));
GNUNET_free (fhc);
}
diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c
index 7449d8042..6fd871cbe 100644
--- a/src/util/gnunet-scrypt.c
+++ b/src/util/gnunet-scrypt.c
@@ -40,7 +40,7 @@ static struct GNUNET_CRYPTO_EddsaPublicKey pub;
static uint64_t proof;
-static struct GNUNET_SCHEDULER_Task * proof_task;
+static struct GNUNET_SCHEDULER_Task *proof_task;
static const struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -51,15 +51,21 @@ static char *pwfn;
/**
* Write our current proof to disk.
+ *
+ * @param cls closure
*/
static void
-write_proof ()
+shutdown_task (void *cls)
{
if (sizeof (proof) !=
- GNUNET_DISK_fn_write (pwfn, &proof, sizeof (proof),
+ GNUNET_DISK_fn_write (pwfn,
+ &proof,
+ sizeof (proof),
GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", proof);
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "write",
+ proof);
}
@@ -120,15 +126,10 @@ find_proof (void *cls)
unsigned int i;
struct GNUNET_TIME_Absolute timestamp;
struct GNUNET_TIME_Relative elapsed;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- {
- write_proof ();
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got Proof of Work %llu\n", proof);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Got Proof of Work %llu\n",
+ proof);
proof_task = NULL;
memcpy (&buf[sizeof (uint64_t)], &pub,
sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
@@ -144,7 +145,7 @@ find_proof (void *cls)
proof = counter;
FPRINTF (stdout, "Proof of work found: %llu!\n",
(unsigned long long) proof);
- write_proof ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
counter++;
@@ -162,16 +163,16 @@ find_proof (void *cls)
(unsigned long long) counter);
/* remember progress every 100 rounds */
proof = counter;
- write_proof ();
+ shutdown_task (NULL);
}
else
{
proof = counter;
}
proof_task =
- GNUNET_SCHEDULER_add_delayed_with_priority (proof_find_delay,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- &find_proof, NULL);
+ GNUNET_SCHEDULER_add_delayed_with_priority (proof_find_delay,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &find_proof, NULL);
}
@@ -193,17 +194,18 @@ run (void *cls,
char *pids;
cfg = config;
-
/* load proof of work */
if (NULL == pwfn)
{
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE",
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "NSE",
"PROOFFILE",
&pwfn))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "NSE", "PROOFFILE");
+ "NSE",
+ "PROOFFILE");
GNUNET_SCHEDULER_shutdown ();
return;
}
@@ -219,19 +221,26 @@ run (void *cls,
/* load private key */
if (NULL == pkfn)
{
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "PEER",
- "PRIVATE_KEY",
- &pkfn))
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "PEER",
+ "PRIVATE_KEY",
+ &pkfn))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "PEER", "PRIVATE_KEY");
+ "PEER",
+ "PRIVATE_KEY");
return;
}
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Private Key file: %s\n", pkfn);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Private Key file: %s\n",
+ pkfn);
if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create_from_file (pkfn)))
{
- FPRINTF (stderr, _("Loading hostkey from `%s' failed.\n"), pkfn);
+ FPRINTF (stderr,
+ _("Loading hostkey from `%s' failed.\n"),
+ pkfn);
GNUNET_free (pkfn);
return;
}
@@ -248,22 +257,28 @@ run (void *cls,
if (0 == nse_work_required)
{
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg, "NSE", "WORKBITS",
+ GNUNET_CONFIGURATION_get_value_number (cfg,
+ "NSE",
+ "WORKBITS",
&nse_work_required))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKBITS");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "NSE",
+ "WORKBITS");
GNUNET_SCHEDULER_shutdown ();
return;
}
if (nse_work_required >= sizeof (struct GNUNET_HashCode) * 8)
{
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKBITS",
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ "NSE",
+ "WORKBITS",
_("Value is too large.\n"));
GNUNET_SCHEDULER_shutdown ();
return;
- } else if (0 == nse_work_required)
+ }
+ else if (0 == nse_work_required)
{
- write_proof ();
GNUNET_SCHEDULER_shutdown ();
return;
}
@@ -275,8 +290,12 @@ run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Delay between tries: %s\n",
GNUNET_STRINGS_relative_time_to_string (proof_find_delay, 1));
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &find_proof, NULL);
+ proof_task =
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &find_proof,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
@@ -307,7 +326,8 @@ main (int argc, char *const *argv)
};
int ret;
- if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
ret = (GNUNET_OK ==
diff --git a/src/util/gnunet-uri.c b/src/util/gnunet-uri.c
index 75e70d2b7..f69508f67 100644
--- a/src/util/gnunet-uri.c
+++ b/src/util/gnunet-uri.c
@@ -52,6 +52,7 @@ static void
maint_child_death (void *cls)
{
enum GNUNET_OS_ProcessStatusType type;
+
if ( (GNUNET_OK !=
GNUNET_OS_process_status (p, &type, &exit_code)) ||
(type != GNUNET_OS_PROCESS_EXITED) )
@@ -80,12 +81,14 @@ run (void *cls, char *const *args, const char *cfgfile,
if (NULL == (uri = args[0]))
{
- fprintf (stderr, _("No URI specified on command line\n"));
+ fprintf (stderr,
+ _("No URI specified on command line\n"));
return;
}
if (0 != strncasecmp ("gnunet://", uri, strlen ("gnunet://")))
{
- fprintf (stderr, _("Invalid URI: does not start with `%s'\n"),
+ fprintf (stderr,
+ _("Invalid URI: does not start with `%s'\n"),
"gnunet://");
return;
}
diff --git a/src/util/helper.c b/src/util/helper.c
index 3ed1c7276..ecfe4ccfa 100644
--- a/src/util/helper.c
+++ b/src/util/helper.c
@@ -142,17 +142,17 @@ struct GNUNET_HELPER_Handle
/**
* Task to read from the helper.
*/
- struct GNUNET_SCHEDULER_Task * read_task;
+ struct GNUNET_SCHEDULER_Task *read_task;
/**
* Task to read from the helper.
*/
- struct GNUNET_SCHEDULER_Task * write_task;
+ struct GNUNET_SCHEDULER_Task *write_task;
/**
* Restart task.
*/
- struct GNUNET_SCHEDULER_Task * restart_task;
+ struct GNUNET_SCHEDULER_Task *restart_task;
/**
* Does the helper support the use of a control pipe for signalling?
@@ -319,19 +319,10 @@ static void
helper_read (void *cls)
{
struct GNUNET_HELPER_Handle *h = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE] GNUNET_ALIGN;
ssize_t t;
h->read_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- /* try again */
- h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->fh_from_helper, &helper_read, h);
- return;
- }
t = GNUNET_DISK_file_read (h->fh_from_helper, &buf, sizeof (buf));
if (t < 0)
{
@@ -348,9 +339,9 @@ helper_read (void *cls)
}
stop_helper (h, GNUNET_NO);
/* Restart the helper */
- h->restart_task = GNUNET_SCHEDULER_add_delayed(
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off), &restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task, h);
return;
}
if (0 == t)
@@ -368,9 +359,10 @@ helper_read (void *cls)
}
stop_helper (h, GNUNET_NO);
/* Restart the helper */
- h->restart_task = GNUNET_SCHEDULER_add_delayed(
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off), &restart_task, h);
+ h->restart_task
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task, h);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -378,9 +370,13 @@ helper_read (void *cls)
(unsigned int) t,
h->binary_name);
h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->fh_from_helper, &helper_read, h);
+ h->fh_from_helper,
+ &helper_read, h);
if (GNUNET_SYSERR ==
- GNUNET_SERVER_mst_receive (h->mst, NULL, buf, t, GNUNET_NO, GNUNET_NO))
+ GNUNET_SERVER_mst_receive (h->mst,
+ NULL,
+ buf, t,
+ GNUNET_NO, GNUNET_NO))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("Failed to parse inbound message from helper `%s'\n"),
@@ -393,9 +389,9 @@ helper_read (void *cls)
}
stop_helper (h, GNUNET_NO);
/* Restart the helper */
- h->restart_task = GNUNET_SCHEDULER_add_delayed(
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off), &restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task, h);
return;
}
}
@@ -416,9 +412,9 @@ start_helper (struct GNUNET_HELPER_Handle *h)
/* out of file descriptors? try again later... */
stop_helper (h, GNUNET_NO);
h->restart_task =
- GNUNET_SCHEDULER_add_delayed(
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off), &restart_task, h);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task, h);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -437,9 +433,9 @@ start_helper (struct GNUNET_HELPER_Handle *h)
{
/* failed to start process? try again later... */
stop_helper (h, GNUNET_NO);
- h->restart_task = GNUNET_SCHEDULER_add_delayed(
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off), &restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task, h);
return;
}
GNUNET_DISK_pipe_close_end (h->helper_out, GNUNET_DISK_PIPE_END_WRITE);
@@ -583,22 +579,11 @@ static void
helper_write (void *cls)
{
struct GNUNET_HELPER_Handle *h = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
struct GNUNET_HELPER_SendHandle *sh;
const char *buf;
ssize_t t;
h->write_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- /* try again */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Helper write triggered during shutdown, retrying\n");
- h->write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->fh_to_helper, &helper_write, h);
- return;
- }
if (NULL == (sh = h->sh_head))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -626,9 +611,9 @@ helper_write (void *cls)
"Stopping and restarting helper task!\n");
stop_helper (h, GNUNET_NO);
/* Restart the helper */
- h->restart_task = GNUNET_SCHEDULER_add_delayed(
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off), &restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task, h);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/util/mq.c b/src/util/mq.c
index aff9f465c..6f8c04224 100644
--- a/src/util/mq.c
+++ b/src/util/mq.c
@@ -302,13 +302,8 @@ static void
impl_send_continue (void *cls)
{
struct GNUNET_MQ_Handle *mq = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
struct GNUNET_MQ_Envelope *current_envelope;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
-
mq->continue_task = NULL;
/* call is only valid if we're actually currently sending
* a message */
@@ -325,7 +320,9 @@ impl_send_continue (void *cls)
GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
mq->envelope_tail,
mq->current_envelope);
- mq->send_impl (mq, mq->current_envelope->mh, mq->impl_state);
+ mq->send_impl (mq,
+ mq->current_envelope->mh,
+ mq->impl_state);
}
if (NULL != current_envelope->sent_cb)
current_envelope->sent_cb (current_envelope->sent_cls);
@@ -334,10 +331,9 @@ impl_send_continue (void *cls)
/**
- * Call the send implementation for the next queued message,
- * if any.
- * Only useful for implementing message queues,
- * results in undefined behavior if not used carefully.
+ * Call the send implementation for the next queued message, if any.
+ * Only useful for implementing message queues, results in undefined
+ * behavior if not used carefully.
*
* @param mq message queue to send the next message with
*/
@@ -471,7 +467,9 @@ GNUNET_MQ_msg_nested_mh_ (struct GNUNET_MessageHeader **mhp,
return NULL;
mqm = GNUNET_MQ_msg_ (mhp, size, type);
- memcpy ((char *) mqm->mh + base_size, nested_mh, ntohs (nested_mh->size));
+ memcpy ((char *) mqm->mh + base_size,
+ nested_mh,
+ ntohs (nested_mh->size));
return mqm;
}
@@ -481,9 +479,9 @@ GNUNET_MQ_msg_nested_mh_ (struct GNUNET_MessageHeader **mhp,
* Transmit a queued message to the session's client.
*
* @param cls consensus session
- * @param size number of bytes available in buf
+ * @param size number of bytes available in @a buf
* @param buf where the callee should write the message
- * @return number of bytes written to buf
+ * @return number of bytes written to @a buf
*/
static size_t
transmit_queued (void *cls, size_t size,
@@ -535,10 +533,10 @@ server_client_send_impl (struct GNUNET_MQ_Handle *mq,
GNUNET_assert (NULL != mq);
GNUNET_assert (NULL != state);
- state->th =
- GNUNET_SERVER_notify_transmit_ready (state->client, ntohs (msg->size),
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_queued, mq);
+ state->th = GNUNET_SERVER_notify_transmit_ready (state->client,
+ ntohs (msg->size),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_queued, mq);
}
@@ -580,10 +578,10 @@ handle_client_message (void *cls,
GNUNET_MQ_inject_error (mq, GNUNET_MQ_ERROR_READ);
return;
}
-
- GNUNET_CLIENT_receive (state->connection, handle_client_message, mq,
+ GNUNET_CLIENT_receive (state->connection,
+ &handle_client_message,
+ mq,
GNUNET_TIME_UNIT_FOREVER_REL);
-
GNUNET_MQ_inject_message (mq, msg);
}
@@ -652,7 +650,8 @@ connection_client_send_impl (struct GNUNET_MQ_Handle *mq,
GNUNET_assert (NULL != state);
GNUNET_assert (NULL == state->th);
state->th =
- GNUNET_CLIENT_notify_transmit_ready (state->connection, ntohs (msg->size),
+ GNUNET_CLIENT_notify_transmit_ready (state->connection,
+ ntohs (msg->size),
GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_NO,
&connection_client_transmit_queued, mq);
GNUNET_assert (NULL != state->th);
@@ -752,8 +751,10 @@ GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq,
if (NULL == mq->assoc_map)
return NULL;
- val = GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map, request_id);
- GNUNET_CONTAINER_multihashmap32_remove_all (mq->assoc_map, request_id);
+ val = GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map,
+ request_id);
+ GNUNET_CONTAINER_multihashmap32_remove_all (mq->assoc_map,
+ request_id);
return val;
}
@@ -785,10 +786,11 @@ GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq)
struct GNUNET_MQ_Envelope *ev;
ev = mq->envelope_head;
ev->parent_queue = NULL;
- GNUNET_CONTAINER_DLL_remove (mq->envelope_head, mq->envelope_tail, ev);
+ GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
+ mq->envelope_tail,
+ ev);
GNUNET_MQ_discard (ev);
}
-
if (NULL != mq->current_envelope)
{
/* we can only discard envelopes that
@@ -797,7 +799,6 @@ GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq)
GNUNET_MQ_discard (mq->current_envelope);
mq->current_envelope = NULL;
}
-
if (NULL != mq->assoc_map)
{
GNUNET_CONTAINER_multihashmap32_destroy (mq->assoc_map);
@@ -851,10 +852,12 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev)
GNUNET_assert (NULL != mq);
GNUNET_assert (NULL != mq->cancel_impl);
- if (mq->current_envelope == ev) {
+ if (mq->current_envelope == ev)
+ {
// complex case, we already started with transmitting
// the message
- mq->cancel_impl (mq, mq->impl_state);
+ mq->cancel_impl (mq,
+ mq->impl_state);
// continue sending the next message, if any
if (NULL == mq->envelope_head)
{
@@ -866,11 +869,17 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev)
GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
mq->envelope_tail,
mq->current_envelope);
- mq->send_impl (mq, mq->current_envelope->mh, mq->impl_state);
+ mq->send_impl (mq,
+ mq->current_envelope->mh,
+ mq->impl_state);
}
- } else {
+ }
+ else
+ {
// simple case, message is still waiting in the queue
- GNUNET_CONTAINER_DLL_remove (mq->envelope_head, mq->envelope_tail, ev);
+ GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
+ mq->envelope_tail,
+ ev);
}
ev->parent_queue = NULL;
diff --git a/src/util/os_installation.c b/src/util/os_installation.c
index 161b0535f..a0e8647a1 100644
--- a/src/util/os_installation.c
+++ b/src/util/os_installation.c
@@ -62,7 +62,7 @@ static const struct GNUNET_OS_ProjectData default_pd = {
.bug_email = "gnunet-developers@gnu.org",
.homepage = "http://www.gnu.org/s/gnunet/",
.config_file = "gnunet.conf",
- .user_config_file = "~/.config/gnunet.conf"
+ .user_config_file = "~/.config/gnunet.conf",
};
/**
diff --git a/src/util/os_priority.c b/src/util/os_priority.c
index 8dfec6c5e..2a6ea8321 100644
--- a/src/util/os_priority.c
+++ b/src/util/os_priority.c
@@ -65,49 +65,68 @@ struct GNUNET_OS_Process
*/
static struct GNUNET_OS_Process current_process;
+/**
+ * Handle for the #parent_control_handler() Task.
+ */
+static struct GNUNET_SCHEDULER_Task *pch;
+
+
+/**
+ * This handler is called on shutdown to remove the #pch.
+ *
+ * @param cls the `struct GNUNET_DISK_FileHandle` of the control pipe
+ */
+static void
+shutdown_pch (void *cls)
+{
+ struct GNUNET_DISK_FileHandle *control_pipe = cls;
+
+ GNUNET_SCHEDULER_cancel (pch);
+ pch = NULL;
+ GNUNET_DISK_file_close (control_pipe);
+ control_pipe = NULL;
+}
+
/**
* This handler is called when there are control data to be read on the pipe
*
- * @param cls the 'struct GNUNET_DISK_FileHandle' of the control pipe
+ * @param cls the `struct GNUNET_DISK_FileHandle` of the control pipe
*/
static void
parent_control_handler (void *cls)
{
struct GNUNET_DISK_FileHandle *control_pipe = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
char sig;
char *pipe_fd;
ssize_t ret;
- tc = GNUNET_SCHEDULER_get_task_context ();
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "`%s' invoked because of %d\n", __FUNCTION__,
- tc->reason);
- if (0 != (tc->reason &
- (GNUNET_SCHEDULER_REASON_SHUTDOWN | GNUNET_SCHEDULER_REASON_TIMEOUT)))
- {
- GNUNET_DISK_file_close (control_pipe);
- control_pipe = NULL;
- return;
- }
- ret = GNUNET_DISK_file_read (control_pipe, &sig, sizeof (sig));
+ pch = NULL;
+ ret = GNUNET_DISK_file_read (control_pipe,
+ &sig,
+ sizeof (sig));
if (sizeof (sig) != ret)
{
if (-1 == ret)
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DISK_file_read");
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Closing control pipe\n");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
+ "GNUNET_DISK_file_read");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Closing control pipe\n");
GNUNET_DISK_file_close (control_pipe);
control_pipe = NULL;
return;
}
pipe_fd = getenv (GNUNET_OS_CONTROL_PIPE);
- GNUNET_assert ( (NULL == pipe_fd) || (strlen (pipe_fd) <= 0) );
+ GNUNET_assert ( (NULL == pipe_fd) ||
+ (strlen (pipe_fd) <= 0) );
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Got control code %d from parent via pipe %s\n", sig, pipe_fd);
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- control_pipe, &parent_control_handler,
- control_pipe);
+ "Got control code %d from parent via pipe %s\n",
+ sig,
+ pipe_fd);
+ pch = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ control_pipe,
+ &parent_control_handler,
+ control_pipe);
GNUNET_SIGNAL_raise ((int) sig);
}
@@ -115,7 +134,7 @@ parent_control_handler (void *cls)
/**
* Task that connects this process to its parent via pipe;
* essentially, the parent control handler will read signal numbers
- * from the 'GNUNET_OS_CONTROL_PIPE' (as given in an environment
+ * from the #GNUNET_OS_CONTROL_PIPE (as given in an environment
* variable) and raise those signals.
*
* @param cls closure (unused)
@@ -128,6 +147,12 @@ GNUNET_OS_install_parent_control_handler (void *cls)
struct GNUNET_DISK_FileHandle *control_pipe;
uint64_t pipe_fd;
+ if (NULL != pch)
+ {
+ /* already done, we've been called twice... */
+ GNUNET_break (0);
+ return;
+ }
env_buf = getenv (GNUNET_OS_CONTROL_PIPE);
if ( (NULL == env_buf) || (strlen (env_buf) <= 0) )
{
@@ -141,7 +166,9 @@ GNUNET_OS_install_parent_control_handler (void *cls)
pipe_fd = strtoull (env_buf, &env_buf_end, 16);
if ((0 != errno) || (env_buf == env_buf_end))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "strtoull", env_buf);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
+ "strtoull",
+ env_buf);
putenv (GNUNET_OS_CONTROL_PIPE "=");
return;
}
@@ -153,7 +180,8 @@ GNUNET_OS_install_parent_control_handler (void *cls)
#endif
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- "GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n", env_buf);
+ "GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n",
+ env_buf);
putenv (GNUNET_OS_CONTROL_PIPE "=");
return;
}
@@ -164,14 +192,21 @@ GNUNET_OS_install_parent_control_handler (void *cls)
#endif
if (NULL == control_pipe)
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", env_buf);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
+ "open",
+ env_buf);
putenv (GNUNET_OS_CONTROL_PIPE "=");
return;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Adding parent control handler pipe `%s' to the scheduler\n", env_buf);
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, control_pipe,
- &parent_control_handler, control_pipe);
+ "Adding parent control handler pipe `%s' to the scheduler\n",
+ env_buf);
+ pch = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ control_pipe,
+ &parent_control_handler,
+ control_pipe);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_pch,
+ control_pipe);
putenv (GNUNET_OS_CONTROL_PIPE "=");
}
@@ -179,8 +214,8 @@ GNUNET_OS_install_parent_control_handler (void *cls)
/**
* Get process structure for current process
*
- * The pointer it returns points to static memory location and must not be
- * deallocated/closed
+ * The pointer it returns points to static memory location and must
+ * not be deallocated/closed.
*
* @return pointer to the process sturcutre for this process
*/
@@ -205,7 +240,8 @@ GNUNET_OS_process_current ()
* @return 0 on success, -1 on error
*/
int
-GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig)
+GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc,
+ int sig)
{
int ret;
char csig;
@@ -213,8 +249,13 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig)
csig = (char) sig;
if (NULL != proc->control_pipe)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending signal %d to pid: %u via pipe\n", sig, proc->pid);
- ret = GNUNET_DISK_file_write (proc->control_pipe, &csig, sizeof (csig));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending signal %d to pid: %u via pipe\n",
+ sig,
+ proc->pid);
+ ret = GNUNET_DISK_file_write (proc->control_pipe,
+ &csig,
+ sizeof (csig));
if (sizeof (csig) == ret)
return 0;
}
@@ -237,14 +278,17 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig)
if (0 != GetExitCodeProcess (proc->handle, &exitcode))
must_kill = (exitcode == STILL_ACTIVE) ? GNUNET_YES : GNUNET_NO;
if (GNUNET_YES == must_kill)
+ {
if (0 == SafeTerminateProcess (proc->handle, 0, 0))
{
DWORD error_code = GetLastError ();
- if ((error_code != WAIT_TIMEOUT) && (error_code != ERROR_PROCESS_ABORTED))
+ if ( (error_code != WAIT_TIMEOUT) &&
+ (error_code != ERROR_PROCESS_ABORTED) )
{
LOG ((error_code == ERROR_ACCESS_DENIED) ?
- GNUNET_ERROR_TYPE_INFO : GNUNET_ERROR_TYPE_WARNING,
- "SafeTermiateProcess failed with code %lu\n", error_code);
+ GNUNET_ERROR_TYPE_INFO : GNUNET_ERROR_TYPE_WARNING,
+ "SafeTermiateProcess failed with code %lu\n",
+ error_code);
/* The problem here is that a process that is already dying
* might cause SafeTerminateProcess to fail with
* ERROR_ACCESS_DENIED, but the process WILL die eventually.
@@ -263,6 +307,7 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig)
}
}
}
+ }
}
return 0;
#else
@@ -277,12 +322,16 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig)
errno = EINVAL;
return -1;
#else
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending signal %d to pid: %u via system call\n", sig, proc->pid);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending signal %d to pid: %u via system call\n",
+ sig,
+ proc->pid);
return PLIBC_KILL (proc->pid, sig);
#endif
}
}
+
/**
* Get the pid of the process in question
*
@@ -298,7 +347,8 @@ GNUNET_OS_process_get_pid (struct GNUNET_OS_Process * proc)
/**
- * Cleans up process structure contents (OS-dependent) and deallocates it
+ * Cleans up process structure contents (OS-dependent) and deallocates
+ * it.
*
* @param proc pointer to process structure
*/
@@ -314,6 +364,7 @@ GNUNET_OS_process_destroy (struct GNUNET_OS_Process *proc)
GNUNET_free (proc);
}
+
#if WINDOWS
#include "gnunet_signal_lib.h"
@@ -324,6 +375,7 @@ extern GNUNET_SIGNAL_Handler w32_sigchld_handler;
*/
#define DWORD_WINAPI DWORD WINAPI
+
/**
* @brief Waits for a process to terminate and invokes the SIGCHLD handler
* @param proc pointer to process structure
@@ -467,7 +519,9 @@ open_dev_null (int target_fd,
fd = open ("/dev/null", flags);
if (-1 == fd)
{
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", "/dev/null");
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "open",
+ "/dev/null");
return;
}
if (fd == target_fd)
@@ -531,23 +585,30 @@ start_process (int pipe_control,
int fd_stdin_read;
int fd_stdin_write;
- if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary (filename, GNUNET_NO, NULL))
+ if (GNUNET_SYSERR ==
+ GNUNET_OS_check_helper_binary (filename, GNUNET_NO, NULL))
return NULL; /* not executable */
if (GNUNET_YES == pipe_control)
{
struct GNUNET_DISK_PipeHandle *childpipe;
int dup_childpipe_read_fd = -1;
- childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO);
+ childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO,
+ GNUNET_YES, GNUNET_NO);
if (NULL == childpipe)
return NULL;
- childpipe_read = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_READ);
- childpipe_write = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_WRITE);
+ childpipe_read = GNUNET_DISK_pipe_detach_end (childpipe,
+ GNUNET_DISK_PIPE_END_READ);
+ childpipe_write = GNUNET_DISK_pipe_detach_end (childpipe,
+ GNUNET_DISK_PIPE_END_WRITE);
GNUNET_DISK_pipe_close (childpipe);
- if ((NULL == childpipe_read) || (NULL == childpipe_write) ||
- (GNUNET_OK != GNUNET_DISK_internal_file_handle_ (childpipe_read,
- &childpipe_read_fd, sizeof (int))) ||
- (-1 == (dup_childpipe_read_fd = dup (childpipe_read_fd))))
+ if ( (NULL == childpipe_read) ||
+ (NULL == childpipe_write) ||
+ (GNUNET_OK !=
+ GNUNET_DISK_internal_file_handle_ (childpipe_read,
+ &childpipe_read_fd,
+ sizeof (int))) ||
+ (-1 == (dup_childpipe_read_fd = dup (childpipe_read_fd))))
{
if (NULL != childpipe_read)
GNUNET_DISK_file_close (childpipe_read);
@@ -1762,17 +1823,19 @@ cmd_read (void *cls)
cmd->rtask = NULL;
tc = GNUNET_SCHEDULER_get_task_context ();
- if (GNUNET_YES != GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, cmd->r))
+ if (GNUNET_YES !=
+ GNUNET_NETWORK_fdset_handle_isset (tc->read_ready,
+ cmd->r))
{
- /* timeout, shutdown, etc. */
+ /* timeout */
proc = cmd->proc;
cmd->proc = NULL;
proc (cmd->proc_cls, NULL);
return;
}
- ret =
- GNUNET_DISK_file_read (cmd->r, &cmd->buf[cmd->off],
- sizeof (cmd->buf) - cmd->off);
+ ret = GNUNET_DISK_file_read (cmd->r,
+ &cmd->buf[cmd->off],
+ sizeof (cmd->buf) - cmd->off);
if (ret <= 0)
{
if ((cmd->off > 0) && (cmd->off < sizeof (cmd->buf)))
@@ -1795,9 +1858,11 @@ cmd_read (void *cls)
cmd->off -= (end + 1 - cmd->buf);
end = memchr (cmd->buf, '\n', cmd->off);
}
- cmd->rtask =
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
- (cmd->timeout), cmd->r, &cmd_read, cmd);
+ cmd->rtask
+ = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
+ (cmd->timeout),
+ cmd->r,
+ &cmd_read, cmd);
}
@@ -1824,12 +1889,15 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc,
struct GNUNET_DISK_PipeHandle *opipe;
va_list ap;
- opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
+ opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES,
+ GNUNET_NO, GNUNET_YES);
if (NULL == opipe)
return NULL;
va_start (ap, binary);
/* redirect stdout, don't inherit stderr/stdin */
- eip = GNUNET_OS_start_process_va (GNUNET_NO, 0, NULL, opipe, NULL, binary, ap);
+ eip = GNUNET_OS_start_process_va (GNUNET_NO, 0, NULL,
+ opipe, NULL, binary,
+ ap);
va_end (ap);
if (NULL == eip)
{
@@ -1843,8 +1911,12 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc,
cmd->opipe = opipe;
cmd->proc = proc;
cmd->proc_cls = proc_cls;
- cmd->r = GNUNET_DISK_pipe_handle (opipe, GNUNET_DISK_PIPE_END_READ);
- cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout, cmd->r, &cmd_read, cmd);
+ cmd->r = GNUNET_DISK_pipe_handle (opipe,
+ GNUNET_DISK_PIPE_END_READ);
+ cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout,
+ cmd->r,
+ &cmd_read,
+ cmd);
return cmd;
}
diff --git a/src/util/program.c b/src/util/program.c
index bf7885fe9..72f6a1e6c 100644
--- a/src/util/program.c
+++ b/src/util/program.c
@@ -76,11 +76,7 @@ static void
program_main (void *cls)
{
struct CommandContext *cc = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
GNUNET_SPEEDUP_start_(cc->cfg);
GNUNET_RESOLVER_connect (cc->cfg);
cc->task (cc->task_cls, cc->args, cc->cfgfile, cc->cfg);
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c
index e7a836f03..0488d6a3c 100644
--- a/src/util/resolver_api.c
+++ b/src/util/resolver_api.c
@@ -118,7 +118,7 @@ struct GNUNET_RESOLVER_RequestHandle
GNUNET_RESOLVER_HostnameCallback name_callback;
/**
- * Closure for the respective "callback".
+ * Closure for the callbacks.
*/
void *cls;
@@ -131,7 +131,7 @@ struct GNUNET_RESOLVER_RequestHandle
* Task handle for making reply callbacks in numeric lookups
* asynchronous, and for timeout handling.
*/
- struct GNUNET_SCHEDULER_Task * task;
+ struct GNUNET_SCHEDULER_Task *task;
/**
* Desired address family.
@@ -638,6 +638,7 @@ loopback_resolution (void *cls)
rh->addr_callback (rh->cls,
(const struct sockaddr *) &v4,
sizeof (v4));
+
break;
default:
GNUNET_break (0);
@@ -683,7 +684,7 @@ process_requests ()
/* nothing to do, release socket really soon if there is nothing
* else happening... */
s_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
&shutdown_task,
NULL);
return;
@@ -727,14 +728,9 @@ process_requests ()
static void
reconnect_task (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
r_task = NULL;
if (NULL == req_head)
return; /* no work pending */
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Trying to connect to DNS service\n");
client = GNUNET_CLIENT_connect ("resolver",
@@ -774,7 +770,9 @@ reconnect ()
break;
case GNUNET_SYSERR:
/* request was cancelled, remove entirely */
- GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
+ GNUNET_CONTAINER_DLL_remove (req_head,
+ req_tail,
+ rh);
GNUNET_free (rh);
break;
default:
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index dcf5aeeaa..81f968dee 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet
- Copyright (C) 2009-2013 GNUnet e.V.
+ Copyright (C) 2009-2016 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
@@ -152,6 +152,11 @@ struct GNUNET_SCHEDULER_Task
int lifeness;
/**
+ * Is this task run on shutdown?
+ */
+ int on_shutdown;
+
+ /**
* Is this task in the ready list?
*/
int in_ready_list;
@@ -184,6 +189,16 @@ static struct GNUNET_SCHEDULER_Task *pending_head;
static struct GNUNET_SCHEDULER_Task *pending_tail;
/**
+ * Head of list of tasks waiting for shutdown.
+ */
+static struct GNUNET_SCHEDULER_Task *shutdown_head;
+
+/**
+ * Tail of list of tasks waiting for shutdown.
+ */
+static struct GNUNET_SCHEDULER_Task *shutdown_tail;
+
+/**
* List of tasks waiting ONLY for a timeout event.
* Sorted by timeout (earliest first). Used so that
* we do not traverse the list of these tasks when
@@ -421,8 +436,6 @@ queue_ready_task (struct GNUNET_SCHEDULER_Task *task)
{
enum GNUNET_SCHEDULER_Priority p = check_priority (task->priority);
- if (0 != (task->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- p = task->priority = GNUNET_SCHEDULER_PRIORITY_SHUTDOWN;
GNUNET_CONTAINER_DLL_insert (ready_head[p],
ready_tail[p],
task);
@@ -477,29 +490,24 @@ check_ready (const struct GNUNET_NETWORK_FDSet *rs,
/**
- * Request the shutdown of a scheduler. Marks all currently
- * pending tasks as ready because of shutdown. This will
- * cause all tasks to run (as soon as possible, respecting
- * priorities and prerequisite tasks). Note that tasks
- * scheduled AFTER this call may still be delayed arbitrarily.
- *
- * Note that we don't move the tasks into the ready queue yet;
- * check_ready() will do that later, possibly adding additional
- * readiness-factors
+ * Request the shutdown of a scheduler. Marks all tasks
+ * awaiting shutdown as ready. Note that tasks
+ * scheduled with #GNUNET_SCHEDULER_add_shutdown() AFTER this call
+ * will be delayed until the next shutdown signal.
*/
void
GNUNET_SCHEDULER_shutdown ()
{
struct GNUNET_SCHEDULER_Task *pos;
- int i;
- for (pos = pending_timeout_head; NULL != pos; pos = pos->next)
- pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
- for (pos = pending_head; NULL != pos; pos = pos->next)
+ while (NULL != (pos = shutdown_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (shutdown_head,
+ shutdown_tail,
+ pos);
pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
- for (i = 0; i < GNUNET_SCHEDULER_PRIORITY_COUNT; i++)
- for (pos = ready_head[i]; NULL != pos; pos = pos->next)
- pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
+ queue_ready_task (pos);
+ }
}
@@ -523,6 +531,27 @@ destroy_task (struct GNUNET_SCHEDULER_Task *t)
/**
+ * Output stack trace of task @a t.
+ *
+ * @param t task to dump stack trace of
+ */
+static void
+dump_backtrace (struct GNUNET_SCHEDULER_Task *t)
+{
+#if EXECINFO
+ unsigned int i;
+
+ for (i = 0; i < t->num_backtrace_strings; i++)
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Task %p trace %u: %s\n",
+ t,
+ i,
+ t->backtrace_strings[i]);
+#endif
+}
+
+
+/**
* Run at least one task in the highest-priority queue that is not
* empty. Keep running tasks until we are either no longer running
* "URGENT" tasks or until we have at least one "pending" task (which
@@ -589,16 +618,7 @@ run_ready (struct GNUNET_NETWORK_FDSet *rs,
"Running task: %p\n",
pos);
pos->callback (pos->callback_cls);
-#if EXECINFO
- unsigned int i;
-
- for (i = 0; i < pos->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Task %p trace %u: %s\n",
- pos,
- i,
- pos->backtrace_strings[i]);
-#endif
+ dump_backtrace (pos);
active_task = NULL;
destroy_task (pos);
tasks_run++;
@@ -684,10 +704,13 @@ check_lifeness ()
for (t = pending_head; NULL != t; t = t->next)
if (t->lifeness == GNUNET_YES)
return GNUNET_OK;
+ for (t = shutdown_head; NULL != t; t = t->next)
+ if (t->lifeness == GNUNET_YES)
+ return GNUNET_OK;
for (t = pending_timeout_head; NULL != t; t = t->next)
if (t->lifeness == GNUNET_YES)
return GNUNET_OK;
- if ((NULL != pending_head) || (NULL != pending_timeout_head))
+ if (NULL != shutdown_head)
{
GNUNET_SCHEDULER_shutdown ();
return GNUNET_OK;
@@ -749,15 +772,21 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task,
my_pid = getpid ();
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Registering signal handlers\n");
- shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown);
- shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown);
+ shc_int = GNUNET_SIGNAL_handler_install (SIGINT,
+ &sighandler_shutdown);
+ shc_term = GNUNET_SIGNAL_handler_install (SIGTERM,
+ &sighandler_shutdown);
#if (SIGTERM != GNUNET_TERM_SIG)
- shc_gterm = GNUNET_SIGNAL_handler_install (GNUNET_TERM_SIG, &sighandler_shutdown);
+ shc_gterm = GNUNET_SIGNAL_handler_install (GNUNET_TERM_SIG,
+ &sighandler_shutdown);
#endif
#ifndef MINGW
- shc_pipe = GNUNET_SIGNAL_handler_install (SIGPIPE, &sighandler_pipe);
- shc_quit = GNUNET_SIGNAL_handler_install (SIGQUIT, &sighandler_shutdown);
- shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP, &sighandler_shutdown);
+ shc_pipe = GNUNET_SIGNAL_handler_install (SIGPIPE,
+ &sighandler_pipe);
+ shc_quit = GNUNET_SIGNAL_handler_install (SIGQUIT,
+ &sighandler_shutdown);
+ shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP,
+ &sighandler_shutdown);
#endif
current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT;
current_lifeness = GNUNET_YES;
@@ -826,14 +855,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task,
LOG (GNUNET_ERROR_TYPE_ERROR,
"Got invalid file descriptor %d!\n",
t->read_fd);
-#if EXECINFO
- unsigned int i;
-
- for (i = 0; i < t->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Trace: %s\n",
- t->backtrace_strings[i]);
-#endif
+ dump_backtrace (t);
}
}
if (-1 != t->write_fd)
@@ -844,14 +866,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task,
LOG (GNUNET_ERROR_TYPE_ERROR,
"Got invalid file descriptor %d!\n",
t->write_fd);
-#if EXECINFO
- unsigned int i;
-
- for (i = 0; i < t->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Trace: %s\n",
- t->backtrace_strings[i]);
-#endif
+ dump_backtrace (t);
}
}
}
@@ -959,7 +974,8 @@ GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Task *task)
enum GNUNET_SCHEDULER_Priority p;
void *ret;
- GNUNET_assert (NULL != active_task);
+ GNUNET_assert ( (NULL != active_task) ||
+ (GNUNET_NO == task->lifeness) );
if (! task->in_ready_list)
{
if ( (-1 == task->read_fd) &&
@@ -967,9 +983,14 @@ GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Task *task)
(NULL == task->read_set) &&
(NULL == task->write_set) )
{
- GNUNET_CONTAINER_DLL_remove (pending_timeout_head,
- pending_timeout_tail,
- task);
+ if (GNUNET_YES == task->on_shutdown)
+ GNUNET_CONTAINER_DLL_remove (shutdown_head,
+ shutdown_tail,
+ task);
+ else
+ GNUNET_CONTAINER_DLL_remove (pending_timeout_head,
+ pending_timeout_tail,
+ task);
if (task == pending_timeout_last)
pending_timeout_last = NULL;
}
@@ -998,6 +1019,27 @@ GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Task *task)
/**
+ * Initialize backtrace data for task @a t
+ *
+ * @param t task to initialize
+ */
+static void
+init_backtrace (struct GNUNET_SCHEDULER_Task *t)
+{
+#if EXECINFO
+ void *backtrace_array[MAX_TRACE_DEPTH];
+
+ t->num_backtrace_strings
+ = backtrace (backtrace_array, MAX_TRACE_DEPTH);
+ t->backtrace_strings =
+ backtrace_symbols (backtrace_array,
+ t->num_backtrace_strings);
+ dump_backtrace (t);
+#endif
+}
+
+
+/**
* Continue the current execution with the given function. This is
* similar to the other "add" functions except that there is no delay
* and the reason code can be specified.
@@ -1015,19 +1057,10 @@ GNUNET_SCHEDULER_add_with_reason_and_priority (GNUNET_SCHEDULER_TaskCallback tas
{
struct GNUNET_SCHEDULER_Task *t;
-#if EXECINFO
- void *backtrace_array[50];
-#endif
-
GNUNET_assert (NULL != task);
GNUNET_assert ((NULL != active_task) ||
(GNUNET_SCHEDULER_REASON_STARTUP == reason));
t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
-#if EXECINFO
- t->num_backtrace_strings = backtrace (backtrace_array, 50);
- t->backtrace_strings =
- backtrace_symbols (backtrace_array, t->num_backtrace_strings);
-#endif
t->read_fd = -1;
t->write_fd = -1;
t->callback = task;
@@ -1041,6 +1074,7 @@ GNUNET_SCHEDULER_add_with_reason_and_priority (GNUNET_SCHEDULER_TaskCallback tas
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Adding continuation task %p\n",
t);
+ init_backtrace (t);
queue_ready_task (t);
}
@@ -1049,8 +1083,7 @@ GNUNET_SCHEDULER_add_with_reason_and_priority (GNUNET_SCHEDULER_TaskCallback tas
* Schedule a new task to be run with a specified delay. The task
* will be scheduled for execution once the delay has expired.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param priority priority to use for the task
* @param task main function of the task
* @param task_cls closure of @a task
@@ -1067,20 +1100,11 @@ GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
struct GNUNET_SCHEDULER_Task *pos;
struct GNUNET_SCHEDULER_Task *prev;
-#if EXECINFO
- void *backtrace_array[MAX_TRACE_DEPTH];
-#endif
-
GNUNET_assert (NULL != active_task);
GNUNET_assert (NULL != task);
t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
t->callback = task;
t->callback_cls = task_cls;
-#if EXECINFO
- t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
- t->backtrace_strings =
- backtrace_symbols (backtrace_array, t->num_backtrace_strings);
-#endif
t->read_fd = -1;
t->write_fd = -1;
#if PROFILE_DELAYS
@@ -1127,16 +1151,7 @@ GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Adding task: %p\n",
t);
-#if EXECINFO
- unsigned int i;
-
- for (i = 0; i < t->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Task %p trace %d: %s\n",
- t,
- i,
- t->backtrace_strings[i]);
-#endif
+ init_backtrace (t);
return t;
}
@@ -1167,16 +1182,16 @@ GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio,
* will be scheduled for execution once the delay has expired. It
* will be run with the DEFAULT priority.
*
- * @param delay when should this operation time out? Use
- * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param task main function of the task
- * @param task_cls closure of task
+ * @param task_cls closure of @a task
* @return unique task identifier for the job
- * only valid until "task" is started!
+ * only valid until @a task is started!
*/
struct GNUNET_SCHEDULER_Task *
GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
- GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
+ GNUNET_SCHEDULER_TaskCallback task,
+ void *task_cls)
{
return GNUNET_SCHEDULER_add_delayed_with_priority (delay,
GNUNET_SCHEDULER_PRIORITY_DEFAULT,
@@ -1197,12 +1212,56 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
* @param task main function of the task
* @param task_cls closure of @a task
* @return unique task identifier for the job
- * only valid until "task" is started!
+ * only valid until @a task is started!
*/
struct GNUNET_SCHEDULER_Task *
-GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
+GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_TaskCallback task,
+ void *task_cls)
{
- return GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_ZERO, task, task_cls);
+ return GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_ZERO,
+ task,
+ task_cls);
+}
+
+
+/**
+ * Schedule a new task to be run on shutdown, that is when a CTRL-C
+ * signal is received, or when #GNUNET_SCHEDULER_shutdown() is being
+ * invoked.
+ *
+ * @param task main function of the task
+ * @param task_cls closure of @a task
+ * @return unique task identifier for the job
+ * only valid until @a task is started!
+ */
+struct GNUNET_SCHEDULER_Task *
+GNUNET_SCHEDULER_add_shutdown (GNUNET_SCHEDULER_TaskCallback task,
+ void *task_cls)
+{
+ struct GNUNET_SCHEDULER_Task *t;
+
+ GNUNET_assert (NULL != active_task);
+ GNUNET_assert (NULL != task);
+ t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
+ t->callback = task;
+ t->callback_cls = task_cls;
+ t->read_fd = -1;
+ t->write_fd = -1;
+#if PROFILE_DELAYS
+ t->start_time = GNUNET_TIME_absolute_get ();
+#endif
+ t->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
+ t->priority = GNUNET_SCHEDULER_PRIORITY_SHUTDOWN;
+ t->on_shutdown = GNUNET_YES;
+ t->lifeness = GNUNET_YES;
+ GNUNET_CONTAINER_DLL_insert (shutdown_head,
+ shutdown_tail,
+ t);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding task: %p\n",
+ t);
+ init_backtrace (t);
+ return t;
}
@@ -1246,12 +1305,10 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
* (prerequisite-run)
* && (delay-ready
* || any-rs-ready
- * || any-ws-ready
- * || shutdown-active )
+ * || any-ws-ready)
* </code>
*
- * @param delay how long should we wait? Use #GNUNET_TIME_UNIT_FOREVER_REL for "forever",
- * which means that the task will only be run after we receive SIGTERM
+ * @param delay how long should we wait?
* @param priority priority to use
* @param rfd file descriptor we want to read (can be -1)
* @param wfd file descriptors we want to write (can be -1)
@@ -1271,20 +1328,11 @@ add_without_sets (struct GNUNET_TIME_Relative delay,
{
struct GNUNET_SCHEDULER_Task *t;
-#if EXECINFO
- void *backtrace_array[MAX_TRACE_DEPTH];
-#endif
-
GNUNET_assert (NULL != active_task);
GNUNET_assert (NULL != task);
t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
t->callback = task;
t->callback_cls = task_cls;
-#if EXECINFO
- t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
- t->backtrace_strings =
- backtrace_symbols (backtrace_array, t->num_backtrace_strings);
-#endif
#if DEBUG_FDS
if (-1 != rfd)
{
@@ -1295,14 +1343,7 @@ add_without_sets (struct GNUNET_TIME_Relative delay,
LOG (GNUNET_ERROR_TYPE_ERROR,
"Got invalid file descriptor %d!\n",
rfd);
-#if EXECINFO
- unsigned int i;
-
- for (i = 0; i < t->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Trace: %s\n",
- t->backtrace_strings[i]);
-#endif
+ init_backtrace (t);
GNUNET_assert (0);
}
}
@@ -1315,14 +1356,7 @@ add_without_sets (struct GNUNET_TIME_Relative delay,
LOG (GNUNET_ERROR_TYPE_ERROR,
"Got invalid file descriptor %d!\n",
wfd);
-#if EXECINFO
- unsigned int i;
-
- for (i = 0; i < t->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Trace: %s\n",
- t->backtrace_strings[i]);
-#endif
+ init_backtrace (t);
GNUNET_assert (0);
}
}
@@ -1344,16 +1378,7 @@ add_without_sets (struct GNUNET_TIME_Relative delay,
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Adding task %p\n",
t);
-#if EXECINFO
- unsigned int i;
-
- for (i = 0; i < t->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Task %p trace %d: %s\n",
- t,
- i,
- t->backtrace_strings[i]);
-#endif
+ init_backtrace (t);
return t;
}
#endif
@@ -1366,8 +1391,7 @@ add_without_sets (struct GNUNET_TIME_Relative delay,
* scheduled for execution once either the delay has expired or the
* socket operation is ready. It will be run with the DEFAULT priority.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param rfd read file-descriptor
* @param task main function of the task
* @param task_cls closure of @a task
@@ -1394,8 +1418,7 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay,
* either the delay has expired or the socket operation is ready. It
* will be run with the DEFAULT priority.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param priority priority to use for the task
* @param rfd read file-descriptor
* @param task main function of the task
@@ -1426,8 +1449,7 @@ GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay,
* socket operation is ready. It will be run with the priority of
* the calling task.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param wfd write file-descriptor
* @param task main function of the task
* @param task_cls closure of @a task
@@ -1454,8 +1476,7 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
* scheduled for execution once either the delay has expired or the
* socket operation is ready.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param priority priority of the task
* @param fd file-descriptor
* @param on_read whether to poll the file-descriptor for readability
@@ -1505,8 +1526,7 @@ GNUNET_SCHEDULER_add_net_with_priority (struct GNUNET_TIME_Relative delay,
* scheduled for execution once either the delay has expired or the
* socket operation is ready. It will be run with the DEFAULT priority.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param rfd read file-descriptor
* @param task main function of the task
* @param task_cls closure of @a task
@@ -1532,8 +1552,7 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
* scheduled for execution once either the delay has expired or the
* socket operation is ready. It will be run with the DEFAULT priority.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param wfd write file-descriptor
* @param task main function of the task
* @param task_cls closure of @a task
@@ -1559,8 +1578,7 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
* scheduled for execution once either the delay has expired or the
* socket operation is ready.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param priority priority of the task
* @param fd file-descriptor
* @param on_read whether to poll the file-descriptor for readability
@@ -1618,13 +1636,11 @@ GNUNET_SCHEDULER_add_file_with_priority (struct GNUNET_TIME_Relative delay,
* (prerequisite-run)
* && (delay-ready
* || any-rs-ready
- * || any-ws-ready
- * || (shutdown-active && run-on-shutdown) )
+ * || any-ws-ready) )
* </code>
*
* @param prio how important is this task?
- * @param delay how long should we wait? Use #GNUNET_TIME_UNIT_FOREVER_REL for "forever",
- * which means that the task will only be run after we receive SIGTERM
+ * @param delay how long should we wait?
* @param rs set of file descriptors we want to read (can be NULL)
* @param ws set of file descriptors we want to write (can be NULL)
* @param task main function of the task
@@ -1641,9 +1657,6 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
void *task_cls)
{
struct GNUNET_SCHEDULER_Task *t;
-#if EXECINFO
- void *backtrace_array[MAX_TRACE_DEPTH];
-#endif
if ( (NULL == rs) &&
(NULL == ws) )
@@ -1656,11 +1669,6 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
t->callback = task;
t->callback_cls = task_cls;
-#if EXECINFO
- t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
- t->backtrace_strings =
- backtrace_symbols (backtrace_array, t->num_backtrace_strings);
-#endif
t->read_fd = -1;
t->write_fd = -1;
if (NULL != rs)
@@ -1689,16 +1697,7 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Adding task %p\n",
t);
-#if EXECINFO
- int i;
-
- for (i = 0; i < t->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Task p trace %d: %s\n",
- t,
- i,
- t->backtrace_strings[i]);
-#endif
+ init_backtrace (t);
return t;
}
diff --git a/src/util/server.c b/src/util/server.c
index 8dedd28fd..00e37c9d9 100644
--- a/src/util/server.c
+++ b/src/util/server.c
@@ -400,12 +400,6 @@ process_listen_socket (void *cls)
server->listen_task = NULL;
tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- /* ignore shutdown, someone else will take care of it! */
- GNUNET_SERVER_resume (server);
- return;
- }
for (i = 0; NULL != server->listen_sockets[i]; i++)
{
if (GNUNET_NETWORK_fdset_isset (tc->read_ready,
@@ -437,7 +431,8 @@ process_listen_socket (void *cls)
* @return NULL on error, otherwise the listen socket
*/
static struct GNUNET_NETWORK_Handle *
-open_listen_socket (const struct sockaddr *server_addr, socklen_t socklen)
+open_listen_socket (const struct sockaddr *server_addr,
+ socklen_t socklen)
{
struct GNUNET_NETWORK_Handle *sock;
uint16_t port;
@@ -683,7 +678,7 @@ test_monitor_clients (struct GNUNET_SERVER_Handle *server)
if (GNUNET_NO == client->is_monitor)
return; /* not done yet */
server->in_soft_shutdown = GNUNET_SYSERR;
- GNUNET_SCHEDULER_add_now (&do_destroy, server);
+ (void) GNUNET_SCHEDULER_add_now (&do_destroy, server);
}
@@ -720,8 +715,8 @@ GNUNET_SERVER_resume (struct GNUNET_SERVER_Handle *server)
return; /* nothing to do, no listen sockets! */
if (NULL == server->listen_sockets[1])
{
- /* simplified method: no fd set needed; this is then much simpler and
- much more efficient */
+ /* simplified method: no fd set needed; this is then much simpler
+ and much more efficient */
server->listen_task =
GNUNET_SCHEDULER_add_read_net_with_priority (GNUNET_TIME_UNIT_FOREVER_REL,
GNUNET_SCHEDULER_PRIORITY_HIGH,
@@ -890,18 +885,16 @@ static void
warn_no_receive_done (void *cls)
{
struct GNUNET_SERVER_Client *client = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
GNUNET_break (0 != client->warn_type); /* type should never be 0 here, as we don't use 0 */
client->warn_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
&warn_no_receive_done, client);
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 == (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Processing code for message of type %u did not call `GNUNET_SERVER_receive_done' after %s\n"),
- (unsigned int) client->warn_type,
- GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (client->warn_start), GNUNET_YES));
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("Processing code for message of type %u did not call `GNUNET_SERVER_receive_done' after %s\n"),
+ (unsigned int) client->warn_type,
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (client->warn_start),
+ GNUNET_YES));
}
@@ -987,7 +980,8 @@ GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server,
sender->warn_start = GNUNET_TIME_absolute_get ();
sender->warn_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &warn_no_receive_done, sender);
+ &warn_no_receive_done,
+ sender);
sender->warn_type = type;
}
sender->suspended++;
diff --git a/src/util/service.c b/src/util/service.c
index 93a51f220..bdef17361 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -187,7 +187,7 @@ struct GNUNET_SERVICE_Context
/**
* Task ID of the shutdown task.
*/
- struct GNUNET_SCHEDULER_Task * shutdown_task;
+ struct GNUNET_SCHEDULER_Task *shutdown_task;
/**
* Idle timeout for server.
@@ -1151,11 +1151,7 @@ service_task (void *cls)
{
struct GNUNET_SERVICE_Context *sctx = cls;
unsigned int i;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
(void) GNUNET_SPEEDUP_start_ (sctx->cfg);
GNUNET_RESOLVER_connect (sctx->cfg);
if (NULL != sctx->lsocks)
@@ -1191,9 +1187,8 @@ service_task (void *cls)
{
/* install a task that will kill the server
* process if the scheduler ever gets a shutdown signal */
- sctx->shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- sctx);
+ sctx->shutdown_task = GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ sctx);
}
sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers));
memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers));
diff --git a/src/util/socks.c b/src/util/socks.c
index cc59858dd..bda8765ad 100644
--- a/src/util/socks.c
+++ b/src/util/socks.c
@@ -328,7 +328,6 @@ register_reciever (struct GNUNET_SOCKS_Handshake *ih, int want)
* @param buf where the callee should write the message
* @return number of bytes written to @a buf
*/
-
size_t
transmit_ready (void *cls,
size_t size,
@@ -353,29 +352,19 @@ transmit_ready (void *cls,
* successful operations, including DNS resolution, do not use this. */
if (NULL == buf)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return 0;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) {
- if (0==ih->step)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- "Timeout contacting SOCKS server, retrying indefinitely, but probably hopeless.\n");
- register_sender (ih);
- }
- else
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Timeout during mid SOCKS handshake (step %u), probably not a SOCKS server.\n",
- ih->step);
- GNUNET_break (0);
- }
- return 0;
+ if (0 == ih->step)
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Timeout contacting SOCKS server, retrying indefinitely, but probably hopeless.\n");
+ register_sender (ih);
+ }
+ else
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Timeout during mid SOCKS handshake (step %u), probably not a SOCKS server.\n",
+ ih->step);
+ GNUNET_break (0);
}
- /* if (reason == 48) register_sender (ih); */
- /* GNUNET_break(0); */
return 0;
}
diff --git a/src/util/speedup.c b/src/util/speedup.c
index 6dce6a490..97df65c8e 100644
--- a/src/util/speedup.c
+++ b/src/util/speedup.c
@@ -41,18 +41,16 @@ static void
do_speedup (void *cls)
{
static long long current_offset;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
speedup_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
current_offset += delta.rel_value_us;
GNUNET_TIME_set_offset (current_offset);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Speeding up execution time by %s\n",
GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_NO));
- speedup_task = GNUNET_SCHEDULER_add_delayed (interval, &do_speedup, NULL);
+ speedup_task = GNUNET_SCHEDULER_add_delayed (interval,
+ &do_speedup,
+ NULL);
}
@@ -65,16 +63,22 @@ do_speedup (void *cls)
int
GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
+ GNUNET_assert (NULL == speedup_task);
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (cfg, "testing",
- "SPEEDUP_INTERVAL", &interval))
+ GNUNET_CONFIGURATION_get_value_time (cfg,
+ "testing",
+ "SPEEDUP_INTERVAL",
+ &interval))
return GNUNET_SYSERR;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (cfg, "testing",
- "SPEEDUP_DELTA", &delta))
+ GNUNET_CONFIGURATION_get_value_time (cfg,
+ "testing",
+ "SPEEDUP_DELTA",
+ &delta))
return GNUNET_SYSERR;
- if ((0 == interval.rel_value_us) || (0 == delta.rel_value_us))
+ if ( (0 == interval.rel_value_us) ||
+ (0 == delta.rel_value_us) )
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Speed up disabled\n");
@@ -87,7 +91,8 @@ GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg)
"Speed up executed every %s\n",
GNUNET_STRINGS_relative_time_to_string (interval, GNUNET_NO));
speedup_task = GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO,
- &do_speedup, NULL);
+ &do_speedup,
+ NULL);
return GNUNET_OK;
}
@@ -109,6 +114,4 @@ GNUNET_SPEEDUP_stop_ ()
"Stopped execution speed up\n");
}
-
-
/* end of speedup.c */
diff --git a/src/util/test_common_logging_runtime_loglevels.c b/src/util/test_common_logging_runtime_loglevels.c
index 21eb3c6c6..033b16ce1 100644
--- a/src/util/test_common_logging_runtime_loglevels.c
+++ b/src/util/test_common_logging_runtime_loglevels.c
@@ -234,7 +234,8 @@ read_call (void *cls)
FPRINTF (stderr, "got %d bytes, reading more\n", rd);
#endif
read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- stdout_read_handle, &read_call,
+ stdout_read_handle,
+ &read_call,
(void*) stdout_read_handle);
return;
}
@@ -411,7 +412,8 @@ runone ()
die_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 10), &end_task,
+ (GNUNET_TIME_UNIT_SECONDS, 10),
+ &end_task,
NULL);
bytes = 0;
@@ -419,7 +421,8 @@ runone ()
memset (&buf, 0, sizeof (buf));
read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- stdout_read_handle, &read_call,
+ stdout_read_handle,
+ &read_call,
(void*) stdout_read_handle);
}
diff --git a/src/util/test_connection_receive_cancel.c b/src/util/test_connection_receive_cancel.c
index 9ec96d8a6..9c0ab699e 100644
--- a/src/util/test_connection_receive_cancel.c
+++ b/src/util/test_connection_receive_cancel.c
@@ -60,7 +60,8 @@ open_listen_socket ()
GNUNET_assert (desc != NULL);
if (GNUNET_NETWORK_socket_setsockopt
(desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "setsockopt");
GNUNET_assert (GNUNET_OK ==
GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa,
sizeof (sa)));
@@ -69,10 +70,13 @@ open_listen_socket ()
}
-
static void
-dead_receive (void *cls, const void *buf, size_t available,
- const struct sockaddr *addr, socklen_t addrlen, int errCode)
+dead_receive (void *cls,
+ const void *buf,
+ size_t available,
+ const struct sockaddr *addr,
+ socklen_t addrlen,
+ int errCode)
{
GNUNET_assert (0);
}
@@ -87,7 +91,8 @@ run_accept_cancel (void *cls)
GNUNET_CONNECTION_destroy (lsock);
GNUNET_CONNECTION_receive (asock, 1024,
GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 5), &dead_receive, cls);
+ (GNUNET_TIME_UNIT_SECONDS, 5),
+ &dead_receive, cls);
}
@@ -103,7 +108,6 @@ receive_cancel_task (void *cls)
}
-
static void
task_receive_cancel (void *cls)
{
@@ -112,14 +116,16 @@ task_receive_cancel (void *cls)
GNUNET_assert (lsock != NULL);
csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT);
GNUNET_assert (csock != NULL);
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls,
- &run_accept_cancel, cls);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &receive_cancel_task,
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ ls,
+ &run_accept_cancel,
+ cls);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &receive_cancel_task,
cls);
}
-
/**
* Main method, starts scheduler with task_timeout.
*/
@@ -130,7 +136,9 @@ check_receive_cancel ()
ok = 1;
cfg = GNUNET_CONFIGURATION_create ();
- GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
+ GNUNET_CONFIGURATION_set_value_string (cfg,
+ "resolver",
+ "HOSTNAME",
"localhost");
GNUNET_SCHEDULER_run (&task_receive_cancel, &ok);
GNUNET_CONFIGURATION_destroy (cfg);
diff --git a/src/util/test_disk.c b/src/util/test_disk.c
index 055e155e9..7b9a6d45c 100644
--- a/src/util/test_disk.c
+++ b/src/util/test_disk.c
@@ -28,6 +28,7 @@
#define TESTSTRING "Hello World\0"
+
static int
testReadWrite ()
{
@@ -79,6 +80,7 @@ testReadWrite ()
return 0;
}
+
static int
testOpenClose ()
{
@@ -104,6 +106,7 @@ testOpenClose ()
static int ok;
+
static int
scan_callback (void *want, const char *filename)
{
@@ -112,41 +115,83 @@ scan_callback (void *want, const char *filename)
return GNUNET_OK;
}
+
static int
testDirScan ()
{
if (GNUNET_OK !=
GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry"))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (GNUNET_OK !=
GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry_more"))
+ {
+ GNUNET_break (0);
return 1;
+ }
GNUNET_DISK_directory_scan ("test", &scan_callback,
"test" DIR_SEPARATOR_STR "entry");
if (GNUNET_OK != GNUNET_DISK_directory_remove ("test"))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (ok < 2)
+ {
+ GNUNET_break (0);
return 1;
+ }
return 0;
}
static int
+iter_callback (void *cls,
+ const char *filename)
+{
+ int *i = cls;
+
+ (*i)++;
+ return GNUNET_OK;
+}
+
+
+static int
testDirIter ()
{
int i;
i = 0;
if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry"))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry_many"))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry_more"))
+ {
+ GNUNET_break (0);
return 1;
+ }
+ GNUNET_DISK_directory_scan ("test",
+ &iter_callback,
+ &i);
if (GNUNET_OK != GNUNET_DISK_directory_remove ("test"))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (i < 3)
+ {
+ GNUNET_break (0);
return 1;
+ }
return 0;
}
@@ -183,19 +228,40 @@ static int
testDirMani ()
{
if (GNUNET_OK != GNUNET_DISK_directory_create_for_file ("test/ing"))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (GNUNET_NO != GNUNET_DISK_file_test ("test"))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (GNUNET_NO != GNUNET_DISK_file_test ("test/ing"))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (GNUNET_OK != GNUNET_DISK_directory_remove ("test"))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (GNUNET_OK != GNUNET_DISK_directory_create ("test"))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (GNUNET_YES != GNUNET_DISK_directory_test ("test", GNUNET_YES))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (GNUNET_OK != GNUNET_DISK_directory_remove ("test"))
+ {
+ GNUNET_break (0);
return 1;
+ }
return 0;
}
@@ -213,9 +279,11 @@ main (int argc, char *argv[])
failureCount += testCanonicalize ();
failureCount += testChangeOwner ();
failureCount += testDirMani ();
- if (failureCount != 0)
+ if (0 != failureCount)
{
- FPRINTF (stderr, "\n%u TESTS FAILED!\n", failureCount);
+ FPRINTF (stderr,
+ "\n%u TESTS FAILED!\n",
+ failureCount);
return -1;
}
return 0;
diff --git a/src/util/test_os_start_process.c b/src/util/test_os_start_process.c
index c617917cc..929b24232 100644
--- a/src/util/test_os_start_process.c
+++ b/src/util/test_os_start_process.c
@@ -55,7 +55,9 @@ struct read_context
const struct GNUNET_DISK_FileHandle *stdout_read_handle;
};
-struct read_context rc;
+
+static struct read_context rc;
+
static void
end_task (void *cls)
@@ -77,35 +79,39 @@ read_call (void *cls)
{
int bytes;
- bytes = GNUNET_DISK_file_read (rc.stdout_read_handle, &rc.buf[rc.buf_offset], \
- sizeof (rc.buf) - rc.buf_offset);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "bytes is %d\n", bytes);
+ bytes = GNUNET_DISK_file_read (rc.stdout_read_handle,
+ &rc.buf[rc.buf_offset],
+ sizeof (rc.buf) - rc.buf_offset);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "bytes is %d\n",
+ bytes);
if (bytes < 1)
{
GNUNET_break (0);
ok = 1;
GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now (&end_task, NULL);
+ (void) GNUNET_SCHEDULER_add_now (&end_task, NULL);
return;
}
ok = strncmp (rc.buf, test_phrase, strlen (test_phrase));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "read %s\n", &rc.buf[rc.buf_offset]);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "read %s\n",
+ &rc.buf[rc.buf_offset]);
rc.buf_offset += bytes;
if (0 == ok)
{
GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now (&end_task, NULL);
+ (void) GNUNET_SCHEDULER_add_now (&end_task, NULL);
return;
}
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- rc.stdout_read_handle, &read_call,
+ rc.stdout_read_handle,
+ &read_call,
NULL);
-
}
@@ -164,13 +170,15 @@ run_task (void *cls)
die_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MINUTES, 1), &end_task,
+ (GNUNET_TIME_UNIT_MINUTES, 1),
+ &end_task,
NULL);
memset (&rc, 0, sizeof (rc));
rc.stdout_read_handle = stdout_read_handle;
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- stdout_read_handle, &read_call,
+ stdout_read_handle,
+ &read_call,
NULL);
}
@@ -205,9 +213,12 @@ check_kill ()
fn = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver");
proc =
GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR,
- hello_pipe_stdin, hello_pipe_stdout, NULL,
+ hello_pipe_stdin,
+ hello_pipe_stdout,
+ NULL,
fn,
- "gnunet-service-resolver", "-", NULL);
+ "gnunet-service-resolver", "-",
+ NULL);
sleep (1); /* give process time to start, so we actually use the pipe-kill mechanism! */
GNUNET_free (fn);
if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG))
diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c
index a246d75c5..55d4c7137 100644
--- a/src/util/test_scheduler.c
+++ b/src/util/test_scheduler.c
@@ -25,7 +25,7 @@
#include "gnunet_util_lib.h"
-struct GNUNET_DISK_PipeHandle *p;
+static struct GNUNET_DISK_PipeHandle *p;
static const struct GNUNET_DISK_FileHandle *fds[2];
@@ -80,7 +80,6 @@ taskLast (void *cls)
{
int *ok = cls;
- /* t4 should be ready (albeit with lower priority) */
GNUNET_assert (8 == *ok);
(*ok) = 0;
}
@@ -98,8 +97,8 @@ taskRd (void *cls)
GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0]));
GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1));
(*ok) = 8;
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, &taskLast,
- cls);
+ GNUNET_SCHEDULER_add_shutdown (&taskLast,
+ cls);
GNUNET_SCHEDULER_shutdown ();
}
@@ -115,10 +114,14 @@ task4 (void *cls)
GNUNET_assert (NULL != p);
fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ);
fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE);
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, fds[0], &taskRd,
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ fds[0],
+ &taskRd,
cls);
- GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, fds[1],
- &taskWrt, cls);
+ GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ fds[1],
+ &taskWrt,
+ cls);
}
@@ -130,9 +133,12 @@ task1 (void *cls)
GNUNET_assert (1 == *ok);
(*ok) = 2;
GNUNET_SCHEDULER_add_now (&task3, cls);
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, &task2,
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI,
+ &task2,
cls);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &task4, cls);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &task4,
+ cls);
}
@@ -158,7 +164,7 @@ taskShutdown (void *cls)
GNUNET_assert (1 == *ok);
*ok = 8;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls);
+ GNUNET_SCHEDULER_add_shutdown (&taskLast, cls);
GNUNET_SCHEDULER_shutdown ();
}
@@ -186,8 +192,9 @@ taskSig (void *cls)
GNUNET_assert (1 == *ok);
*ok = 8;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls);
- GNUNET_break (0 == PLIBC_KILL (getpid (), GNUNET_TERM_SIG));
+ GNUNET_SCHEDULER_add_shutdown (&taskLast, cls);
+ GNUNET_break (0 == PLIBC_KILL (getpid (),
+ GNUNET_TERM_SIG));
}
@@ -214,8 +221,7 @@ taskCancel (void *cls)
GNUNET_assert (1 == *ok);
*ok = 0;
- GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_now
- (&taskNeverRun, NULL));
+ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_now (&taskNeverRun, NULL));
}
diff --git a/src/util/test_scheduler_delay.c b/src/util/test_scheduler_delay.c
index c55f28e9b..93568cd81 100644
--- a/src/util/test_scheduler_delay.c
+++ b/src/util/test_scheduler_delay.c
@@ -62,7 +62,8 @@ test_task (void *cls)
return;
}
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MICROSECONDS, i), &test_task,
+ (GNUNET_TIME_UNIT_MICROSECONDS, i),
+ &test_task,
NULL);
i += INCR;
}
@@ -71,7 +72,9 @@ test_task (void *cls)
int
main (int argc, char *argv[])
{
- GNUNET_log_setup ("test-scheduler-delay", "WARNING", NULL);
+ GNUNET_log_setup ("test-scheduler-delay",
+ "WARNING",
+ NULL);
target = GNUNET_TIME_absolute_get ();
GNUNET_SCHEDULER_run (&test_task, NULL);
FPRINTF (stdout,
diff --git a/src/util/test_server_disconnect.c b/src/util/test_server_disconnect.c
index 21abf92bb..f59fa547f 100644
--- a/src/util/test_server_disconnect.c
+++ b/src/util/test_server_disconnect.c
@@ -76,7 +76,8 @@ server_disconnect (void *cls)
static void
-recv_cb (void *cls, struct GNUNET_SERVER_Client *client,
+recv_cb (void *cls,
+ struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
GNUNET_assert (ok == 2);
diff --git a/src/util/test_server_with_client_unix.c b/src/util/test_server_with_client_unix.c
index ec84b08f8..64f1d9c23 100644
--- a/src/util/test_server_with_client_unix.c
+++ b/src/util/test_server_with_client_unix.c
@@ -50,16 +50,18 @@ send_done (void *cls)
static void
-recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient,
+recv_cb (void *cls,
+ struct GNUNET_SERVER_Client *argclient,
const struct GNUNET_MessageHeader *message)
{
switch (ok)
{
case 2:
ok++;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MILLISECONDS, 50),
- &send_done, argclient);
+ (void) GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 50),
+ &send_done,
+ argclient);
break;
case 4:
ok++;
@@ -91,13 +93,14 @@ clean_up (void *cls)
* @param client identification of the client
*/
static void
-notify_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
+notify_disconnect (void *cls,
+ struct GNUNET_SERVER_Client *client)
{
if (client == NULL)
return;
GNUNET_assert (ok == 5);
ok = 0;
- GNUNET_SCHEDULER_add_now (&clean_up, NULL);
+ (void) GNUNET_SCHEDULER_add_now (&clean_up, NULL);
}
diff --git a/src/util/test_speedup.c b/src/util/test_speedup.c
index 5d46e3127..b9f2cfb4d 100644
--- a/src/util/test_speedup.c
+++ b/src/util/test_speedup.c
@@ -53,7 +53,9 @@ run (void *cls)
fprintf (stderr, "..%u", cycles);
if (cycles <= 5)
{
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &run, NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &run,
+ NULL);
return;
}
end = GNUNET_TIME_absolute_get();
@@ -66,21 +68,22 @@ run (void *cls)
*
*/
static void
-check (void *cls, char *const *args,
+check (void *cls,
+ char *const *args,
const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *
- cfg)
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
fprintf (stderr, "0");
- fflush(stdout);
- GNUNET_SCHEDULER_add_now(&run, NULL);
+ fflush (stdout);
+ GNUNET_SCHEDULER_add_now (&run, NULL);
}
int
main (int argc, char *argv[])
{
- static char *const argvn[] = { "test-speedup",
+ static char *const argvn[] = {
+ "test-speedup",
"-c", "test_speedup_data.conf",
NULL
};
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c
index 58eda367f..2c3ac72fa 100644
--- a/src/vpn/gnunet-service-vpn.c
+++ b/src/vpn/gnunet-service-vpn.c
@@ -3099,9 +3099,8 @@ run (void *cls,
&message_token, NULL, NULL);
nc = GNUNET_SERVER_notification_context_create (server, 1);
GNUNET_SERVER_add_handlers (server, service_handlers);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &cleanup,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup,
+ NULL);
}
diff --git a/src/vpn/gnunet-vpn.c b/src/vpn/gnunet-vpn.c
index d4acee49e..2e7daf7f7 100644
--- a/src/vpn/gnunet-vpn.c
+++ b/src/vpn/gnunet-vpn.c
@@ -163,7 +163,9 @@ allocation_cb (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)
{
int dst_af;
@@ -177,8 +179,7 @@ run (void *cls, char *const *args, const char *cfgfile,
struct GNUNET_TIME_Absolute etime;
etime = GNUNET_TIME_relative_to_absolute (duration);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_disconnect, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_disconnect, NULL);
handle = GNUNET_VPN_connect (cfg);
if (NULL == handle)
goto error;