[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet] branch master updated: randomized exponential back
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet] branch master updated: randomized exponential backoff |
Date: |
Wed, 26 Sep 2018 17:36:24 +0200 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new ed6b45c02 randomized exponential backoff
ed6b45c02 is described below
commit ed6b45c02fabd040f25c6ea3e7c5d1e03c9725e8
Author: Florian Dold <address@hidden>
AuthorDate: Wed Sep 26 17:34:51 2018 +0200
randomized exponential backoff
---
src/include/gnunet_time_lib.h | 13 +++++++++++
src/util/time.c | 54 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+)
diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h
index 2fc20d2cd..41840e9a3 100644
--- a/src/include/gnunet_time_lib.h
+++ b/src/include/gnunet_time_lib.h
@@ -173,6 +173,19 @@ GNUNET_NETWORK_STRUCT_END
#define GNUNET_TIME_STD_BACKOFF(r) GNUNET_TIME_relative_min
(GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD, \
GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_max
(GNUNET_TIME_UNIT_MILLISECONDS, (r)), 2));
+
+/**
+ * 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.
+ *
+ * @param r current backoff time, initially zero
+ * @return the next backoff time
+ */
+struct GNUNET_TIME_Relative
+GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt);
+
+
/**
* Return relative time of 0ms.
*/
diff --git a/src/util/time.c b/src/util/time.c
index ee90eb8ae..0c177c381 100644
--- a/src/util/time.c
+++ b/src/util/time.c
@@ -444,6 +444,39 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative
rel,
/**
+ * Multiply relative time by a given floating-point factor. The factor must be
+ * positive.
+ *
+ * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor
+ */
+struct GNUNET_TIME_Relative
+relative_multiply_double (struct GNUNET_TIME_Relative rel,
+ double factor)
+{
+ struct GNUNET_TIME_Relative out;
+ double m;
+
+ GNUNET_assert (0 <= factor);
+
+ if (0 == factor)
+ return GNUNET_TIME_UNIT_ZERO;
+ if (rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
+ return GNUNET_TIME_UNIT_FOREVER_REL;
+
+ m = ((double) rel.rel_value_us) * factor;
+
+ if (m >= (double) (GNUNET_TIME_UNIT_FOREVER_REL).rel_value_us)
+ {
+ GNUNET_break (0);
+ return GNUNET_TIME_UNIT_FOREVER_REL;
+ }
+
+ out.rel_value_us = (uint64_t) m;
+ return out;
+}
+
+
+/**
* Saturating multiply relative time by a given factor.
*
* @param rel some duration
@@ -701,5 +734,26 @@ 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.
+ *
+ * @param r current backoff time, initially zero
+ * @return the next backoff time
+ */
+struct GNUNET_TIME_Relative
+GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt)
+{
+ double r = (rand() % 500) / 1000.0;
+ struct GNUNET_TIME_Relative t;
+
+ 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,
+ t);
+}
+
/* end of time.c */
--
To stop receiving notification emails like this one, please contact
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [gnunet] branch master updated: randomized exponential backoff,
gnunet <=