diff --git a/src/or/dirserv.c b/src/or/dirserv.c index 73869273a3..b68e005531 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -969,11 +969,17 @@ dirserv_set_router_is_running(routerinfo_t *router, time_t now) } if (!answer && running_long_enough_to_decide_unreachable()) { - /* not considered reachable. tell rephist. */ + /* Not considered reachable. tell rephist about that. + + Because we launch a reachability test for each router every + REACHABILITY_TEST_CYCLE_PERIOD seconds, then the router has probably + been down since at least that time after we last successfully reached + it. + */ time_t when = now; if (router->last_reachable && - router->last_reachable + REACHABILITY_TEST_PERIOD < now) - when = router->last_reachable + REACHABILITY_TEST_PERIOD; + router->last_reachable + REACHABILITY_TEST_CYCLE_PERIOD < now) + when = router->last_reachable + REACHABILITY_TEST_CYCLE_PERIOD; rep_hist_note_router_unreachable(router->cache_info.identity_digest, when); } diff --git a/src/or/dirserv.h b/src/or/dirserv.h index 949482ba73..569abfca2e 100644 --- a/src/or/dirserv.h +++ b/src/or/dirserv.h @@ -17,8 +17,12 @@ * test? */ #define REACHABILITY_MODULO_PER_TEST 128 +/** How often (in seconds) do we launch reachability tests? */ +#define REACHABILITY_TEST_INTERVAL 10 + /** How many seconds apart are the reachability tests for a given relay? */ -#define REACHABILITY_TEST_PERIOD (10*REACHABILITY_MODULO_PER_TEST) +#define REACHABILITY_TEST_CYCLE_PERIOD \ + (REACHABILITY_TEST_INTERVAL*REACHABILITY_MODULO_PER_TEST) /** Maximum length of an exit policy summary. */ #define MAX_EXITPOLICY_SUMMARY_LEN 1000 diff --git a/src/or/main.c b/src/or/main.c index 558608ec8c..214a4fad5d 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -872,6 +872,7 @@ run_scheduled_events(time_t now) static time_t time_to_check_for_expired_networkstatus = 0; static time_t time_to_write_stats_files = 0; static time_t time_to_write_bridge_stats = 0; + static time_t time_to_launch_reachability_tests = 0; static int should_init_bridge_stats = 1; static time_t time_to_retry_dns_init = 0; or_options_t *options = get_options(); @@ -962,9 +963,10 @@ run_scheduled_events(time_t now) if (accounting_is_enabled(options)) accounting_run_housekeeping(now); - if (now % REACHABILITY_TEST_PERIOD/REACHABILITY_MODULO_PER_TEST == 0 && + if (time_to_launch_reachability_tests < now && (authdir_mode_tests_reachability(options)) && !we_are_hibernating()) { + time_to_launch_reachability_tests = now + REACHABILITY_TEST_INTERVAL; /* try to determine reachability of the other Tor relays */ dirserv_test_reachability(now); }