[or-cvs] backport the code to automatically pick a TestVia node that...

arma at seul.org arma at seul.org
Sun Jun 18 21:08:24 UTC 2006


Update of /home/or/cvsroot/tor/src/or
In directory moria:/home/arma/work/onion/tor-011x/tor/src/or

Modified Files:
      Tag: tor-0_1_1-patches
	circuitbuild.c 
Log Message:
backport the code to automatically pick a TestVia node that is
running a non-buggy tor.


Index: circuitbuild.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/circuitbuild.c,v
retrieving revision 1.230.2.6
retrieving revision 1.230.2.7
diff -u -p -d -r1.230.2.6 -r1.230.2.7
--- circuitbuild.c	10 Jun 2006 00:32:31 -0000	1.230.2.6
+++ circuitbuild.c	18 Jun 2006 21:08:22 -0000	1.230.2.7
@@ -1465,6 +1465,49 @@ onion_append_to_cpath(crypt_path_t **hea
   }
 }
 
+/** Pick a random server digest that's running a Tor version that
+ * doesn't have the reachability bug. These are versions 0.1.1.21-cvs+
+ * and 0.1.2.1-alpha+. Avoid picking authorities, since we're
+ * probably already connected to them.
+ *
+ * We only return one, so this doesn't become stupid when the
+ * whole network has upgraded. */
+static char *
+compute_preferred_testing_list(const char *answer)
+{ 
+  smartlist_t *choices;
+  routerlist_t *rl = router_get_routerlist();
+  routerinfo_t *router;
+  char *s;
+
+  if (answer) /* they have one in mind -- easy */
+    return tor_strdup(answer);
+
+  choices = smartlist_create();
+  /* now count up our choices */
+  SMARTLIST_FOREACH(rl->routers, routerinfo_t *, r,
+    if (r->is_running && r->is_valid &&
+        ((tor_version_as_new_as(r->platform,"0.1.1.21-cvs") &&
+          !tor_version_as_new_as(r->platform,"0.1.2.0-alpha-cvs")) ||
+         tor_version_as_new_as(r->platform,"0.1.2.1-alpha")) &&
+        !router_get_trusteddirserver_by_digest(r->cache_info.identity_digest))
+      smartlist_add(choices, r));
+  router = smartlist_choose(choices);
+  smartlist_free(choices);
+  if (!router) {
+    log_info(LD_CIRC, "Looking for middle server that doesn't have the "
+             "reachability bug, but didn't find one. Oh well.");
+    return NULL;
+  }
+  log_info(LD_CIRC, "Looking for middle server that doesn't have the "
+             "reachability bug, and chose '%s'. Great.", router->nickname);
+  s = tor_malloc(HEX_DIGEST_LEN+2);
+  s[0] = '$';
+  base16_encode(s+1, HEX_DIGEST_LEN+1,
+                router->cache_info.identity_digest, DIGEST_LEN);
+  return s;
+}
+
 /** A helper function used by onion_extend_cpath(). Use <b>purpose</b>
  * and <b>state</b> and the cpath <b>head</b> (currently populated only
  * to length <b>cur_len</b> to decide a suitable middle hop for a
@@ -1481,6 +1524,8 @@ choose_good_middle_server(uint8_t purpos
   routerinfo_t *r, *choice;
   crypt_path_t *cpath;
   smartlist_t *excluded;
+  or_options_t *options = get_options();
+  char *preferred = NULL;
   tor_assert(_CIRCUIT_PURPOSE_MIN <= purpose &&
              purpose <= _CIRCUIT_PURPOSE_MAX);
 
@@ -1500,11 +1545,14 @@ choose_good_middle_server(uint8_t purpos
       routerlist_add_family(excluded, r);
     }
   }
-  choice = router_choose_random_node(
-           purpose == CIRCUIT_PURPOSE_TESTING ? get_options()->TestVia : NULL,
-           get_options()->ExcludeNodes, excluded,
+  if (purpose == CIRCUIT_PURPOSE_TESTING)
+    preferred = compute_preferred_testing_list(options->TestVia);
+  choice = router_choose_random_node(preferred,
+           options->ExcludeNodes, excluded,
            state->need_uptime, state->need_capacity, 0,
-           get_options()->_AllowInvalid & ALLOW_INVALID_MIDDLE, 0);
+           options->_AllowInvalid & ALLOW_INVALID_MIDDLE, 0);
+  if (preferred)
+    tor_free(preferred);
   smartlist_free(excluded);
   return choice;
 }



More information about the tor-commits mailing list