aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_time_lib.h7
-rw-r--r--src/util/time.c9
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
177/** 177/**
178 * Randomized exponential back-off, starting at 1 ms 178 * Randomized exponential back-off, starting at 1 ms
179 * and going up by a factor of 2+r, where 0 <= r <= 0.5, up 179 * and going up by a factor of 2+r, where 0 <= r <= 0.5, up
180 * to a maximum of 15 m. 180 * to a maximum of the given threshold.
181 * 181 *
182 * @param r current backoff time, initially zero 182 * @param rt current backoff time, initially zero
183 * @param threshold maximum value for backoff
183 * @return the next backoff time 184 * @return the next backoff time
184 */ 185 */
185struct GNUNET_TIME_Relative 186struct GNUNET_TIME_Relative
186GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt); 187GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt, struct GNUNET_TIME_Relative threshold);
187 188
188 189
189/** 190/**
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)
737/** 737/**
738 * Randomized exponential back-off, starting at 1 ms 738 * Randomized exponential back-off, starting at 1 ms
739 * and going up by a factor of 2+r, where 0 <= r <= 0.5, up 739 * and going up by a factor of 2+r, where 0 <= r <= 0.5, up
740 * to a maximum of 15 m. 740 * to a maximum of the given threshold.
741 * 741 *
742 * @param r current backoff time, initially zero 742 * @param r current backoff time, initially zero
743 * @param threshold maximum value for backoff
743 * @return the next backoff time 744 * @return the next backoff time
744 */ 745 */
745struct GNUNET_TIME_Relative 746struct GNUNET_TIME_Relative
746GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt) 747GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt, struct GNUNET_TIME_Relative threshold)
747{ 748{
748 double r = (rand() % 500) / 1000.0; 749 double r = (rand() % 500) / 1000.0;
749 struct GNUNET_TIME_Relative t; 750 struct GNUNET_TIME_Relative t;
@@ -751,9 +752,11 @@ GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt)
751 t = relative_multiply_double (GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS, 752 t = relative_multiply_double (GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS,
752 rt), 753 rt),
753 2 + r); 754 2 + r);
754 return GNUNET_TIME_relative_min (GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD, 755 return GNUNET_TIME_relative_min (threshold,
755 t); 756 t);
756} 757}
757 758
758 759
760
761
759/* end of time.c */ 762/* end of time.c */