-ensure stats queues do not grow too big
[oweals/gnunet.git] / src / nse / gnunet-service-nse.c
index 31d05690af8e0802d1fd7706e259a35af6631a3e..3db33020469879f73069729c33617f5d633ccec9 100644 (file)
@@ -1,6 +1,6 @@
 /*
   This file is part of GNUnet.
-  Copyright (C) 2009, 2010, 2011, 2012, 2013 Christian Grothoff (and other contributing authors)
+  Copyright (C) 2009, 2010, 2011, 2012, 2013 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
@@ -14,8 +14,8 @@
 
   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., 59 Temple Place - Suite 330,
-  Boston, MA 02111-1307, USA.
+  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+  Boston, MA 02110-1301, USA.
  */
 
 /**
@@ -593,11 +593,9 @@ get_transmit_delay (int round_offset)
  * Task that triggers a NSE P2P transmission.
  *
  * @param cls the `struct NSEPeerEntry *`
- * @param tc scheduler context
  */
 static void
-transmit_task_cb (void *cls,
-                 const struct GNUNET_SCHEDULER_TaskContext *tc);
+transmit_task_cb (void *cls);
 
 
 /**
@@ -650,7 +648,7 @@ transmit_ready (void *cls,
     return 0;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "In round s, sending to `%s' estimate with %u bits\n",
+              "In round %s, sending to `%s' estimate with %u bits\n",
               GNUNET_STRINGS_absolute_time_to_string (GNUNET_TIME_absolute_ntoh (size_estimate_messages[idx].timestamp)),
               GNUNET_i2s (&peer_entry->id),
               (unsigned int) ntohl (size_estimate_messages[idx].matching_bits));
@@ -673,11 +671,9 @@ transmit_ready (void *cls,
  * Task that triggers a NSE P2P transmission.
  *
  * @param cls the `struct NSEPeerEntry *`
- * @param tc scheduler context
  */
 static void
-transmit_task_cb (void *cls,
-                 const struct GNUNET_SCHEDULER_TaskContext *tc)
+transmit_task_cb (void *cls)
 {
   struct NSEPeerEntry *peer_entry = cls;
 
@@ -788,7 +784,9 @@ schedule_current_round (void *cls,
   delay =
       get_transmit_delay ((peer_entry->previous_round == GNUNET_NO) ? -1 : 0);
   peer_entry->transmit_task =
-      GNUNET_SCHEDULER_add_delayed (delay, &transmit_task_cb, peer_entry);
+      GNUNET_SCHEDULER_add_delayed (delay,
+                                   &transmit_task_cb,
+                                   peer_entry);
   return GNUNET_OK;
 }
 
@@ -797,24 +795,21 @@ schedule_current_round (void *cls,
  * Update our flood message to be sent (and our timestamps).
  *
  * @param cls unused
- * @param tc context for this message
  */
 static void
-update_flood_message (void *cls,
-                     const struct GNUNET_SCHEDULER_TaskContext *tc)
+update_flood_message (void *cls)
 {
   struct GNUNET_TIME_Relative offset;
   unsigned int i;
 
   flood_task = NULL;
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   offset = GNUNET_TIME_absolute_get_remaining (next_timestamp);
   if (0 != offset.rel_value_us)
   {
     /* somehow run early, delay more */
     flood_task =
-        GNUNET_SCHEDULER_add_delayed (offset, &update_flood_message, NULL);
+        GNUNET_SCHEDULER_add_delayed (offset,
+                                     &update_flood_message, NULL);
     return;
   }
   estimate_index = (estimate_index + 1) % HISTORY_SIZE;
@@ -845,7 +840,8 @@ update_flood_message (void *cls,
                                          NULL);
   flood_task =
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
-                                    (next_timestamp), &update_flood_message,
+                                    (next_timestamp),
+                                   &update_flood_message,
                                     NULL);
 }
 
@@ -918,11 +914,9 @@ write_proof ()
  * Find our proof of work.
  *
  * @param cls closure (unused)
- * @param tc task context
  */
 static void
-find_proof (void *cls,
-           const struct GNUNET_SCHEDULER_TaskContext *tc)
+find_proof (void *cls)
 {
 #define ROUND_SIZE 10
   uint64_t counter;
@@ -954,7 +948,8 @@ find_proof (void *cls,
   }
   if (my_proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing proofs currently at %llu\n",
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Testing proofs currently at %llu\n",
                 (unsigned long long) counter);
     /* remember progress every 100 rounds */
     my_proof = counter;
@@ -1048,7 +1043,8 @@ update_flood_times (void *cls,
   }
   delay = get_transmit_delay (0);
   peer_entry->transmit_task =
-      GNUNET_SCHEDULER_add_delayed (delay, &transmit_task_cb, peer_entry);
+      GNUNET_SCHEDULER_add_delayed (delay,
+                                   &transmit_task_cb, peer_entry);
   return GNUNET_OK;
 }
 
@@ -1132,6 +1128,9 @@ handle_p2p_size_estimate (void *cls,
       return GNUNET_OK;         /* ignore, simply too early/late */
     if (GNUNET_YES != verify_message_crypto (incoming_flood))
     {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Peer %s is likely ill-configured!\n",
+                  GNUNET_i2s (peer));
       GNUNET_break_op (0);
       return GNUNET_OK;
     }
@@ -1339,11 +1338,9 @@ flush_comp_cb (void *cls,
  * Task run during shutdown.
  *
  * @param cls unused
- * @param tc unused
  */
 static void
-shutdown_task (void *cls,
-              const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls)
 {
   if (NULL != flood_task)
   {
@@ -1389,9 +1386,9 @@ shutdown_task (void *cls,
   }
   if (NULL != lh)
   {
-    struct GNUNET_TIME_Relative timeout;
-    timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30);
-    GNUNET_TESTBED_LOGGER_flush (lh, timeout, &flush_comp_cb, NULL);
+    GNUNET_TESTBED_LOGGER_flush (lh,
+                                 &flush_comp_cb,
+                                 NULL);
   }
   if (NULL != histogram)
   {
@@ -1443,7 +1440,8 @@ core_init (void *cls,
   }
   flood_task =
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
-                                    (next_timestamp), &update_flood_message,
+                                    (next_timestamp),
+                                   &update_flood_message,
                                     NULL);
 }
 
@@ -1564,8 +1562,8 @@ run (void *cls,
   }
 #endif
 
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+                                NULL);
   pk = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
   GNUNET_assert (NULL != pk);
   my_private_key = pk;
@@ -1629,7 +1627,7 @@ main (int argc,
 }
 
 
-#ifdef LINUX
+#if defined(LINUX) && defined(__GLIBC__)
 #include <malloc.h>
 
 /**