aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-service-fs_pe.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-service-fs_pe.c')
-rw-r--r--src/fs/gnunet-service-fs_pe.c36
1 files changed, 35 insertions, 1 deletions
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,
251static void 251static void
252plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp) 252plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp)
253{ 253{
254#define N ((double)128.0)
255 /**
256 * Running average delay we currently impose.
257 */
258 static double avg_delay;
259
254 struct GSF_PendingRequestData *prd; 260 struct GSF_PendingRequestData *prd;
255 struct GNUNET_TIME_Relative delay; 261 struct GNUNET_TIME_Relative delay;
256 262
@@ -259,7 +265,7 @@ plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp)
259 gettext_noop ("# average retransmission delay (ms)"), 265 gettext_noop ("# average retransmission delay (ms)"),
260 total_delay * 1000LL / plan_count, GNUNET_NO); 266 total_delay * 1000LL / plan_count, GNUNET_NO);
261 prd = GSF_pending_request_get_data_ (rp->prl_head->pr); 267 prd = GSF_pending_request_get_data_ (rp->prl_head->pr);
262 // FIXME: calculate 'rp->priority'! 268
263 if (rp->transmission_counter < 8) 269 if (rp->transmission_counter < 8)
264 delay = 270 delay =
265 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 271 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
@@ -276,6 +282,33 @@ plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp)
276 delay.rel_value = 282 delay.rel_value =
277 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 283 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
278 delay.rel_value + 1); 284 delay.rel_value + 1);
285 /* Add 0.01 to avg_delay to avoid division-by-zero later */
286 avg_delay = (((avg_delay * (N-1.0)) + delay.rel_value) / N) + 0.01;
287
288 /*
289 For the priority, we need to consider a few basic rules:
290 1) if we just started requesting (delay is small), we should
291 virtually always have a priority of zero.
292 2) for requests with average latency, our priority should match
293 the average priority observed on the network
294 3) even the longest-running requests should not be WAY out of
295 the observed average (thus we bound by a factor of 2)
296 4) we add +1 to the observed average priority to avoid everyone
297 staying put at zero (2 * 0 = 0...).
298
299 Using the specific calculation below, we get:
300
301 delay = 0 => priority = 0;
302 delay = avg delay => priority = running-average-observed-priority;
303 delay >> avg_delay => priority = 2 * running-average-observed-priority;
304
305 which satisfies all of the rules above.
306
307 Note: M_PI_4 = PI/4 = arctan(1)
308 */
309 rp->priority = round ((GSF_current_priorities + 1.0) * atan (delay.rel_value / avg_delay)) / M_PI_4;
310 /* Note: usage of 'round' and 'atan' requires -lm */
311
279 if (rp->transmission_counter != 0) 312 if (rp->transmission_counter != 0)
280 delay.rel_value += TTL_DECREMENT; 313 delay.rel_value += TTL_DECREMENT;
281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -304,6 +337,7 @@ plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp)
304 if (GNUNET_SCHEDULER_NO_TASK != pp->task) 337 if (GNUNET_SCHEDULER_NO_TASK != pp->task)
305 GNUNET_SCHEDULER_cancel (pp->task); 338 GNUNET_SCHEDULER_cancel (pp->task);
306 pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp); 339 pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
340#undef N
307} 341}
308 342
309 343