Commit 78a7de30 authored by Roger Dingledine's avatar Roger Dingledine
Browse files

make options.ExitNodes work

if your best choices happen to include any of your preferred exit nodes,
you choose among just those preferred exit nodes.


svn:r911
parent 4d3d99fa
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -247,7 +247,7 @@ static routerinfo_t *choose_good_exit_server(routerlist_t *dir)
  int best_support_idx = -1;
  int best_maybe_support_idx = -1;
  int n_best_support=0, n_best_maybe_support=0;
  smartlist_t *sl;
  smartlist_t *sl, *preferredexits;
  routerinfo_t *router;

  get_connection_array(&carray, &n_connections);
@@ -335,6 +335,10 @@ static routerinfo_t *choose_good_exit_server(routerlist_t *dir)
                   "pending connections, and %d that might support %d/%d.",
         n_best_support, best_support, n_pending_connections,
         n_best_maybe_support, best_maybe_support, n_pending_connections);

  preferredexits = smartlist_create(MAX_ROUTERS_IN_DIR);
  add_nickname_list_to_smartlist(preferredexits,options.ExitNodes);

  /* If any routers definitely support any pending connections, choose one
   * at random. */
  if (best_support > 0) {
@@ -343,7 +347,10 @@ static routerinfo_t *choose_good_exit_server(routerlist_t *dir)
      if (n_supported[i] == best_support)
        smartlist_add(sl, dir->routers[i]);

    if (smartlist_overlap(sl,preferredexits))
      smartlist_intersect(sl,preferredexits);
    router = smartlist_choose(sl);
    smartlist_free(preferredexits);
    smartlist_free(sl);
    tor_free(n_supported); tor_free(n_maybe_supported);
    log_fn(LOG_DEBUG, "Chose exit server '%s'", router->nickname);
@@ -358,7 +365,10 @@ static routerinfo_t *choose_good_exit_server(routerlist_t *dir)
      if(n_maybe_supported[i] == best_maybe_support)
        smartlist_add(sl, dir->routers[i]);

    if (smartlist_overlap(sl,preferredexits))
      smartlist_intersect(sl,preferredexits);
    router = smartlist_choose(sl);
    smartlist_free(preferredexits);
    smartlist_free(sl);
    tor_free(n_supported); tor_free(n_maybe_supported);
    log_fn(LOG_DEBUG, "Chose exit server '%s'", router->nickname);
@@ -372,7 +382,10 @@ static routerinfo_t *choose_good_exit_server(routerlist_t *dir)
    if(n_supported[i] != -1)
      smartlist_add(sl, dir->routers[i]);

  if (smartlist_overlap(sl,preferredexits))
    smartlist_intersect(sl,preferredexits);
  router = smartlist_choose(sl);
  smartlist_free(preferredexits);
  smartlist_free(sl);
  if(router) {
    tor_free(n_supported); tor_free(n_maybe_supported);