Explorar el Código

Tweak bug2716 patch a little

Name the magic value "10" rather than re-deriving it.

Comment more.

Use the pattern that works for periodic timers, not the pattern that
doesn't work. ;)
Nick Mathewson hace 13 años
padre
commit
176fde505f
Se han modificado 3 ficheros con 17 adiciones y 5 borrados
  1. 9 3
      src/or/dirserv.c
  2. 5 1
      src/or/dirserv.h
  3. 3 1
      src/or/main.c

+ 9 - 3
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);
   }
 

+ 5 - 1
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

+ 3 - 1
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);
   }