allow empty/NULL context message
[oweals/gnunet.git] / src / peerinfo / gnunet-service-peerinfo.c
index 456a3546b162ae9b0451ab69befbb6ebc59f762e..66082e8f783a1565382a0150466926baaea0aa47 100644 (file)
@@ -161,6 +161,16 @@ static struct NotificationContext *nc_head;
  */
 static struct NotificationContext *nc_tail;
 
+/**
+ * Handle for task to run #cron_clean_data_hosts()
+ */
+static struct GNUNET_SCHEDULER_Task *cron_clean;
+
+/**
+ * Handle for task to run #cron_scan_directory_hosts()
+ */
+static struct GNUNET_SCHEDULER_Task *cron_scan;
+
 
 /**
  * Notify all clients in the notify list about the
@@ -651,22 +661,20 @@ hosts_directory_scan_callback (void *cls,
  * Call this method periodically to scan data/hosts for new hosts.
  *
  * @param cls unused
- * @param tc scheduler context, aborted if reason is shutdown
  */
 static void
-cron_scan_directory_data_hosts (void *cls,
-                                const struct GNUNET_SCHEDULER_TaskContext *tc)
+cron_scan_directory_data_hosts (void *cls)
 {
   static unsigned int retries;
   struct DirScanContext dsc;
 
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
-  if (GNUNET_SYSERR == GNUNET_DISK_directory_create (networkIdDirectory))
+  cron_scan = NULL;
+  if (GNUNET_SYSERR ==
+      GNUNET_DISK_directory_create (networkIdDirectory))
   {
-    GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
-                                               GNUNET_SCHEDULER_PRIORITY_IDLE,
-                                               &cron_scan_directory_data_hosts, NULL);
+    cron_scan = GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
+                                                           GNUNET_SCHEDULER_PRIORITY_IDLE,
+                                                           &cron_scan_directory_data_hosts, NULL);
     return;
   }
   dsc.matched = 0;
@@ -680,10 +688,10 @@ cron_scan_directory_data_hosts (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
                 _("Still no peers found in `%s'!\n"),
                 networkIdDirectory);
-  GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
-                                             GNUNET_SCHEDULER_PRIORITY_IDLE,
-                                             &cron_scan_directory_data_hosts,
-                                             NULL);
+  cron_scan = GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
+                                                         GNUNET_SCHEDULER_PRIORITY_IDLE,
+                                                         &cron_scan_directory_data_hosts,
+                                                         NULL);
 }
 
 
@@ -1041,16 +1049,13 @@ discard_hosts_helper (void *cls,
  * HELLOs to expire.
  *
  * @param cls unused
- * @param tc scheduler context, aborted if reason is shutdown
  */
 static void
-cron_clean_data_hosts (void *cls,
-                       const struct GNUNET_SCHEDULER_TaskContext *tc)
+cron_clean_data_hosts (void *cls)
 {
   struct GNUNET_TIME_Absolute now;
 
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
+  cron_clean = NULL;
   now = GNUNET_TIME_absolute_get ();
   GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
               _("Cleaning up directory `%s'\n"),
@@ -1058,9 +1063,9 @@ cron_clean_data_hosts (void *cls,
   GNUNET_DISK_directory_scan (networkIdDirectory,
                               &discard_hosts_helper,
                               &now);
-  GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ,
-                                &cron_clean_data_hosts,
-                                NULL);
+  cron_clean = GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ,
+                                            &cron_clean_data_hosts,
+                                            NULL);
 }
 
 
@@ -1277,11 +1282,9 @@ free_host_entry (void *cls,
  * Clean up our state.  Called during shutdown.
  *
  * @param cls unused
- * @param tc scheduler task context, unused
  */
 static void
-shutdown_task (void *cls,
-               const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls)
 {
   struct NotificationContext *cur;
   struct NotificationContext *next;
@@ -1304,6 +1307,16 @@ shutdown_task (void *cls,
     GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
     stats = NULL;
   }
+  if (NULL != cron_clean)
+  {
+    GNUNET_SCHEDULER_cancel (cron_clean);
+    cron_clean = NULL;
+  }
+  if (NULL != cron_scan)
+  {
+    GNUNET_SCHEDULER_cancel (cron_scan);
+    cron_scan = NULL;
+  }
 }
 
 
@@ -1344,9 +1357,8 @@ run (void *cls,
                                                        "USE_INCLUDED_HELLOS");
   if (GNUNET_SYSERR == use_included)
     use_included = GNUNET_NO;
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &shutdown_task,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+                                NULL);
   if (GNUNET_YES != noio)
   {
     GNUNET_assert (GNUNET_OK ==
@@ -1360,11 +1372,13 @@ run (void *cls,
       return;
     }
 
-    GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
-                                       &cron_scan_directory_data_hosts, NULL);
+    cron_scan = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+                                                   &cron_scan_directory_data_hosts,
+                                                   NULL);
 
-    GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
-                                       &cron_clean_data_hosts, NULL);
+    cron_clean = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+                                                    &cron_clean_data_hosts,
+                                                    NULL);
     if (GNUNET_YES == use_included)
     {
       ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);