[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/maint-0.3.2] Merge branch 'bug23816_029_squashed' into maint-0.3.2
commit e5a83062ed4e9e6b908efc6b75f13ab269f97377
Merge: 3dc61a5d7 cb29687e9
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Wed Nov 8 08:11:22 2017 -0500
Merge branch 'bug23816_029_squashed' into maint-0.3.2
changes/bug23816 | 6 +++++
src/or/directory.c | 76 +++++++++++++++++++++++++++++++----------------------
src/or/directory.h | 10 ++++++-
src/test/test_dir.c | 69 +++++++++++++++++++++++++++---------------------
4 files changed, 99 insertions(+), 62 deletions(-)
diff --cc src/or/directory.h
index 79984be32,c055e60d9..d26d83537
--- a/src/or/directory.h
+++ b/src/or/directory.h
@@@ -226,23 -167,15 +226,31 @@@ STATIC const smartlist_t *find_dl_sched
STATIC void find_dl_min_and_max_delay(download_status_t *dls,
const or_options_t *options,
int *min, int *max);
- STATIC int next_random_exponential_delay(int delay, int max_delay);
++
+ STATIC int next_random_exponential_delay(int delay,
+ int base_delay,
+ int max_delay);
+
+ STATIC void next_random_exponential_delay_range(int *low_bound_out,
+ int *high_bound_out,
+ int delay,
+ int base_delay);
-#endif
-#endif
+STATIC int parse_hs_version_from_post(const char *url, const char *prefix,
+ const char **end_pos);
+
+STATIC unsigned parse_accept_encoding_header(const char *h);
+#endif /* defined(TOR_UNIT_TESTS) */
+
+#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 /* defined(TOR_UNIT_TESTS) || defined(DIRECTORY_PRIVATE) */
+
+#endif /* !defined(TOR_DIRECTORY_H) */
diff --cc src/test/test_dir.c
index 87b86c38b,1c6662147..ee4a9780b
--- a/src/test/test_dir.c
+++ b/src/test/test_dir.c
@@@ -4124,11 -3608,16 +4124,11 @@@ download_status_random_backoff_helper(i
{ 0, 0, 0, DL_SCHED_GENERIC, DL_WANT_AUTHORITY,
DL_SCHED_INCREMENT_FAILURE, DL_SCHED_RANDOM_EXPONENTIAL, 0, 0 };
int increment = -1;
- int old_increment;
+ int old_increment = -1;
time_t current_time = time(NULL);
- const int exponent = DIR_DEFAULT_RANDOM_MULTIPLIER + 1;
- const int min_delay = 0;
- const int max_delay = 1000000;
-
- (void)arg;
/* Check the random backoff cases */
- old_increment = 0;
+ int n_attempts = 0;
do {
increment = download_status_schedule_get_delay(&dls_random,
NULL,
@@@ -4148,33 -3626,14 +4148,12 @@@
/* Test */
tt_int_op(increment, OP_GE, min_delay);
tt_int_op(increment, OP_LE, max_delay);
- if (dls_random.last_backoff_position == 0) {
- /* regression tests for 17750
- * Always use the minimum delay for the first increment */
- tt_int_op(increment, OP_EQ, min_delay);
- } else {
- /* It's times like these I'd love a good saturating arithmetic
- * implementation */
- int min_inc = INT_MAX;
- if (old_increment <= INT_MAX - 1) {
- min_inc = old_increment + 1;
- }
-
- int max_inc = INT_MAX;
- if (old_increment <= (INT_MAX - 1)/exponent) {
- max_inc = (exponent * old_increment) + 1;
- }
-
- /* Regression test for 20534 and friends:
- * increment must always increase after the first */
- tt_int_op(increment, OP_GE, min_inc);
- /* We at most quadruple, and always add one */
- tt_int_op(increment, OP_LE, max_inc);
- }
- if (old_increment)
- tt_int_op(increment, OP_LE, old_increment * 3);
-
/* Advance */
- current_time += increment;
-- ++(dls_random.n_download_attempts);
-- ++(dls_random.n_download_failures);
++ if (dls_random.n_download_attempts < IMPOSSIBLE_TO_DOWNLOAD - 1) {
++ ++(dls_random.n_download_attempts);
++ ++(dls_random.n_download_failures);
++ }
/* Try another maybe */
old_increment = increment;
@@@ -4188,27 -3644,38 +4164,59 @@@
}
static void
+test_dir_download_status_random_backoff(void *arg)
+{
+ (void)arg;
+
+ /* Do a standard test */
+ download_status_random_backoff_helper(0, 1000000);
+ /* Regression test for 20534 and friends:
+ * try tighter bounds */
+ download_status_random_backoff_helper(0, 100);
+ /* regression tests for 17750: initial delay */
+ download_status_random_backoff_helper(10, 1000);
+ download_status_random_backoff_helper(20, 30);
+
+ /* Pathological cases */
+ download_status_random_backoff_helper(0, 0);
+ download_status_random_backoff_helper(1, 1);
+ download_status_random_backoff_helper(0, INT_MAX);
+ download_status_random_backoff_helper(INT_MAX/2, INT_MAX);
+}
+
+static void
+ test_dir_download_status_random_backoff_ranges(void *arg)
+ {
+ (void)arg;
+ int lo, hi;
+ next_random_exponential_delay_range(&lo, &hi, 0, 10);
+ tt_int_op(lo, OP_EQ, 10);
+ tt_int_op(hi, OP_EQ, 11);
+
+ next_random_exponential_delay_range(&lo, &hi, 6, 10);
+ tt_int_op(lo, OP_EQ, 10);
+ tt_int_op(hi, OP_EQ, 6*3);
+
+ next_random_exponential_delay_range(&lo, &hi, 13, 10);
+ tt_int_op(lo, OP_EQ, 10);
+ tt_int_op(hi, OP_EQ, 13 * 3);
+
+ next_random_exponential_delay_range(&lo, &hi, 37, 10);
+ tt_int_op(lo, OP_EQ, 10);
+ tt_int_op(hi, OP_EQ, 111);
+
+ next_random_exponential_delay_range(&lo, &hi, 123, 10);
+ tt_int_op(lo, OP_EQ, 10);
+ tt_int_op(hi, OP_EQ, 369);
+
+ next_random_exponential_delay_range(&lo, &hi, INT_MAX-5, 10);
+ tt_int_op(lo, OP_EQ, 10);
+ tt_int_op(hi, OP_EQ, INT_MAX);
+ done:
+ ;
+ }
+
+ static void
test_dir_download_status_increment(void *arg)
{
(void)arg;
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits