[or-cvs] make options.ExitNodes work

Roger Dingledine arma at seul.org
Sat Dec 13 23:32:59 UTC 2003


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or

Modified Files:
	onion.c 
Log Message:
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.


Index: onion.c
===================================================================
RCS file: /home/or/cvsroot/src/or/onion.c,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -d -r1.107 -r1.108
--- onion.c	13 Dec 2003 07:01:46 -0000	1.107
+++ onion.c	13 Dec 2003 23:32:57 -0000	1.108
@@ -247,7 +247,7 @@
   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,15 +335,22 @@
                    "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) {
     sl = smartlist_create(MAX_ROUTERS_IN_DIR);
-    for(i = best_support_idx; i < dir->n_routers; i++)
-      if(n_supported[i] == best_support)
+    for (i = best_support_idx; i < dir->n_routers; i++)
+      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 @@
       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 @@
     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);



More information about the tor-commits mailing list