Ver código fonte

Don't set unreachable from dirvote unless we've been running a while.

This is a possible fix for bug 1023, where if we vote (or make a v2
consensus networkstatus) right after we come online, we can call
rep_hist_note_router_unreachable() on every router we haven't connected
to yet, and thereby make all their uptime values reset.
Nick Mathewson 15 anos atrás
pai
commit
5a6575c2d4
2 arquivos alterados com 16 adições e 6 exclusões
  1. 3 0
      ChangeLog
  2. 13 6
      src/or/dirserv.c

+ 3 - 0
ChangeLog

@@ -28,6 +28,9 @@ Changes in version 0.2.2.4-alpha - 2009-10-??
     - Don't count one-hop circuits when we're estimating how long it
     - Don't count one-hop circuits when we're estimating how long it
       takes circuits to build on average. Otherwise we'll set our circuit
       takes circuits to build on average. Otherwise we'll set our circuit
       build timeout lower than we should. Bugfix on 0.2.2.2-alpha.
       build timeout lower than we should. Bugfix on 0.2.2.2-alpha.
+    - Directory authorities no longer change their opinion of, or vote on,
+      whether a router is Running, unless they have themselves been online
+      long enough to have some idea.  Fix for bug 1023.
 
 
   o Code simplifications and refactoring:
   o Code simplifications and refactoring:
     - Revise our unit tests to use the "tinytest" framework, so we
     - Revise our unit tests to use the "tinytest" framework, so we

+ 13 - 6
src/or/dirserv.c

@@ -896,6 +896,13 @@ list_single_server_status(routerinfo_t *desc, int is_live)
   return tor_strdup(buf);
   return tor_strdup(buf);
 }
 }
 
 
+static INLINE int
+running_long_enough_to_decide_unreachable(void)
+{
+  return time_of_process_start
+    + get_options()->TestingAuthDirTimeToLearnReachability < approx_time();
+}
+
 /** Each server needs to have passed a reachability test no more
 /** Each server needs to have passed a reachability test no more
  * than this number of seconds ago, or he is listed as down in
  * than this number of seconds ago, or he is listed as down in
  * the directory. */
  * the directory. */
@@ -907,6 +914,10 @@ list_single_server_status(routerinfo_t *desc, int is_live)
 void
 void
 dirserv_set_router_is_running(routerinfo_t *router, time_t now)
 dirserv_set_router_is_running(routerinfo_t *router, time_t now)
 {
 {
+  /*XXXX022 This function is a mess.  Separate out the part that calculates
+    whether it's reachable and the part that tells rephist that the router was
+    unreachable.
+   */
   int answer;
   int answer;
 
 
   if (router_is_me(router) && !we_are_hibernating())
   if (router_is_me(router) && !we_are_hibernating())
@@ -915,7 +926,7 @@ dirserv_set_router_is_running(routerinfo_t *router, time_t now)
     answer = get_options()->AssumeReachable ||
     answer = get_options()->AssumeReachable ||
              now < router->last_reachable + REACHABLE_TIMEOUT;
              now < router->last_reachable + REACHABLE_TIMEOUT;
 
 
-  if (!answer) {
+  if (!answer && running_long_enough_to_decide_unreachable()) {
     /* not considered reachable. tell rephist. */
     /* not considered reachable. tell rephist. */
     rep_hist_note_router_unreachable(router->cache_info.identity_digest, now);
     rep_hist_note_router_unreachable(router->cache_info.identity_digest, now);
   }
   }
@@ -2420,15 +2431,11 @@ dirserv_generate_networkstatus_vote_obj(crypto_pk_env_t *private_key,
   networkstatus_voter_info_t *voter = NULL;
   networkstatus_voter_info_t *voter = NULL;
   vote_timing_t timing;
   vote_timing_t timing;
   digestmap_t *omit_as_sybil = NULL;
   digestmap_t *omit_as_sybil = NULL;
-  int vote_on_reachability = 1;
+  const int vote_on_reachability = running_long_enough_to_decide_unreachable();
 
 
   tor_assert(private_key);
   tor_assert(private_key);
   tor_assert(cert);
   tor_assert(cert);
 
 
-  if (now - time_of_process_start <
-      options->TestingAuthDirTimeToLearnReachability)
-    vote_on_reachability = 0;
-
   if (resolve_my_address(LOG_WARN, options, &addr, &hostname)<0) {
   if (resolve_my_address(LOG_WARN, options, &addr, &hostname)<0) {
     log_warn(LD_NET, "Couldn't resolve my hostname");
     log_warn(LD_NET, "Couldn't resolve my hostname");
     return NULL;
     return NULL;