[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Refactor exponential backoff multipliers into macros
commit 32f0cbc0f6fc7a53fc88a144e42fea9aca2cd073
Author: teor <teor2345@xxxxxxxxx>
Date: Wed Jul 5 01:32:06 2017 +1000
Refactor exponential backoff multipliers into macros
There are only so many times you can type "4".
---
src/or/directory.c | 8 +++++---
src/or/directory.h | 10 ++++++++++
src/test/test_dir.c | 2 +-
3 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/src/or/directory.c b/src/or/directory.c
index ea9d69b..ccec810 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -11,6 +11,7 @@
#include "connection.h"
#include "connection_edge.h"
#include "control.h"
+#define DIRECTORY_PRIVATE
#include "directory.h"
#include "dirserv.h"
#include "dirvote.h"
@@ -3778,7 +3779,8 @@ find_dl_min_and_max_delay(download_status_t *dls, const or_options_t *options,
/** Advance one delay step. The algorithm is to use the previous delay to
* compute an increment, we construct a value uniformly at random between
- * delay+1 and (delay*4)+1 (or *3 in test networks).
+ * delay+1 and (delay*(DIR_DEFAULT_RANDOM_MULTIPLIER+1))+1 (or
+ * DIR_TEST_NET_RANDOM_MULTIPLIER in test networks).
* We then clamp that value to be no larger than max_delay, and return it.
*
* Requires that delay is less than INT_MAX, and delay is in [0,max_delay].
@@ -3798,11 +3800,11 @@ next_random_exponential_delay(int delay, int max_delay)
/* How much are we willing to add to the delay? */
int max_increment;
- int multiplier = 3; /* no more than quadruple the previous delay */
+ int multiplier = DIR_DEFAULT_RANDOM_MULTIPLIER;
if (get_options()->TestingTorNetwork) {
/* Decrease the multiplier in testing networks. This reduces the variance,
* so that bootstrap is more reliable. */
- multiplier = 2; /* no more than triple the previous delay */
+ multiplier = DIR_TEST_NET_RANDOM_MULTIPLIER;
}
if (delay && delay < (INT_MAX-1) / multiplier) {
diff --git a/src/or/directory.h b/src/or/directory.h
index c473d8e..0b54943 100644
--- a/src/or/directory.h
+++ b/src/or/directory.h
@@ -177,5 +177,15 @@ STATIC int next_random_exponential_delay(int delay, int max_delay);
#endif
+#if defined(TOR_UNIT_TESTS) || defined(DIRECTORY_PRIVATE)
+/* Used only by directory.c and test_dir.c */
+
+/* no more than quadruple the previous delay (multiplier + 1) */
+#define DIR_DEFAULT_RANDOM_MULTIPLIER (3)
+/* no more than triple the previous delay */
+#define DIR_TEST_NET_RANDOM_MULTIPLIER (2)
+
+#endif
+
#endif
diff --git a/src/test/test_dir.c b/src/test/test_dir.c
index 4fddf7a..53911e8 100644
--- a/src/test/test_dir.c
+++ b/src/test/test_dir.c
@@ -3610,7 +3610,7 @@ download_status_random_backoff_helper(int min_delay, int max_delay)
int increment = -1;
int old_increment = -1;
time_t current_time = time(NULL);
- const int exponent = 4;
+ const int exponent = DIR_DEFAULT_RANDOM_MULTIPLIER + 1;
/* Check the random backoff cases */
do {
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits