keep current priority average and use it
authorChristian Grothoff <christian@grothoff.org>
Wed, 7 Jul 2010 20:57:30 +0000 (20:57 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 7 Jul 2010 20:57:30 +0000 (20:57 +0000)
src/fs/gnunet-service-fs.c

index ea79d0711e797c237d366bfcf8a31bc89c65b7ea..44d787a964d080f3aec2355a940d2c32f02c618c 100644 (file)
@@ -24,9 +24,8 @@
  * @author Christian Grothoff
  *
  * TODO:
- * - trust not properly received and pushed back to peerinfo!
- * - bound_priority by priorities used by other peers
- * - have a way to drop queries based on load
+ * - bound_priority should not charge if we are not loaded (excess-based economy)
+ * - have a way to drop queries based on load (or just forward...)
  * - introduce random latency in processing
  * - consider more precise latency estimation (per-peer & request)
  * - better algorithm for priority selection for requests we initiate?
@@ -94,12 +93,6 @@ static uint64_t max_pending_requests = (32 * 1024);
  */
 struct PendingMessage;
 
-/**
- * Our connection to the datastore.
- */
-static struct GNUNET_DATASTORE_Handle *dsh;
-
-
 /**
  * Function called upon completion of a transmission.
  *
@@ -624,6 +617,12 @@ struct MigrationReadyBlock
 };
 
 
+/**
+ * Our connection to the datastore.
+ */
+static struct GNUNET_DATASTORE_Handle *dsh;
+
+
 /**
  * Our scheduler.
  */
@@ -716,6 +715,17 @@ static unsigned int mig_size;
  */
 static int active_migration;
 
+/**
+ * Typical priorities we're seeing from other peers right now.  Since
+ * most priorities will be zero, this value is the weighted average of
+ * non-zero priorities seen "recently".  In order to ensure that new
+ * values do not dramatically change the ratio, values are first
+ * "capped" to a reasonable range (+N of the current value) and then
+ * averaged into the existing value by a ratio of 1:N.  Hence
+ * receiving the largest possible priority can still only raise our
+ * "current_priorities" by at most 1.
+ */
+static double current_priorities;
 
 /**
  * Get the filename under which we would store the GNUNET_HELLO_Message
@@ -1395,11 +1405,6 @@ peer_disconnect_handler (void *cls,
                                             &consider_migration,
                                             pos);
     }
-  if (cp->trust > 0)
-    {
-      /* FIXME: push trust back to peerinfo! 
-        (need better peerinfo API!) */
-    }
   GNUNET_PEER_change_rc (cp->pid, -1);
   GNUNET_PEER_decrement_rcs (cp->last_p2p_replies, P2P_SUCCESS_LIST_SIZE);
   if (NULL != cp->cth)
@@ -2316,8 +2321,12 @@ forward_request_task (void *cls,
       if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
                                         4))
        pr->priority++;
-      /* FIXME: bound priority by "customary" priority used by other peers
-        at this time! */
+      /* bound priority we use by priorities we see from other peers
+        rounded up (must round up so that we can see non-zero
+        priorities, but round up as little as possible to make it
+        plausible that we forwarded another peers request) */
+      if (pr->priority > current_priorities + 1.0)
+       pr->priority = (uint32_t) current_priorities + 1.0;
       pr->ttl = bound_ttl (pr->ttl + TTL_DECREMENT * 2,
                           pr->priority);
 #if DEBUG_FS
@@ -3099,9 +3108,23 @@ static uint32_t
 bound_priority (uint32_t prio_in,
                struct ConnectedPeer *cp)
 {
+#define N ((double)128.0)
+  uint32_t ret;
+  double rret;
   /* FIXME: check if load is low and we
      hence should not charge... */
-  return change_host_trust (cp, prio_in);
+  ret = change_host_trust (cp, prio_in);
+  if (ret > 0)
+    {
+      if (ret > current_priorities + N)
+       rret = current_priorities + N;
+      else
+       rret = ret;
+      current_priorities 
+       = (current_priorities * (N-1) + rret)/N;
+    }
+#undef N
+  return ret;
 }