nicer loop structure
[oweals/gnunet.git] / src / regex / gnunet-daemon-regexprofiler.c
index 1ff3b55e36fd194fca671a69e5fcad68ff612a00..f1c00a55450e0bb82addac871be1654d3765ad7a 100644 (file)
@@ -2,20 +2,20 @@
      This file is part of GNUnet.
      Copyright (C) 2012, 2013 Christian Grothoff
 
-     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 free software: you can redistribute it and/or modify it
+     under the terms of the GNU Affero General Public License as published
+     by the Free Software Foundation, either version 3 of the License,
+     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.
+     Affero General Public License for more details.
+    
+     You should have received a copy of the GNU Affero General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-     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.
+     SPDX-License-Identifier: AGPL3.0-or-later
 */
 
 /**
@@ -117,7 +117,11 @@ shutdown_task (void *cls)
     REGEX_INTERNAL_announce_cancel (announce_handle);
     announce_handle = NULL;
   }
-
+  if (NULL != reannounce_task)
+  {
+    GNUNET_free (GNUNET_SCHEDULER_cancel (reannounce_task));
+    reannounce_task = NULL;
+  }
   if (NULL != dht_handle)
   {
     GNUNET_DHT_disconnect (dht_handle);
@@ -142,16 +146,8 @@ reannounce_regex (void *cls)
 {
   char *regex = cls;
   struct GNUNET_TIME_Relative random_delay;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   reannounce_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    GNUNET_free (regex);
-    return;
-  }
-
   if (0 == rounds--)
   {
     global_ret = 0;
@@ -195,7 +191,7 @@ reannounce_regex (void *cls)
  * @param regex regular expression to announce on this peer's cadet.
  */
 static void
-announce_regex (const char * regex)
+announce_regex (const char *regex)
 {
   char *copy;
 
@@ -210,7 +206,8 @@ announce_regex (const char * regex)
               policy_filename);
   GNUNET_assert (NULL == reannounce_task);
   copy = GNUNET_strdup (regex);
-  reannounce_task = GNUNET_SCHEDULER_add_now (reannounce_regex, (void *) copy);
+  reannounce_task = GNUNET_SCHEDULER_add_now (&reannounce_regex,
+                                             (void *) copy);
 }
 
 
@@ -343,18 +340,21 @@ run (void *cls, char *const *args GNUNET_UNUSED,
     return;
   }
   GNUNET_free (policy_dir);
-  regex = REGEX_TEST_combine (components);
+  regex = REGEX_TEST_combine (components, 16);
   REGEX_TEST_free_from_file (components);
 
   /* Announcing regexes from policy_filename */
-  GNUNET_asprintf (&rx_with_pfx, "%s(%s)(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f)*", regex_prefix, regex);
+  GNUNET_asprintf (&rx_with_pfx,
+                  "%s(%s)(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f)*",
+                  regex_prefix,
+                  regex);
   announce_regex (rx_with_pfx);
   GNUNET_free (regex);
   GNUNET_free (rx_with_pfx);
 
   /* Scheduled the task to clean up when shutdown is called */
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+                                NULL);
 }