prevent loopback routing, add some statistics, faster re-transmit
authorChristian Grothoff <christian@grothoff.org>
Wed, 19 Oct 2011 14:09:50 +0000 (14:09 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 19 Oct 2011 14:09:50 +0000 (14:09 +0000)
src/fs/gnunet-service-fs.c
src/fs/gnunet-service-fs_cp.c
src/fs/gnunet-service-fs_lc.c
src/fs/gnunet-service-fs_pe.c
src/fs/gnunet-service-fs_pr.c
src/fs/gnunet-service-fs_pr.h

index bf6984dd672930f188d1a4b18e6d5b0563016f88..6ea47c2e291bbd33ef729e72d0f9549f10c04e27 100644 (file)
@@ -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);
 }
 
@@ -430,7 +439,12 @@ consider_peer_for_forwarding (void *cls, const GNUNET_HashCode * key,
   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;
 }
index 35a21f07a2376ec81cc62c33a8e6b55954e30210..1e535d0891d21c1c3487b1cd6efe615ed6862de1 100644 (file)
@@ -1322,7 +1322,9 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
                                      0) ? (const char *) &opt[bits] : NULL,
                                     bfsize, ntohl (gm->filter_mutator),
                                     1 /* anonymity */ ,
-                                    (uint32_t) priority, ttl, spid, NULL, 0,    /* replies_seen */
+                                    (uint32_t) priority, ttl, spid,
+                                   GNUNET_PEER_intern (other),
+                                   NULL, 0,    /* replies_seen */
                                     &handle_p2p_reply, peerreq);
   GNUNET_assert (NULL != pr);
   peerreq->pr = pr;
index a7e78a6ed7302fc2631ea661071f38535cafadbd..9f284ed8fba2453ee4879c0a3c2bf1f7def98987 100644 (file)
@@ -375,7 +375,7 @@ GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
                                         ntohl (sm->anonymity_level),
                                         0 /* priority */ ,
                                         0 /* ttl */ ,
-                                        0 /* sender PID */ ,
+                                        0 /* sender PID */ , 0 /* origin PID */,
                                         (const GNUNET_HashCode *) &sm[1], sc,
                                         &client_response_handler, cr);
   return cr->pr;
index dc83c996011e2c29808d9fc97b35454d046ce3d1..6bf85df929bcc67f14ac4fa709ee14caf3a2dab9 100644 (file)
@@ -229,12 +229,25 @@ plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp)
                          total_delay * 1000LL / plan_count, GNUNET_NO);
   prd = GSF_pending_request_get_data_ (rp->prl_head->pr);
   // FIXME: calculate 'rp->priority'!
+#if 0
   if (rp->transmission_counter < 32)
     delay =
         GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
                                        1LL << rp->transmission_counter);
   else
     delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, UINT_MAX);
+#else
+  if (rp->transmission_counter < 32)
+    delay =
+        GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+                                       rp->transmission_counter);
+  else if (rp->transmission_counter < 32)
+    delay =
+        GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+                                       32 + (1LL << rp->transmission_counter));
+  else
+    delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, UINT_MAX);
+#endif
   rp->earliest_transmission = GNUNET_TIME_relative_to_absolute (delay);
 #if DEBUG_FS
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -361,14 +374,6 @@ schedule_peer_transmission (void *cls,
     GSF_peer_transmit_cancel_ (pp->pth);
     pp->pth = NULL;
   }
-  GNUNET_STATISTICS_set (GSF_stats,
-                        gettext_noop ("# query delay heap size"), 
-                        GNUNET_CONTAINER_heap_get_size (pp->delay_heap),
-                        GNUNET_NO);
-  GNUNET_STATISTICS_set (GSF_stats,
-                        gettext_noop ("# query priority heap size"), 
-                        GNUNET_CONTAINER_heap_get_size (pp->priority_heap),
-                        GNUNET_NO);
   /* move ready requests to priority queue */
   while ((NULL != (rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap))) &&
          (GNUNET_TIME_absolute_get_remaining
index 9a8a3f23a2ea9f7c7505e2743c02a4b7628a3202..7d205fef96e4206112c719578628f627acef4768 100644 (file)
@@ -103,6 +103,12 @@ struct GSF_PendingRequest
    */
   GNUNET_PEER_Id sender_pid;
 
+  /**
+   * Identity of the peer that we should never forward this query
+   * to since it originated this query (0 for none).
+   */
+  GNUNET_PEER_Id origin_pid;
+
   /**
    * Time we started the last datastore lookup.
    */
@@ -226,6 +232,7 @@ refresh_bloomfilter (struct GSF_PendingRequest *pr)
  * @param priority maximum outgoing cummulative request priority to use
  * @param ttl current time-to-live for the request
  * @param sender_pid peer ID to use for the sender when forwarding, 0 for none
+ * @param origin_pid peer ID of origin of query (do not loop back)
  * @param replies_seen hash codes of known local replies
  * @param replies_seen_count size of the 'replies_seen' array
  * @param rh handle to call when we get a reply
@@ -242,6 +249,7 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
                              uint32_t mingle, uint32_t anonymity_level,
                              uint32_t priority, int32_t ttl,
                              GNUNET_PEER_Id sender_pid,
+                             GNUNET_PEER_Id origin_pid,
                              const GNUNET_HashCode * replies_seen,
                              unsigned int replies_seen_count,
                              GSF_PendingRequestReplyHandler rh, void *rh_cls)
@@ -278,6 +286,7 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
   pr->public_data.type = type;
   pr->public_data.start_time = GNUNET_TIME_absolute_get ();
   pr->sender_pid = sender_pid;
+  pr->origin_pid = origin_pid;
   pr->rh = rh;
   pr->rh_cls = rh_cls;
   GNUNET_assert ((sender_pid != 0) || (0 == (options & GSF_PRO_FORWARD_ONLY)));
@@ -562,6 +571,8 @@ clean_request (void *cls, const GNUNET_HashCode * key, void *value)
   }
   GNUNET_PEER_change_rc (pr->sender_pid, -1);
   pr->sender_pid = 0;
+  GNUNET_PEER_change_rc (pr->origin_pid, -1);
+  pr->origin_pid = 0;
   if (NULL != pr->hnode)
   {
     GNUNET_CONTAINER_heap_remove_node (pr->hnode);
@@ -1214,7 +1225,7 @@ process_local_reply (void *cls, const GNUNET_HashCode * key, size_t size,
                                   /* queue priority */ ,
                                   (0 !=
                                    (GSF_PRO_PRIORITY_UNLIMITED &
-                                    pr->public_data.options)) ? UINT_MAX : 1
+                                    pr->public_data.options)) ? UINT_MAX : 16
                                   /* max queue size */ ,
                                   GNUNET_TIME_UNIT_FOREVER_REL,
                                   &process_local_reply, pr);
@@ -1253,7 +1264,7 @@ process_local_reply (void *cls, const GNUNET_HashCode * key, size_t size,
                                   /* queue priority */ ,
                                   (0 !=
                                    (GSF_PRO_PRIORITY_UNLIMITED &
-                                    pr->public_data.options)) ? UINT_MAX : 1
+                                    pr->public_data.options)) ? UINT_MAX : 16
                                   /* max queue size */ ,
                                   GNUNET_TIME_UNIT_FOREVER_REL,
                                   &process_local_reply, pr);
@@ -1279,7 +1290,7 @@ process_local_reply (void *cls, const GNUNET_HashCode * key, size_t size,
   {
     GNUNET_STATISTICS_update (GSF_stats,
                               gettext_noop
-                              ("# Datastore lookups concluded (found ultimate result)"),
+                              ("# Datastore lookups concluded (found last result)"),
                               1, GNUNET_NO);
     goto check_error_and_continue;
   }
@@ -1312,7 +1323,7 @@ process_local_reply (void *cls, const GNUNET_HashCode * key, size_t size,
                                 /* queue priority */ ,
                                 (0 !=
                                  (GSF_PRO_PRIORITY_UNLIMITED & pr->
-                                  public_data.options)) ? UINT_MAX : 1
+                                  public_data.options)) ? UINT_MAX : 16
                                 /* max queue size */ ,
                                 GNUNET_TIME_UNIT_FOREVER_REL,
                                 &process_local_reply, pr);
@@ -1347,9 +1358,9 @@ GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr,
 {
   struct GNUNET_PeerIdentity pi;
   
-  if (0 == pr->sender_pid)
+  if (0 == pr->origin_pid)
     return GNUNET_YES;
-  GNUNET_PEER_resolve (pr->sender_pid, &pi);
+  GNUNET_PEER_resolve (pr->origin_pid, &pi);
   return (0 == memcmp (&pi, target, sizeof (struct GNUNET_PeerIdentity))) ? GNUNET_NO :GNUNET_YES;
 }
 
@@ -1388,7 +1399,7 @@ GSF_local_lookup_ (struct GSF_PendingRequest *pr,
                                 /* queue priority */ ,
                                 (0 !=
                                  (GSF_PRO_PRIORITY_UNLIMITED & pr->
-                                  public_data.options)) ? UINT_MAX : 1
+                                  public_data.options)) ? UINT_MAX : 16
                                 /* max queue size */ ,
                                 GNUNET_TIME_UNIT_FOREVER_REL,
                                 &process_local_reply, pr);
index c8b52398e198034df7d9519498ff53b6a87c5b7a..538a382480862adc66f788e3e25fd318cc86b012 100644 (file)
@@ -195,6 +195,7 @@ typedef void (*GSF_PendingRequestReplyHandler) (void *cls,
  * @param ttl current time-to-live for the request
  * @param sender_pid peer ID to use for the sender when forwarding, 0 for none;
  *                   reference counter is taken over by this function
+ * @param origin_pid peer ID of origin of query (do not loop back)
  * @param replies_seen hash codes of known local replies
  * @param replies_seen_count size of the 'replies_seen' array
  * @param rh handle to call when we get a reply
@@ -211,6 +212,7 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
                              uint32_t mingle, uint32_t anonymity_level,
                              uint32_t priority, int32_t ttl,
                              GNUNET_PEER_Id sender_pid,
+                             GNUNET_PEER_Id origin_pid,
                              const GNUNET_HashCode * replies_seen,
                              unsigned int replies_seen_count,
                              GSF_PendingRequestReplyHandler rh, void *rh_cls);