summaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorteor <teor2345@gmail.com>2017-07-05 01:32:06 +1000
committerNick Mathewson <nickm@torproject.org>2017-07-07 13:18:04 -0400
commit32f0cbc0f6fc7a53fc88a144e42fea9aca2cd073 (patch)
tree6964e9d4f8456a9bc1b45125caf707f7341820fd /src/or
parentf30d355903343af3611ed2ec9828c4b6d1851168 (diff)
downloadtor-32f0cbc0f6fc7a53fc88a144e42fea9aca2cd073.tar.gz
tor-32f0cbc0f6fc7a53fc88a144e42fea9aca2cd073.zip
Refactor exponential backoff multipliers into macros
There are only so many times you can type "4".
Diffstat (limited to 'src/or')
-rw-r--r--src/or/directory.c8
-rw-r--r--src/or/directory.h10
2 files changed, 15 insertions, 3 deletions
diff --git a/src/or/directory.c b/src/or/directory.c
index ea9d69b158..ccec810bae 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 c473d8e4ca..0b54943b60 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