prevent loopback routing, add some statistics, faster re-transmit
[oweals/gnunet.git] / src / fs / gnunet-service-fs.c
index 4d12b8bfd08fd2b468cef12e50dc0260d200928e..6ea47c2e291bbd33ef729e72d0f9549f10c04e27 100644 (file)
@@ -24,7 +24,7 @@
  * @author Christian Grothoff
  *
  * To use:
- * - consider re-issue GSF_dht_lookup_ after non-DHT reply received 
+ * - consider re-issue GSF_dht_lookup_ after non-DHT reply received
  * - implement 'SUPPORT_DELAYS'
  *
  */
@@ -59,7 +59,7 @@
 
 
 /**
- * How quickly do we age cover traffic?  At the given 
+ * How quickly do we age cover traffic?  At the given
  * time interval, remaining cover traffic counters are
  * decremented by 1/16th.
  */
@@ -106,13 +106,13 @@ struct GNUNET_LOAD_Value *GSF_rt_entry_lifetime;
 double GSF_current_priorities;
 
 /**
- * How many query messages have we received 'recently' that 
+ * How many query messages have we received 'recently' that
  * have not yet been claimed as cover traffic?
  */
 unsigned int GSF_cover_query_count;
 
 /**
- * How many content messages have we received 'recently' that 
+ * How many content messages have we received 'recently' that
  * have not yet been claimed as cover traffic?
  */
 unsigned int GSF_cover_content_count;
@@ -166,8 +166,9 @@ age_cover_counters (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   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, NULL);
+  cover_age_task =
+      GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, &age_cover_counters,
+                                    NULL);
 }
 
 
@@ -191,8 +192,8 @@ GSF_update_datastore_delay_ (struct GNUNET_TIME_Absolute start)
 /**
  * Test if the DATABASE (GET) load on this peer is too high
  * to even consider processing the query at
- * all.  
- * 
+ * all.
+ *
  * @return GNUNET_YES if the load is too high to do anything (load high)
  *         GNUNET_NO to process normally (load normal)
  *         GNUNET_SYSERR to process for free (load low)
@@ -223,10 +224,9 @@ GSF_test_get_load_too_high_ (uint32_t priority)
  *         GNUNET_SYSERR to close it (signal serious error)
  */
 static int
-handle_p2p_put (void *cls,
-                const struct GNUNET_PeerIdentity *other,
+handle_p2p_put (void *cls, const struct GNUNET_PeerIdentity *other,
                 const struct GNUNET_MessageHeader *message,
-                const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+                const struct GNUNET_ATS_Information *atsi)
 {
   struct GSF_ConnectedPeer *cp;
 
@@ -258,6 +258,15 @@ consider_request_for_forwarding (void *cls,
 {
   struct GSF_PendingRequest *pr = cls;
 
+  if (GNUNET_YES !=
+      GSF_pending_request_test_target_ (pr,
+                                       peer))
+  {
+    GNUNET_STATISTICS_update (GSF_stats,
+                             gettext_noop ("# Loopback routes suppressed"), 1,
+                             GNUNET_NO);
+    return;
+  }
   GSF_plan_add_ (cp, pr);
 }
 
@@ -273,8 +282,7 @@ consider_request_for_forwarding (void *cls,
  * @param result final datastore lookup result
  */
 static void
-consider_forwarding (void *cls,
-                     struct GSF_PendingRequest *pr,
+consider_forwarding (void *cls, struct GSF_PendingRequest *pr,
                      enum GNUNET_BLOCK_EvaluationResult result)
 {
   if (GNUNET_BLOCK_EVALUATION_OK_LAST == result)
@@ -295,10 +303,9 @@ consider_forwarding (void *cls,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
 static int
-handle_p2p_get (void *cls,
-                const struct GNUNET_PeerIdentity *other,
+handle_p2p_get (void *cls, const struct GNUNET_PeerIdentity *other,
                 const struct GNUNET_MessageHeader *message,
-                const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+                const struct GNUNET_ATS_Information *atsi)
 {
   struct GSF_PendingRequest *pr;
 
@@ -313,7 +320,7 @@ handle_p2p_get (void *cls,
 /**
  * We're done with the local lookup, now consider
  * P2P processing (depending on request options and
- * result status).  Also signal that we can now 
+ * result status).  Also signal that we can now
  * receive more request information from the client.
  *
  * @param cls the client doing the request ('struct GNUNET_SERVER_Client')
@@ -321,8 +328,7 @@ handle_p2p_get (void *cls,
  * @param result final datastore lookup result
  */
 static void
-start_p2p_processing (void *cls,
-                      struct GSF_PendingRequest *pr,
+start_p2p_processing (void *cls, struct GSF_PendingRequest *pr,
                       enum GNUNET_BLOCK_EvaluationResult result)
 {
   struct GNUNET_SERVER_Client *client = cls;
@@ -355,8 +361,7 @@ start_p2p_processing (void *cls,
  * @param message the actual message
  */
 static void
-handle_start_search (void *cls,
-                     struct GNUNET_SERVER_Client *client,
+handle_start_search (void *cls, struct GNUNET_SERVER_Client *client,
                      const struct GNUNET_MessageHeader *message)
 {
   struct GSF_PendingRequest *pr;
@@ -424,12 +429,22 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * @return GNUNET_YES to continue to iterate
  */
 static int
-consider_peer_for_forwarding (void *cls,
-                              const GNUNET_HashCode * key,
+consider_peer_for_forwarding (void *cls, const GNUNET_HashCode * key,
                               struct GSF_PendingRequest *pr)
 {
   struct GSF_ConnectedPeer *cp = cls;
+  struct GNUNET_PeerIdentity pid;
 
+  GSF_connected_peer_get_identity_ (cp, &pid);
+  if (GNUNET_YES !=
+      GSF_pending_request_test_target_ (pr,
+                                       &pid))
+  {
+    GNUNET_STATISTICS_update (GSF_stats,
+                             gettext_noop ("# Loopback routes suppressed"), 1,
+                             GNUNET_NO);
+    return GNUNET_YES;
+  }
   GSF_plan_add_ (cp, pr);
   return GNUNET_YES;
 }
@@ -443,9 +458,8 @@ consider_peer_for_forwarding (void *cls,
  * @param atsi performance information
  */
 static void
-peer_connect_handler (void *cls,
-                      const struct GNUNET_PeerIdentity *peer,
-                      const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
+                      const struct GNUNET_ATS_Information *atsi)
 {
   struct GSF_ConnectedPeer *cp;
 
@@ -468,14 +482,10 @@ peer_connect_handler (void *cls,
  * @param cls closure
  * @param server handle to the server, NULL if we failed
  * @param my_identity ID of this peer, NULL if we failed
- * @param publicKey public key of this peer, NULL if we failed
  */
 static void
-peer_init_handler (void *cls,
-                   struct GNUNET_CORE_Handle *server,
-                   const struct GNUNET_PeerIdentity *my_identity,
-                   const struct
-                   GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
+peer_init_handler (void *cls, struct GNUNET_CORE_Handle *server,
+                   const struct GNUNET_PeerIdentity *my_identity)
 {
   my_id = *my_identity;
 }
@@ -515,11 +525,9 @@ main_init (struct GNUNET_SERVER_Handle *server,
   };
 
   GSF_core = GNUNET_CORE_connect (GSF_cfg, 2,   /* larger? */
-                                  NULL,
-                                  &peer_init_handler,
+                                  NULL, &peer_init_handler,
                                   &peer_connect_handler,
                                   &GSF_peer_disconnect_handler_,
-                                  &GSF_peer_status_handler_,
                                   NULL, GNUNET_NO,
                                   NULL, GNUNET_NO, p2p_handlers);
   if (NULL == GSF_core)
@@ -528,14 +536,15 @@ main_init (struct GNUNET_SERVER_Handle *server,
                 _("Failed to connect to `%s' service.\n"), "core");
     return GNUNET_SYSERR;
   }
-  GNUNET_SERVER_disconnect_notify (server,
-                                   &GSF_client_disconnect_handler_, NULL);
+  GNUNET_SERVER_disconnect_notify (server, &GSF_client_disconnect_handler_,
+                                   NULL);
   GNUNET_SERVER_add_handlers (server, handlers);
-  cover_age_task = GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY,
-                                                 &age_cover_counters, NULL);
+  cover_age_task =
+      GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, &age_cover_counters,
+                                    NULL);
   datastore_get_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &shutdown_task, NULL);
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
+                                NULL);
   return GNUNET_OK;
 }
 
@@ -548,8 +557,7 @@ main_init (struct GNUNET_SERVER_Handle *server,
  * @param cfg configuration to use
  */
 static void
-run (void *cls,
-     struct GNUNET_SERVER_Handle *server,
+run (void *cls, struct GNUNET_SERVER_Handle *server,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   GSF_cfg = cfg;
@@ -594,10 +602,8 @@ int
 main (int argc, char *const *argv)
 {
   return (GNUNET_OK ==
-          GNUNET_SERVICE_run (argc,
-                              argv,
-                              "fs",
-                              GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
+          GNUNET_SERVICE_run (argc, argv, "fs", GNUNET_SERVICE_OPTION_NONE,
+                              &run, NULL)) ? 0 : 1;
 }
 
 /* end of gnunet-service-fs.c */