소스 검색

implementing new scheduler shutdown semantics

Christian Grothoff 8 년 전
부모
커밋
95f9076a21
100개의 변경된 파일1130개의 추가작업 그리고 1102개의 파일을 삭제
  1. 9 4
      src/arm/arm_api.c
  2. 50 29
      src/arm/gnunet-arm.c
  3. 44 45
      src/arm/gnunet-service-arm.c
  4. 1 1
      src/arm/test_arm_api.c
  5. 10 6
      src/arm/test_exponential_backoff.c
  6. 3 5
      src/ats-tests/ats-testing-log.c
  7. 5 10
      src/ats-tests/perf_ats_logging.c
  8. 11 11
      src/ats-tool/gnunet-ats.c
  9. 2 6
      src/ats/gnunet-service-ats.c
  10. 4 6
      src/cadet/cadet_api.c
  11. 32 35
      src/cadet/cadet_path.c
  12. 128 96
      src/cadet/gnunet-cadet-profiler.c
  13. 71 64
      src/cadet/gnunet-cadet.c
  14. 2 2
      src/cadet/gnunet-service-cadet.c
  15. 2 12
      src/cadet/gnunet-service-cadet_channel.c
  16. 10 41
      src/cadet/gnunet-service-cadet_connection.c
  17. 1 7
      src/cadet/gnunet-service-cadet_dht.c
  18. 19 14
      src/cadet/gnunet-service-cadet_peer.c
  19. 22 48
      src/cadet/gnunet-service-cadet_tunnel.c
  20. 53 65
      src/cadet/test_cadet.c
  21. 22 26
      src/cadet/test_cadet_local.c
  22. 17 29
      src/cadet/test_cadet_single.c
  23. 1 1
      src/consensus/gnunet-service-consensus.c
  24. 4 10
      src/consensus/test_consensus_api.c
  25. 2 3
      src/conversation/gnunet-conversation-test.c
  26. 2 2
      src/conversation/gnunet-conversation.c
  27. 5 4
      src/conversation/gnunet-service-conversation.c
  28. 1 2
      src/core/gnunet-core.c
  29. 2 3
      src/core/gnunet-service-core.c
  30. 4 3
      src/core/gnunet-service-core_kx.c
  31. 19 11
      src/core/test_core_api_mq.c
  32. 3 10
      src/core/test_core_quota_compliance.c
  33. 1 0
      src/curl/Makefile.am
  34. 1 2
      src/datastore/gnunet-datastore.c
  35. 5 4
      src/datastore/gnunet-service-datastore.c
  36. 0 4
      src/datastore/perf_datastore_api.c
  37. 27 18
      src/datastore/perf_plugin_datastore.c
  38. 0 7
      src/datastore/test_plugin_datastore.c
  39. 27 3
      src/dht/gnunet-dht-get.c
  40. 32 4
      src/dht/gnunet-dht-monitor.c
  41. 5 2
      src/dht/gnunet-dht-put.c
  42. 2 3
      src/dht/gnunet-service-dht.c
  43. 0 4
      src/dht/gnunet-service-dht_clients.c
  44. 1 4
      src/dht/gnunet-service-dht_neighbours.c
  45. 2 3
      src/dht/gnunet-service-wdht.c
  46. 0 4
      src/dht/gnunet-service-wdht_clients.c
  47. 2 5
      src/dht/gnunet-service-xdht.c
  48. 0 4
      src/dht/gnunet-service-xdht_clients.c
  49. 46 53
      src/dht/gnunet_dht_profiler.c
  50. 1 1
      src/dns/dnsstub.c
  51. 1 2
      src/dns/gnunet-dns-monitor.c
  52. 1 2
      src/dns/gnunet-dns-redirector.c
  53. 2 3
      src/dns/gnunet-service-dns.c
  54. 1 2
      src/dv/gnunet-dv.c
  55. 1 2
      src/dv/gnunet-service-dv.c
  56. 2 2
      src/dv/test_transport_dv.c
  57. 4 7
      src/exit/gnunet-daemon-exit.c
  58. 2 10
      src/fs/gnunet-auto-share.c
  59. 2 10
      src/fs/gnunet-daemon-fsprofiler.c
  60. 2 2
      src/fs/gnunet-download.c
  61. 23 6
      src/fs/gnunet-fs-profiler.c
  62. 2 3
      src/fs/gnunet-publish.c
  63. 16 4
      src/fs/gnunet-search.c
  64. 6 4
      src/fs/gnunet-service-fs.c
  65. 20 23
      src/fs/gnunet-service-fs_cp.c
  66. 0 4
      src/fs/gnunet-service-fs_put.c
  67. 2 2
      src/fs/gnunet-unindex.c
  68. 9 8
      src/fs/test_gnunet_service_fs_migration.c
  69. 4 3
      src/gns/gns_api.c
  70. 10 11
      src/gns/gnunet-bcd.c
  71. 51 45
      src/gns/gnunet-dns2gns.c
  72. 2 2
      src/gns/gnunet-gns-helper-service-w32.c
  73. 1 2
      src/gns/gnunet-gns-import.c
  74. 1 6
      src/gns/gnunet-gns-proxy.c
  75. 29 3
      src/gns/gnunet-gns.c
  76. 1 2
      src/gns/gnunet-service-gns.c
  77. 3 3
      src/gns/plugin_rest_gns.c
  78. 10 7
      src/gns/test_gns_proxy.c
  79. 2 3
      src/hostlist/gnunet-daemon-hostlist.c
  80. 23 48
      src/hostlist/gnunet-daemon-hostlist_client.c
  81. 8 11
      src/hostlist/gnunet-daemon-hostlist_server.c
  82. 19 10
      src/hostlist/test_gnunet_daemon_hostlist.c
  83. 7 7
      src/hostlist/test_gnunet_daemon_hostlist_learning.c
  84. 12 6
      src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
  85. 22 16
      src/identity-provider/gnunet-service-identity-provider.c
  86. 43 17
      src/identity-provider/plugin_rest_identity_provider.c
  87. 1 2
      src/identity/gnunet-identity.c
  88. 2 2
      src/identity/gnunet-service-identity.c
  89. 5 3
      src/identity/plugin_rest_identity.c
  90. 1 2
      src/identity/test_identity.c
  91. 1 1
      src/include/gnunet_common.h
  92. 32 30
      src/include/gnunet_scheduler_lib.h
  93. 6 5
      src/multicast/gnunet-service-multicast.c
  94. 13 8
      src/multicast/test_multicast.c
  95. 2 4
      src/namecache/gnunet-namecache.c
  96. 2 2
      src/namecache/gnunet-service-namecache.c
  97. 4 3
      src/namecache/test_namecache_api_cache_block.c
  98. 1 2
      src/namestore/gnunet-namestore-fcfsd.c
  99. 1 2
      src/namestore/gnunet-namestore.c
  100. 2 2
      src/namestore/gnunet-service-namestore.c

+ 9 - 4
src/arm/arm_api.c

@@ -241,7 +241,9 @@ reconnect_arm_later (struct GNUNET_ARM_Handle *h)
   h->currently_down = GNUNET_YES;
   GNUNET_assert (NULL == h->reconnect_task);
   h->reconnect_task =
-      GNUNET_SCHEDULER_add_delayed (h->retry_backoff, &reconnect_arm_task, h);
+      GNUNET_SCHEDULER_add_delayed (h->retry_backoff,
+				    &reconnect_arm_task,
+				    h);
   /* Don't clear pending messages on disconnection, deliver them later
   clear_pending_messages (h, GNUNET_ARM_REQUEST_DISCONNECTED);
   GNUNET_assert (NULL == h->control_pending_head);
@@ -635,7 +637,8 @@ reconnect_arm (struct GNUNET_ARM_Handle *h)
  */
 struct GNUNET_ARM_Handle *
 GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                    GNUNET_ARM_ConnectionStatusCallback conn_status, void *cls)
+                    GNUNET_ARM_ConnectionStatusCallback conn_status,
+		    void *cls)
 {
   struct GNUNET_ARM_Handle *h;
 
@@ -942,7 +945,8 @@ change_service (struct GNUNET_ARM_Handle *h, const char *service_name,
                                     h->control_pending_tail, cm);
   cm->timeout_task_id =
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
-                                    (cm->timeout), &control_message_timeout, cm);
+                                    (cm->timeout),
+				    &control_message_timeout, cm);
   trigger_next_request (h, GNUNET_NO);
 }
 
@@ -1106,7 +1110,8 @@ GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h,
                                     h->control_pending_tail, cm);
   cm->timeout_task_id =
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
-                                    (cm->timeout), &control_message_timeout, cm);
+                                    (cm->timeout),
+				    &control_message_timeout, cm);
   trigger_next_request (h, GNUNET_NO);
 }
 

+ 50 - 29
src/arm/gnunet-arm.c

@@ -145,6 +145,11 @@ static unsigned int no_stdout;
  */
 static unsigned int no_stderr;
 
+/**
+ * Handle for the task running the #action_loop().
+ */
+static struct GNUNET_SCHEDULER_Task *al_task;
+
 
 /**
  * Attempts to delete configuration file and GNUNET_HOME
@@ -183,6 +188,11 @@ delete_files ()
 static void
 shutdown_task (void *cls)
 {
+  if (NULL != al_task)
+  {
+    GNUNET_SCHEDULER_cancel (al_task);
+    al_task = NULL;
+  }
   if (NULL != h)
   {
     GNUNET_ARM_disconnect_and_free (h);
@@ -314,7 +324,8 @@ conn_status (void *cls,
  */
 static void
 start_callback (void *cls,
-		enum GNUNET_ARM_RequestStatus rs, const char *service,
+		enum GNUNET_ARM_RequestStatus rs,
+		const char *service,
 		enum GNUNET_ARM_Result result)
 {
   char *msg;
@@ -336,9 +347,10 @@ start_callback (void *cls,
     GNUNET_SCHEDULER_shutdown ();
     return;
   }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM service [re]start successful\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+	      "ARM service [re]start successful\n");
   start = 0;
-  GNUNET_SCHEDULER_add_now (action_loop, NULL);
+  al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
 }
 
 
@@ -356,7 +368,8 @@ start_callback (void *cls,
  */
 static void
 stop_callback (void *cls,
-	       enum GNUNET_ARM_RequestStatus rs, const char *service,
+	       enum GNUNET_ARM_RequestStatus rs,
+	       const char *service,
 	       enum GNUNET_ARM_Result result)
 {
   char *msg;
@@ -374,7 +387,8 @@ stop_callback (void *cls,
       (GNUNET_ARM_RESULT_STOPPED != result) &&
       (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result))
   {
-    GNUNET_asprintf (&msg, "%s", _("Failed to stop the ARM service: %s\n"));
+    GNUNET_asprintf (&msg, "%s",
+		     _("Failed to stop the ARM service: %s\n"));
     FPRINTF (stdout, msg, ret_string (result));
     GNUNET_free (msg);
     GNUNET_SCHEDULER_shutdown ();
@@ -390,7 +404,7 @@ stop_callback (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
 		"Initiating an ARM restart\n");
   }
-  GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+  al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
 }
 
 
@@ -408,7 +422,8 @@ stop_callback (void *cls,
  */
 static void
 init_callback (void *cls,
-	       enum GNUNET_ARM_RequestStatus rs, const char *service,
+	       enum GNUNET_ARM_RequestStatus rs,
+	       const char *service,
 	       enum GNUNET_ARM_Result result)
 {
   char *msg;
@@ -438,7 +453,7 @@ init_callback (void *cls,
 	      init);
   GNUNET_free (init);
   init = NULL;
-  GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+  al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
 }
 
 
@@ -456,7 +471,8 @@ init_callback (void *cls,
  */
 static void
 term_callback (void *cls,
-	       enum GNUNET_ARM_RequestStatus rs, const char *service,
+	       enum GNUNET_ARM_RequestStatus rs,
+	       const char *service,
 	       enum GNUNET_ARM_Result result)
 {
   char *msg;
@@ -487,7 +503,7 @@ term_callback (void *cls,
               term);
   GNUNET_free (term);
   term = NULL;
-  GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+  al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
 }
 
 
@@ -503,7 +519,8 @@ term_callback (void *cls,
  */
 static void
 list_callback (void *cls,
-	       enum GNUNET_ARM_RequestStatus rs, unsigned int count,
+	       enum GNUNET_ARM_RequestStatus rs,
+	       unsigned int count,
 	       const char *const*list)
 {
   unsigned int i;
@@ -512,7 +529,8 @@ list_callback (void *cls,
   {
     char *msg;
 
-    GNUNET_asprintf (&msg, "%s", _("Failed to request a list of services: %s\n"));
+    GNUNET_asprintf (&msg, "%s",
+		     _("Failed to request a list of services: %s\n"));
     FPRINTF (stdout, msg, req_string (rs));
     GNUNET_free (msg);
     ret = 3;
@@ -520,7 +538,8 @@ list_callback (void *cls,
   }
   if (NULL == list)
   {
-    FPRINTF (stderr, "%s", _("Error communicating with ARM. ARM not running?\n"));
+    FPRINTF (stderr, "%s",
+	     _("Error communicating with ARM. ARM not running?\n"));
     GNUNET_SCHEDULER_shutdown ();
     ret = 3;
     return;
@@ -528,7 +547,7 @@ list_callback (void *cls,
   FPRINTF (stdout, "%s", _("Running services:\n"));
   for (i = 0; i < count; i++)
     FPRINTF (stdout, "%s\n", list[i]);
-  GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+  al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
 }
 
 
@@ -541,12 +560,9 @@ list_callback (void *cls,
 static void
 action_loop (void *cls)
 {
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
-
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running requested actions\n");
+  al_task = NULL;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+	      "Running requested actions\n");
   while (1)
   {
     switch (phase++)
@@ -554,7 +570,8 @@ action_loop (void *cls)
     case 0:
       if (NULL != term)
       {
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Termination action\n");
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+		    "Termination action\n");
         GNUNET_ARM_request_service_stop (h, term,
 					 (0 == timeout.rel_value_us) ? STOP_TIMEOUT : timeout,
 					 &term_callback, NULL);
@@ -564,7 +581,8 @@ action_loop (void *cls)
     case 1:
       if (end || restart)
       {
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "End action\n");
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+		    "End action\n");
         GNUNET_ARM_request_service_stop (h, "arm",
 					 (0 == timeout.rel_value_us) ? STOP_TIMEOUT_ARM : timeout,
 					 &stop_callback, NULL);
@@ -574,7 +592,8 @@ action_loop (void *cls)
     case 2:
       if (start)
       {
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start action\n");
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+		    "Start action\n");
         GNUNET_ARM_request_service_start (h, "arm",
             (no_stdout ? 0 : GNUNET_OS_INHERIT_STD_OUT) |
             (no_stderr ? 0 : GNUNET_OS_INHERIT_STD_ERR),
@@ -586,8 +605,10 @@ action_loop (void *cls)
     case 3:
       if (NULL != init)
       {
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initialization action\n");
-        GNUNET_ARM_request_service_start (h, init, GNUNET_OS_INHERIT_STD_NONE,
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+		    "Initialization action\n");
+        GNUNET_ARM_request_service_start (h, init,
+					  GNUNET_OS_INHERIT_STD_NONE,
 					  (0 == timeout.rel_value_us) ? STOP_TIMEOUT : timeout,
 					  &init_callback, NULL);
         return;
@@ -631,7 +652,8 @@ action_loop (void *cls)
  */
 static void
 srv_status (void *cls,
-	    const char *service, enum GNUNET_ARM_ServiceStatus status)
+	    const char *service,
+	    enum GNUNET_ARM_ServiceStatus status)
 {
   const char *msg;
 
@@ -704,9 +726,8 @@ run (void *cls,
     return;
   if (monitor)
     m = GNUNET_ARM_monitor (cfg, &srv_status, NULL);
-  GNUNET_SCHEDULER_add_now (&action_loop, NULL);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-				&shutdown_task, NULL);
+  al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
 }
 
 

+ 44 - 45
src/arm/gnunet-service-arm.c

@@ -610,13 +610,9 @@ accept_connection (void *cls)
 {
   struct ServiceListeningInfo *sli = cls;
   struct ServiceList *sl = sli->sl;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   sli->accept_task = NULL;
   GNUNET_assert (GNUNET_NO == in_shutdown);
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
-    return;
   start_process (sl, NULL, 0);
 }
 
@@ -734,7 +730,9 @@ create_listen_socket (struct sockaddr *sa,
   sli->accept_task =
     GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, sock,
 				   &accept_connection, sli);
-  GNUNET_CONTAINER_DLL_insert (sl->listen_head, sl->listen_tail, sli);
+  GNUNET_CONTAINER_DLL_insert (sl->listen_head,
+			       sl->listen_tail,
+			       sli);
 }
 
 
@@ -866,17 +864,24 @@ handle_stop (void *cls,
 	      servicename);
   if (0 == strcasecmp (servicename, "arm"))
   {
-    broadcast_status (servicename, GNUNET_ARM_SERVICE_STOPPING, NULL);
-    signal_result (client, servicename, request_id, GNUNET_ARM_RESULT_STOPPING);
+    broadcast_status (servicename,
+		      GNUNET_ARM_SERVICE_STOPPING, NULL);
+    signal_result (client,
+		   servicename,
+		   request_id,
+		   GNUNET_ARM_RESULT_STOPPING);
     GNUNET_SERVER_client_persist_ (client);
-    GNUNET_SCHEDULER_add_now (trigger_shutdown, NULL);
+    GNUNET_SCHEDULER_add_now (&trigger_shutdown, NULL);
     GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }
   sl = find_service (servicename);
   if (sl == NULL)
     {
-      signal_result (client, servicename, request_id, GNUNET_ARM_RESULT_IS_NOT_KNOWN);
+      signal_result (client,
+		     servicename,
+		     request_id,
+		     GNUNET_ARM_RESULT_IS_NOT_KNOWN);
       GNUNET_SERVER_receive_done (client, GNUNET_OK);
       return;
     }
@@ -884,14 +889,19 @@ handle_stop (void *cls,
   if (GNUNET_YES == in_shutdown)
     {
       /* shutdown in progress */
-      signal_result (client, servicename, request_id, GNUNET_ARM_RESULT_IN_SHUTDOWN);
+      signal_result (client,
+		     servicename,
+		     request_id,
+		     GNUNET_ARM_RESULT_IN_SHUTDOWN);
       GNUNET_SERVER_receive_done (client, GNUNET_OK);
       return;
     }
   if (NULL != sl->killing_client)
   {
     /* killing already in progress */
-    signal_result (client, servicename, request_id,
+    signal_result (client,
+		   servicename,
+		   request_id,
 		   GNUNET_ARM_RESULT_IS_STOPPING_ALREADY);
     GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
@@ -899,7 +909,9 @@ handle_stop (void *cls,
   if (NULL == sl->proc)
   {
     /* process is down */
-    signal_result (client, servicename, request_id,
+    signal_result (client,
+		   servicename,
+		   request_id,
 		   GNUNET_ARM_RESULT_IS_STOPPED_ALREADY);
     GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
@@ -907,7 +919,9 @@ handle_stop (void *cls,
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
 	      "Sending kill signal to service `%s', waiting for process to die.\n",
 	      servicename);
-  broadcast_status (servicename, GNUNET_ARM_SERVICE_STOPPING, NULL);
+  broadcast_status (servicename,
+		    GNUNET_ARM_SERVICE_STOPPING,
+		    NULL);
   /* no signal_start - only when it's STOPPED */
   sl->killed_at = GNUNET_TIME_absolute_get ();
   if (0 != GNUNET_OS_process_kill (sl->proc, GNUNET_TERM_SIG))
@@ -1055,7 +1069,8 @@ shutdown_task (void *cls)
     while (NULL != (sli = pos->listen_head))
       {
 	GNUNET_CONTAINER_DLL_remove (pos->listen_head,
-				     pos->listen_tail, sli);
+				     pos->listen_tail,
+				     sli);
 	if (NULL != sli->accept_task)
 	  {
 	    GNUNET_SCHEDULER_cancel (sli->accept_task);
@@ -1072,7 +1087,7 @@ shutdown_task (void *cls)
   while (NULL != (pos = nxt))
   {
     nxt = pos->next;
-    if (pos->proc != NULL)
+    if (NULL != pos->proc)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_INFO,
 		  "Stopping service `%s'\n",
@@ -1087,7 +1102,7 @@ shutdown_task (void *cls)
     }
   }
   /* finally, should all service processes be already gone, terminate for real */
-  if (running_head == NULL)
+  if (NULL == running_head)
     do_shutdown ();
   else
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1105,15 +1120,11 @@ static void
 delayed_restart_task (void *cls)
 
 {
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
   struct ServiceList *sl;
   struct GNUNET_TIME_Relative lowestRestartDelay;
   struct ServiceListeningInfo *sli;
 
   child_restart_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   GNUNET_assert (GNUNET_NO == in_shutdown);
   lowestRestartDelay = GNUNET_TIME_UNIT_FOREVER_REL;
 
@@ -1144,7 +1155,8 @@ delayed_restart_task (void *cls)
 	    /* accept was actually paused, so start it again */
 	    sli->accept_task =
 	      GNUNET_SCHEDULER_add_read_net
-	      (GNUNET_TIME_UNIT_FOREVER_REL, sli->listen_socket,
+	      (GNUNET_TIME_UNIT_FOREVER_REL,
+	       sli->listen_socket,
 	       &accept_connection, sli);
 	  }
       }
@@ -1180,7 +1192,6 @@ delayed_restart_task (void *cls)
 static void
 maint_child_death (void *cls)
 {
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
   struct ServiceList *pos;
   struct ServiceList *next;
   struct ServiceListeningInfo *sli;
@@ -1192,19 +1203,9 @@ maint_child_death (void *cls)
   unsigned long statusCode;
   const struct GNUNET_DISK_FileHandle *pr;
 
-  pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
+  pr = GNUNET_DISK_pipe_handle (sigpipe,
+				GNUNET_DISK_PIPE_END_READ);
   child_death_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
-  {
-    /* shutdown scheduled us, ignore! */
-    child_death_task =
-      GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
-                                      pr,
-                                      &maint_child_death,
-                                      NULL);
-    return;
-  }
   /* consume the signal */
   GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c)));
 
@@ -1353,14 +1354,13 @@ maint_child_death (void *cls)
       }
       else
       {
-        if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-          GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                      _("Service `%s' terminated with status %s/%d, will restart in %s\n"),
-                      pos->name,
-                      statstr,
-                      statcode,
-                      GNUNET_STRINGS_relative_time_to_string (pos->backoff,
-                                                              GNUNET_YES));
+	GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+		    _("Service `%s' terminated with status %s/%d, will restart in %s\n"),
+		    pos->name,
+		    statstr,
+		    statcode,
+		    GNUNET_STRINGS_relative_time_to_string (pos->backoff,
+							    GNUNET_YES));
         /* schedule restart */
         pos->restart_at = GNUNET_TIME_relative_to_absolute (pos->backoff);
         pos->backoff = GNUNET_TIME_STD_BACKOFF (pos->backoff);
@@ -1601,9 +1601,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *serv,
   cfg = c;
   server = serv;
   GNUNET_assert (NULL != serv);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &shutdown_task,
-				NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+				 NULL);
   child_death_task =
     GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
 				    GNUNET_DISK_pipe_handle (sigpipe,

+ 1 - 1
src/arm/test_arm_api.c

@@ -157,7 +157,7 @@ arm_conn (void *cls,
       ok = 3;
     else if (ok == 1)
       ok = 0;
-    GNUNET_SCHEDULER_add_now (trigger_disconnect, arm);
+    GNUNET_SCHEDULER_add_now (&trigger_disconnect, arm);
   }
 }
 

+ 10 - 6
src/arm/test_exponential_backoff.c

@@ -90,7 +90,7 @@ struct ShutdownContext
   /**
    * Task set up to cancel the shutdown request on timeout.
    */
-  struct GNUNET_SCHEDULER_Task * cancel_task;
+  struct GNUNET_SCHEDULER_Task *cancel_task;
 
   /**
    * Task to call once shutdown complete
@@ -235,7 +235,7 @@ shutdown_cont (void *cls, int reason)
   {
     /* Re-try shutdown */
     LOG ("do-nothing didn't die, trying again\n");
-    GNUNET_SCHEDULER_add_now (kill_task, NULL);
+    GNUNET_SCHEDULER_add_now (&kill_task, NULL);
     return;
   }
   startedWaitingAt = GNUNET_TIME_absolute_get ();
@@ -290,12 +290,15 @@ trigger_disconnect (void *cls)
 
 
 static void
-arm_stop_cb (void *cls, enum GNUNET_ARM_RequestStatus status, const char *servicename, enum GNUNET_ARM_Result result)
+arm_stop_cb (void *cls,
+	     enum GNUNET_ARM_RequestStatus status,
+	     const char *servicename,
+	     enum GNUNET_ARM_Result result)
 {
   GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
   GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED);
   LOG ("ARM service stopped\n");
-  GNUNET_SCHEDULER_add_now (trigger_disconnect, NULL);
+  GNUNET_SCHEDULER_add_now (&trigger_disconnect, NULL);
 }
 
 
@@ -318,7 +321,8 @@ srv_status (void *cls, const char *service, enum GNUNET_ARM_ServiceStatus status
     LOG ("do-nothing is starting\n");
     phase++;
     ok = 1;
-    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &kill_task, NULL);
+    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+				  &kill_task, NULL);
   }
   else if ((phase == 2) && (strcasecmp (SERVICE, service) == 0))
   {
@@ -328,7 +332,7 @@ srv_status (void *cls, const char *service, enum GNUNET_ARM_ServiceStatus status
     if (status == GNUNET_ARM_SERVICE_STARTING)
     {
       LOG ("do-nothing is starting\n");
-      GNUNET_SCHEDULER_add_now (kill_task, &ok);
+      GNUNET_SCHEDULER_add_now (&kill_task, &ok);
     }
     else if ((status == GNUNET_ARM_SERVICE_STOPPED) && (trialCount == 14))
     {

+ 3 - 5
src/ats-tests/ats-testing-log.c

@@ -804,13 +804,9 @@ static void
 collect_log_task (void *cls)
 {
   struct LoggingHandle *l = cls;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   l->log_task = NULL;
   GNUNET_ATS_TEST_logging_now (l);
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
-    return;
   l->log_task = GNUNET_SCHEDULER_add_delayed (l->frequency,
                                               &collect_log_task,
                                               l);
@@ -829,8 +825,10 @@ GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l)
     return;
 
   if (NULL != l->log_task)
+  {
     GNUNET_SCHEDULER_cancel (l->log_task);
-  l->log_task = NULL;
+    l->log_task = NULL;
+  }
   l->running = GNUNET_NO;
 
   GNUNET_log(GNUNET_ERROR_TYPE_INFO,

+ 5 - 10
src/ats-tests/perf_ats_logging.c

@@ -639,15 +639,8 @@ collect_log_now (void)
 static void
 collect_log_task (void *cls)
 {
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
-
   log_task = NULL;
-
-  collect_log_now();
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
-    return;
-
+  collect_log_now ();
   log_task = GNUNET_SCHEDULER_add_delayed (frequency,
                                            &collect_log_task, NULL);
 }
@@ -659,12 +652,14 @@ perf_logging_stop ()
   int c_m;
   struct PeerLoggingTimestep *cur;
 
-  if (GNUNET_YES!= running)
+  if (GNUNET_YES != running)
     return;
 
   if (NULL != log_task)
+  {
     GNUNET_SCHEDULER_cancel (log_task);
-  log_task = NULL;
+    log_task = NULL;
+  }
   collect_log_task (NULL);
 
   GNUNET_log(GNUNET_ERROR_TYPE_INFO,

+ 11 - 11
src/ats-tool/gnunet-ats.c

@@ -363,7 +363,7 @@ transport_addr_to_str_cb (void *cls,
       /* All messages received and no resolutions pending*/
       if (shutdown_task != NULL)
         GNUNET_SCHEDULER_cancel (shutdown_task);
-      shutdown_task = GNUNET_SCHEDULER_add_now (end, NULL);
+      shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL);
     }
     return;
   }
@@ -604,7 +604,7 @@ ats_perf_cb (void *cls,
       /* All messages received and no resolutions pending*/
       if (shutdown_task != NULL)
         GNUNET_SCHEDULER_cancel (shutdown_task);
-      shutdown_task = GNUNET_SCHEDULER_add_now (end, NULL);
+      shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL);
     }
     return;
   }
@@ -807,9 +807,8 @@ run (void *cls,
       shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL);
       return;
     }
-    shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                                  &end,
-                                                  NULL);
+    shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end,
+						   NULL);
     return;
   }
   if (opt_list_used)
@@ -834,9 +833,8 @@ run (void *cls,
       shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL);
       return;
     }
-    shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                             &end,
-                                             NULL);
+    shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end,
+						   NULL);
     return;
   }
   if (opt_monitor)
@@ -844,13 +842,15 @@ run (void *cls,
     ph = GNUNET_ATS_performance_init (cfg,
                                       &ats_perf_mon_cb,
                                       NULL);
+    shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end,
+						   NULL);
     if (NULL == ph)
+    {
       FPRINTF (stderr,
                "%s",
                _("Cannot connect to ATS service, exiting...\n"));
-    shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                                  &end,
-                                                  NULL);
+      GNUNET_SCHEDULER_shutdown ();
+    }
     return;
   }
   if (opt_set_pref)

+ 2 - 6
src/ats/gnunet-service-ats.c

@@ -138,9 +138,6 @@ cleanup_task (void *cls)
   GAS_performance_done ();
   GAS_preference_done ();
   GAS_reservations_done ();
-  GNUNET_SERVER_disconnect_notify_cancel (GSA_server,
-                                          &client_disconnect_handler,
-                                          NULL);
   if (NULL != GSA_stats)
   {
     GNUNET_STATISTICS_destroy (GSA_stats, GNUNET_NO);
@@ -221,9 +218,8 @@ run (void *cls,
                                    &client_disconnect_handler,
 				   NULL);
   GNUNET_SERVER_add_handlers (server, handlers);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &cleanup_task,
-				NULL);
+  GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
+				 NULL);
 }
 
 

+ 4 - 6
src/cadet/cadet_api.c

@@ -1,20 +1,22 @@
 /*
      This file is part of GNUnet.
      Copyright (C) 2011 GNUnet e.V.
+
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
      by the Free Software Foundation; either version 3, or (at your
      option) any later version.
+
      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      General Public License for more details.
+
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
      Boston, MA 02110-1301, USA.
 */
-
 /**
  * @file cadet/cadet_api.c
  * @brief cadet api: client implementation of new cadet service
@@ -702,12 +704,8 @@ static void
 reconnect_cbk (void *cls)
 {
   struct GNUNET_CADET_Handle *h = cls;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   h->reconnect_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   do_reconnect (h);
 }
 
@@ -718,7 +716,7 @@ reconnect_cbk (void *cls)
  *
  * @param h handle to the cadet
  *
- * @return GNUNET_YES in case of sucess, GNUNET_NO otherwise (service down...)
+ * @return #GNUNET_YES in case of sucess, #GNUNET_NO otherwise (service down...)
  */
 static void
 reconnect (struct GNUNET_CADET_Handle *h)

+ 32 - 35
src/cadet/cadet_path.c

@@ -33,10 +33,7 @@
 
 /**
  * @brief Destroy a path after some time has past.
- *
- * If the path is returned from DHT again after a while, try again.
- *
- * Removes the path from the peer (except for direct paths).
+ * Removes the path from the peer (must not be used for direct paths).
  *
  * @param cls Closure (path to destroy).
  */
@@ -45,28 +42,17 @@ path_destroy_delayed (void *cls)
 {
   struct CadetPeerPath *path = cls;
   struct CadetPeer *peer;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
-  LOG (GNUNET_ERROR_TYPE_INFO, "Destroy delayed %p (%u)\n", path, path->length);
   path->path_delete = NULL;
-
-  /* During shutdown, the peers peermap might not exist anymore. */
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) == 0)
-  {
-    if (2 >= path->length)
-    {
-      /* This is not the place to destroy direct paths, only core_disconnect
-       * should do it and never delay it.
-       */
-      GNUNET_break (0);
-    }
-    peer = GCP_get_short (path->peers[path->length - 1], GNUNET_NO);
-    if (NULL != peer)
-      GCP_remove_path (peer, path);
-  }
-  else
-    path_destroy (path);
+  LOG (GNUNET_ERROR_TYPE_INFO,
+       "Destroy delayed %p (%u)\n",
+       path,
+       path->length);
+  GNUNET_assert (2 < path->length);
+  peer = GCP_get_short (path->peers[path->length - 1],
+			GNUNET_NO);
+  GNUNET_assert (NULL != peer);
+  GCP_remove_path (peer, path);
 }
 
 
@@ -74,7 +60,6 @@ path_destroy_delayed (void *cls)
  * Create a new path
  *
  * @param length How many hops will the path have.
- *
  * @return A newly allocated path with a peer array of the specified length.
  */
 struct CadetPeerPath *
@@ -125,7 +110,9 @@ path_duplicate (const struct CadetPeerPath *path)
   unsigned int i;
 
   aux = path_new (path->length);
-  memcpy (aux->peers, path->peers, path->length * sizeof (GNUNET_PEER_Id));
+  memcpy (aux->peers,
+	  path->peers,
+	  path->length * sizeof (GNUNET_PEER_Id));
   for (i = 0; i < aux->length; i++)
     GNUNET_PEER_change_rc (aux->peers[i], 1);
   return aux;
@@ -167,9 +154,13 @@ path_invalidate (struct CadetPeerPath *p)
   if (NULL != p->path_delete)
     return;
 
-  LOG (GNUNET_ERROR_TYPE_INFO, "Invalidating path %p (%u)\n", p, p->length);
-  p->path_delete = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
-                                                 &path_destroy_delayed, p);
+  LOG (GNUNET_ERROR_TYPE_INFO,
+       "Invalidating path %p (%u)\n",
+       p,
+       p->length);
+  p->path_delete
+    = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+				    &path_destroy_delayed, p);
 }
 
 
@@ -242,8 +233,8 @@ path_build_from_peer_ids (struct GNUNET_PeerIdentity *peers,
  * @param p1 First path
  * @param p2 Second path
  *
- * @return GNUNET_YES if both paths are equivalent
- *         GNUNET_NO otherwise
+ * @return #GNUNET_YES if both paths are equivalent
+ *         #GNUNET_NO otherwise
  */
 int
 path_equivalent (const struct CadetPeerPath *p1,
@@ -293,7 +284,7 @@ path_is_valid (const struct CadetPeerPath *path)
  *
  * @param p the path to destroy
  *
- * @return GNUNET_OK on success
+ * @return #GNUNET_OK on success
  */
 int
 path_destroy (struct CadetPeerPath *p)
@@ -301,7 +292,10 @@ path_destroy (struct CadetPeerPath *p)
   if (NULL == p)
     return GNUNET_OK;
 
-  LOG (GNUNET_ERROR_TYPE_INFO, "destroying path %p (%u)\n", p, p->length);
+  LOG (GNUNET_ERROR_TYPE_INFO,
+       "destroying path %p (%u)\n",
+       p,
+       p->length);
   GNUNET_PEER_decrement_rcs (p->peers, p->length);
   GNUNET_free_non_null (p->peers);
   if (NULL != p->path_delete)
@@ -322,7 +316,8 @@ path_destroy (struct CadetPeerPath *p)
  *         0 if they are identical.
  */
 int
-path_cmp (const struct CadetPeerPath *p1, const struct CadetPeerPath *p2)
+path_cmp (const struct CadetPeerPath *p1,
+	  const struct CadetPeerPath *p2)
 {
   if (p1->length > p2->length)
     return 1;
@@ -330,7 +325,9 @@ path_cmp (const struct CadetPeerPath *p1, const struct CadetPeerPath *p2)
   if (p1->length < p2->length)
     return -1;
 
-  return memcmp (p1->peers, p2->peers, sizeof (GNUNET_PEER_Id) * p1->length);
+  return memcmp (p1->peers,
+		 p2->peers,
+		 sizeof (GNUNET_PEER_Id) * p1->length);
 }
 
 

+ 128 - 96
src/cadet/gnunet-cadet-profiler.c

@@ -147,7 +147,12 @@ struct CadetPeer
   /**
    * Task to do the next ping.
    */
-  struct GNUNET_SCHEDULER_Task * ping_task;
+  struct GNUNET_SCHEDULER_Task *ping_task;
+
+  /**
+   * NTR operation for the next ping.
+   */
+  struct GNUNET_CADET_TransmitHandle *ping_ntr;
 
   float mean[number_rounds];
   float var[number_rounds];
@@ -179,7 +184,7 @@ static struct GNUNET_TESTBED_Operation *stats_op;
 /**
  * Operation to get peer ids.
  */
-struct CadetPeer *peers;
+static struct CadetPeer *peers;
 
 /**
  * Peer ids counter.
@@ -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;

+ 71 - 64
src/cadet/gnunet-cadet.c

@@ -72,22 +72,22 @@ static uint32_t listen_port;
 /**
  * Request echo service
  */
-int echo;
+static int echo;
 
 /**
  * Request a debug dump
  */
-int dump;
+static int dump;
 
 /**
  * Time of last echo request.
  */
-struct GNUNET_TIME_Absolute echo_time;
+static struct GNUNET_TIME_Absolute echo_time;
 
 /**
  * Task for next echo request.
  */
-struct GNUNET_SCHEDULER_Task * echo_task;
+static struct GNUNET_SCHEDULER_Task *echo_task;
 
 /**
  * Peer to connect to.
@@ -102,8 +102,7 @@ static uint32_t target_port;
 /**
  * Data pending in netcat mode.
  */
-size_t data_size;
-
+static size_t data_size;
 
 /**
  * Cadet handle.
@@ -123,8 +122,17 @@ static struct GNUNET_CADET_TransmitHandle *th;
 /**
  * Shutdown task handle.
  */
-struct GNUNET_SCHEDULER_Task * sd;
+static struct GNUNET_SCHEDULER_Task *sd;
 
+/**
+ * Task for reading from stdin.
+ */
+static struct GNUNET_SCHEDULER_Task *rd_task;
+
+/**
+ * Task for main job.
+ */
+static struct GNUNET_SCHEDULER_Task *job;
 
 
 static void
@@ -195,7 +203,8 @@ conn_2s (uint16_t status)
 static void
 shutdown_task (void *cls)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+	      "Shutdown\n");
   if (NULL != th)
   {
     GNUNET_CADET_notify_transmit_ready_cancel (th);
@@ -209,7 +218,22 @@ shutdown_task (void *cls)
   if (NULL != mh)
   {
     GNUNET_CADET_disconnect (mh);
-        mh = NULL;
+    mh = NULL;
+  }
+  if (NULL != rd_task)
+  {
+    GNUNET_SCHEDULER_cancel (rd_task);
+    rd_task = NULL;
+  }
+  if (NULL != echo_task)
+  {
+    GNUNET_SCHEDULER_cancel (echo_task);
+    echo_task = NULL;
+  }
+  if (NULL != job)
+  {
+    GNUNET_SCHEDULER_cancel (job);
+    job = NULL;
   }
 }
 
@@ -227,7 +251,7 @@ shutdown_task (void *cls)
  * @param buf where the callee should write the message
  * @return number of bytes written to buf
  */
-size_t
+static size_t
 data_ready (void *cls, size_t size, void *buf)
 {
   struct GNUNET_MessageHeader *msg;
@@ -271,13 +295,6 @@ static void
 read_stdio (void *cls)
 {
   static char buf[60000];
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
-
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    return;
-  }
 
   data_size = read (0, buf, 60000);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "stdio read %u bytes\n", data_size);
@@ -305,10 +322,10 @@ listen_stdio (void)
 
   rs = GNUNET_NETWORK_fdset_create ();
   GNUNET_NETWORK_fdset_set_native (rs, 0);
-  GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
-                               GNUNET_TIME_UNIT_FOREVER_REL,
-                               rs, NULL,
-                               &read_stdio, NULL);
+  rd_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+					 GNUNET_TIME_UNIT_FOREVER_REL,
+					 rs, NULL,
+					 &read_stdio, NULL);
   GNUNET_NETWORK_fdset_destroy (rs);
 }
 
@@ -408,12 +425,8 @@ channel_incoming (void *cls,
 static void
 send_echo (void *cls)
 {
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
-
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) || NULL == ch)
+  if (NULL == ch)
     return;
-
   GNUNET_assert (NULL == th);
   th = GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO,
                                            GNUNET_TIME_UNIT_FOREVER_REL,
@@ -432,7 +445,8 @@ request_dump (void *cls)
 {
   GNUNET_CADET_request_dump (mh);
   GNUNET_SCHEDULER_cancel (sd);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &shutdown_task, NULL);
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+				&shutdown_task, NULL);
 }
 
 
@@ -466,7 +480,7 @@ create_channel (void *cls)
   if (GNUNET_NO == echo)
     listen_stdio ();
   else
-    GNUNET_SCHEDULER_add_now (send_echo, NULL);
+    echo_task = GNUNET_SCHEDULER_add_now (&send_echo, NULL);
 }
 
 
@@ -561,8 +575,11 @@ data_callback (void *cls,
  *                  (0 = unknown, 1 = ourselves, 2 = neighbor)
  */
 static void
-peers_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
-                int tunnel, unsigned int n_paths, unsigned int best_path)
+peers_callback (void *cls,
+		const struct GNUNET_PeerIdentity *peer,
+                int tunnel,
+		unsigned int n_paths,
+		unsigned int best_path)
 {
   if (NULL == peer)
   {
@@ -589,7 +606,7 @@ peers_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
  *              Each path starts with the local peer.
  *              Each path ends with the destination peer (given in @c peer).
  */
-void
+static void
 peer_callback (void *cls,
                const struct GNUNET_PeerIdentity *peer,
                int tunnel,
@@ -629,7 +646,7 @@ peer_callback (void *cls,
  * @param estate Encryption state.
  * @param cstate Connectivity state.
  */
-void
+static void
 tunnels_callback (void *cls,
                   const struct GNUNET_PeerIdentity *peer,
                   unsigned int channels,
@@ -665,7 +682,7 @@ tunnels_callback (void *cls,
  * @param estate Encryption status.
  * @param cstate Connectivity status.
  */
-void
+static void
 tunnel_callback (void *cls,
                  const struct GNUNET_PeerIdentity *peer,
                  unsigned int n_channels,
@@ -691,7 +708,7 @@ tunnel_callback (void *cls,
   }
   if (GNUNET_YES != monitor_mode)
   {
-    GNUNET_SCHEDULER_shutdown();
+    GNUNET_SCHEDULER_shutdown ();
   }
   return;
 }
@@ -705,14 +722,7 @@ tunnel_callback (void *cls,
 static void
 get_peers (void *cls)
 {
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
-
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
-    return;
-  }
+  job = NULL;
   GNUNET_CADET_get_peers (mh, &peers_callback, NULL);
 }
 
@@ -727,6 +737,7 @@ show_peer (void *cls)
 {
   struct GNUNET_PeerIdentity pid;
 
+  job = NULL;
   if (GNUNET_OK !=
       GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
                                                   strlen (peer_id),
@@ -741,6 +752,7 @@ show_peer (void *cls)
   GNUNET_CADET_get_peer (mh, &pid, peer_callback, NULL);
 }
 
+
 /**
  * Call CADET's meta API, get all tunnels known to a peer.
  *
@@ -749,14 +761,7 @@ show_peer (void *cls)
 static void
 get_tunnels (void *cls)
 {
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
-
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
-    return;
-  }
+  job = NULL;
   GNUNET_CADET_get_tunnels (mh, &tunnels_callback, NULL);
 }
 
@@ -779,7 +784,7 @@ show_tunnel (void *cls)
     fprintf (stderr,
              _("Invalid tunnel owner `%s'\n"),
              tunnel_id);
-    GNUNET_SCHEDULER_shutdown();
+    GNUNET_SCHEDULER_shutdown ();
     return;
   }
   GNUNET_CADET_get_tunnel (mh, &pid, tunnel_callback, NULL);
@@ -794,7 +799,8 @@ show_tunnel (void *cls)
 static void
 show_channel (void *cls)
 {
-
+  job = NULL;
+  GNUNET_break (0);
 }
 
 
@@ -806,7 +812,8 @@ show_channel (void *cls)
 static void
 show_connection (void *cls)
 {
-
+  job = NULL;
+  GNUNET_break (0);
 }
 
 
@@ -819,7 +826,9 @@ show_connection (void *cls)
  * @param cfg configuration
  */
 static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+     char *const *args,
+     const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   GNUNET_CADET_InboundChannelNotificationHandler *newch = NULL;
@@ -871,32 +880,32 @@ run (void *cls, char *const *args, const char *cfgfile,
   else if (NULL != peer_id)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show peer\n");
-    GNUNET_SCHEDULER_add_now (&show_peer, NULL);
+    job = GNUNET_SCHEDULER_add_now (&show_peer, NULL);
   }
   else if (NULL != tunnel_id)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show tunnel\n");
-    GNUNET_SCHEDULER_add_now (&show_tunnel, NULL);
+    job = GNUNET_SCHEDULER_add_now (&show_tunnel, NULL);
   }
   else if (NULL != channel_id)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show channel\n");
-    GNUNET_SCHEDULER_add_now (&show_channel, NULL);
+    job = GNUNET_SCHEDULER_add_now (&show_channel, NULL);
   }
   else if (NULL != conn_id)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show connection\n");
-    GNUNET_SCHEDULER_add_now (&show_connection, NULL);
+    job = GNUNET_SCHEDULER_add_now (&show_connection, NULL);
   }
   else if (GNUNET_YES == request_peers)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all peers\n");
-    GNUNET_SCHEDULER_add_now (&get_peers, NULL);
+    job = GNUNET_SCHEDULER_add_now (&get_peers, NULL);
   }
   else if (GNUNET_YES == request_tunnels)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all tunnels\n");
-    GNUNET_SCHEDULER_add_now (&get_tunnels, NULL);
+    job = GNUNET_SCHEDULER_add_now (&get_tunnels, NULL);
   }
   else
   {
@@ -913,11 +922,9 @@ run (void *cls, char *const *args, const char *cfgfile,
                             ports);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done\n");
   if (NULL == mh)
-    GNUNET_SCHEDULER_add_now (shutdown_task, NULL);
+    GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
   else
-    sd = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                       shutdown_task, NULL);
-
+    sd = GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
 }
 
 

+ 2 - 2
src/cadet/gnunet-service-cadet.c

@@ -135,8 +135,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
   stats = GNUNET_STATISTICS_create ("cadet", c);
 
   /* Scheduled the task to clean up when shutdown is called */
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+				 NULL);
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "reading key\n");
   my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (c);
   GNUNET_assert (NULL != my_private_key);

+ 2 - 12
src/cadet/gnunet-service-cadet_channel.c

@@ -730,13 +730,8 @@ channel_retransmit_message (void *cls)
   struct CadetChannel *ch;
   struct GNUNET_CADET_Data *payload;
   int fwd;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   rel->retry_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
-
   ch = rel->ch;
   copy = rel->head_sent;
   if (NULL == copy)
@@ -765,15 +760,11 @@ static void
 channel_recreate (void *cls)
 {
   struct CadetChannelReliability *rel = cls;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   rel->retry_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
-
   LOG (GNUNET_ERROR_TYPE_DEBUG, "RE-CREATE\n");
-  GNUNET_STATISTICS_update (stats, "# data retransmitted", 1, GNUNET_NO);
+  GNUNET_STATISTICS_update (stats,
+			    "# data retransmitted", 1, GNUNET_NO);
 
   if (rel == rel->ch->root_rel)
   {
@@ -787,7 +778,6 @@ channel_recreate (void *cls)
   {
     GNUNET_break (0);
   }
-
 }
 
 

+ 10 - 41
src/cadet/gnunet-service-cadet_connection.c

@@ -1192,11 +1192,10 @@ connection_maintain (struct CadetConnection *c, int fwd)
  *
  * @param c Connection to keep alive.
  * @param fwd Direction.
- * @param shutdown Are we shutting down? (Don't send traffic)
- *                 Non-zero value for true, not necessarily GNUNET_YES.
  */
 static void
-connection_keepalive (struct CadetConnection *c, int fwd, int shutdown)
+connection_keepalive (struct CadetConnection *c,
+		      int fwd)
 {
   GCC_check_connections ();
   LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1207,10 +1206,6 @@ connection_keepalive (struct CadetConnection *c, int fwd, int shutdown)
     c->fwd_maintenance_task = NULL;
   else
     c->bck_maintenance_task = NULL;
-
-  if (GNUNET_NO != shutdown)
-    return;
-
   connection_maintain (c, fwd);
   GCC_check_connections ();
   /* Next execution will be scheduled by message_sent or _maintain*/
@@ -1225,13 +1220,11 @@ connection_keepalive (struct CadetConnection *c, int fwd, int shutdown)
 static void
 connection_fwd_keepalive (void *cls)
 {
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
+  struct CadetConnection *c = cls;
 
   GCC_check_connections ();
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  connection_keepalive ((struct CadetConnection *) cls,
-                        GNUNET_YES,
-                        tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN);
+  connection_keepalive (c,
+                        GNUNET_YES);
   GCC_check_connections ();
 }
 
@@ -1244,13 +1237,11 @@ connection_fwd_keepalive (void *cls)
 static void
 connection_bck_keepalive (void *cls)
 {
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
+  struct CadetConnection *c = cls;
 
   GCC_check_connections ();
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  connection_keepalive ((struct CadetConnection *) cls,
-                        GNUNET_NO,
-                        tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN);
+  connection_keepalive (c,
+                        GNUNET_NO);
   GCC_check_connections ();
 }
 
@@ -1461,16 +1452,9 @@ connection_poll (void *cls)
   struct GNUNET_CADET_Poll msg;
   struct CadetConnection *c;
   int fwd;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   fc->poll_task = NULL;
   GCC_check_connections ();
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    return;
-  }
-
   c = fc->c;
   fwd = fc == &c->fwd_fc;
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Polling connection %s %s\n",
@@ -1592,12 +1576,8 @@ static void
 connection_fwd_timeout (void *cls)
 {
   struct CadetConnection *c = cls;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   c->fwd_maintenance_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   GCC_check_connections ();
   connection_timeout (c, GNUNET_YES);
   GCC_check_connections ();
@@ -1614,12 +1594,8 @@ static void
 connection_bck_timeout (void *cls)
 {
   struct CadetConnection *c = cls;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   c->bck_maintenance_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   GCC_check_connections ();
   connection_timeout (c, GNUNET_NO);
   GCC_check_connections ();
@@ -1767,13 +1743,8 @@ static void
 check_duplicates (void *cls)
 {
   struct CadetConnection *c = cls;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   c->check_duplicates_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
-
   if (GNUNET_YES == does_connection_exist (c))
   {
     GCT_debug (c->t, GNUNET_ERROR_TYPE_DEBUG);
@@ -1783,7 +1754,6 @@ check_duplicates (void *cls)
 }
 
 
-
 /**
  * Wait for enough time to let any dead connections time out and check for
  * any remaining duplicates.
@@ -1797,7 +1767,6 @@ schedule_check_duplicates (struct CadetConnection *c)
 
   if (NULL != c->check_duplicates_task)
     return;
-
   delay = GNUNET_TIME_relative_multiply (refresh_connection_time, 5);
   c->check_duplicates_task = GNUNET_SCHEDULER_add_delayed (delay,
                                                            &check_duplicates,
@@ -1805,7 +1774,6 @@ schedule_check_duplicates (struct CadetConnection *c)
 }
 
 
-
 /**
  * Add the connection to the list of both neighbors.
  *
@@ -1903,7 +1871,8 @@ unregister_neighbors (struct CadetConnection *c)
  * @param disconnected Peer that disconnected.
  */
 static void
-invalidate_paths (struct CadetConnection *c, struct CadetPeer *disconnected)
+invalidate_paths (struct CadetConnection *c,
+		  struct CadetPeer *disconnected)
 {
   struct CadetPeer *peer;
   unsigned int i;

+ 1 - 7
src/cadet/gnunet-service-cadet_dht.c

@@ -215,14 +215,8 @@ announce_id (void *cls)
   size_t size;
   struct GNUNET_TIME_Absolute expiration;
   struct GNUNET_TIME_Relative retry_time;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    announce_id_task = NULL;
-    return;
-  }
+  announce_id_task = NULL;
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Announce ID\n");
   /* TODO
    * - Set data expiration in function of X

+ 19 - 14
src/cadet/gnunet-service-cadet_peer.c

@@ -387,7 +387,6 @@ notify_broken (void *cls,
  * Remove the direct path to the peer.
  *
  * @param peer Peer to remove the direct path from.
- *
  */
 static struct CadetPeerPath *
 pop_direct_path (struct CadetPeer *peer)
@@ -398,7 +397,9 @@ pop_direct_path (struct CadetPeer *peer)
   {
     if (2 >= iter->length)
     {
-      GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, iter);
+      GNUNET_CONTAINER_DLL_remove (peer->path_head,
+				   peer->path_tail,
+				   iter);
       return iter;
     }
   }
@@ -750,7 +751,8 @@ peer_destroy (struct CadetPeer *peer)
        "destroying peer %s\n",
        GNUNET_i2s (&id));
 
-  if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_remove (peers, &id, peer))
+  if (GNUNET_YES !=
+      GNUNET_CONTAINER_multipeermap_remove (peers, &id, peer))
   {
     GNUNET_break (0);
     LOG (GNUNET_ERROR_TYPE_WARNING, " peer not in peermap!!\n");
@@ -846,12 +848,8 @@ static void
 delayed_search (void *cls)
 {
   struct CadetPeer *peer = cls;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   peer->search_delayed = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
-    return;
   GCC_check_connections ();
   GCP_start_search (peer);
   GCC_check_connections ();
@@ -1934,8 +1932,9 @@ GCP_get (const struct GNUNET_PeerIdentity *peer_id, int create)
 
 
 /**
- * Retrieve the CadetPeer stucture associated with the peer. Optionally create
- * one and insert it in the appropriate structures if the peer is not known yet.
+ * Retrieve the CadetPeer stucture associated with the
+ * peer. Optionally create one and insert it in the appropriate
+ * structures if the peer is not known yet.
  *
  * @param peer Short identity of the peer.
  * @param create #GNUNET_YES if a new peer should be created if unknown.
@@ -2223,7 +2222,8 @@ GCP_add_path (struct CadetPeer *peer,
       }
     }
   }
-  GNUNET_CONTAINER_DLL_insert_tail (peer->path_head, peer->path_tail,
+  GNUNET_CONTAINER_DLL_insert_tail (peer->path_head,
+				    peer->path_tail,
                                     path);
   LOG (GNUNET_ERROR_TYPE_DEBUG, "  added last\n");
 
@@ -2300,7 +2300,8 @@ GCP_add_path_to_all (const struct CadetPeerPath *p, int confirmed)
  * @param path Path to remove. Is always destroyed .
  */
 void
-GCP_remove_path (struct CadetPeer *peer, struct CadetPeerPath *path)
+GCP_remove_path (struct CadetPeer *peer,
+		 struct CadetPeerPath *path)
 {
   struct CadetPeerPath *iter;
   struct CadetPeerPath *next;
@@ -2309,7 +2310,8 @@ GCP_remove_path (struct CadetPeer *peer, struct CadetPeerPath *path)
   GNUNET_assert (myid == path->peers[0]);
   GNUNET_assert (peer->id == path->peers[path->length - 1]);
 
-  LOG (GNUNET_ERROR_TYPE_INFO, "Removing path %p (%u) from %s\n",
+  LOG (GNUNET_ERROR_TYPE_INFO,
+       "Removing path %p (%u) from %s\n",
        path, path->length, GCP_2s (peer));
 
   for (iter = peer->path_head; NULL != iter; iter = next)
@@ -2317,7 +2319,9 @@ GCP_remove_path (struct CadetPeer *peer, struct CadetPeerPath *path)
     next = iter->next;
     if (0 == path_cmp (path, iter))
     {
-      GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, iter);
+      GNUNET_CONTAINER_DLL_remove (peer->path_head,
+				   peer->path_tail,
+				   iter);
       if (iter != path)
         path_destroy (iter);
     }
@@ -2512,7 +2516,8 @@ GCP_get_tunnel (const struct CadetPeer *peer)
  * @param hello Hello message.
  */
 void
-GCP_set_hello (struct CadetPeer *peer, const struct GNUNET_HELLO_Message *hello)
+GCP_set_hello (struct CadetPeer *peer,
+	       const struct GNUNET_HELLO_Message *hello)
 {
   struct GNUNET_HELLO_Message *old;
   size_t size;

+ 22 - 48
src/cadet/gnunet-service-cadet_tunnel.c

@@ -1735,16 +1735,8 @@ static void
 finish_kx (void *cls)
 {
   struct CadetTunnel *t = cls;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   LOG (GNUNET_ERROR_TYPE_INFO, "finish KX for %s\n", GCT_2s (t));
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    LOG (GNUNET_ERROR_TYPE_INFO, "  shutdown\n");
-    return;
-  }
-
   GNUNET_free (t->kx_ctx);
   t->kx_ctx = NULL;
 }
@@ -1767,14 +1759,15 @@ destroy_kx_ctx (struct CadetTunnel *t)
 
   if (is_key_null (&t->kx_ctx->e_key_old))
   {
-    t->kx_ctx->finish_task = GNUNET_SCHEDULER_add_now (finish_kx, t);
+    t->kx_ctx->finish_task = GNUNET_SCHEDULER_add_now (&finish_kx, t);
     return;
   }
 
   delay = GNUNET_TIME_relative_divide (rekey_period, 4);
   delay = GNUNET_TIME_relative_min (delay, GNUNET_TIME_UNIT_MINUTES);
 
-  t->kx_ctx->finish_task = GNUNET_SCHEDULER_add_delayed (delay, finish_kx, t);
+  t->kx_ctx->finish_task = GNUNET_SCHEDULER_add_delayed (delay,
+							 &finish_kx, t);
 }
 
 
@@ -2103,13 +2096,8 @@ static void
 ax_kx_resend (void *cls)
 {
   struct CadetTunnel *t = cls;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   t->rekey_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
-
   if (CADET_TUNNEL_KEY_OK == t->estate)
   {
     /* Should have been canceled on estate change */
@@ -2333,14 +2321,9 @@ static void
 rekey_tunnel (void *cls)
 {
   struct CadetTunnel *t = cls;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   t->rekey_task = NULL;
   LOG (GNUNET_ERROR_TYPE_INFO, "Re-key Tunnel %s\n", GCT_2s (t));
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (NULL != tc && 0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
-    return;
-
   GNUNET_assert (NULL != t->kx_ctx);
   struct GNUNET_TIME_Relative duration;
 
@@ -2453,13 +2436,8 @@ global_otr_rekey (void *cls)
 {
   struct GNUNET_TIME_Absolute time;
   long n;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   rekey_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
-    return;
-
   GNUNET_free_non_null (otr_ephemeral_key);
   otr_ephemeral_key = GNUNET_CRYPTO_ecdhe_key_create ();
 
@@ -2501,7 +2479,8 @@ destroy_iterator (void *cls,
 {
   struct CadetTunnel *t = value;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "GCT_shutdown destroying tunnel at %p\n", t);
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "GCT_shutdown destroying tunnel at %p\n", t);
   GCT_destroy (t);
   return GNUNET_YES;
 }
@@ -3472,13 +3451,8 @@ static void
 trim_connections (void *cls)
 {
   struct CadetTunnel *t = cls;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   t->trim_connections_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
-
   if (GCT_count_connections (t) > 2 * CONNECTIONS_PER_TUNNEL)
   {
     struct CadetTConnection *iter;
@@ -3624,8 +3598,11 @@ GCT_add_channel (struct CadetTunnel *t, struct CadetChannel *ch)
 
   aux = GNUNET_new (struct CadetTChannel);
   aux->ch = ch;
-  LOG (GNUNET_ERROR_TYPE_DEBUG, " adding %p to %p\n", aux, t->channel_head);
-  GNUNET_CONTAINER_DLL_insert_tail (t->channel_head, t->channel_tail, aux);
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       " adding %p to %p\n", aux, t->channel_head);
+  GNUNET_CONTAINER_DLL_insert_tail (t->channel_head,
+				    t->channel_tail,
+				    aux);
 
   if (NULL != t->destroy_task)
   {
@@ -3653,7 +3630,9 @@ GCT_remove_channel (struct CadetTunnel *t, struct CadetChannel *ch)
     if (aux->ch == ch)
     {
       LOG (GNUNET_ERROR_TYPE_DEBUG, " found! %s\n", GCCH_2s (ch));
-      GNUNET_CONTAINER_DLL_remove (t->channel_head, t->channel_tail, aux);
+      GNUNET_CONTAINER_DLL_remove (t->channel_head,
+				   t->channel_tail,
+				   aux);
       GNUNET_free (aux);
       return;
     }
@@ -3701,20 +3680,12 @@ delayed_destroy (void *cls)
 {
   struct CadetTunnel *t = cls;
   struct CadetTConnection *iter;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "delayed destroying tunnel %p\n", t);
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
-  {
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-         "Not destroying tunnel, due to shutdown. "
-         "Tunnel at %p should have been freed by GCT_shutdown\n", t);
-    return;
-  }
   t->destroy_task = NULL;
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "delayed destroying tunnel %p\n",
+       t);
   t->cstate = CADET_TUNNEL_SHUTDOWN;
-
   for (iter = t->connection_head; NULL != iter; iter = iter->next)
   {
     GCC_send_destroy (iter->c);
@@ -3800,8 +3771,9 @@ GCT_destroy (struct CadetTunnel *t)
   if (NULL == t)
     return;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying tunnel %s\n", GCP_2s (t->peer));
-
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "destroying tunnel %s\n",
+       GCP_2s (t->peer));
   GNUNET_break (GNUNET_YES ==
                 GNUNET_CONTAINER_multipeermap_remove (tunnels,
                                                       GCP_get_id (t->peer), t));
@@ -3850,7 +3822,9 @@ GCT_destroy (struct CadetTunnel *t)
 
   if (NULL != t->destroy_task)
   {
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "cancelling dest: %p\n", t->destroy_task);
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+	 "cancelling dest: %p\n",
+	 t->destroy_task);
     GNUNET_SCHEDULER_cancel (t->destroy_task);
     t->destroy_task = NULL;
   }

+ 53 - 65
src/cadet/test_cadet.c

@@ -144,17 +144,17 @@ struct GNUNET_CADET_TEST_Context *test_ctx;
 /**
  * Task called to disconnect peers.
  */
-static struct GNUNET_SCHEDULER_Task * disconnect_task;
+static struct GNUNET_SCHEDULER_Task *disconnect_task;
 
 /**
  * Task To perform tests
  */
-static struct GNUNET_SCHEDULER_Task * test_task;
+static struct GNUNET_SCHEDULER_Task *test_task;
 
 /**
- * Task called to shutdown test.
+ * Task runnining #data_task().
  */
-static struct GNUNET_SCHEDULER_Task * shutdown_handle;
+static struct GNUNET_SCHEDULER_Task *data_job;
 
 /**
  * Cadet handle for the root peer
@@ -230,6 +230,7 @@ get_expected_target ()
     return peers_requested - 1;
 }
 
+
 /**
  * Show the results of the test (banwidth acheived) and log them to GAUGER
  */
@@ -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);

+ 22 - 26
src/cadet/test_cadet_local.c

@@ -42,9 +42,9 @@ static int result = GNUNET_OK;
 
 static int got_data = GNUNET_NO;
 
-static struct GNUNET_SCHEDULER_Task * abort_task;
+static struct GNUNET_SCHEDULER_Task *abort_task;
 
-static struct GNUNET_SCHEDULER_Task * shutdown_task;
+static struct GNUNET_SCHEDULER_Task *connect_task;
 
 static struct GNUNET_CADET_TransmitHandle *mth;
 
@@ -68,20 +68,29 @@ do_shutdown (void *cls)
   if (NULL != abort_task)
   {
     GNUNET_SCHEDULER_cancel (abort_task);
+    abort_task = NULL;
+  }
+  if (NULL != connect_task)
+  {
+    GNUNET_SCHEDULER_cancel (connect_task);
+    connect_task = NULL;
   }
   if (NULL != ch)
   {
     GNUNET_CADET_channel_destroy (ch);
+    ch = NULL;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect client 1\n");
   if (NULL != cadet_peer_1)
   {
     GNUNET_CADET_disconnect (cadet_peer_1);
+    cadet_peer_1 = NULL;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect client 2\n");
   if (NULL != cadet_peer_2)
   {
     GNUNET_CADET_disconnect (cadet_peer_2);
+    cadet_peer_2 = NULL;
   }
 }
 
@@ -95,12 +104,7 @@ do_abort (void *cls)
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ABORT\n");
   result = GNUNET_SYSERR;
   abort_task = NULL;
-  if (NULL != shutdown_task)
-  {
-    GNUNET_SCHEDULER_cancel (shutdown_task);
-    shutdown_task = NULL;
-  }
-  do_shutdown (cls);
+  GNUNET_SCHEDULER_shutdown ();
 }
 
 
@@ -120,14 +124,10 @@ data_callback (void *cls, struct GNUNET_CADET_Channel *channel,
                void **channel_ctx,
                const struct GNUNET_MessageHeader *message)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Data callback! Shutting down.\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+	      "Data callback! Shutting down.\n");
   got_data = GNUNET_YES;
-  if (NULL != shutdown_task)
-    GNUNET_SCHEDULER_cancel (shutdown_task);
-  shutdown_task =
-    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
-                                  &do_shutdown,
-                                  NULL);
+  GNUNET_SCHEDULER_shutdown ();
   GNUNET_CADET_receive_done (channel);
   return GNUNET_OK;
 }
@@ -254,12 +254,8 @@ static void
 do_connect (void *cls)
 {
   struct GNUNET_PeerIdentity id;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
-
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (NULL != tc && 0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
-    return;
 
+  connect_task = NULL;
   GNUNET_TESTING_peer_get_identity (me, &id);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n");
   ch = GNUNET_CADET_channel_create (cadet_peer_1, NULL, &id, 1,
@@ -286,9 +282,11 @@ run (void *cls,
   static uint32_t ports[] = {1, 0};
 
   me = peer;
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
   abort_task =
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
-                                    (GNUNET_TIME_UNIT_SECONDS, 15), &do_abort,
+                                    (GNUNET_TIME_UNIT_SECONDS, 15),
+				    &do_abort,
                                     NULL);
   cadet_peer_1 = GNUNET_CADET_connect (cfg,       /* configuration */
                                      (void *) 1L,       /* cls */
@@ -305,14 +303,12 @@ run (void *cls,
                                      ports);     /* ports offered */
   if (NULL == cadet_peer_1 || NULL == cadet_peer_2)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to cadet :(\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+		"Couldn't connect to cadet :(\n");
     result = GNUNET_SYSERR;
+    GNUNET_SCHEDULER_shutdown ();
     return;
   }
-  else
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO CADET :D\n");
-  }
   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
                                   GNUNET_TIME_UNIT_SECONDS,
                                   2),

+ 17 - 29
src/cadet/test_cadet_single.c

@@ -43,9 +43,9 @@ static struct GNUNET_CADET_Channel *ch2;
 
 static int result;
 
-static struct GNUNET_SCHEDULER_Task * abort_task;
+static struct GNUNET_SCHEDULER_Task *abort_task;
 
-static struct GNUNET_SCHEDULER_Task * shutdown_task;
+static struct GNUNET_SCHEDULER_Task *connect_task;
 
 static unsigned int repetition;
 
@@ -65,10 +65,17 @@ do_shutdown (void *cls)
   if (NULL != abort_task)
   {
     GNUNET_SCHEDULER_cancel (abort_task);
+    abort_task = NULL;
+  }
+  if (NULL != connect_task)
+  {
+    GNUNET_SCHEDULER_cancel (connect_task);
+    connect_task = NULL;
   }
   if (NULL != ch1)
   {
     GNUNET_CADET_channel_destroy (ch1);
+    ch1 = NULL;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect client 1\n");
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect client 2\n");
@@ -93,22 +100,7 @@ do_abort (void *cls)
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ABORT\n");
   result = GNUNET_SYSERR;
   abort_task = NULL;
-  if (NULL != shutdown_task)
-  {
-    GNUNET_SCHEDULER_cancel (shutdown_task);
-    shutdown_task = NULL;
-  }
-  do_shutdown (cls);
-}
-
-
-static void
-finish (void)
-{
-  if (NULL != shutdown_task)
-    GNUNET_SCHEDULER_cancel (shutdown_task);
-  shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
-                                                &do_shutdown, NULL);
+  GNUNET_SCHEDULER_shutdown ();
 }
 
 
@@ -202,7 +194,7 @@ channel_end (void *cls, const struct GNUNET_CADET_Channel *channel,
     ch2 = NULL;
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "everything fine! finishing!\n");
     result = GNUNET_OK;
-    finish ();
+    GNUNET_SCHEDULER_shutdown ();
   }
 }
 
@@ -253,12 +245,8 @@ do_connect (void *cls)
 {
   struct GNUNET_PeerIdentity id;
   size_t size = sizeof (struct GNUNET_MessageHeader) + DATA_SIZE;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
-
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
-    return;
 
+  connect_task = NULL;
   GNUNET_TESTING_peer_get_identity (me, &id);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n");
   ch1 = GNUNET_CADET_channel_create (cadet, NULL, &id, 1,
@@ -284,6 +272,7 @@ run (void *cls,
   static uint32_t ports[] = {1, 0};
 
   me = peer;
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
   abort_task =
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
                                     (GNUNET_TIME_UNIT_SECONDS, 15), &do_abort,
@@ -301,11 +290,10 @@ run (void *cls,
     result = GNUNET_SYSERR;
     return;
   }
-  else
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO CADET :D\n");
-  }
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_connect, NULL);
+  connect_task
+    = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+				    &do_connect,
+				    NULL);
 }
 
 

+ 1 - 1
src/consensus/gnunet-service-consensus.c

@@ -3231,7 +3231,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
   }
   statistics = GNUNET_STATISTICS_create ("consensus", cfg);
   GNUNET_SERVER_add_handlers (server, server_handlers);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
   GNUNET_SERVER_disconnect_notify (server, handle_client_disconnect, NULL);
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "consensus running\n");
 }

+ 4 - 10
src/consensus/test_consensus_api.c

@@ -92,10 +92,7 @@ run (void *cls,
   GNUNET_log_setup ("test_consensus_api",
                     "INFO",
                     NULL);
-
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "testing consensus api\n");
-
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &on_shutdown, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&on_shutdown, NULL);
 
   GNUNET_CRYPTO_hash (str, strlen (str), &session_id);
   consensus = GNUNET_CONSENSUS_create (cfg, 0, NULL, &session_id,
@@ -112,10 +109,7 @@ run (void *cls,
 int
 main (int argc, char **argv)
 {
-  int ret;
-
-  ret = GNUNET_TESTING_peer_run ("test_consensus_api",
-                                 "test_consensus.conf",
-                                 &run, NULL);
-  return ret;
+  return GNUNET_TESTING_peer_run ("test_consensus_api",
+				  "test_consensus.conf",
+				  &run, NULL);
 }

+ 2 - 3
src/conversation/gnunet-conversation-test.c

@@ -204,9 +204,8 @@ run (void *cls, char *const *args, const char *cfgfile,
   switch_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
 					      &switch_to_speaker,
 					      NULL);
-  st = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-				     &do_shutdown,
-				     NULL);
+  st = GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+				      NULL);
   fprintf (stderr,
 	   _("We will now be recording you for %s. After that time, the recording will be played back to you..."),
 	   GNUNET_STRINGS_relative_time_to_string (TIMEOUT, GNUNET_YES));

+ 2 - 2
src/conversation/gnunet-conversation.c

@@ -1249,8 +1249,8 @@ run (void *cls,
   handle_cmd_task =
     GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI,
 					&handle_command, NULL);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_stop_task,
-				NULL);
+  GNUNET_SCHEDULER_add_shutdown (&do_stop_task,
+				 NULL);
 }
 
 

+ 5 - 4
src/conversation/gnunet-service-conversation.c

@@ -1574,10 +1574,11 @@ run (void *cls,
   }
   nc = GNUNET_SERVER_notification_context_create (server, 16);
   GNUNET_SERVER_add_handlers (server, server_handlers);
-  GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &do_shutdown,
-				NULL);
+  GNUNET_SERVER_disconnect_notify (server,
+				   &handle_client_disconnect,
+				   NULL);
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+				 NULL);
 }
 
 

+ 1 - 2
src/core/gnunet-core.c

@@ -155,8 +155,7 @@ run (void *cls, char *const *args, const char *cfgfile,
              _("Failed to connect to CORE service!\n"));
     return;
   }
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &shutdown_task, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
 }
 
 

+ 2 - 3
src/core/gnunet-service-core.c

@@ -106,9 +106,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
     return;
   }
   GSC_stats = GNUNET_STATISTICS_create ("core", GSC_cfg);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &shutdown_task,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+				 NULL);
   GNUNET_SERVER_suspend (server);
   GSC_TYPEMAP_init ();
   pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);

+ 4 - 3
src/core/gnunet-service-core_kx.c

@@ -745,9 +745,10 @@ GSC_KX_start (const struct GNUNET_PeerIdentity *pid)
   {
     /* peer with "higher" identity starts a delayed  KX, if the "lower" peer
      * does not start a KX since he sees no reasons to do so  */
-    kx->retry_set_key_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
-                                                           &set_key_retry_task,
-                                                           kx);
+    kx->retry_set_key_task
+      = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+				      &set_key_retry_task,
+				      kx);
   }
   return kx;
 }

+ 19 - 11
src/core/test_core_api_mq.c

@@ -29,15 +29,15 @@
 /**
  * Has the test been successful?
  */
-int result;
+static int result;
 
-unsigned int num_received;
+static unsigned int num_received;
 
-struct GNUNET_CORE_Handle *core;
+static struct GNUNET_CORE_Handle *core;
 
-struct GNUNET_MQ_Handle *mq;
+static struct GNUNET_MQ_Handle *mq;
 
-struct GNUNET_PeerIdentity myself;
+static struct GNUNET_PeerIdentity myself;
 
 
 static void
@@ -55,15 +55,19 @@ init_cb (void *cls,
 
 
 static void
-connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
+connect_cb (void *cls,
+	    const struct GNUNET_PeerIdentity *peer)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %s.\n",
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+	      "Connected to peer %s.\n",
               GNUNET_i2s (peer));
   if (0 == memcmp (peer, &myself, sizeof (struct GNUNET_PeerIdentity)))
   {
     unsigned int i;
     struct GNUNET_MQ_Envelope *ev;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing messages.\n");
+
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+		"Queueing messages.\n");
     for (i = 0; i < NUM_MSG; i++)
     {
       ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_TEST);
@@ -78,7 +82,9 @@ handle_test (void *cls,
              const struct GNUNET_PeerIdentity *other,
              const struct GNUNET_MessageHeader *message)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got test message %d\n", num_received);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+	      "Got test message %d\n",
+	      num_received);
   num_received++;
   if (NUM_MSG == num_received)
   {
@@ -98,7 +104,8 @@ handle_test (void *cls,
 static void
 shutdown_task (void *cls)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+	      "Shutting down\n");
   GNUNET_MQ_destroy (mq);
   GNUNET_CORE_disconnect (core);
 }
@@ -129,9 +136,10 @@ run (void *cls,
     GNUNET_assert (0);
     return;
   }
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
 }
 
+
 int
 main (int argc, char *argv1[])
 {

+ 3 - 10
src/core/test_core_quota_compliance.c

@@ -163,13 +163,9 @@ terminate_task (void *cls)
 static void
 terminate_task_error (void *cls)
 {
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
-
   err_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Testcase failed!\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+	      "Testcase failed!\n");
   terminate_peer (&p1);
   terminate_peer (&p2);
   //GNUNET_break (0);
@@ -301,7 +297,6 @@ measurement_stop (void *cls)
 */
   GNUNET_SCHEDULER_cancel (err_task);
   err_task = GNUNET_SCHEDULER_add_now (&terminate_task, NULL);
-
 }
 
 
@@ -357,7 +352,6 @@ transmit_ready (void *cls, size_t size, void *buf)
 }
 
 
-
 static void
 connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
 {
@@ -375,8 +369,7 @@ connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Asking core (1) for transmission to peer `%4s'\n",
                 GNUNET_i2s (&p2.id));
-    if (err_task != NULL)
-      GNUNET_SCHEDULER_cancel (err_task);
+    GNUNET_SCHEDULER_cancel (err_task);
     err_task =
         GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL);
     start_time = GNUNET_TIME_absolute_get ();

+ 1 - 0
src/curl/Makefile.am

@@ -17,6 +17,7 @@ libgnunetcurl_la_SOURCES = \
 libgnunetcurl_la_LIBADD = \
   $(top_builddir)/src/util/libgnunetutil.la \
   -ljansson \
+  -lcurl \
   $(XLIB)
 
 #check_PROGRAMS = \

+ 1 - 2
src/datastore/gnunet-datastore.c

@@ -224,8 +224,7 @@ run (void *cls, char *const *args, const char *cfgfile,
     ret = 1;
     return;
   }
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-				&do_shutdown, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
   do_get ();
 }
 

+ 5 - 4
src/datastore/gnunet-service-datastore.c

@@ -391,7 +391,9 @@ static void
 delete_expired (void *cls)
 {
   expired_kill_task = NULL;
-  plugin->api->get_expiration (plugin->api->cls, &expired_processor, NULL);
+  plugin->api->get_expiration (plugin->api->cls,
+			       &expired_processor,
+			       NULL);
 }
 
 
@@ -1819,9 +1821,8 @@ run (void *cls,
   GNUNET_SERVER_disconnect_notify (server,
                                    &cleanup_reservations,
                                    NULL);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &cleaning_task,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&cleaning_task,
+				 NULL);
 }
 
 

+ 0 - 4
src/datastore/perf_datastore_api.c

@@ -351,11 +351,7 @@ run_continuation (void *cls)
   static struct GNUNET_HashCode key;
   static char data[65536];
   char gstr[128];
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    crc->phase = RP_ERROR;
   ok = (int) crc->phase;
   switch (crc->phase)
   {

+ 27 - 18
src/datastore/perf_plugin_datastore.c

@@ -133,6 +133,7 @@ put_continuation (void *cls,
   GNUNET_SCHEDULER_add_now (&test, crc);
 }
 
+
 static void
 do_put (struct CpsRunContext *crc)
 {
@@ -195,9 +196,14 @@ do_put (struct CpsRunContext *crc)
 
 
 static int
-iterate_zeros (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
-               const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
-               uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
+iterate_zeros (void *cls,
+	       const struct GNUNET_HashCode *key,
+	       uint32_t size,
+               const void *data,
+	       enum GNUNET_BLOCK_Type type,
+	       uint32_t priority,
+               uint32_t anonymity,
+	       struct GNUNET_TIME_Absolute expiration,
                uint64_t uid)
 {
   struct CpsRunContext *crc = cls;
@@ -246,10 +252,15 @@ iterate_zeros (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
 
 
 static int
-expiration_get (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
-                const void *data, enum GNUNET_BLOCK_Type type,
-                uint32_t priority, uint32_t anonymity,
-                struct GNUNET_TIME_Absolute expiration, uint64_t uid)
+expiration_get (void *cls,
+		const struct GNUNET_HashCode *key,
+		uint32_t size,
+                const void *data,
+		enum GNUNET_BLOCK_Type type,
+                uint32_t priority,
+		uint32_t anonymity,
+                struct GNUNET_TIME_Absolute expiration,
+		uint64_t uid)
 {
   struct CpsRunContext *crc = cls;
   int i;
@@ -293,10 +304,15 @@ expiration_get (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
 
 
 static int
-replication_get (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
-                 const void *data, enum GNUNET_BLOCK_Type type,
-                 uint32_t priority, uint32_t anonymity,
-                 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
+replication_get (void *cls,
+		 const struct GNUNET_HashCode *key,
+		 uint32_t size,
+                 const void *data,
+		 enum GNUNET_BLOCK_Type type,
+                 uint32_t priority,
+		 uint32_t anonymity,
+                 struct GNUNET_TIME_Absolute expiration,
+		 uint64_t uid)
 {
   struct CpsRunContext *crc = cls;
   int i;
@@ -388,14 +404,7 @@ static void
 test (void *cls)
 {
   struct CpsRunContext *crc = cls;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    GNUNET_break (0);
-    crc->phase = RP_ERROR;
-  }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
 	      "In phase %d, iteration %u\n", crc->phase, crc->cnt);
   switch (crc->phase)

+ 0 - 7
src/datastore/test_plugin_datastore.c

@@ -267,14 +267,7 @@ test (void *cls)
 {
   struct CpsRunContext *crc = cls;
   struct GNUNET_HashCode key;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test aborted.\n");
-    crc->phase = RP_ERROR;
-  }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
 	      "In phase %d, iteration %u\n", crc->phase, crc->cnt);
   switch (crc->phase)

+ 27 - 3
src/dht/gnunet-dht-get.c

@@ -82,9 +82,14 @@ static unsigned int result_count;
  */
 static int ret;
 
+/**
+ * Task scheduled to handle timeout.
+ */
+static struct GNUNET_SCHEDULER_Task *tt;
+
 
 /**
- * Task run to clean up on timeout.
+ * Task run to clean up on shutdown.
  *
  * @param cls unused
  */
@@ -101,6 +106,24 @@ cleanup_task (void *cls)
     GNUNET_DHT_disconnect (dht_handle);
     dht_handle = NULL;
   }
+  if (NULL != tt)
+  {
+    GNUNET_SCHEDULER_cancel (tt);
+    tt = NULL;
+  }
+}
+
+
+/**
+ * Task run on timeout. Triggers shutdown.
+ *
+ * @param cls unused
+ */
+static void
+timeout_task (void *cls)
+{
+  tt = NULL;
+  GNUNET_SCHEDULER_shutdown ();
 }
 
 
@@ -170,8 +193,9 @@ run (void *cls, char *const *args, const char *cfgfile,
   GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key);
   if (verbose)
     FPRINTF (stderr, "%s `%s' \n",  _("Issueing DHT GET with key"), GNUNET_h2s_full (&key));
-  GNUNET_SCHEDULER_add_delayed (timeout_request,
-				&cleanup_task, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL);
+  tt = GNUNET_SCHEDULER_add_delayed (timeout_request,
+				     &timeout_task, NULL);
   get_handle =
       GNUNET_DHT_get_start (dht_handle, query_type, &key, replication,
                             (demultixplex_everywhere) ? GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE : GNUNET_DHT_RO_NONE,

+ 32 - 4
src/dht/gnunet-dht-monitor.c

@@ -71,6 +71,11 @@ static unsigned int result_count;
  */
 static int ret;
 
+/**
+ * Task scheduled to handle timeout.
+ */
+static struct GNUNET_SCHEDULER_Task *tt;
+
 
 /**
  * Stop monitoring request and start shutdown
@@ -92,9 +97,28 @@ cleanup_task (void *cls)
     GNUNET_DHT_disconnect (dht_handle);
     dht_handle = NULL;
   }
+  if (NULL != tt)
+  {
+    GNUNET_SCHEDULER_cancel (tt);
+    tt = NULL;
+  }
+}
+
+
+/**
+ * We hit a timeout. Stop monitoring request and start shutdown
+ *
+ * @param cls closure (unused)
+ */
+static void
+timeout_task (void *cls)
+{
+  tt = NULL;
+  GNUNET_SCHEDULER_shutdown ();
 }
 
 
+
 /**
  * Callback called on each GET request going through the DHT.
  *
@@ -107,7 +131,7 @@ cleanup_task (void *cls)
  * @param desired_replication_level Desired replication level.
  * @param key Key of the requested data.
  */
-void
+static void
 get_callback (void *cls,
               enum GNUNET_DHT_RouteOption options,
               enum GNUNET_BLOCK_Type type,
@@ -139,7 +163,7 @@ get_callback (void *cls,
  * @param data Pointer to the result data.
  * @param size Number of bytes in data.
  */
-void
+static void
 get_resp_callback (void *cls,
                    enum GNUNET_BLOCK_Type type,
                    const struct GNUNET_PeerIdentity *get_path,
@@ -177,7 +201,7 @@ get_resp_callback (void *cls,
  * @param data Pointer to the data carried.
  * @param size Number of bytes in data.
  */
-void
+static void
 put_callback (void *cls,
               enum GNUNET_DHT_RouteOption options,
               enum GNUNET_BLOCK_Type type,
@@ -242,7 +266,11 @@ run (void *cls, char *const *args, const char *cfgfile,
     FPRINTF (stderr,
 	     "Monitoring for %s\n",
 	     GNUNET_STRINGS_relative_time_to_string (timeout_request, GNUNET_NO));
-  GNUNET_SCHEDULER_add_delayed (timeout_request, &cleanup_task, NULL);
+  tt = GNUNET_SCHEDULER_add_delayed (timeout_request,
+				     &timeout_task,
+				     NULL);
+  GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
+				NULL);
   monitor_handle = GNUNET_DHT_monitor_start (dht_handle,
                                              block_type,
                                              key,

+ 5 - 2
src/dht/gnunet-dht-put.c

@@ -98,6 +98,7 @@ shutdown_task (void *cls)
   }
 }
 
+
 /**
  * Signature of the main function of a task.
  *
@@ -132,6 +133,7 @@ message_sent_cont (void *cls, int success)
   GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
 }
 
+
 /**
  * Main function that will be run by the scheduler.
  *
@@ -141,14 +143,15 @@ message_sent_cont (void *cls, int success)
  * @param c configuration
  */
 static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+     char *const *args,
+     const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
   struct GNUNET_TIME_Relative timeout;
   struct GNUNET_TIME_Absolute expiration;
 
   cfg = c;
-
   if ((NULL == query_key) || (NULL == data))
   {
     FPRINTF (stderr, "%s",  _("Must provide KEY and DATA for DHT put!\n"));

+ 2 - 3
src/dht/gnunet-service-dht.c

@@ -161,9 +161,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
     shutdown_task (NULL);
     return;
   }
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &shutdown_task,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+				 NULL);
   GDS_transport_handle =
       GNUNET_TRANSPORT_connect (GDS_cfg, NULL, NULL, NULL, NULL, NULL);
   if (GDS_transport_handle == NULL)

+ 0 - 4
src/dht/gnunet-service-dht_clients.c

@@ -456,12 +456,8 @@ transmit_next_request_task (void *cls)
 {
   struct ClientQueryRecord *cqr;
   struct GNUNET_TIME_Relative delay;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   retry_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap)))
   {
     cqr->hnode = NULL;

+ 1 - 4
src/dht/gnunet-service-dht_neighbours.c

@@ -712,12 +712,8 @@ send_find_peer_message (void *cls)
   struct GNUNET_TIME_Relative next_send_time;
   struct BloomConstructorContext bcc;
   struct GNUNET_CONTAINER_BloomFilter *peer_bf;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   find_peer_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
-    return;
   if (newly_found_peers > bucket_size)
   {
     /* If we are finding many peers already, no need to send out our request right now! */
@@ -2443,6 +2439,7 @@ GDS_NEIGHBOURS_done ()
   }
 }
 
+
 /**
  * Get the ID of the local node.
  *

+ 2 - 3
src/dht/gnunet-service-wdht.c

@@ -102,9 +102,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
     shutdown_task (NULL);
     return;
   }
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &shutdown_task,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+				 NULL);
 }
 
 

+ 0 - 4
src/dht/gnunet-service-wdht_clients.c

@@ -880,12 +880,8 @@ transmit_next_request_task (void *cls)
 {
   struct ClientQueryRecord *cqr;
   struct GNUNET_TIME_Relative delay;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   retry_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap)))
   {
     cqr->hnode = NULL;

+ 2 - 5
src/dht/gnunet-service-xdht.c

@@ -17,14 +17,12 @@
      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
      Boston, MA 02110-1301, USA.
 */
-
 /**
  * @file dht/gnunet-service-xdht.c
  * @brief GNUnet DHT service
  * @author Christian Grothoff
  * @author Nathan Evans
  */
-
 #include "platform.h"
 #include "gnunet_block_lib.h"
 #include "gnunet_util_lib.h"
@@ -125,9 +123,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
     shutdown_task (NULL);
     return;
   }
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &shutdown_task,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+				 NULL);
 }
 
 

+ 0 - 4
src/dht/gnunet-service-xdht_clients.c

@@ -877,12 +877,8 @@ transmit_next_request_task (void *cls)
 {
   struct ClientQueryRecord *cqr;
   struct GNUNET_TIME_Relative delay;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   retry_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap)))
   {
     cqr->hnode = NULL;

+ 46 - 53
src/dht/gnunet_dht_profiler.c

@@ -461,9 +461,21 @@ do_shutdown (void *cls)
     a_ctx = NULL;
   }
   //FIXME: Should we collect stats only for put/get not for other messages.
-  if(NULL != bandwidth_stats_op)
+  if (NULL != bandwidth_stats_op)
+  {
     GNUNET_TESTBED_operation_done (bandwidth_stats_op);
-  bandwidth_stats_op = NULL;
+    bandwidth_stats_op = NULL;
+  }
+  if (NULL != successor_stats_op)
+  {
+    GNUNET_TESTBED_operation_done (successor_stats_op);
+    successor_stats_op = NULL;
+  }
+  if (NULL != successor_stats_task)
+  {
+    GNUNET_SCHEDULER_cancel (successor_stats_task);
+    successor_stats_task = NULL;
+  }
   GNUNET_free_non_null (a_ac);
 }
 
@@ -687,11 +699,7 @@ teardown_dht_connection (void *cls)
 {
   struct Context *ctx = cls;
   struct GNUNET_TESTBED_Operation *op;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
-    return;
   GNUNET_assert (NULL != ctx);
   GNUNET_assert (NULL != (op = ctx->op));
   ctx->op = NULL;
@@ -1070,7 +1078,7 @@ successor_stats_cont (void *cls,
   successor_stats_op = NULL;
   if (0 == max_searches)
   {
-    start_func();
+    start_func ();
     return;
   }
 
@@ -1108,39 +1116,27 @@ successor_stats_cont (void *cls,
                                                                  GNUNET_NO);
   if ((start_val == val) && (count == num_peers))
   {
-    DEBUG("CIRCLE COMPLETED after %u tries", tries);
+    DEBUG ("CIRCLE COMPLETED after %u tries", tries);
     if(NULL == successor_stats_task)
     {
       start_func();
     }
     return;
   }
-  else
+  if (max_searches == ++tries)
   {
-    if (max_searches == ++tries)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Maximum tries %u exceeded while checking successor TOTAL TRIES %u"
-                  " circle formation.  Exiting\n",
-                  max_searches,tries);
-      if (NULL != successor_stats_task)
-      {
-        successor_stats_task = NULL;
-      }
-      if(NULL == successor_stats_task)
-      {
-        start_func();
-      }
-
-      return;
-    }
-    else
-    {
-      flag = 0;
-      successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay_stats,
-                                                           &collect_stats, cls);
-    }
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+		"Maximum tries %u exceeded while checking successor TOTAL TRIES %u"
+		" circle formation.  Exiting\n",
+		max_searches,tries);
+    start_func();
+    return;
   }
+  flag = 0;
+  successor_stats_task
+    = GNUNET_SCHEDULER_add_delayed (delay_stats,
+				    &collect_stats,
+				    cls);
 }
 
 
@@ -1214,26 +1210,21 @@ successor_stats_iterator (void *cls,
 static void
 collect_stats (void *cls)
 {
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
-
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
-    return;
-
+  successor_stats_task = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Start collecting statistics...\n");
   GNUNET_assert(NULL != testbed_handles);
 
   if (0 != max_searches)
-  successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (num_peers,
-                                                                    GNUNET_NO);
-  successor_stats_op =
-          GNUNET_TESTBED_get_statistics (num_peers, testbed_handles,
-                                         "dht", NULL,
-                                          successor_stats_iterator,
-                                          successor_stats_cont, cls);
-
-  GNUNET_assert(NULL != successor_stats_op);
+    successor_peer_hashmap
+      = GNUNET_CONTAINER_multihashmap_create (num_peers,
+					      GNUNET_NO);
+  successor_stats_op
+    = GNUNET_TESTBED_get_statistics (num_peers, testbed_handles,
+				     "dht", NULL,
+				     successor_stats_iterator,
+				     successor_stats_cont, cls);
+  GNUNET_assert (NULL != successor_stats_op);
 }
 
 
@@ -1265,9 +1256,10 @@ service_started (void *cls,
      collect_stat_cls->service_connect_ctx = cls;
      collect_stat_cls->op = op;
 
-     successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay_stats,
-                                                          &collect_stats,
-                                                          collect_stat_cls);
+     successor_stats_task
+       = GNUNET_SCHEDULER_add_delayed (delay_stats,
+				       &collect_stats,
+				       collect_stat_cls);
   }
 }
 
@@ -1393,7 +1385,8 @@ run (void *cls, char *const *args, const char *cfgfile,
 
   if (0 == num_peers)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Exiting as the number of peers is %u\n"),
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+		_("Exiting as the number of peers is %u\n"),
                 num_peers);
     return;
   }
@@ -1401,8 +1394,8 @@ run (void *cls, char *const *args, const char *cfgfile,
   event_mask = 0;
   GNUNET_TESTBED_run (hosts_file, cfg, num_peers, event_mask, NULL,
                       NULL, &test_run, NULL);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+				 NULL);
 }
 
 

+ 1 - 1
src/dns/dnsstub.c

@@ -476,7 +476,7 @@ read_response (void *cls)
   tc = GNUNET_SCHEDULER_get_task_context ();
   if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
   {
-    /* timeout or shutdown */
+    /* timeout */
     cleanup_rs (rs);
     return;
   }

+ 1 - 2
src/dns/gnunet-dns-monitor.c

@@ -339,8 +339,7 @@ run (void *cls, char *const *args, const char *cfgfile,
 			flags,
 			&display_request,
 			NULL);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-				&do_disconnect, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&do_disconnect, NULL);
 }
 
 

+ 1 - 2
src/dns/gnunet-dns-redirector.c

@@ -223,8 +223,7 @@ run (void *cls, char *const *args, const char *cfgfile,
 			GNUNET_DNS_FLAG_POST_RESOLUTION,
 			&modify_request,
 			NULL);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-				&do_disconnect, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&do_disconnect, NULL);
 }
 
 

+ 2 - 3
src/dns/gnunet-service-dns.c

@@ -1045,9 +1045,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
   cfg = cfg_;
   stats = GNUNET_STATISTICS_create ("dns", cfg);
   nc = GNUNET_SERVER_notification_context_create (server, 1);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &cleanup_task,
-                                cls);
+  GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
+				 cls);
   dns_exit = NULL;
   if ( ( (GNUNET_OK !=
 	  GNUNET_CONFIGURATION_get_value_string (cfg,

+ 1 - 2
src/dv/gnunet-dv.c

@@ -145,8 +145,7 @@ run (void *cls, char *const *args, const char *cfgfile,
 				  &change_cb,
 				  &disconnect_cb,
 				  &message_cb);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-				&shutdown_task, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
 }
 
 

+ 1 - 2
src/dv/gnunet-service-dv.c

@@ -2229,8 +2229,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
 						  MAX_QUEUE_SIZE_PLUGIN);
   stats = GNUNET_STATISTICS_create ("dv", cfg);
   GNUNET_SERVER_add_handlers (server, plugin_handlers);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-				&shutdown_task, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
 }
 
 

+ 2 - 2
src/dv/test_transport_dv.c

@@ -82,8 +82,8 @@ test_connection (void *cls,
                  unsigned int links_succeeded,
                  unsigned int links_failed)
 {
-  shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                                &do_shutdown, NULL);
+  shutdown_task = GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+						 NULL);
   if (4 != num_peers)
   {
     ok = 1;

+ 4 - 7
src/exit/gnunet-daemon-exit.c

@@ -3149,7 +3149,6 @@ dummy_task (void *cls)
  * Function scheduled as very last function, cleans up after us
  *
  * @param cls NULL
- * @param tc scheduler context
  */
 static void
 cleanup (void *cls)
@@ -3548,9 +3547,8 @@ run (void *cls,
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
 		  _("`%s' must be installed SUID, EXIT will not work\n"),
 		  "gnunet-helper-exit");
-      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                    &dummy_task,
-                                    NULL);
+      GNUNET_SCHEDULER_add_shutdown (&dummy_task,
+				     NULL);
       global_ret = 1;
       return;
     }
@@ -3639,9 +3637,8 @@ run (void *cls,
     app_idx++;
   }
   GNUNET_free_non_null (dns_exit);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &cleanup,
-                                cls);
+  GNUNET_SCHEDULER_add_shutdown (&cleanup,
+				 NULL);
 
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_number (cfg, "exit", "MAX_CONNECTIONS",

+ 2 - 10
src/fs/gnunet-auto-share.c

@@ -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);
 }
 
 

+ 2 - 10
src/fs/gnunet-daemon-fsprofiler.c

@@ -500,12 +500,8 @@ start_publish (void *cls)
 {
   struct Pattern *p = cls;
   struct GNUNET_FS_FileInformation *fi;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   p->task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   fi = make_file (p->x, p->y, p);
   p->start_time = GNUNET_TIME_absolute_get ();
   p->ctx = GNUNET_FS_publish_start (fs_handle,
@@ -525,12 +521,8 @@ start_download (void *cls)
 {
   struct Pattern *p = cls;
   struct GNUNET_FS_Uri *keywords;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   p->task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   keywords = make_keywords (p->x);
   p->start_time = GNUNET_TIME_absolute_get ();
   p->sctx = GNUNET_FS_search_start (fs_handle, keywords,
@@ -558,8 +550,8 @@ run (void *cls, char *const *args GNUNET_UNUSED,
 
   cfg = cfg_;
   /* Scheduled the task to clean up when shutdown is called */
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+				 NULL);
 
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_number (cfg,

+ 2 - 2
src/fs/gnunet-download.c

@@ -284,8 +284,8 @@ run (void *cls, char *const *args, const char *cfgfile,
     ctx = NULL;
     return;
   }
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+				 NULL);
 }
 
 

+ 23 - 6
src/fs/gnunet-fs-profiler.c

@@ -105,7 +105,7 @@ process_stats (void *cls,
 
 
 /**
- * Task run on timeout to terminate.  Triggers printing out
+ * Task run on shutdown to terminate.  Triggers printing out
  * all statistics.
  *
  * @param cls NULL
@@ -113,7 +113,11 @@ process_stats (void *cls,
 static void
 terminate_task (void *cls)
 {
-  terminate_taskid = NULL;
+  if (NULL != terminate_taskid)
+  {
+    GNUNET_SCHEDULER_cancel (terminate_taskid);
+    terminate_taskid = NULL;
+  }
   GNUNET_TESTBED_get_statistics (0, NULL,
                                  NULL, NULL,
 				 &process_stats,
@@ -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);
 }
 
 

+ 2 - 3
src/fs/gnunet-publish.c

@@ -872,9 +872,8 @@ run (void *cls,
     ret = 1;
     return;
   }
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &do_stop_task,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&do_stop_task,
+				 NULL);
   if (NULL != pseudonym)
     identity = GNUNET_IDENTITY_connect (cfg,
 					&identity_cb,

+ 16 - 4
src/fs/gnunet-search.c

@@ -55,6 +55,9 @@ static int verbose;
 
 static int local_only;
 
+static struct GNUNET_SCHEDULER_Task *tt;
+
+
 /**
  * Type of a function that libextractor calls for each
  * meta data item found.
@@ -220,6 +223,14 @@ shutdown_task (void *cls)
 }
 
 
+static void
+timeout_task (void *cls)
+{
+  tt = NULL;
+  GNUNET_SCHEDULER_shutdown ();
+}
+
+
 /**
  * Main function that will be run by the scheduler.
  *
@@ -272,10 +283,11 @@ run (void *cls, char *const *args, const char *cfgfile,
     return;
   }
   if (0 != timeout.rel_value_us)
-    GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_task, NULL);
-  else
-    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
-                                  NULL);
+    tt = GNUNET_SCHEDULER_add_delayed (timeout,
+				       &timeout_task,
+				       NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+				 NULL);
 }
 
 

+ 6 - 4
src/fs/gnunet-service-fs.c

@@ -191,7 +191,8 @@ age_cover_counters (void *cls)
   GSF_cover_content_count = (GSF_cover_content_count * 15) / 16;
   GSF_cover_query_count = (GSF_cover_query_count * 15) / 16;
   cover_age_task =
-      GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, &age_cover_counters,
+      GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY,
+				    &age_cover_counters,
                                     NULL);
 }
 
@@ -759,13 +760,14 @@ main_init (struct GNUNET_SERVER_Handle *server,
                                    NULL);
   GNUNET_SERVER_add_handlers (server, handlers);
   cover_age_task =
-      GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, &age_cover_counters,
+      GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY,
+				    &age_cover_counters,
                                     NULL);
   datastore_get_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE);
   GSF_cadet_start_server ();
   GSF_cadet_start_client ();
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+				 NULL);
   return GNUNET_OK;
 }
 

+ 20 - 23
src/fs/gnunet-service-fs_cp.c

@@ -335,6 +335,11 @@ static struct GNUNET_CONTAINER_MultiPeerMap *cp_map;
  */
 static struct GNUNET_PEERSTORE_Handle *peerstore;
 
+/**
+ * Task used to flush respect values to disk.
+ */
+static struct GNUNET_SCHEDULER_Task *fr_task;
+
 
 /**
  * Update the latency information kept for the given peer.
@@ -876,19 +881,11 @@ transmit_delayed_now (void *cls)
 {
   struct GSF_DelayedHandle *dh = cls;
   struct GSF_ConnectedPeer *cp = dh->cp;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   GNUNET_CONTAINER_DLL_remove (cp->delayed_head,
                                cp->delayed_tail,
                                dh);
   cp->delay_queue_size--;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
-  {
-    GNUNET_free (dh->pm);
-    GNUNET_free (dh);
-    return;
-  }
   (void) GSF_peer_transmit_ (cp,
                              GNUNET_NO,
                              UINT32_MAX,
@@ -1977,18 +1974,13 @@ GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp,
 static void
 cron_flush_respect (void *cls)
 {
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
-
-  if (NULL == cp_map)
-    return;
+  fr_task = NULL;
   GNUNET_CONTAINER_multipeermap_iterate (cp_map,
-                                         &flush_respect, NULL);
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
-  GNUNET_SCHEDULER_add_delayed_with_priority (RESPECT_FLUSH_FREQ,
-					      GNUNET_SCHEDULER_PRIORITY_HIGH,
-					      &cron_flush_respect, NULL);
+                                         &flush_respect,
+					 NULL);
+  fr_task = GNUNET_SCHEDULER_add_delayed_with_priority (RESPECT_FLUSH_FREQ,
+							GNUNET_SCHEDULER_PRIORITY_HIGH,
+							&cron_flush_respect, NULL);
 }
 
 
@@ -2000,8 +1992,8 @@ GSF_connected_peer_init_ ()
 {
   cp_map = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES);
   peerstore = GNUNET_PEERSTORE_connect (GSF_cfg);
-  GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_HIGH,
-                                      &cron_flush_respect, NULL);
+  fr_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_HIGH,
+						&cron_flush_respect, NULL);
 }
 
 
@@ -2033,10 +2025,15 @@ GSF_connected_peer_done_ ()
                                          &flush_respect,
                                          NULL);
   GNUNET_CONTAINER_multipeermap_iterate (cp_map,
-                                         &clean_peer, NULL);
+                                         &clean_peer,
+					 NULL);
+  GNUNET_SCHEDULER_cancel (fr_task);
+  fr_task = NULL;
   GNUNET_CONTAINER_multipeermap_destroy (cp_map);
   cp_map = NULL;
-  GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_YES);
+  GNUNET_PEERSTORE_disconnect (peerstore,
+			       GNUNET_YES);
+  
 }
 
 

+ 0 - 4
src/fs/gnunet-service-fs_put.c

@@ -215,12 +215,8 @@ static void
 gather_dht_put_blocks (void *cls)
 {
   struct PutOperator *po = cls;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   po->dht_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   po->dht_qe =
       GNUNET_DATASTORE_get_zero_anonymity (GSF_dsh, po->current_offset++, 0,
                                            UINT_MAX,

+ 2 - 2
src/fs/gnunet-unindex.c

@@ -147,8 +147,8 @@ run (void *cls, char *const *args, const char *cfgfile,
     GNUNET_FS_stop (ctx);
     return;
   }
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+				 NULL);
 }
 
 

+ 9 - 8
src/fs/test_gnunet_service_fs_migration.c

@@ -142,15 +142,13 @@ static void
 stop_source_peer (void *cls)
 {
   struct DownloadContext *dc = cls;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  /* Do not interact with testbed when shutting down */
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
+  /* FIXME: We should not interact with testbed when shutting down */
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Stopping source peer\n");
-  op = GNUNET_TESTBED_peer_stop (NULL, daemons[1], &do_download, dc);
+  op = GNUNET_TESTBED_peer_stop (NULL,
+				 daemons[1],
+				 &do_download, dc);
   GNUNET_assert (NULL != op);
 }
 
@@ -176,7 +174,9 @@ do_wait (void *cls,
   dc->uri = GNUNET_FS_uri_dup (uri);
   if (NULL != fn)
     dc->fn = GNUNET_strdup (fn);
-  (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY, &stop_source_peer, dc);
+  (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY,
+				       &stop_source_peer,
+				       dc);
 }
 
 
@@ -196,7 +196,8 @@ do_publish (void *cls,
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Publishing %llu bytes\n",
               (unsigned long long) FILESIZE);
-  GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED,
+  GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, 1, GNUNET_NO,
+			  FILESIZE, SEED,
                           VERBOSE, &do_wait, NULL);
 }
 

+ 4 - 3
src/gns/gns_api.c

@@ -239,9 +239,10 @@ force_reconnect (struct GNUNET_GNS_Handle *handle)
 				 p);
   }
   handle->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff);
-  handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff,
-                                                    &reconnect_task,
-                                                    handle);
+  handle->reconnect_task
+    = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff,
+				    &reconnect_task,
+				    handle);
 }
 
 

+ 10 - 11
src/gns/gnunet-bcd.c

@@ -90,10 +90,14 @@ struct Entry
  * Main request handler.
  */
 static int
-access_handler_callback (void *cls, struct MHD_Connection *connection,
-                         const char *url, const char *method,
-                         const char *version, const char *upload_data,
-                         size_t * upload_data_size, void **con_cls)
+access_handler_callback (void *cls,
+			 struct MHD_Connection *connection,
+                         const char *url,
+			 const char *method,
+                         const char *version,
+			 const char *upload_data,
+                         size_t * upload_data_size,
+			 void **con_cls)
 {
   static int dummy;
   static const struct Entry map[] = {
@@ -290,12 +294,8 @@ static void
 run_daemon (void *cls)
 {
   struct MHD_Daemon *daemon_handle = cls;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   http_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
   http_task = prepare_daemon (daemon_handle);
 }
@@ -499,9 +499,8 @@ run (void *cls,
   if (GNUNET_OK !=
       server_start ())
     return;
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &server_stop,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&server_stop,
+				 NULL);
 }
 
 

+ 51 - 45
src/gns/gnunet-dns2gns.c

@@ -175,9 +175,15 @@ static void
 do_shutdown (void *cls)
 {
   if (NULL != t4)
+  {
     GNUNET_SCHEDULER_cancel (t4);
+    t4 = NULL;
+  }
   if (NULL != t6)
+  {
     GNUNET_SCHEDULER_cancel (t6);
+    t6 = NULL;
+  }
   if (NULL != listen_socket4)
   {
     GNUNET_NETWORK_socket_close (listen_socket4);
@@ -607,57 +613,57 @@ run_dnsd ()
 						 SOCK_DGRAM,
 						 IPPROTO_UDP);
   if (NULL != listen_socket4)
-    {
-      struct sockaddr_in v4;
-
-      memset (&v4, 0, sizeof (v4));
-      v4.sin_family = AF_INET;
+  {
+    struct sockaddr_in v4;
+    
+    memset (&v4, 0, sizeof (v4));
+    v4.sin_family = AF_INET;
 #if HAVE_SOCKADDR_IN_SIN_LEN
-      v4.sin_len = sizeof (v4);
+    v4.sin_len = sizeof (v4);
 #endif
-      v4.sin_port = htons (listen_port);
-      if (GNUNET_OK !=
-	  GNUNET_NETWORK_socket_bind (listen_socket4,
-				      (struct sockaddr *) &v4,
-				      sizeof (v4)))
-	{
-	  GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
-	  GNUNET_NETWORK_socket_close (listen_socket4);
-	  listen_socket4 = NULL;
-	}
+    v4.sin_port = htons (listen_port);
+    if (GNUNET_OK !=
+	GNUNET_NETWORK_socket_bind (listen_socket4,
+				    (struct sockaddr *) &v4,
+				    sizeof (v4)))
+    {
+      GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
+      GNUNET_NETWORK_socket_close (listen_socket4);
+      listen_socket4 = NULL;
     }
+  }
   listen_socket6 = GNUNET_NETWORK_socket_create (PF_INET6,
 						SOCK_DGRAM,
 						IPPROTO_UDP);
   if (NULL != listen_socket6)
-    {
-      struct sockaddr_in6 v6;
-
-      memset (&v6, 0, sizeof (v6));
-      v6.sin6_family = AF_INET6;
+  {
+    struct sockaddr_in6 v6;
+    
+    memset (&v6, 0, sizeof (v6));
+    v6.sin6_family = AF_INET6;
 #if HAVE_SOCKADDR_IN_SIN_LEN
-      v6.sin6_len = sizeof (v6);
+    v6.sin6_len = sizeof (v6);
 #endif
-      v6.sin6_port = htons (listen_port);
-      if (GNUNET_OK !=
-	  GNUNET_NETWORK_socket_bind (listen_socket6,
-				      (struct sockaddr *) &v6,
-				      sizeof (v6)))
-	{
-	  GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
-	  GNUNET_NETWORK_socket_close (listen_socket6);
-	  listen_socket6 = NULL;
-	}
+    v6.sin6_port = htons (listen_port);
+    if (GNUNET_OK !=
+	GNUNET_NETWORK_socket_bind (listen_socket6,
+				    (struct sockaddr *) &v6,
+				    sizeof (v6)))
+    {
+      GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
+      GNUNET_NETWORK_socket_close (listen_socket6);
+      listen_socket6 = NULL;
     }
+  }
   if ( (NULL == listen_socket4) &&
        (NULL == listen_socket6) )
-    {
-      GNUNET_GNS_disconnect (gns);
-      gns = NULL;
-      GNUNET_DNSSTUB_stop (dns_stub);
-      dns_stub = NULL;
-      return;
-    }
+  {
+    GNUNET_GNS_disconnect (gns);
+    gns = NULL;
+    GNUNET_DNSSTUB_stop (dns_stub);
+    dns_stub = NULL;
+    return;
+  }
   if (NULL != listen_socket4)
     t4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
 					listen_socket4,
@@ -668,7 +674,6 @@ run_dnsd ()
 					listen_socket6,
 					&read_dns6,
 					listen_socket6);
-
 }
 
 
@@ -719,7 +724,9 @@ identity_cb (void *cls,
  * @param c configuration
  */
 static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+     char *const *args,
+     const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
   cfg = c;
@@ -730,8 +737,7 @@ run (void *cls, char *const *args, const char *cfgfile,
                 _("No DNS server specified!\n"));
     return;
   }
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-				&do_shutdown, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
   if (NULL == gns_zone_str)
     {
       identity = GNUNET_IDENTITY_connect (cfg,
@@ -745,8 +751,8 @@ run (void *cls, char *const *args, const char *cfgfile,
   if ( (NULL == gns_zone_str) ||
        (GNUNET_OK !=
 	GNUNET_CRYPTO_ecdsa_public_key_from_string (gns_zone_str,
-						  strlen (gns_zone_str),
-						  &my_zone)) )
+						    strlen (gns_zone_str),
+						    &my_zone)) )
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
 		_("No valid GNS zone specified!\n"));

+ 2 - 2
src/gns/gnunet-gns-helper-service-w32.c

@@ -827,8 +827,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
     GNUNET_SCHEDULER_shutdown ();
     return;
   }
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown,
-      NULL);
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+				 NULL);
 
   identity = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
   if (NULL == identity)

+ 1 - 2
src/gns/gnunet-gns-import.c

@@ -454,8 +454,7 @@ run (void *cls, char *const *args, const char *cfgfile,
 
   ns = GNUNET_NAMESTORE_connect (cfg);
   sh = GNUNET_IDENTITY_connect (cfg, &get_ego, NULL);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-				&shutdown_task, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
 }
 
 

+ 1 - 6
src/gns/gnunet-gns-proxy.c

@@ -2713,15 +2713,11 @@ do_accept (void *cls)
   struct GNUNET_NETWORK_Handle *lsock = cls;
   struct GNUNET_NETWORK_Handle *s;
   struct Socks5Request *s5r;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   if (lsock == lsock4)
     ltask4 = NULL;
   else
     ltask6 = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   if (lsock == lsock4)
     ltask4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
                                             lsock,
@@ -3126,8 +3122,7 @@ run (void *cls, char *const *args, const char *cfgfile,
 			       "gns-proxy",
 			       &identity_master_cb,
 			       NULL);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &do_shutdown, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
 }
 
 

+ 29 - 3
src/gns/gnunet-gns.c

@@ -100,6 +100,11 @@ static struct GNUNET_IDENTITY_Handle *identity;
  */
 static struct GNUNET_IDENTITY_Operation *id_op;
 
+/**
+ * Task scheduled to handle timeout.
+ */
+static struct GNUNET_SCHEDULER_Task *tt;
+
 
 /**
  * Task run on shutdown.  Cleans up everything.
@@ -134,6 +139,24 @@ do_shutdown (void *cls)
     GNUNET_GNS_disconnect (gns);
     gns = NULL;
   }
+  if (NULL != tt)
+  {
+    GNUNET_SCHEDULER_cancel (tt);
+    tt = NULL;
+  }
+}
+
+
+/**
+ * Task run on timeout. Triggers shutdown.
+ *
+ * @param cls unused
+ */
+static void
+do_timeout (void *cls)
+{
+  tt = NULL;
+  GNUNET_SCHEDULER_shutdown ();
 }
 
 
@@ -376,7 +399,9 @@ identity_master_cb (void *cls,
  * @param c configuration
  */
 static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+     char *const *args,
+     const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
   struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
@@ -390,8 +415,9 @@ run (void *cls, char *const *args, const char *cfgfile,
 	     _("Failed to connect to GNS\n"));
     return;
   }
-  GNUNET_SCHEDULER_add_delayed (timeout,
-				&do_shutdown, NULL);
+  tt = GNUNET_SCHEDULER_add_delayed (timeout,
+				     &do_timeout, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
   if (NULL != public_key)
   {
     if (GNUNET_OK !=

+ 1 - 2
src/gns/gnunet-service-gns.c

@@ -1010,8 +1010,7 @@ run (void *cls,
                                               &monitor_sync_event,
                                               NULL);
   GNUNET_break (NULL != zmon);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-				&shutdown_task, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
 }
 
 

+ 3 - 3
src/gns/plugin_rest_gns.c

@@ -632,9 +632,10 @@ options_cont (struct RestConnectionDataHandle *con_handle,
   MHD_add_response_header (resp,
                            "Access-Control-Allow-Methods",
                            MHD_HTTP_METHOD_GET);
-  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
+  handle->proc (handle->proc_cls,
+		resp,
+		MHD_HTTP_OK);
   cleanup_handle (handle);
-  return;
 }
 
 
@@ -671,7 +672,6 @@ rest_gns_process_request(struct RestConnectionDataHandle *conndata_handle,
 }
 
 
-
 /**
  * Entry point for the plugin.
  *

+ 10 - 7
src/gns/test_gns_proxy.c

@@ -245,6 +245,7 @@ curl_main ()
 					      NULL);
 }
 
+
 static void
 start_curl (void *cls)
 {
@@ -289,25 +290,27 @@ disco_ns (void* cls)
  *                specified target peer; NULL on error
  */
 static void
-commence_testing (void *cls, int32_t success, const char *emsg)
+commence_testing (void *cls,
+		  int32_t success,
+		  const char *emsg)
 {
   GNUNET_SCHEDULER_add_now (&disco_ns, NULL);
 
-  if ((emsg != NULL) && (GNUNET_YES != success))
+  if ( (emsg != NULL) && (GNUNET_YES != success) )
   {
     fprintf (stderr,
-	     "NS failed to create record %s\n", emsg);
+	     "NS failed to create record %s\n",
+	     emsg);
     GNUNET_SCHEDULER_shutdown ();
     return;
   }
 
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), start_curl, NULL);
-
+  curl_task_id =
+    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 
+				  &start_curl, NULL);
 }
 
 
-
-
 /**
  * Function to keep the HTTP server running.
  */

+ 2 - 3
src/hostlist/gnunet-daemon-hostlist.c

@@ -299,9 +299,8 @@ run (void *cls,
     GNUNET_HOSTLIST_server_start (cfg, stats, core, &server_ch, &server_dh,
                                   advertising);
 #endif
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-				&cleaning_task,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&cleaning_task,
+				 NULL);
 
   if (NULL == core)
   {

+ 23 - 48
src/hostlist/gnunet-daemon-hostlist_client.c

@@ -210,27 +210,27 @@ static struct GNUNET_TIME_Relative hostlist_delay;
 /**
  * ID of the task, checking if hostlist download should take plate
  */
-static struct GNUNET_SCHEDULER_Task * ti_check_download;
+static struct GNUNET_SCHEDULER_Task *ti_check_download;
 
 /**
  * ID of the task downloading the hostlist
  */
-static struct GNUNET_SCHEDULER_Task * ti_download;
+static struct GNUNET_SCHEDULER_Task *ti_download;
 
 /**
  * ID of the task saving the hostlsit in a regular intervall
  */
-static struct GNUNET_SCHEDULER_Task * ti_saving_task;
+static struct GNUNET_SCHEDULER_Task *ti_saving_task;
 
 /**
  * ID of the task called to initiate a download
  */
-static struct GNUNET_SCHEDULER_Task * ti_download_dispatcher_task;
+static struct GNUNET_SCHEDULER_Task *ti_download_dispatcher_task;
 
 /**
  * ID of the task controlling the locking between two hostlist tests
  */
-static struct GNUNET_SCHEDULER_Task * ti_testing_intervall_task;
+static struct GNUNET_SCHEDULER_Task *ti_testing_intervall_task;
 
 /**
  * At what time MUST the current hostlist request be done?
@@ -719,8 +719,9 @@ clean_up ()
 {
   CURLMcode mret;
 
-  if ((stat_testing_hostlist == GNUNET_YES) &&
-      (GNUNET_NO == stat_download_successful) && (NULL != hostlist_to_test))
+  if ( (stat_testing_hostlist == GNUNET_YES) &&
+       (GNUNET_NO == stat_download_successful) &&
+       (NULL != hostlist_to_test) )
   {
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                 _
@@ -738,7 +739,7 @@ clean_up ()
     hostlist_to_test = NULL;
   }
 
-  if (multi != NULL)
+  if (NULL != multi)
   {
     mret = curl_multi_remove_handle (multi, curl);
     if (mret != CURLM_OK)
@@ -754,7 +755,7 @@ clean_up ()
                   curl_multi_strerror (mret));
     multi = NULL;
   }
-  if (curl != NULL)
+  if (NULL != curl)
   {
     curl_easy_cleanup (curl);
     curl = NULL;
@@ -847,19 +848,8 @@ task_download (void *cls)
   int running;
   struct CURLMsg *msg;
   CURLMcode mret;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   ti_download = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Shutdown requested while trying to download hostlist from `%s'\n",
-                current_url);
-    update_hostlist ();
-    clean_up ();
-    return;
-  }
   if (0 == GNUNET_TIME_absolute_get_remaining (end_time).rel_value_us)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -1047,12 +1037,7 @@ download_hostlist ()
 static void
 task_download_dispatcher (void *cls)
 {
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
-
   ti_download_dispatcher_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n");
   if (GNUNET_NO == stat_download_in_progress)
   {
@@ -1080,12 +1065,8 @@ task_check (void *cls)
 {
   static int once;
   struct GNUNET_TIME_Relative delay;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   ti_check_download = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   if (stats == NULL)
   {
     curl_global_cleanup ();
@@ -1120,7 +1101,8 @@ task_check (void *cls)
               _("Have %u/%u connections.  Will consider downloading hostlist in %s\n"),
               stat_connection_count, MIN_CONNECTIONS,
               GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
-  ti_check_download = GNUNET_SCHEDULER_add_delayed (delay, &task_check, NULL);
+  ti_check_download = GNUNET_SCHEDULER_add_delayed (delay,
+						    &task_check, NULL);
 }
 
 
@@ -1132,12 +1114,7 @@ task_check (void *cls)
 static void
 task_testing_intervall_reset (void *cls)
 {
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
-
   ti_testing_intervall_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   stat_testing_allowed = GNUNET_OK;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Testing new hostlist advertisements is allowed again\n");
@@ -1152,19 +1129,15 @@ task_testing_intervall_reset (void *cls)
 static void
 task_hostlist_saving (void *cls)
 {
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
-
   ti_saving_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   save_hostlist_file (GNUNET_NO);
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Hostlists will be saved to file again in %s\n",
 	      GNUNET_STRINGS_relative_time_to_string(SAVING_INTERVAL, GNUNET_YES));
   ti_saving_task =
-      GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, &task_hostlist_saving,
+      GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL,
+				    &task_hostlist_saving,
                                     NULL);
 }
 
@@ -1684,7 +1657,8 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
 void
 GNUNET_HOSTLIST_client_stop ()
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+	      "Hostlist client shutdown\n");
   if (NULL != sget)
   {
     GNUNET_STATISTICS_get_cancel (sget);
@@ -1693,28 +1667,29 @@ GNUNET_HOSTLIST_client_stop ()
   stats = NULL;
   if (GNUNET_YES == stat_learning)
     save_hostlist_file (GNUNET_YES);
-  if (ti_saving_task != NULL)
+  if (NULL != ti_saving_task)
   {
     GNUNET_SCHEDULER_cancel (ti_saving_task);
     ti_saving_task = NULL;
   }
-
-  if (ti_download_dispatcher_task != NULL)
+  if (NULL != ti_download_dispatcher_task)
     {
     GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task);
     ti_download_dispatcher_task = NULL;
   }
-  if (ti_testing_intervall_task != NULL)
+  if (NULL != ti_testing_intervall_task)
   {
     GNUNET_SCHEDULER_cancel (ti_testing_intervall_task);
     ti_testing_intervall_task = NULL;
   }
-  if (ti_download != NULL)
+  if (NULL != ti_download)
   {
     GNUNET_SCHEDULER_cancel (ti_download);
     ti_download = NULL;
+    update_hostlist ();
+    clean_up ();
   }
-  if (ti_check_download != NULL)
+  if (NULL != ti_check_download)
   {
     GNUNET_SCHEDULER_cancel (ti_check_download);
     ti_check_download = NULL;

+ 8 - 11
src/hostlist/gnunet-daemon-hostlist_server.c

@@ -74,12 +74,12 @@ static struct GNUNET_PEERINFO_NotifyContext *notify;
 /**
  * Our primary task for IPv4.
  */
-static struct GNUNET_SCHEDULER_Task * hostlist_task_v4;
+static struct GNUNET_SCHEDULER_Task *hostlist_task_v4;
 
 /**
  * Our primary task for IPv6.
  */
-static struct GNUNET_SCHEDULER_Task * hostlist_task_v6;
+static struct GNUNET_SCHEDULER_Task *hostlist_task_v6;
 
 /**
  * Our canonical response.
@@ -632,15 +632,11 @@ static void
 run_daemon (void *cls)
 {
   struct MHD_Daemon *daemon_handle = cls;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   if (daemon_handle == daemon_handle_v4)
     hostlist_task_v4 = NULL;
   else
     hostlist_task_v6 = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
   if (daemon_handle == daemon_handle_v4)
     hostlist_task_v4 = prepare_daemon (daemon_handle);
@@ -675,7 +671,9 @@ prepare_daemon (struct MHD_Daemon *daemon_handle)
   wrs = GNUNET_NETWORK_fdset_create ();
   wws = GNUNET_NETWORK_fdset_create ();
   max = -1;
-  GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max));
+  GNUNET_assert (MHD_YES ==
+		 MHD_get_fdset (daemon_handle,
+				&rs, &ws, &es, &max));
   haveto = MHD_get_timeout (daemon_handle, &timeout);
   if (haveto == MHD_YES)
     tv.rel_value_us = (uint64_t) timeout * 1000LL;
@@ -683,10 +681,9 @@ prepare_daemon (struct MHD_Daemon *daemon_handle)
     tv = GNUNET_TIME_UNIT_FOREVER_REL;
   GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
   GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
-  ret =
-      GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
-				   tv, wrs, wws,
-                                   &run_daemon, daemon_handle);
+  ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
+				     tv, wrs, wws,
+				     &run_daemon, daemon_handle);
   GNUNET_NETWORK_fdset_destroy (wrs);
   GNUNET_NETWORK_fdset_destroy (wws);
   return ret;

+ 19 - 10
src/hostlist/test_gnunet_daemon_hostlist.c

@@ -35,7 +35,7 @@
 
 static int ok;
 
-static struct GNUNET_SCHEDULER_Task * timeout_task;
+static struct GNUNET_SCHEDULER_Task *timeout_task;
 
 struct PeerContext
 {
@@ -100,11 +100,13 @@ timeout_error (void *cls)
  * @param distance in overlay hops, as given by transport plugin
  */
 static void
-notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
+notify_connect (void *cls,
+		const struct GNUNET_PeerIdentity *peer)
 {
   if (peer == NULL)
     return;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+	      "Peers connected, shutting down.\n");
   ok = 0;
   if (timeout_task != NULL)
   {
@@ -116,7 +118,8 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
 
 
 static void
-process_hello (void *cls, const struct GNUNET_MessageHeader *message)
+process_hello (void *cls,
+	       const struct GNUNET_MessageHeader *message)
 {
   struct PeerContext *p = cls;
 
@@ -170,8 +173,10 @@ waitpid_task (void *cls)
 static void
 stop_arm (struct PeerContext *p)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n");
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+	      "Asking ARM to stop core service\n");
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+				&waitpid_task, p);
 }
 
 
@@ -187,14 +192,18 @@ shutdown_task (void *cls)
 
 
 static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+     char *const *args,
+     const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   GNUNET_assert (ok == 1);
   ok++;
-  timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
-                                NULL);
+  timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+					       &timeout_error,
+					       NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+				 NULL);
   setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf");
   setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf");
 }

+ 7 - 7
src/hostlist/test_gnunet_daemon_hostlist_learning.c

@@ -242,7 +242,9 @@ process_adv_sent_done (void *cls, int success)
 
 
 static int
-process_adv_sent (void *cls, const char *subsystem, const char *name,
+process_adv_sent (void *cls,
+		  const char *subsystem,
+		  const char *name,
                   uint64_t value, int is_persistent)
 {
   if ((value >= 1) && (adv_sent == GNUNET_NO))
@@ -267,13 +269,10 @@ static void
 check_statistics (void *cls)
 {
   char *stat;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   check_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
-  GNUNET_asprintf (&stat, gettext_noop ("# advertised URI `%s' downloaded"),
+  GNUNET_asprintf (&stat,
+		   gettext_noop ("# advertised URI `%s' downloaded"),
                    current_adv_uri);
   if (NULL != learn_peer.stats)
   {
@@ -313,7 +312,8 @@ check_statistics (void *cls)
  * Core handler for p2p hostlist advertisements
  */
 static int
-ad_arrive_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
+ad_arrive_handler (void *cls,
+		   const struct GNUNET_PeerIdentity *peer,
                    const struct GNUNET_MessageHeader *message)
 {
   char *hostname;

+ 12 - 6
src/hostlist/test_gnunet_daemon_hostlist_reconnect.c

@@ -100,11 +100,13 @@ timeout_error (void *cls)
  * @param distance in overlay hops, as given by transport plugin
  */
 static void
-notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
+notify_connect (void *cls,
+		const struct GNUNET_PeerIdentity *peer)
 {
   if (peer == NULL)
     return;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+	      "Peers connected, shutting down.\n");
   ok = 0;
   if (timeout_task != NULL)
   {
@@ -116,7 +118,8 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
 
 
 static void
-process_hello (void *cls, const struct GNUNET_MessageHeader *message)
+process_hello (void *cls,
+	       const struct GNUNET_MessageHeader *message)
 {
   struct PeerContext *p = cls;
 
@@ -171,7 +174,8 @@ static void
 stop_arm (struct PeerContext *p)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n");
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p);
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+				&waitpid_task, p);
 }
 
 
@@ -192,8 +196,10 @@ run (void *cls, char *const *args, const char *cfgfile,
 {
   GNUNET_assert (ok == 1);
   ok++;
-  timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
+  timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+					       &timeout_error, NULL);
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+				&shutdown_task,
                                 NULL);
   setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf");
   setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf");

+ 22 - 16
src/identity-provider/gnunet-service-identity-provider.c

@@ -105,13 +105,12 @@ static struct GNUNET_NAMESTORE_ZoneIterator *ns_it;
 /**
  * Timeout task
  */
-static struct GNUNET_SCHEDULER_Task * timeout_task;
-
+static struct GNUNET_SCHEDULER_Task *timeout_task;
 
 /**
  * Update task
  */
-static struct GNUNET_SCHEDULER_Task * update_task;
+static struct GNUNET_SCHEDULER_Task *update_task;
 
 /**
  * Timeout for next update pass
@@ -494,9 +493,11 @@ handle_token_update (void *cls)
   scopes = NULL;
 }
 
+
 static void
 update_identities(void *cls);
 
+
 /**
  *
  * Cleanup attr_map
@@ -504,7 +505,7 @@ update_identities(void *cls);
  * @param cls NULL
  * @param key the key
  * @param value the json_t attribute value
- * @return GNUNET_YES
+ * @return #GNUNET_YES
  */
 static int
 clear_ego_attrs (void *cls,
@@ -530,6 +531,7 @@ clear_ego_attrs (void *cls,
   return GNUNET_YES;
 }
 
+
 /**
  *
  * Update all ID_TOKEN records for an identity and store them
@@ -539,7 +541,6 @@ clear_ego_attrs (void *cls,
  * @param lbl the name of the record
  * @param rd_count number of records
  * @param rd record data
- *
  */
 static void
 token_collect (void *cls,
@@ -579,7 +580,9 @@ token_collect (void *cls,
   {
     token_metadata_record = &rd[0];
     token_record = &rd[1];
-  } else {
+  }
+  else
+  {
     token_record = &rd[0];
     token_metadata_record = &rd[1];
   }
@@ -607,7 +610,8 @@ token_collect (void *cls,
   label = GNUNET_strdup (lbl);
   rd_exp = token_record->expiration_time;
 
-  GNUNET_SCHEDULER_add_now (&handle_token_update, ego_entry);
+  GNUNET_SCHEDULER_add_now (&handle_token_update,
+			    ego_entry);
 }
 
 
@@ -642,7 +646,8 @@ attribute_collect (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 ">>> Updating Attributes finished\n");
     ego_entry->attributes_dirty = GNUNET_NO;
-    update_task = GNUNET_SCHEDULER_add_now (&update_identities, ego_entry);
+    update_task = GNUNET_SCHEDULER_add_now (&update_identities,
+					    ego_entry);
     return;
   }
 
@@ -752,7 +757,6 @@ update_identities(void *cls)
 }
 
 
-
 /**
  * Function called initially to start update task
  */
@@ -761,9 +765,11 @@ init_cont ()
 {
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, ">>> Starting Service\n");
   //Initially iterate all itenties and refresh all tokens
-  update_task = GNUNET_SCHEDULER_add_now (&update_identities, ego_head);
+  update_task = GNUNET_SCHEDULER_add_now (&update_identities,
+					  ego_head);
 }
 
+
 /**
  * Initial ego collection function.
  *
@@ -934,6 +940,7 @@ store_token_issue_cont (void *cls,
   struct GNUNET_IDENTITY_PROVIDER_IssueResultMessage *irm;
   char *ticket_str;
   char *token_str;
+  
   handle->ns_qe = NULL;
   if (GNUNET_SYSERR == success)
   {
@@ -964,7 +971,9 @@ store_token_issue_cont (void *cls,
     GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
     return;
   }
-  irm = create_issue_result_message (handle->label, ticket_str, token_str);
+  irm = create_issue_result_message (handle->label,
+				     ticket_str,
+				     token_str);
   GNUNET_SERVER_notification_context_unicast (nc,
                                               handle->client,
                                               &irm->header,
@@ -1528,19 +1537,16 @@ run (void *cls,
     token_expiration_interval = DEFAULT_TOKEN_EXPIRATION_INTERVAL;
   }
 
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &do_shutdown, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
 }
 
 
 /**
- *
  * The main function
  *
  * @param argc number of arguments from the cli
  * @param argv command line arguments
  * @return 0 ok, 1 on error
- *
  */
 int
 main (int argc, char *const *argv)
@@ -1551,4 +1557,4 @@ main (int argc, char *const *argv)
                                &run, NULL)) ? 0 : 1;
 }
 
-/* end of gnunet-rest-server.c */
+/* end of gnunet-service-identity-provider.c */

+ 43 - 17
src/identity-provider/plugin_rest_identity_provider.c

@@ -248,7 +248,7 @@ struct RequestHandle
   /**
    * ID of a task associated with the resolution process.
    */
-  struct GNUNET_SCHEDULER_Task * timeout_task;
+  struct GNUNET_SCHEDULER_Task *timeout_task;
 
   /**
    * The plugin result processor
@@ -321,9 +321,9 @@ cleanup_handle (struct RequestHandle *handle)
 
 
 /**
- * Task run on shutdown.  Cleans up everything.
+ * Task run on error, sends error message.  Cleans up everything.
  *
- * @param cls unused
+ * @param cls the `struct RequestHandle`
  */
 static void
 do_error (void *cls)
@@ -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");
 }

+ 1 - 2
src/identity/gnunet-identity.c

@@ -302,8 +302,7 @@ run (void *cls, char *const *args, const char *cfgfile,
 					create_ego,
 					&create_finished,
 					&create_op);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-				&shutdown_task, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
   test_finished ();
 }
 

+ 2 - 2
src/identity/gnunet-service-identity.c

@@ -916,8 +916,8 @@ run (void *cls,
   GNUNET_DISK_directory_scan (ego_directory,
 			      &process_ego_file,
 			      NULL);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+				 NULL);
 }
 
 

+ 5 - 3
src/identity/plugin_rest_identity.c

@@ -257,9 +257,9 @@ cleanup_handle (struct RequestHandle *handle)
 
 
 /**
- * Task run on shutdown.  Cleans up everything.
+ * Task run on errors.  Reports an error and cleans up everything.
  *
- * @param cls unused
+ * @param cls the `struct RequestHandle`
  */
 static void
 do_error (void *cls)
@@ -273,7 +273,9 @@ do_error (void *cls)
                    &handle->emsg);
 
   resp = GNUNET_REST_create_json_response (json_error);
-  handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST);
+  handle->proc (handle->proc_cls,
+		resp,
+		MHD_HTTP_BAD_REQUEST);
   cleanup_handle (handle);
   GNUNET_free (json_error);
 }

+ 1 - 2
src/identity/test_identity.c

@@ -110,8 +110,7 @@ end ()
     GNUNET_SCHEDULER_cancel (endbadly_task);
     endbadly_task = NULL;
   }
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
-				&end_normally, NULL);
+  GNUNET_SCHEDULER_add_now (&end_normally, NULL);
 }
 
 

+ 1 - 1
src/include/gnunet_common.h

@@ -66,7 +66,7 @@ extern "C"
 /**
  * Version of the API (for entire gnunetutil.so library).
  */
-#define GNUNET_UTIL_VERSION 0x000A0100
+#define GNUNET_UTIL_VERSION 0x000A0101
 
 
 /**

+ 32 - 30
src/include/gnunet_scheduler_lib.h

@@ -65,8 +65,7 @@ enum GNUNET_SCHEDULER_Reason
   GNUNET_SCHEDULER_REASON_STARTUP = 1,
 
   /**
-   * We are shutting down and are running all shutdown-related tasks
-   * (regardless of timeout, etc.).
+   * We are shutting down and are running all shutdown-related tasks.
    */
   GNUNET_SCHEDULER_REASON_SHUTDOWN = 2,
 
@@ -158,7 +157,7 @@ typedef int
  * tasks have completed.  On systems with signals, receiving a SIGTERM
  * (and other similar signals) will cause #GNUNET_SCHEDULER_shutdown
  * to be run after the active task is complete.  As a result, SIGTERM
- * causes all active tasks to be scheduled with reason
+ * causes all shutdown tasks to be scheduled with reason
  * #GNUNET_SCHEDULER_REASON_SHUTDOWN.  (However, tasks added
  * afterwards will execute normally!).  Note that any particular
  * signal will only shut down one scheduler; applications should
@@ -173,11 +172,10 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task,
 
 
 /**
- * Request the shutdown of the scheduler.  Marks all currently
- * pending tasks as ready because of shutdown.  This will
- * cause all tasks to run (as soon as possible, respecting
- * priorities and prerequisite tasks).  Note that tasks
- * scheduled AFTER this call may still be delayed arbitrarily.
+ * Request the shutdown of a scheduler.  Marks all tasks 
+ * awaiting shutdown as ready. Note that tasks
+ * scheduled with #GNUNET_SCHEDULER_add_shutdown() AFTER this call
+ * will be delayed until the next shutdown signal.
  */
 void
 GNUNET_SCHEDULER_shutdown (void);
@@ -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

+ 6 - 5
src/multicast/gnunet-service-multicast.c

@@ -1837,10 +1837,10 @@ core_connected_cb  (void *cls, const struct GNUNET_PeerIdentity *my_identity)
 
   nc = GNUNET_SERVER_notification_context_create (server, 1);
   GNUNET_SERVER_add_handlers (server, server_handlers);
-  GNUNET_SERVER_disconnect_notify (server, &client_notify_disconnect, NULL);
-
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
-                                NULL);
+  GNUNET_SERVER_disconnect_notify (server,
+				   &client_notify_disconnect, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+				 NULL);
 }
 
 
@@ -1852,7 +1852,8 @@ core_connected_cb  (void *cls, const struct GNUNET_PeerIdentity *my_identity)
  * @param cfg configuration to use
  */
 static void
-run (void *cls, struct GNUNET_SERVER_Handle *srv,
+run (void *cls,
+     struct GNUNET_SERVER_Handle *srv,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
   cfg = c;

+ 13 - 8
src/multicast/test_multicast.c

@@ -276,7 +276,7 @@ member_parted (void *cls)
     break;
 
   case TEST_MEMBER_PART:
-    GNUNET_SCHEDULER_add_now (schedule_origin_stop, NULL);
+    GNUNET_SCHEDULER_add_now (&schedule_origin_stop, NULL);
     break;
 
   default:
@@ -302,7 +302,7 @@ member_part ()
   test = TEST_MEMBER_PART;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
               "Test #%u: member_part()\n", test);
-  GNUNET_SCHEDULER_add_now (schedule_member_part, NULL);
+  GNUNET_SCHEDULER_add_now (&schedule_member_part, NULL);
 }
 
 
@@ -569,7 +569,7 @@ member_recv_join_decision (void *cls,
   {
   case TEST_MEMBER_JOIN_REFUSE:
     GNUNET_assert (0 == relay_count);
-    GNUNET_SCHEDULER_add_now (schedule_member_part, NULL);
+    GNUNET_SCHEDULER_add_now (&schedule_member_part, NULL);
     break;
 
   case TEST_MEMBER_JOIN_ADMIT:
@@ -695,7 +695,9 @@ core_connected (void *cls, const struct GNUNET_PeerIdentity *my_identity)
  */
 static void
 #if DEBUG_TEST_MULTICAST
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+     char *const *args,
+     const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *c)
 #else
 run (void *cls,
@@ -704,10 +706,13 @@ run (void *cls,
 #endif
 {
   cfg = c;
-  end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
-
-  core = GNUNET_CORE_connect (cfg, NULL, &core_connected, NULL, NULL,
-                              NULL, GNUNET_NO, NULL, GNUNET_NO, NULL);
+  end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+						 &end_badly, NULL);
+  core = GNUNET_CORE_connect (cfg, NULL,
+			      &core_connected, NULL, NULL,
+                              NULL, GNUNET_NO,
+			      NULL, GNUNET_NO,
+			      NULL);
 }
 
 

+ 2 - 4
src/namecache/gnunet-namecache.c

@@ -202,10 +202,8 @@ run (void *cls, char *const *args, const char *cfgfile,
     return;
   }
 
-
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &do_shutdown,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+				 NULL);
   ns = GNUNET_NAMECACHE_connect (cfg);
   GNUNET_GNSRECORD_query_from_public_key (&pubkey,
                                           name,

+ 2 - 2
src/namecache/gnunet-service-namecache.c

@@ -404,8 +404,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
   GNUNET_SERVER_disconnect_notify (server,
                                    &client_disconnect_notification,
                                    NULL);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
+				 NULL);
 }
 
 

+ 4 - 3
src/namecache/test_namecache_api_cache_block.c

@@ -108,10 +108,11 @@ rd_decrypt_cb (void *cls,
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
 	      "Block was decrypted successfully \n");
-
-	GNUNET_SCHEDULER_add_now (&end, NULL);
+  
+  GNUNET_SCHEDULER_add_now (&end, NULL);
 }
 
+
 static void
 name_lookup_proc (void *cls,
                   const struct GNUNET_GNSRECORD_Block *block)
@@ -131,7 +132,7 @@ name_lookup_proc (void *cls,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
   	      _("Namecache returned no block\n"));
-    if (endbadly_task != NULL)
+    if (NULL != endbadly_task)
       GNUNET_SCHEDULER_cancel (endbadly_task);
     endbadly_task =  GNUNET_SCHEDULER_add_now (&endbadly, NULL);
     return;

+ 1 - 2
src/namestore/gnunet-namestore-fcfsd.c

@@ -988,8 +988,7 @@ run (void *cls, char *const *args, const char *cfgfile,
   }
   id_op = GNUNET_IDENTITY_get (identity, "fcfsd",
 			       &identity_cb, NULL);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-				&do_shutdown, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
 }
 
 

+ 1 - 2
src/namestore/gnunet-namestore.c

@@ -1006,8 +1006,7 @@ testservice_id_task (void *cls, int result)
     ret = -1;
     return;
   }
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &do_shutdown, (void *) cfg);
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown, (void *) cfg);
 
   if (NULL == ego_name)
   {

+ 2 - 2
src/namestore/gnunet-service-namestore.c

@@ -1689,8 +1689,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
   GNUNET_SERVER_disconnect_notify (server,
                                    &client_disconnect_notification,
                                    NULL);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
+				 NULL);
 }
 
 

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.