diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-11-11 19:56:55 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-11-11 19:56:55 +0000 |
commit | 284cdb8ef69455ea47c60eb7533cfe4ddcf090f6 (patch) | |
tree | c5be85d64f99a086596d88314f0ae922c5a6254d | |
parent | c8fc4ee0101c52fa60e536e9879599dc8f818532 (diff) | |
download | gnunet-284cdb8ef69455ea47c60eb7533cfe4ddcf090f6.tar.gz gnunet-284cdb8ef69455ea47c60eb7533cfe4ddcf090f6.zip |
fixing 1787
-rw-r--r-- | src/fs/Makefile.am | 2 | ||||
-rw-r--r-- | src/fs/gnunet-service-fs_pe.c | 36 |
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 = \ | |||
138 | $(top_builddir)/src/ats/libgnunetats.la \ | 138 | $(top_builddir)/src/ats/libgnunetats.la \ |
139 | $(top_builddir)/src/core/libgnunetcore.la \ | 139 | $(top_builddir)/src/core/libgnunetcore.la \ |
140 | $(top_builddir)/src/util/libgnunetutil.la \ | 140 | $(top_builddir)/src/util/libgnunetutil.la \ |
141 | $(GN_LIBINTL) | 141 | $(GN_LIBINTL) -lm |
142 | gnunet_service_fs_DEPENDENCIES = \ | 142 | gnunet_service_fs_DEPENDENCIES = \ |
143 | libgnunetfs.la | 143 | libgnunetfs.la |
144 | 144 | ||
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, | |||
251 | static void | 251 | static void |
252 | plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp) | 252 | plan (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 | ||