From 28273c70836e834793cfb03b82325e38e566e65a Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 26 Sep 2018 22:58:21 +0200 Subject: [PATCH] configurable threshold for randomized backoff --- src/include/gnunet_time_lib.h | 7 ++++--- src/util/time.c | 9 ++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h index 41840e9a3..c7a06ba23 100644 --- a/src/include/gnunet_time_lib.h +++ b/src/include/gnunet_time_lib.h @@ -177,13 +177,14 @@ GNUNET_NETWORK_STRUCT_END /** * Randomized exponential back-off, starting at 1 ms * and going up by a factor of 2+r, where 0 <= r <= 0.5, up - * to a maximum of 15 m. + * to a maximum of the given threshold. * - * @param r current backoff time, initially zero + * @param rt current backoff time, initially zero + * @param threshold maximum value for backoff * @return the next backoff time */ struct GNUNET_TIME_Relative -GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt); +GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt, struct GNUNET_TIME_Relative threshold); /** diff --git a/src/util/time.c b/src/util/time.c index 0c177c381..b02c43c1b 100644 --- a/src/util/time.c +++ b/src/util/time.c @@ -737,13 +737,14 @@ GNUNET_TIME_year_to_time (unsigned int year) /** * Randomized exponential back-off, starting at 1 ms * and going up by a factor of 2+r, where 0 <= r <= 0.5, up - * to a maximum of 15 m. + * to a maximum of the given threshold. * * @param r current backoff time, initially zero + * @param threshold maximum value for backoff * @return the next backoff time */ struct GNUNET_TIME_Relative -GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt) +GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt, struct GNUNET_TIME_Relative threshold) { double r = (rand() % 500) / 1000.0; struct GNUNET_TIME_Relative t; @@ -751,9 +752,11 @@ GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt) t = relative_multiply_double (GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS, rt), 2 + r); - return GNUNET_TIME_relative_min (GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD, + return GNUNET_TIME_relative_min (threshold, t); } + + /* end of time.c */ -- 2.25.1