implementing new scheduler shutdown semantics
authorChristian Grothoff <christian@grothoff.org>
Sat, 30 Apr 2016 08:17:37 +0000 (08:17 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sat, 30 Apr 2016 08:17:37 +0000 (08:17 +0000)
233 files changed:
src/arm/arm_api.c
src/arm/gnunet-arm.c
src/arm/gnunet-service-arm.c
src/arm/test_arm_api.c
src/arm/test_exponential_backoff.c
src/ats-tests/ats-testing-log.c
src/ats-tests/perf_ats_logging.c
src/ats-tool/gnunet-ats.c
src/ats/gnunet-service-ats.c
src/cadet/cadet_api.c
src/cadet/cadet_path.c
src/cadet/gnunet-cadet-profiler.c
src/cadet/gnunet-cadet.c
src/cadet/gnunet-service-cadet.c
src/cadet/gnunet-service-cadet_channel.c
src/cadet/gnunet-service-cadet_connection.c
src/cadet/gnunet-service-cadet_dht.c
src/cadet/gnunet-service-cadet_peer.c
src/cadet/gnunet-service-cadet_tunnel.c
src/cadet/test_cadet.c
src/cadet/test_cadet_local.c
src/cadet/test_cadet_single.c
src/consensus/gnunet-service-consensus.c
src/consensus/test_consensus_api.c
src/conversation/gnunet-conversation-test.c
src/conversation/gnunet-conversation.c
src/conversation/gnunet-service-conversation.c
src/core/gnunet-core.c
src/core/gnunet-service-core.c
src/core/gnunet-service-core_kx.c
src/core/test_core_api_mq.c
src/core/test_core_quota_compliance.c
src/curl/Makefile.am
src/datastore/gnunet-datastore.c
src/datastore/gnunet-service-datastore.c
src/datastore/perf_datastore_api.c
src/datastore/perf_plugin_datastore.c
src/datastore/test_plugin_datastore.c
src/dht/gnunet-dht-get.c
src/dht/gnunet-dht-monitor.c
src/dht/gnunet-dht-put.c
src/dht/gnunet-service-dht.c
src/dht/gnunet-service-dht_clients.c
src/dht/gnunet-service-dht_neighbours.c
src/dht/gnunet-service-wdht.c
src/dht/gnunet-service-wdht_clients.c
src/dht/gnunet-service-xdht.c
src/dht/gnunet-service-xdht_clients.c
src/dht/gnunet_dht_profiler.c
src/dns/dnsstub.c
src/dns/gnunet-dns-monitor.c
src/dns/gnunet-dns-redirector.c
src/dns/gnunet-service-dns.c
src/dv/gnunet-dv.c
src/dv/gnunet-service-dv.c
src/dv/test_transport_dv.c
src/exit/gnunet-daemon-exit.c
src/fs/gnunet-auto-share.c
src/fs/gnunet-daemon-fsprofiler.c
src/fs/gnunet-download.c
src/fs/gnunet-fs-profiler.c
src/fs/gnunet-publish.c
src/fs/gnunet-search.c
src/fs/gnunet-service-fs.c
src/fs/gnunet-service-fs_cp.c
src/fs/gnunet-service-fs_put.c
src/fs/gnunet-unindex.c
src/fs/test_gnunet_service_fs_migration.c
src/gns/gns_api.c
src/gns/gnunet-bcd.c
src/gns/gnunet-dns2gns.c
src/gns/gnunet-gns-helper-service-w32.c
src/gns/gnunet-gns-import.c
src/gns/gnunet-gns-proxy.c
src/gns/gnunet-gns.c
src/gns/gnunet-service-gns.c
src/gns/plugin_rest_gns.c
src/gns/test_gns_proxy.c
src/hostlist/gnunet-daemon-hostlist.c
src/hostlist/gnunet-daemon-hostlist_client.c
src/hostlist/gnunet-daemon-hostlist_server.c
src/hostlist/test_gnunet_daemon_hostlist.c
src/hostlist/test_gnunet_daemon_hostlist_learning.c
src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
src/identity-provider/gnunet-service-identity-provider.c
src/identity-provider/plugin_rest_identity_provider.c
src/identity/gnunet-identity.c
src/identity/gnunet-service-identity.c
src/identity/plugin_rest_identity.c
src/identity/test_identity.c
src/include/gnunet_common.h
src/include/gnunet_scheduler_lib.h
src/multicast/gnunet-service-multicast.c
src/multicast/test_multicast.c
src/namecache/gnunet-namecache.c
src/namecache/gnunet-service-namecache.c
src/namecache/test_namecache_api_cache_block.c
src/namestore/gnunet-namestore-fcfsd.c
src/namestore/gnunet-namestore.c
src/namestore/gnunet-service-namestore.c
src/namestore/plugin_rest_namestore.c
src/nat/gnunet-nat-server.c
src/nat/nat.c
src/nat/nat_auto.c
src/nat/nat_mini.c
src/nat/nat_test.c
src/nat/test_nat.c
src/nse/gnunet-nse-profiler.c
src/nse/gnunet-nse.c
src/nse/gnunet-service-nse.c
src/nse/nse_api.c
src/nse/test_nse_multipeer.c
src/peerinfo-tool/gnunet-peerinfo.c
src/peerinfo/gnunet-service-peerinfo.c
src/peerinfo/peerinfo_api.c
src/peerinfo/peerinfo_api_notify.c
src/peerinfo/test_peerinfo_api_notify_friend_only.c
src/peerstore/gnunet-peerstore.c
src/peerstore/gnunet-service-peerstore.c
src/peerstore/peerstore_api.c
src/psyc/gnunet-service-psyc.c
src/psyc/test_psyc.c
src/psycstore/gnunet-service-psycstore.c
src/psycstore/psycstore_api.c
src/psycstore/test_psycstore.c
src/pt/gnunet-daemon-pt.c
src/pt/test_gnunet_vpn.c
src/regex/gnunet-daemon-regexprofiler.c
src/regex/gnunet-regex-profiler.c
src/regex/gnunet-regex-simulation-profiler.c
src/regex/gnunet-service-regex.c
src/rest/gnunet-rest-server.c
src/revocation/gnunet-revocation.c
src/revocation/gnunet-service-revocation.c
src/rps/gnunet-rps.c
src/rps/gnunet-service-rps.c
src/rps/gnunet-service-rps_sampler.c
src/rps/test_rps.c
src/scalarproduct/gnunet-scalarproduct.c
src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c
src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c
src/scalarproduct/gnunet-service-scalarproduct_alice.c
src/scalarproduct/gnunet-service-scalarproduct_bob.c
src/secretsharing/gnunet-secretsharing-profiler.c
src/secretsharing/gnunet-service-secretsharing.c
src/secretsharing/test_secretsharing_api.c
src/set/gnunet-service-set.c
src/set/gnunet-set-profiler.c
src/set/set_api.c
src/set/test_set_api.c
src/set/test_set_union_copy.c
src/set/test_set_union_result_symmetric.c
src/social/gnunet-service-social.c
src/social/test_social.c
src/statistics/gnunet-service-statistics.c
src/statistics/gnunet-statistics.c
src/statistics/statistics_api.c
src/statistics/test_statistics_api_watch.c
src/template/gnunet-service-template.c
src/testbed/gnunet-daemon-latency-logger.c
src/testbed/gnunet-daemon-testbed-blacklist.c
src/testbed/gnunet-daemon-testbed-underlay.c
src/testbed/gnunet-helper-testbed.c
src/testbed/gnunet-service-test-barriers.c
src/testbed/gnunet-service-testbed-logger.c
src/testbed/gnunet-service-testbed.c
src/testbed/gnunet-service-testbed_cpustatus.c
src/testbed/gnunet-service-testbed_oc.c
src/testbed/gnunet-testbed-profiler.c
src/testbed/gnunet_testbed_mpi_spawn.c
src/testbed/test_testbed_api_3peers_3controllers.c
src/testbed/test_testbed_api_hosts.c
src/testbed/test_testbed_api_testbed_run.c
src/testbed/test_testbed_logger_api.c
src/testbed/testbed_api_testbed.c
src/testing/gnunet-testing.c
src/topology/gnunet-daemon-topology.c
src/transport/gnunet-service-transport.c
src/transport/gnunet-service-transport_validation.c
src/transport/gnunet-transport-profiler.c
src/transport/gnunet-transport.c
src/transport/plugin_transport_http_client.c
src/transport/plugin_transport_http_server.c
src/transport/plugin_transport_udp.c
src/transport/plugin_transport_unix.c
src/transport/test_transport_api.c
src/transport/test_transport_api_bidirectional_connect.c
src/transport/test_transport_api_blacklisting.c
src/transport/test_transport_api_disconnect.c
src/transport/test_transport_api_http_reverse_peer2.conf
src/transport/test_transport_api_https_peer1.conf
src/transport/test_transport_api_https_peer2.conf
src/transport/test_transport_api_limited_sockets.c
src/transport/test_transport_api_manipulation_cfg.c
src/transport/test_transport_api_manipulation_recv_tcp.c
src/transport/test_transport_api_manipulation_send_tcp.c
src/transport/test_transport_api_monitor_peers.c
src/transport/test_transport_api_monitor_validation.c
src/transport/test_transport_api_restart_1peer.c
src/transport/test_transport_api_restart_2peers.c
src/transport/test_transport_api_timeout.c
src/transport/test_transport_startonly.c
src/transport/transport-testing.c
src/transport/transport_api.c
src/util/bandwidth.c
src/util/client.c
src/util/client_manager.c
src/util/connection.c
src/util/crypto_hash_file.c
src/util/gnunet-scrypt.c
src/util/gnunet-uri.c
src/util/helper.c
src/util/mq.c
src/util/os_installation.c
src/util/os_priority.c
src/util/program.c
src/util/resolver_api.c
src/util/scheduler.c
src/util/server.c
src/util/service.c
src/util/socks.c
src/util/speedup.c
src/util/test_common_logging_runtime_loglevels.c
src/util/test_connection_receive_cancel.c
src/util/test_disk.c
src/util/test_os_start_process.c
src/util/test_scheduler.c
src/util/test_scheduler_delay.c
src/util/test_server_disconnect.c
src/util/test_server_with_client_unix.c
src/util/test_speedup.c
src/vpn/gnunet-service-vpn.c
src/vpn/gnunet-vpn.c

index c708f91507d11cffceef091351aeeebfa82f5937..5fb2a811a9cefde27bbb4f361b7d2c4a0bd2e933 100644 (file)
@@ -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);
 }
 
index af85372d8ccfb6a17720a1f673aca95111199968..4501ed036c1f229f6ff3fe267ad06d7a4b4eba61 100644 (file)
@@ -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);
 }
 
 
index 9feb6e9c171f66b76f9d0d4cab1061e2ff45a345..152a358fc3550a032ef9786186181bfc52d772e7 100644 (file)
@@ -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,
index 149ec46c43bb0c4d59328643da711e12ca489dc5..f5283d714f80397f36fe04b7ec3e4bbce662b2f5 100644 (file)
@@ -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);
   }
 }
 
index 1032a90105fafc862fd562f20e172eb48ef4dc73..3f33c91e69b28760ae73b9ede6027fc28ec011da 100644 (file)
@@ -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))
     {
index 650be29f39661aceab619e1febc62de502717725..5e22d4b47ac41a18f5ef64ab82d50d783fa1b866 100644 (file)
@@ -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,
index 1e4b1543283a7715e8aae9e2743b593d0ac0d15b..d4c4f2cd920d5e4404ea70c44381688e8813a1b2 100644 (file)
@@ -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,
index a2ef80cef89f4da5f92ba4b6feb7bd8f25f218bd..5fc1d6e92e93181b706523d1934cb50c596ae8e1 100644 (file)
@@ -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)
index 7b8dfe2220a4a32a3f12b877e603609edffb7447..045a5bb67307748a0134526874e84a42a8af903f 100644 (file)
@@ -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);
 }
 
 
index 6894d2482257203a0fbcd5019cd87b582be959bd..d5b0688e633b085c04c588a216c896af3e807d84 100644 (file)
@@ -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)
index 47241292bc14ed6ae8850583b775390210467b73..0358d64ca27bde20a46043f80b01cb80571aa534 100644 (file)
 
 /**
  * @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);
 }
 
 
index ffa993f8e40c7c8e457574e36afbbc78a4ea2019..b2a07cb0c0814eb0e807df2e3fb190e51487625c 100644 (file)
@@ -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.
@@ -206,20 +211,15 @@ 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.
@@ -309,19 +314,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.
  *
@@ -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;
index 14b499aaee12f64fa8fb1e75459207120c76499d..6453392d85cea8950fa9f5aaf343e7d6b58358eb 100644 (file)
@@ -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);
 }
 
 
index a2e00300b6262454633b1943abb9b82d70d89456..3a07f0ee58e3de12258fbe4d85be84dc02e648b5 100644 (file)
@@ -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);
index debae7d7786dd8c6971ab6f0040ca7729e0cc80b..d4f9754da2315743d3dd0d75fa35502240eae61b 100644 (file)
@@ -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);
   }
-
 }
 
 
index d11368a79cd6e3d6361a69939e7e4571531b3cc2..188041feb235a536aa65c0f6e826b45c33bff3a5 100644 (file)
@@ -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;
index 088d40eaca32fcb4ee3bcc59de100e5cdea3adea..88a601b52e5a91a3cc0f00b2703dfaf71224e8ef 100644 (file)
@@ -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
index 51af0452777ac09eac2128a44529aec0595dd323..46961250b0ad6a43575cc10f19d54fbbaccec4b9 100644 (file)
@@ -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;
index 73bd28643bf9c3937e4fb1fe18fc502957032022..b9f0e1fa25f9ff13855c9592f02081b2503436c9 100644 (file)
@@ -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;
   }
index 39bfc5fed4b02b34621185c052441c8b4444419e..b3ded1bdf6d5e997f81d501da42ba63e90cededb 100644 (file)
@@ -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
  */
@@ -255,20 +256,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.
  *
@@ -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);
index 42663b146aa0e304d87fc7d7f34b580ee2c1e5cc..a17d8f1abc76ee9c66a3078c6fe323cf9fe1d88f 100644 (file)
@@ -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),
index 93a50c02c5c7353ba6868f7c3b8451014044a527..b9ab7e23a283782718c7005ce57ccfea014ad4fa 100644 (file)
@@ -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);
 }
 
 
index 82b05d136ef0101b27326341c12eac8c7eb51efb..99e7aca978a6c8199f71703aad61203ad3bcced0 100644 (file)
@@ -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");
 }
index 0073267f8ad8b97b16a646775c62bbf1ef26bf94..85707eed10625da9de5cf9484113b0dcd749b51a 100644 (file)
@@ -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);
 }
index fe6eae925ff91821a3105774d838b5ae1f98b4cb..815c7ef11a1332c292ac3c2998c95ccac3b59e55 100644 (file)
@@ -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));
index 9000bcf3f89d5aa35e18e123940004b7e2072a20..d899ee5ca920bea41c068d01c304cea194e9cc7f 100644 (file)
@@ -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);
 }
 
 
index fdaa2999c27067e5d1c21a5de293a7f8494d138d..10f169105391540a718c5fc7aa3e53be5a25ce91 100644 (file)
@@ -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);
 }
 
 
index 968072e228b43dfc8db979ab0bde381817f7d783..d91dc304d5c1b88152b44f994e958f9d221f9fea 100644 (file)
@@ -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);
 }
 
 
index 1d9de86665686ce29209f8c4a27accb02db60a31..70b83b24cdc067e7d5e20fc4962084ec90cbe1be 100644 (file)
@@ -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);
index 8250bcc6f205f3529e6c1afa339bbc36772e4213..9bb5af100720928cda164ad6fd10389206ee2fe6 100644 (file)
@@ -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;
 }
index a82465e74cde0bbe88012b9a0d21ceb35f3f526d..8ece78e58b27c0e005bb75b7da8d608ea70aa1d8 100644 (file)
 /**
  * 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[])
 {
index ed895df423ff3d453e791f2785c23cedf5b20b04..e28f57fa6099f4d09fdc8336cfd41baaa0f1d14b 100644 (file)
@@ -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 ();
index 4bdd030397f08515e48e475c7069ef438db7dfc3..9867ba6341d9747aea5edb3a24cdc597b450e3bc 100644 (file)
@@ -17,6 +17,7 @@ libgnunetcurl_la_SOURCES = \
 libgnunetcurl_la_LIBADD = \
   $(top_builddir)/src/util/libgnunetutil.la \
   -ljansson \
+  -lcurl \
   $(XLIB)
 
 #check_PROGRAMS = \
index 186889e4cdc53c8953a6ec481eaf3d131a850d21..ddca4ee06b596c1e19aabd086c16e56fffc1391f 100644 (file)
@@ -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 ();
 }
 
index fdccd925eeb4115007adfa42b3366f604cfc8acf..6ebfba7fc91b713ab5dcbbcb94451196fa2e6dd6 100644 (file)
@@ -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);
 }
 
 
index 41cac1283872ef6bfcbe0a5a1127b5556245e684..97774198c3b3070d168b555697979d95c0be036e 100644 (file)
@@ -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)
   {
index 0aeb426abf7269252ebfe5d674d7f5313430ba9a..cbc01844e5aa1ad63be96f4ae29218138186feb2 100644 (file)
@@ -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)
index d7dff1041ebda5b7d3cb8408eda0c282ffe3894c..9ec0c53a22033a90cc59c5b409d53c376fe0a1e0 100644 (file)
@@ -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)
index 6846b3af7686068c3d797bea373546b6e018d923..8a1b836f67798fb1acaa51493fdb77cf38531ffc 100644 (file)
@@ -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,
index 0502496d7b8b32a12d9b97c9e4a194c295806822..7f14255d320cac38a35ff780add5d092351071f8 100644 (file)
@@ -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,
index 19e385be1035a4904b919df67b5e9607d822d211..972369e102b1ff7e380708e6f197480840fda2be 100644 (file)
@@ -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"));
index 1aeca9b85cf18812508b0529a5a4b7d3be71bcb9..a44be2dfe6bc50580b3e58275606a01544185cef 100644 (file)
@@ -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)
index e42069fe0a5da7c3f6767b33bdfb7c11f15f5788..a5757c25a33c2732c28c806de07d00a761d75d54 100644 (file)
@@ -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;
index d82effb3433710c3066eff648442819639afc48b..8ab39c9aaf71d132c8ec3c459197e416b82004e0 100644 (file)
@@ -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.
  *
index 0668c9078fb8f0ace83ad49fa852e7f0c3a1cd62..b58bb729d514835fda4885181c6c62ec84f71e27 100644 (file)
@@ -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);
 }
 
 
index c3aff03aa33fc445db866d8d71ce4d3b817d890c..8eb114660fe4e449cef5f52cfc3a177cef05a0f0 100644 (file)
@@ -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;
index f6c7c516709c622cf00acefe71515a6b121c7a6f..8a60a8d9db496c157233a3ba865fbdff95c23ce9 100644 (file)
      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);
 }
 
 
index e08ccf792b999159e9640676a5cfdd677a8f5ac1..3475d00c969cc0b4f6e70e60eecb4fce502ce6a2 100644 (file)
@@ -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;
index f0c4ec7bec125012826328fa9c796a5092951f61..03ea62152960755f11fce5b84c7d33ebef4f705f 100644 (file)
@@ -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);
 }
 
 
index 957777cba205feb18b268efe866375c1001bae6b..c1e7b5f617b276a5f926577e46a6ee56688be897 100644 (file)
@@ -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;
   }
index c9d8403259b958583a7e8802613b667e961d5129..5e6f90555c75b14b3e299d08d9f72c284d18ed5c 100644 (file)
@@ -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);
 }
 
 
index 8ef69eb91708632feb73f9f491870ddafc1221c0..89929815a2e9467cbc03af0ca544211f43322e17 100644 (file)
@@ -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);
 }
 
 
index 972c96f6df7cce52c5437b5efe526ca2a26ec703..b580f433fc851872a83b400c26758eb0e09bc4ec 100644 (file)
@@ -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,
index d5d95acca4cd9b8f040cc197f56e97db5e957181..d0917d3631bd15086b44ffbdd15f7f84d4597ee2 100644 (file)
@@ -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);
 }
 
 
index bd0057ab47a2c37027e27666dd559f03643bbfe6..df95fd67b36f5498ffdb72ab5bfbfba2325f231c 100644 (file)
@@ -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);
 }
 
 
index 1afa30fa9e3288dd8a0e011d24202e6d0a42d371..0a43252a5cd883022bb870e07fad93471c5a0bc5 100644 (file)
@@ -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;
index 8456018abadbd1fe637d566e4928ebbd594deb32..f31e11d8331c7eadb575ca65aaf792c3ed38e8f6 100644 (file)
@@ -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",
index aef66614cee22626655054fe1fc6dbac2e396d1c..96f86bf5d43c3347ed01b44ce8336dcd4026859c 100644 (file)
@@ -94,11 +94,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.
  */
@@ -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);
 }
 
 
index 326178df9004c6c3c7a9650f9b0ea17a364318fb..e6bc33e1059258a3eadca5bba5742e6ac4525b26 100644 (file)
@@ -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,
index a2b0aa5fc6618e928fa247f35da70d7c4ae12dc4..6d9adb8abe46db55bb120291db753818d0683da7 100644 (file)
@@ -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);
 }
 
 
index 69433346f95a1c786dc57c212610dcf0d013b455..cfbe57bbdbca4a40b9295900e33fd1d41203afe5 100644 (file)
@@ -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,
@@ -122,6 +126,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.
  *
@@ -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);
 }
 
 
index f058c10b2fa0c1b07cb948d6612e3e4e0395b3f7..a563d7b7a76d9e1c9baebde7ce73f9d5335aa732 100644 (file)
@@ -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,
index a15d0d883a65595f5209d118366f230d6120d2e8..0ddcd892ee76a15b2635bd86043280a1ac117e61 100644 (file)
@@ -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);
 }
 
 
index 2ba96334c13c34101d25f2632f5996395cf16200..348bab09276536aed5b418a1cf9f415b69e6aa61 100644 (file)
@@ -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;
 }
 
index e916a73a8792a726ed8e2cb9e543d8b2aef56909..53838a542cde00d52a38c05305da424720d0f001 100644 (file)
@@ -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);
+  
 }
 
 
index fa5aa461d698b4da25aedfce3c91778ba102b793..045b640db8682724625db38ba85d9f37d10f0804 100644 (file)
@@ -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,
index cab963e0d532c18b701a73d2e8a0766901cf218b..40fa13b629467a92350e6d9d4b6cc26e5ef0d2cc 100644 (file)
@@ -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);
 }
 
 
index f00290b0d3fde87b38654d2e93c9bb95d9c65c07..2ff495ac35f7e7a5db8a0cd9c7db6f071ff3ba1b 100644 (file)
@@ -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);
 }
 
index 6696158c9c9deb74f1d2e5530d0541efd313eb04..a1fe3680aba4ff888880c533d56f02c2dfcdc968 100644 (file)
@@ -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);
 }
 
 
index e7be8fd841b434fe55d37af77d52e0fe88f72526..28480417523d7a61976fc5b2a0f8dc06519c62c2 100644 (file)
@@ -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);
 }
 
 
index 119bda91a75be2305c72e508ce4c5a8b8470bc0e..df3b4e88226457a49365668a126049a7cd56d4a0 100644 (file)
@@ -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"));
index 112bcd258b5e2092c1094b8f5fa1e7c3b1d83c05..c9c9e3fec7caca3117203391c1b580abf06ade74 100644 (file)
@@ -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)
index 5f94e779203ffb2c091cccd1397fa3b31cbc3faa..e98babfa8a4fda2bea31730afa468be0b979da80 100644 (file)
@@ -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);
 }
 
 
index 9a34c83af4607d206ccf7a24ed860d7f13a70273..6793d6f5c6e5cd7b7c217e36cad7b240543f4e6d 100644 (file)
@@ -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);
 }
 
 
index c8310db4635e55957294ba7e68a07fd340e5f386..62cec54cb1065534c0b332337ebd420b52870cc6 100644 (file)
@@ -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 !=
index 87b0fd04e276a59bf629a1a4884290740483e7b2..682d8f5f7059b7f8617892cb54a55628c74d8f57 100644 (file)
@@ -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);
 }
 
 
index 8a3f2604185f8bbdd56c942f1679db0d97068cc0..1315e6cdaa47a10280457a6447a0bbd8a0d9f4bf 100644 (file)
@@ -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.
  *
index 0afc3ea0b7e97df52c1ec7dea4b1cec114297ea4..55ada84d775fbc3c5890de0440e4d3494df5bff3 100644 (file)
@@ -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.
  */
index 6a4689af1bebc4f9166dc7be69b367b19827033f..21fab323b9d48293b1123b048601614e83c00f20 100644 (file)
@@ -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)
   {
index dbf6eaedac71f1654e73a812792b35b244dec0ad..15a82c2d543c29f3ec705b469450857e38963643 100644 (file)
@@ -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;
index 6e2cb7ee4663bb218cf39d32586b66de1816f0fc..5b45af831dd41f9bf661a05e1b2261828e8cc2aa 100644 (file)
@@ -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;
index 2f99b887d0e97ed92f2113750bfa63c3b5e60184..5f8ece9b8d5cbc735915a6e67295e160adcead59 100644 (file)
@@ -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");
 }
index a71b8ecaee3872322b69affca1f36eb155fccc60..717311be74dbb03c1d7bfdac50638997429ee49d 100644 (file)
@@ -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;
index 0af16e06597428509eb512915fe2309d71b028f9..562eec55bf72a4c52c799b2b7fa580c304802216 100644 (file)
@@ -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");
index 59e678b243477084eaafe7a4cf711d2c36061e67..0bb400e07bfc58107e5e1bdc56257de1651b375d 100644 (file)
@@ -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 */
index b104950bab07bed9d677f0abc0acbd007a725a1b..376110a6d2d23bc89ed267503b5500d5caf03c63 100644 (file)
@@ -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)
@@ -341,6 +341,21 @@ do_error (void *cls)
   GNUNET_free (json_error);
 }
 
+/**
+ * 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.
  *
@@ -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");
 }
index dc9174d21ccb6c59ca89d197ce3230d214fecaeb..23c20d91fdb512803866fb79e44adbebddbf332e 100644 (file)
@@ -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 ();
 }
 
index d36319a99ab89e60794a7cd4fc94f9da1ea5272f..9185aac64d8b757bbc3df4990d9845c52c31a247 100644 (file)
@@ -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);
 }
 
 
index 22ade6a0e5b29e7bb1bf21fac62b5b813883a809..5bed8af55af20db439d67cc3cc23ca445183e565 100644 (file)
@@ -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);
 }
index 6eaa86e919506502a6478608e7ba8651af42f190..37065ce089c903914f4da93be910e71dcffd65d9 100644 (file)
@@ -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);
 }
 
 
index 3d7dede17afa9e861c23caf617d15c47da02a4d5..89b69278995dc3ca384e834b1dc449cc781fc823 100644 (file)
@@ -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
 
 
 /**
index d9b63775a82366e5c85d8eb63a499a3e8b65be7f..87cb3b6f146af35ae47de69cc8d7e1ec439baa68 100644 (file)
@@ -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);
@@ -271,6 +269,21 @@ GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_TaskCallback task,
                           void *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);
+
+
 /**
  * Schedule a new task to be run as soon as possible with the
  * (transitive) ignore-shutdown flag either explicitly set or
@@ -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
index 8041119b0716d6170711de7c417ab566a1c1fdae..f157041bc0f9d0ca9575280e6dbf993d8b1f3f93 100644 (file)
@@ -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;
index 9550b8894ec590fc3d7665797b9e8136223c76b7..9e042d61b9229d8f0781e066ef89fbbe2754765f 100644 (file)
@@ -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);
 }
 
 
index 6abcb7b921703667619fbf14506a473feccd5f38..490197b1e90666f87ed573954c64d7e5f87ea96c 100644 (file)
@@ -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,
index 81b1cce9bd054a4470eab414750b082b7ab85330..e01dfcdf30b10a4d64abfbb7b42d163d9c4efb04 100644 (file)
@@ -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);
 }
 
 
index 5522b207d6784e1eba60d69bc99a03c53c7a945e..7b0e6e31853543b5edcf3bf791a08cda7432bb74 100644 (file)
@@ -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;
index 82d73f6de27107f82bdc8c0d67c2bffe6f83838a..c2f506f6d3b8cbb9bdd5cc1a53377ccebb615ea6 100644 (file)
@@ -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);
 }
 
 
index 0965d8cbeec5ffc4921fb4aa3035650dc848eb73..90214e9d64517d96fb0cb09000b30c7b5f605933 100644 (file)
@@ -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)
   {
index 0bfd002f534d7127b686d90435546bfd190d5547..4be55cf9ba91faab318246e1fb6016437033b30c 100644 (file)
@@ -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);
 }
 
 
index cfebd63a7b13f2319c483428069da5749aa5a110..4612528c66cbf0e432d48edffbd6079ccb180077 100644 (file)
@@ -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);
-
-
 }
 
 /**
index 0069303ca9531c3a2cc80a8d27fa61e64f008d83..db51ef89a347b27f0c3b3b9036c70a375b4b671d 100644 (file)
@@ -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);
 }
 
 
index 1c60e4e0d10bf2b874800d6667ee1d2993e77b4e..042a0f686b55768c89f5711c634acb7f66381be9 100644 (file)
@@ -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);
 }
 
index 82e067f73319e381402f9b3d9d682781a80eae4f..4611edc6296d7dedd7141075046084f6dc1826a0 100644 (file)
@@ -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;
-
   }
-
-
-
 }
 
 
index d310b3e14432eb2ace82eaaa55ab3b2c55f38fcd..915bcbdb691aba2b330b6271f6a5905e63cc8eff 100644 (file)
@@ -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;
 }
index 33f81d80041442fd487e02b633e6236602444942..b2f22781ecf67d61779ddbdc0d8250ba7bb948de 100644 (file)
@@ -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);
index a840f3ef964e5bd7f07e2402d5e54a74b8704e0f..fd67473ee352b46fa626d3cda8e7549a2b8047bb 100644 (file)
@@ -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);
 }
 
index 5b893ae474fbda2f8814eb3ee9f03a59580c0804..48afd929829c0eb2f064468e7ff75727ca10ce6f 100644 (file)
@@ -176,11 +176,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.
  */
@@ -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);
 }
 
 
index 97c3da29b10dd33079b83c1977d3418ea1c14504..840b8e64df304373f15f526025c433c6f1ea1f7e 100644 (file)
@@ -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);
 }
 
 
index 608274ae12646ee24dbd37751d13645824681f6b..d4098d1bca55eb8213e4b1802a092e2ca337f52f 100644 (file)
@@ -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;
index a42dcb369d5fdb9056b5d8dde1a86ef09f7afa8d..1c260d537aeab0632418b21c792cadb49ef84487 100644 (file)
@@ -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);
 }
 
index 5e6c31e6c2e958a568f8c0ebd798eb1736c4a30c..d6d63778e49b6db05dca3f4dad1a082536a0bb1b 100644 (file)
@@ -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);
 }
 
 
index 8cfb67a7393ffc8aaceba8bf0ce6fc560bf1aa59..5f28fd484d015ec66ba7dcbaaddb663dfe4a6509 100644 (file)
@@ -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);
 }
 
 
index a0defb8ccdb32c1d5ba697f26281c4da72d01782..66082e8f783a1565382a0150466926baaea0aa47 100644 (file)
@@ -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);
index ad4576fc23ab01c0a4e326902be408b6b06bf430..0637eda7297782e9228b9e2a59adb08836b46da5 100644 (file)
@@ -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);
index 16331548d12e46bacd95a8597fd28c868240598f..2a80c6c1ac2142fd4e1d7c495042bb092711e1ab 100644 (file)
@@ -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);
index d0322713c15f7259dca65413b8ec1f8516a654c4..403ed4b71e931f24a25850e29b292df0df9eddf7 100644 (file)
@@ -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;
 }
index 68ae1746f2141c0f8caa21bf28f1fa74ab328fa5..25a4f0ff4b5b593e6c0f6ce5fb4539e9c2ae6f7f 100644 (file)
@@ -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;
 }
 
index 3a2d928e38e4e6b8f6e223242a99c6665cc11497..048201c776ab5ac9cfcdf2d8ce6ccbdcc34e1edd 100644 (file)
@@ -90,6 +90,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
  */
@@ -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);
 }
 
 
index 14117a333ea3e907961c4933f11a7bc9b22e17fe..f1c5ccd3228e5ac40d744ef0096035bbcf599728 100644 (file)
@@ -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;
index 2b436aa214008e1ac7dbb0a18f5b262c75c0efef..0f221642811f85059a9eeb460a11bc7d6b5995d1 100644 (file)
@@ -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);
 }
 
 
index 1169b49d5f11a6b529178a865c1b1c07511a47bd..5ea83dd63a7b5e77868ac84b1cea00f1e5e9bfd2 100644 (file)
 /**
  * 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)
index 737cff42279f88e55a55e004c7b24db92eb94b8a..e02f7771497e848b5d5bce11f157493a7dc1a946 100644 (file)
@@ -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);
 }
 
 
index b8f00a41ce8017ffb20681e12daf7419f20990de..234218fbaf38ae9418204a52736e97d0dc017e1c 100644 (file)
@@ -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.
index 266ee5c1de6a27b00d40ccad01885e4ac67b3451..2582cbf3f859aa3cdc4638496ced8c267bb3720e 100644 (file)
@@ -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;
index a86cbd31694c8f2f3849445cefaf557b091403e7..02c0df3cc7d4d06ae2b7bec51cc440b163de8ead 100644 (file)
@@ -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
index 85b28fbf85c6e23dfb4d09145a84549bf59bb814..df87da30abc78eed3cbef05c94fe645acf712b7c 100644 (file)
@@ -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;
index 1ff3b55e36fd194fca671a69e5fcad68ff612a00..42fc8ace0f549bbc7d9d99a1fb4d17afdcb68de1 100644 (file)
@@ -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);
 }
 
 
index 5938c99b18d9284b5f625fda6e71b4f5b8421f91..db5432845cfc19cce3233a19afa326f8523bf763 100644 (file)
@@ -213,11 +213,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
  */
@@ -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++)
index 27dfa773d32ea3689f4e9d1db667db1451bf39ce..0f955f7b5cc5ce00af782a2e56237a82e876667b 100644 (file)
@@ -88,20 +88,10 @@ 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);
 }
 
 
index a7087653433152e8e201a9a1b35add0ba79e4006..530e4f3584195a4601cef28a756339c611473e9c 100644 (file)
@@ -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);
index 705fcbeb39bb25bb42ab4c50cd8e96dea9c0fbb2..ffd65228a779c32a2e4eab82177c18c2ed7f7993 100644 (file)
@@ -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);
 }
 
 
index f68c18aa4f965dac4b0efc526e24e8cec9504047..5e983a07912eb2a577783b46b2d3662e14c95996 100644 (file)
@@ -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.
@@ -225,33 +230,61 @@ 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;
index e41195d5590baed7753a346cb6a141dc6014ab86..9f3162690e6df68f35b57a4bd5b0f6edd74e7aca 100644 (file)
@@ -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);
index 01be2aeb3c02dac5a61e5eff048bb28609693cbf..705c2c9b0609ce258f3e28e05432561b5cee4ce8 100644 (file)
@@ -45,12 +45,6 @@ static struct GNUNET_RPS_Request_Handle *req_handle;
 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
@@ -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);
   }
 }
 
index af06cf1bdfe79c073e6d76d06a13760a10f382e4..91d4840bb76861e71ee54eb43335f3d68ceea5c3 100644 (file)
@@ -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
@@ -183,12 +180,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.
  */
@@ -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);
 }
 
 
index e5f6595bbb99078277e0b1c8c2806e22a99c86ab..2ac6054f4934735a4a3bb912faa18d9653546b0d 100644 (file)
@@ -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;
 }
index aca58d55e2b5aae92636a277ab55fd7b797780f1..128a81f218634b49ab818d4a955b47da037fe1ce 100644 (file)
@@ -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,18 +256,11 @@ 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
  */
@@ -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);
 }
 
 
index 5811ee57b2754c144123636984d90f56ac1c3595..aa894b61d644f44f6a6d6f0af53c2acacd4400ee 100644 (file)
@@ -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;
 }
 
index c22b4e09e49f84603745553e4026895ca25e93d5..7485d5de1168d6521ff3e1b2a57360e716df31d8 100644 (file)
@@ -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);
 
 }
 
index 41cf7d1a817ea257b73ea284efb1977a18242e38..3162d125244e21b31fd8c73381354d09d19f7d9c 100644 (file)
@@ -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);
 }
 
 
index 0b7ba00d5793175691380ccd75dd0f1caf16e828..7eb2d006ca81de7f8742c1203dc6239a8f31636b 100644 (file)
@@ -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);
 
 }
 
index c9db1e9ae94d3b76dd7762f942a89115f14d0660..8d97ea1b658d36f4a593d4a1e4329602fc675456 100644 (file)
@@ -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);
 }
 
 
index 917431df46fc4b27cf5f6ac2f248e705bdd0fd7c..34f959d1ae1284ce004bfd2145ae79630d00e19b 100644 (file)
@@ -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;
 
index 6babe209acbc66a943474f96bd48d910dec9039e..a264bfdd5cad2a2c455f3b6c19a4ac3601d3709e 100644 (file)
@@ -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);
 }
 
 
index 5057d5c3357fce5a5e27639f2d7d8016ed4dc0ea..341a33b847b8d0289c15254430ffbb589a9422ff 100644 (file)
@@ -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");
 
index e9555928a2ece493d0025b1a64c3bc3751227038..2aad6030949241d900742eef35e668084da03f09 100644 (file)
@@ -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,
index ff76b27ce32150f1bfb0bd41138c6cbb64ba84c5..186a2763e2fec6fae34785d3d44943ab92dfdbf8 100644 (file)
@@ -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";
index 7721402698580fbcb405401c61a12b9e7fedf3a5..794ae57b774955197e69c9337261c1a0c2ac9e72 100644 (file)
@@ -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);
index b5c21f8a34f8c2566a6185f8b555bc1fa30f699a..d04877b39744852bd52e18b43c48971f56796dc4 100644 (file)
@@ -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);
index fdf6bf9df3848f5bd496e673074c62f0c70c040f..7fedf426b99f781358b8df404759730b1402c104 100644 (file)
@@ -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,
index b312bcb4c2c0a676f07a567f7f433dd79fe15ed3..77fec71c66be8e007c0bbab60c49abd360993fc9 100644 (file)
@@ -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;
 }
index 1746a82ca536d3c1d8b237381e7faff5cf38c8bd..03a113d7e768b2e2dfeb9c16fb16877c8a13ec62 100644 (file)
@@ -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);
 }
 
 
index 5eeb20196f9b9d0e05f5414c4f333e27f0cffe3a..e2639f4d6c4ca4f05ac3e1c44bd10d620ae66d24 100644 (file)
@@ -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);
index 0126f149b49036a17d68f6d585f04746b3a6ea17..adec5a96d5173fa7fdd916adcbc2af5eeff188cb 100644 (file)
@@ -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);
 }
 
 
index 2bf5959e321c20b16cad06a7620e748b538438fb..f21da6059d66489cc2412c663a3fbce6d9715019 100644 (file)
@@ -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);
 }
 
 
index 2b491df72ec663c1431d066633a10ced691d9c64..32b973eeccfe8af5ab306a6a7ee536c018af0625 100644 (file)
@@ -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;
index c7fe54b1fd36955b82af90619ae773a7a9683eda..9b004d1d52966de4aa5262996b0ea11cb75e5f69 100644 (file)
@@ -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);
 }
 
index 556d44bd8f7756b1556e0468f48d527a5dd0a5fc..6ff63c073fbd9abf0075bddb0fb4bf9c1b69f334 100644 (file)
@@ -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);
 }
 
 
index 9652721a100557989408e24545001714a0ff6c6e..b2c7b1043bef5c58fc9f102347e9bda0bce084a7 100644 (file)
@@ -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);
 }
 
 
index 0e0c7ebd506cc37b8a763b7cb6af4c1473b9a873..0cb83aacfdface0c2d490e3c5bea9d5de4c2e417 100644 (file)
@@ -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
@@ -80,26 +75,6 @@ static struct GNUNET_SCHEDULER_Task * shutdown_task;
 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
  */
@@ -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;
index ce0cc46d9747632561174605a8fb53c1129bb820..663ab2d08c082ba56c006ace1d34f9d864975b3d 100644 (file)
@@ -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;
 }
 
 
index b43f109830bcb1bb7fc48bd2d251364d0f9778ed..e27e21588d4631f88ac333c21bf811d983781c56 100644 (file)
@@ -124,23 +124,18 @@ 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
  */
 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?
  */
@@ -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)
   {
@@ -202,18 +200,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
  *
@@ -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);
 }
 
 
index 281172cbfaefd8077794979ba7870bc08c455966..ce52496969f3bb793e1e72e65fbda33ae749836d 100644 (file)
@@ -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
index ab5b17460be2369fbcd14c50f4f39f933b3c3c72..0f9fab01bf20e3d4febb0a9fd490efe3af8fdc82 100644 (file)
@@ -80,11 +80,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
  */
@@ -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 */
index e4fe87fcd000663d0df6ca73a1d72bde4a744913..8a286742c60688c369dbc56394dafd4e1468ead9 100644 (file)
@@ -129,12 +129,6 @@ static struct MessageQueue *mq_head;
 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
@@ -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;
 }
 
index cda669caaa86fa61145a4ccf5726be3a8bffcd9f..ae49e31f9ecea6344575139c153e6839612ff704 100644 (file)
@@ -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) )
index 34bf8e047e63992f2f22c7fc778604457d2db0f3..55dd5cad944999dd33b908de568b744a415ef1e1 100644 (file)
@@ -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)
   {
index 308ec03868a7c96e8d3afd9df3d17318186bc640..9468b3c91e4f1e75bf4502e3c0b798aa2801d7d0 100644 (file)
@@ -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 ();
 }
 
 
index 191f658b7589841b0e93fe16382df0a8f7ae1746..d69812cd2020ce8ab06ae13efdd73e540cf093be 100644 (file)
@@ -55,11 +55,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
  */
@@ -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,
index a728048f330eac976284cc4ce5802e895c1d813b..0ee1fc5669996f3d10a4c24adb73545a6298d713 100644 (file)
@@ -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;
   }
index 2141dc46f30002cbade38d5c2178aaee32143214..0999020a8352a39b4e171e19e683a456343d322a 100644 (file)
@@ -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);
 }
 
 
index 10beebc1f2e9c68b640a0b119af806d71b102c6b..45c9f5adf36cf12785fdf87657f7be012797f440 100644 (file)
@@ -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);
 }
 
index 30740c94df5e5ee03f3076b6d0210ecfd21d0edc..f140dfbadc88c0a0fbad48efecacc6f1e76842f0 100644 (file)
@@ -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
index de99fb5a3159aa9919991784673dce2fe7ad08de..b3b2c3987ee43eb6a1ea126923e672fe71eeae1d 100644 (file)
@@ -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:
index 92dd17d9812fd8d6d64ae146438b21852f1266f0..07f1560cb9bcf0c164f93f5f4acee5da7dbd7eb0 100644 (file)
@@ -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);
 }
 
index 1a6c163eea22d8f355656d6a8e765e60718f66c7..eddac8c8ad01e35fcb443cb038f2550632160ef2 100644 (file)
@@ -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,
index 9fde3d83e66e48b0bcb7e4afd9f85aadf718871d..119e5e5643422b22bbf4192f0b9272f371a5092b 100644 (file)
@@ -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,
index 836aa418c8fbe7483f8b4c108af79da68dced3b7..6ea5394bf7c4afdad9daaf00b9451502f7b92140 100644 (file)
@@ -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)
index 624d1a16cb5f3d26fb04d45771db734d20d2967d..af47c5c567c4c7da16ed597b6f98a5f24181a2c9 100644 (file)
@@ -145,11 +145,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.
  */
@@ -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);
 }
 
 
index bed9bdc8546b782d8039318b0ce88f0b128f38cd..cbddee9055345b033abe53978c3ca0ec66f4e416 100644 (file)
@@ -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);
 }
 
 
index 2b0b8939e8614f9b0284522d98ed34cd0b5f1e40..13240679930ba07f2d0d392fbf4dfaab28008b17 100644 (file)
@@ -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);
   }
 }
 
index dfd0294e57abd67210b73630bc7ae5be661f1957..c43124c2e86652112a7c896603f0a61704b30c80 100644 (file)
@@ -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
 }
index 89feb8f5ce5c510bfcd80b3ce6a19ddaa095aab6..b5706f024aed26e395730e0cc6e06eed9a23c39b 100644 (file)
@@ -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)) )
index e320785d418cb56b7db1e8c341f9ba999114872f..d0566c2d30636d90fb8b8aa73cbe623b1f4cb666 100644 (file)
@@ -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)
index 13333b37163077dc70f3878ea45fdc537ef32c6a..528b8f2bf2fd5edc878d12a0777cd0525ba0d6b5 100644 (file)
@@ -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,
index 1e00e982d9071ad5e4b2d0209746aedd25d58ceb..a5d6b6b710884ba6a6855dd9c5272531893bc468 100644 (file)
@@ -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);
index f65fb74f9553c418625ac131edbe45a4ff033632..963d3b0454afa8868ba44d67d97dab717e56d365 100644 (file)
@@ -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,
index 36497ece5592c6cb2efef603ca1e4c64e5abea15..f52634bde2d993e47fecb6bea461ada73c4b0dcc 100644 (file)
@@ -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,
index 7117895efb626158dea7ad13fbada9fddd03f2d6..136c09008bb6ab33a53c224d9429e87bd45294bd 100644 (file)
@@ -10,4 +10,3 @@ EXTERNAL_HOSTNAME_ONLY = YES
 [transport]
 PLUGINS = http_server
 
-
index 8fc2edf2ee0551f98d2562eac8c2eb5d0da145ff..c6a083f3704f41f1fa0d8fe5e0b4baeddd7220f5 100644 (file)
@@ -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
 
 
index d2bf200119d3be99b0f60fa6b8324b0ef76f718b..49210651c484a982a7c3e0b8ea911ea27cc2c82e 100644 (file)
@@ -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
 
 
index 8d875ed52e4ea4ef84096e2a14f90eb735f6d6df..0ae807077f5cf7eac79751be471a587df80fede3 100644 (file)
@@ -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);
 }
index 915b7971930a1cb828180300c55bca3a20d3eda0..fe3d31f7bb0a50043ccac7102935e6ee19fef151 100644 (file)
@@ -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));
 
index 7b82236f9ac29ff6cbf14a38c52bc548a84f35c3..02c9408a6d2f6dea44e2482da26205df166e3ea1 100644 (file)
@@ -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,
index 22b420c279667949966be990fc4b4972a2871ab2..e031b7111eca57f5c086df1ea49ffae416aeebfd 100644 (file)
@@ -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,
index 79b39325c8a64f2557d1664dd26900bde8bb46cb..549394944eef6a406cf09a03ef2d5a1ef0f0e0dc 100644 (file)
@@ -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,
index 37b8494f120663c4f3a7e5b10ce40c52b10c2865..49550e0116ba77ac1625998587b63605050711ee 100644 (file)
@@ -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,
index adec15f4f5c204157e95a33c256aa91a07ac250d..50f9ebb9c8fb5e15e7c2650150b57dcca19fb01b 100644 (file)
@@ -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,
index 2a669c9a02dd7e8b4d75ecab822ca93fef0de7b8..18cc87c788580796ecc2cc8d3a269d803183b4a5 100644 (file)
@@ -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));
 
index aa9884a2ebfdd4c33ed485fefeb403106d8d83b6..89fabdefdc4d3d076e5558e539305710107f7e84 100644 (file)
@@ -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)
 {
index d49e3a8c026ba3f00e5363c12af8cf5ea0abc5a9..7dd4984e23a053416cc77f592742da6cecc667fc 100644 (file)
@@ -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)
index 652a4e08f6f057657744e9df04cd70e708fc85e1..4a514ea724cbfe404b15da11bd8524c1824641b7 100644 (file)
@@ -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));
 
index 6fc538f25588f647f451e928c541f2b8d57345a2..59f249686f19d8fd621e0d0df9170c38a79de4b4 100644 (file)
@@ -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);
index 2df2a9449f2e111528160c017fdab0a74c506a42..364c469779e170d69ec64847c5cd455b9c3128a2 100644 (file)
@@ -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);
 }
index f93fd1d109e710e24d24d114dc6a30a8317031cb..d00e8bbd0622110b2c89a6758f791b6e0fa2e6df 100644 (file)
@@ -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);
index f334bb5b61ba1d5e9bc3e1a0e9a5bce7acd95896..0268378413b83b1af2b52c245af4188461c18ae1 100644 (file)
@@ -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);
 }
index b3ea3b5af60150457b7c05d820a4f4638e7bf523..95fbb13f8b4909d204765767e5266a7ef6861e9c 100644 (file)
@@ -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);
 }
index f2d49d164394c71c8f848399760210d29d891169..ace5212c9d9c4d986edbd6d6d4789d35ce77620a 100644 (file)
@@ -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);
 }
 
index 7449d8042431caeb066bd72b72532574a677f0e3..6fd871cbeef49ca3bca5f742438c709e0eb20756 100644 (file)
@@ -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 ==
index 75e70d2b754cf66b9930891ac346971ba8ae4418..f69508f6728e19fe8436c52448fc3f9841527e25 100644 (file)
@@ -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;
   }
index 3ed1c7276f040190f63224d1c7d5795cd6530cdf..ecfe4ccfa820ecb5912c9b759bce122e3e6598d8 100644 (file)
@@ -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,
index aff9f465c0e04e2ae7271dbc0584beb1cca284f1..6f8c042246af8be124bfa4a904f2d7b9c0219553 100644 (file)
@@ -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;
index 161b0535f6217a9bdaa6e2ff358e3e5b21270d10..a0e8647a1211bce37fe0fe4e7a7487cfbe27a73c 100644 (file)
@@ -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",
 };
 
 /**
index 8dfec6c5e8bddb208262abed9b77ca13cf21e5c7..2a6ea8321005ae00df08b3dd0a5a7a7cd13d79a1 100644 (file)
@@ -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;
 }
 
index bf7885fe91587655da23e14eca26865733bc6f94..72f6a1e6c8158e4535a7a2d75dc80eb8665455c7 100644 (file)
@@ -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);
index e7a836f03df1f628a5cadec766d960a246ea7cc0..0488d6a3c1227c2fa3e7e4054ec8647d3bf875ed 100644 (file)
@@ -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:
index dcf5aeeaa4e188eb0a24c26faa1e8f5f59788943..81f968dee073732b6ea2b22d6df71ac057d7257e 100644 (file)
@@ -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
@@ -151,6 +151,11 @@ struct GNUNET_SCHEDULER_Task
    */
   int lifeness;
 
+  /**
+   * Is this task run on shutdown?
+   */
+  int on_shutdown;
+  
   /**
    * Is this task in the ready list?
    */
@@ -183,6 +188,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
@@ -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);
+  }
 }
 
 
@@ -522,6 +530,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
@@ -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;
     }
@@ -997,6 +1018,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
@@ -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;
 }
 
index 8dedd28fd93659bd6065e9d9570e886b4a2c7930..00e37c9d9e4767b7d96bbc2311a895f8699c820b 100644 (file)
@@ -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++;
index 93a51f2202df2e3e9f68b66f8c7227fe6c491623..bdef1736143a76885784f32597329d187bef706f 100644 (file)
@@ -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));
index cc59858dd3b2d023887f3277eaba628a86d966cf..bda8765ad9a4c18863db2be5bda7a21d459976ed 100644 (file)
@@ -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;
   }
 
index 6dce6a4901a6c71c84156b6063396acfbb298b82..97df65c8e7224808812e71ce57ff3bf60cd838d5 100644 (file)
@@ -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 */
index 21eb3c6c62ad7131d2592a13d738dfb57fa5f9b9..033b16ce1fd42200de257d5fd91cdb25bba846c9 100644 (file)
@@ -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);
 }
 
index 9ec96d8a697e885d56e677ff2ed579e9337e049a..9c0ab699e6ce4395db418641d891a7b60fe3e7ed 100644 (file)
@@ -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);
index 055e155e96c5193b1d27545c6a510daca2d45e28..7b9a6d45cf31bb87aad62fbaa7d5b9081e45eed0 100644 (file)
@@ -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,25 +115,49 @@ 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 ()
 {
@@ -138,15 +165,33 @@ testDirIter ()
 
   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;
index c617917ccf4cd41d8e197de9b2210b206bc36bc2..929b242324f507f5bdc708a44d69f507bda217b3 100644 (file)
@@ -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))
index a246d75c5947faba08e00ee8e945cf15af2412e1..55d4c7137e5366e662f2d52a0703665cfd714435 100644 (file)
@@ -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));
 }
 
 
index c55f28e9b0916096c955e060fa0d63a32eb5c6e3..93568cd81b3b6e79f833ca0b5f1cfca0e7d15f39 100644 (file)
@@ -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,
index 21abf92bb9123c915b9a4a22e2afe9fd5c2a63cb..f59fa547f213fa1beeaf1205926c0f4a6d15cc01 100644 (file)
@@ -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);
index ec84b08f8adfc282b9a3a69d3c3e917543f71f66..64f1d9c239edb79b1d9d02f4d41d39488a4cecb1 100644 (file)
@@ -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);
 }
 
 
index 5d46e3127a319dd18011f4377a37eb84e2ae7f11..b9f2cfb4d0909ec351bc0e0213370ee0ab1cbe79 100644 (file)
@@ -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
   };
index 58eda367f2c7a68c78c9b8dda540cf3442da33dd..2c3ac72fa82cc63296dd3c42c4a5498a940c574b 100644 (file)
@@ -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);
 }
 
 
index d4acee49ef18b58772b37f7216fd36f028d396c8..2e7daf7f7291b11f396034341cdb37c0fa38bf72 100644 (file)
@@ -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;