Merge branch 'master' of ssh://gnunet.org/gnunet
[oweals/gnunet.git] / src / fs / gnunet-auto-share.c
index aef66614cee22626655054fe1fc6dbac2e396d1c..cc0111111e98915d21e674ce33f26bb2450be205 100644 (file)
@@ -29,9 +29,9 @@
 #include "platform.h"
 #include "gnunet_util_lib.h"
 
-#define MIN_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
+#define MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
 
-#define MAX_FREQUENCY GNUNET_TIME_UNIT_MINUTES
+#define MIN_DELAY GNUNET_TIME_UNIT_MINUTES
 
 
 /**
@@ -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)
   {
@@ -678,11 +672,11 @@ schedule_next_task ()
     /* delay by at most 4h, at least 1s, and otherwise in between depending
        on how long it took to scan */
     delay = GNUNET_TIME_absolute_get_duration (start_time);
-    delay = GNUNET_TIME_relative_min (MIN_FREQUENCY,
-                                     GNUNET_TIME_relative_multiply (delay,
-                                                                    100));
+    delay = GNUNET_TIME_relative_saturating_multiply (delay, 100);
+    delay = GNUNET_TIME_relative_min (delay,
+                                      MAX_DELAY);
     delay = GNUNET_TIME_relative_max (delay,
-                                     MAX_FREQUENCY);
+                                      MIN_DELAY);
     run_task = GNUNET_SCHEDULER_add_delayed (delay,
                                             &scan,
                                             NULL);
@@ -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);
 }