summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-11-11 19:56:55 +0000
committerChristian Grothoff <christian@grothoff.org>2011-11-11 19:56:55 +0000
commit284cdb8ef69455ea47c60eb7533cfe4ddcf090f6 (patch)
treec5be85d64f99a086596d88314f0ae922c5a6254d /src
parentc8fc4ee0101c52fa60e536e9879599dc8f818532 (diff)
fixing 1787
Diffstat (limited to 'src')
-rw-r--r--src/fs/Makefile.am2
-rw-r--r--src/fs/gnunet-service-fs_pe.c36
2 files changed, 36 insertions, 2 deletions
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am
index 264bb45d6..8cc0f9bf3 100644
--- a/src/fs/Makefile.am
+++ b/src/fs/Makefile.am
@@ -138,7 +138,7 @@ gnunet_service_fs_LDADD = \
$(top_builddir)/src/ats/libgnunetats.la \
$(top_builddir)/src/core/libgnunetcore.la \
$(top_builddir)/src/util/libgnunetutil.la \
- $(GN_LIBINTL)
+ $(GN_LIBINTL) -lm
gnunet_service_fs_DEPENDENCIES = \
libgnunetfs.la
diff --git a/src/fs/gnunet-service-fs_pe.c b/src/fs/gnunet-service-fs_pe.c
index 41dd61a64..200d7a0e4 100644
--- a/src/fs/gnunet-service-fs_pe.c
+++ b/src/fs/gnunet-service-fs_pe.c
@@ -251,6 +251,12 @@ schedule_peer_transmission (void *cls,
static void
plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp)
{
+#define N ((double)128.0)
+ /**
+ * Running average delay we currently impose.
+ */
+ static double avg_delay;
+
struct GSF_PendingRequestData *prd;
struct GNUNET_TIME_Relative delay;
@@ -259,7 +265,7 @@ plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp)
gettext_noop ("# average retransmission delay (ms)"),
total_delay * 1000LL / plan_count, GNUNET_NO);
prd = GSF_pending_request_get_data_ (rp->prl_head->pr);
- // FIXME: calculate 'rp->priority'!
+
if (rp->transmission_counter < 8)
delay =
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
@@ -276,6 +282,33 @@ plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp)
delay.rel_value =
GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
delay.rel_value + 1);
+ /* Add 0.01 to avg_delay to avoid division-by-zero later */
+ avg_delay = (((avg_delay * (N-1.0)) + delay.rel_value) / N) + 0.01;
+
+ /*
+ For the priority, we need to consider a few basic rules:
+ 1) if we just started requesting (delay is small), we should
+ virtually always have a priority of zero.
+ 2) for requests with average latency, our priority should match
+ the average priority observed on the network
+ 3) even the longest-running requests should not be WAY out of
+ the observed average (thus we bound by a factor of 2)
+ 4) we add +1 to the observed average priority to avoid everyone
+ staying put at zero (2 * 0 = 0...).
+
+ Using the specific calculation below, we get:
+
+ delay = 0 => priority = 0;
+ delay = avg delay => priority = running-average-observed-priority;
+ delay >> avg_delay => priority = 2 * running-average-observed-priority;
+
+ which satisfies all of the rules above.
+
+ Note: M_PI_4 = PI/4 = arctan(1)
+ */
+ rp->priority = round ((GSF_current_priorities + 1.0) * atan (delay.rel_value / avg_delay)) / M_PI_4;
+ /* Note: usage of 'round' and 'atan' requires -lm */
+
if (rp->transmission_counter != 0)
delay.rel_value += TTL_DECREMENT;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -304,6 +337,7 @@ plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp)
if (GNUNET_SCHEDULER_NO_TASK != pp->task)
GNUNET_SCHEDULER_cancel (pp->task);
pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
+#undef N
}