-only trigger check config if we actually need it
[oweals/gnunet.git] / src / fs / gnunet-service-fs.c
index 11cbe5a7064494c4bb976dd9c1caf966a92bde3a..348bab09276536aed5b418a1cf9f415b69e6aa61 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2009-2014 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2009-2014 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
@@ -184,16 +184,15 @@ static struct GNUNET_PeerIdentity my_id;
  * Task that periodically ages our cover traffic statistics.
  *
  * @param cls unused closure
- * @param tc task context
  */
 static void
-age_cover_counters (void *cls,
-                    const struct GNUNET_SCHEDULER_TaskContext *tc)
+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);
 }
 
@@ -355,7 +354,11 @@ consider_forwarding (void *cls,
 {
   if (GNUNET_BLOCK_EVALUATION_OK_LAST == result)
     return;                     /* we're done... */
-  GSF_iterate_connected_peers_ (&consider_request_for_forwarding, pr);
+  if (GNUNET_YES !=
+      GSF_pending_request_test_active_ (pr))
+    return; /* request is not actually active, skip! */
+  GSF_iterate_connected_peers_ (&consider_request_for_forwarding,
+                                pr);
 }
 
 
@@ -376,12 +379,14 @@ handle_p2p_get (void *cls,
 {
   struct GSF_PendingRequest *pr;
 
-  pr = GSF_handle_p2p_query_ (other, message);
+  pr = GSF_handle_p2p_query_ (other,
+                              message);
   if (NULL == pr)
-    return GNUNET_SYSERR;
+    return GNUNET_OK; /* exists, identical to existing request, or malformed */
   GSF_pending_request_get_data_ (pr)->has_started = GNUNET_YES;
   GSF_local_lookup_ (pr,
-                     &consider_forwarding, NULL);
+                     &consider_forwarding,
+                     NULL);
   return GNUNET_OK;
 }
 
@@ -439,7 +444,8 @@ start_p2p_processing (void *cls,
 
 
 /**
- * Handle START_SEARCH-message (search request from client).
+ * Handle #GNUNET_MESSAGE_TYPE_FS_START_SEARCH-message (search request
+ * from client).
  *
  * @param cls closure
  * @param client identification of the client
@@ -524,11 +530,9 @@ handle_loc_sign (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)
 {
   GSF_cadet_stop_client ();
   GSF_cadet_stop_server ();
@@ -575,7 +579,7 @@ shutdown_task (void *cls,
  * peer connects, giving us a chance to decide about submitting
  * the existing request to the new peer.
  *
- * @param cls the 'struct GSF_ConnectedPeer' of the new peer
+ * @param cls the `struct GSF_ConnectedPeer` of the new peer
  * @param key query for the request
  * @param pr handle to the pending request
  * @return #GNUNET_YES to continue to iterate
@@ -588,11 +592,16 @@ consider_peer_for_forwarding (void *cls,
   struct GSF_ConnectedPeer *cp = cls;
   struct GNUNET_PeerIdentity pid;
 
+  if (GNUNET_YES !=
+      GSF_pending_request_test_active_ (pr))
+    return GNUNET_YES; /* request is not actually active, skip! */
   GSF_connected_peer_get_identity_ (cp, &pid);
-  if (GNUNET_YES != GSF_pending_request_test_target_ (pr, &pid))
+  if (GNUNET_YES !=
+      GSF_pending_request_test_target_ (pr, &pid))
   {
     GNUNET_STATISTICS_update (GSF_stats,
-                              gettext_noop ("# Loopback routes suppressed"), 1,
+                              gettext_noop ("# Loopback routes suppressed"),
+                              1,
                               GNUNET_NO);
     return GNUNET_YES;
   }
@@ -608,11 +617,13 @@ consider_peer_for_forwarding (void *cls,
  * @param cp handle to the newly created connected peer record
  */
 static void
-connected_peer_cb (void *cls, struct GSF_ConnectedPeer *cp)
+connected_peer_cb (void *cls,
+                   struct GSF_ConnectedPeer *cp)
 {
   if (NULL == cp)
     return;
-  GSF_iterate_pending_requests_ (&consider_peer_for_forwarding, cp);
+  GSF_iterate_pending_requests_ (&consider_peer_for_forwarding,
+                                 cp);
 }
 
 
@@ -749,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;
 }
 
@@ -807,7 +819,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
       (GNUNET_OK != main_init (server, cfg)))
   {
     GNUNET_SCHEDULER_shutdown ();
-    shutdown_task (NULL, NULL);
+    shutdown_task (NULL);
     return;
   }
 }