[or-cvs] Implement strict{entry|exit}nodes config options

Nick Mathewson nickm at seul.org
Sun Aug 15 20:14:46 UTC 2004


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv20642/src/or

Modified Files:
	circuitbuild.c routerlist.c config.c or.h 
Log Message:
Implement strict{entry|exit}nodes config options

Index: circuitbuild.c
===================================================================
RCS file: /home/or/cvsroot/src/or/circuitbuild.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- circuitbuild.c	15 Aug 2004 08:15:12 -0000	1.21
+++ circuitbuild.c	15 Aug 2004 20:14:44 -0000	1.22
@@ -897,7 +897,7 @@
         smartlist_add(sl, smartlist_get(dir->routers, i));
 
     smartlist_subtract(sl,excludedexits);
-    if (smartlist_overlap(sl,preferredexits))
+    if (options.StrictExitNodes || smartlist_overlap(sl,preferredexits))
       smartlist_intersect(sl,preferredexits);
     router = smartlist_choose(sl);
   } else {
@@ -911,7 +911,7 @@
         smartlist_add(sl, smartlist_get(dir->routers, i));
 
     smartlist_subtract(sl,excludedexits);
-    if (smartlist_overlap(sl,preferredexits))
+    if (options.StrictExitNodes || smartlist_overlap(sl,preferredexits))
       smartlist_intersect(sl,preferredexits);
     router = smartlist_choose(sl);
   }
@@ -924,7 +924,9 @@
     log_fn(LOG_INFO, "Chose exit server '%s'", router->nickname);
     return router;
   }
-  log_fn(LOG_WARN, "No exit routers seem to be running; can't choose an exit.");
+  if (options.StrictExitNodes)
+    log_fn(LOG_WARN, "No exit routers seem to be running; can't choose an exit.");
+  
   return NULL;
 }
 
@@ -946,7 +948,7 @@
     case CIRCUIT_PURPOSE_C_GENERAL:
       return choose_good_exit_server_general(dir);
     case CIRCUIT_PURPOSE_C_ESTABLISH_REND:
-      r = router_choose_random_node(options.RendNodes, options.RendExcludeNodes, NULL, 0, 1);
+      r = router_choose_random_node(options.RendNodes, options.RendExcludeNodes, NULL, 0, 1, 0);
       return r;
     default:
       log_fn(LOG_WARN,"unhandled purpose %d", purpose);
@@ -1101,7 +1103,7 @@
     tor_assert(r);
     smartlist_add(excluded, r);
   }
-  choice = router_choose_random_node("", options.ExcludeNodes, excluded, 0, 1);
+  choice = router_choose_random_node("", options.ExcludeNodes, excluded, 0, 1, 0);
   smartlist_free(excluded);
   return choice;
 }
@@ -1131,7 +1133,8 @@
     }
   }
   choice = router_choose_random_node(options.EntryNodes,
-                                     options.ExcludeNodes, excluded, 0, 1);
+                                     options.ExcludeNodes, excluded, 0, 1,
+                                     options.StrictEntryNodes);
   smartlist_free(excluded);
   return choice;
 }

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.119
retrieving revision 1.120
diff -u -d -r1.119 -r1.120
--- routerlist.c	15 Aug 2004 08:15:12 -0000	1.119
+++ routerlist.c	15 Aug 2004 20:14:44 -0000	1.120
@@ -275,13 +275,16 @@
 }
 
 /** Return a random running router from the routerlist.  If any node
- * named in <b>preferred</b> is available, pick one of those.  Never pick a
- * node named in <b>excluded</b>, or whose routerinfo is in
- * <b>excludedsmartlist</b>, even if they are the only nodes available.
+ * named in <b>preferred</b> is available, pick one of those.  Never
+ * pick a node named in <b>excluded</b>, or whose routerinfo is in
+ * <b>excludedsmartlist</b>, even if they are the only nodes
+ * available.  If <b>strict</b> is true, never pick any node besides
+ * those in <b>preferred</b>.
  */
 routerinfo_t *router_choose_random_node(char *preferred, char *excluded,
                                         smartlist_t *excludedsmartlist,
-                                        int preferuptime, int preferbandwidth)
+                                        int preferuptime, int preferbandwidth,
+                                        int strict)
 {
   smartlist_t *sl, *excludednodes;
   routerinfo_t *choice;
@@ -302,7 +305,7 @@
   else
     choice = smartlist_choose(sl);
   smartlist_free(sl);
-  if(!choice) {
+  if(!choice && !strict) {
     sl = smartlist_create();
     router_add_running_routers_to_smartlist(sl);
     smartlist_subtract(sl,excludednodes);

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.132
retrieving revision 1.133
diff -u -d -r1.132 -r1.133
--- config.c	15 Aug 2004 08:15:12 -0000	1.132
+++ config.c	15 Aug 2004 20:14:44 -0000	1.133
@@ -204,6 +204,8 @@
 
     config_compare(list, "ExitNodes",      CONFIG_TYPE_STRING, &options->ExitNodes) ||
     config_compare(list, "EntryNodes",     CONFIG_TYPE_STRING, &options->EntryNodes) ||
+    config_compare(list, "StrictExitNodes", CONFIG_TYPE_BOOL, &options->StrictExitNodes) ||
+    config_compare(list, "StrictEntryNodes", CONFIG_TYPE_BOOL, &options->StrictEntryNodes) ||
     config_compare(list, "ExitPolicy",     CONFIG_TYPE_LINELIST, &options->ExitPolicy) ||
     config_compare(list, "ExcludeNodes",   CONFIG_TYPE_STRING, &options->ExcludeNodes) ||
 
@@ -529,6 +531,7 @@
   options->LogOptions = NULL;
   options->ExitNodes = tor_strdup("");
   options->EntryNodes = tor_strdup("");
+  options->StrictEntryNodes = options->StrictExitNodes = 0;
   options->ExcludeNodes = tor_strdup("");
   options->RendNodes = tor_strdup("");
   options->RendExcludeNodes = tor_strdup("");
@@ -713,6 +716,14 @@
     result = -1;
   }
 
+  if(options->StrictExitNodes && !strlen(options->ExitNodes)) {
+    log(LOG_WARN,"StrictExitNodes set, but no ExitNodes listed.");
+  }
+
+  if(options->StrictEntryNodes && !strlen(options->EntryNodes)) {
+    log(LOG_WARN,"StrictEntryNodes set, but no EntryNodes listed.");
+  }
+
   if(options->AuthoritativeDir && options->RecommendedVersions == NULL) {
     log(LOG_WARN,"Directory servers must configure RecommendedVersions.");
     result = -1;

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.403
retrieving revision 1.404
diff -u -d -r1.403 -r1.404
--- or.h	15 Aug 2004 08:15:12 -0000	1.403
+++ or.h	15 Aug 2004 20:14:44 -0000	1.404
@@ -824,6 +824,10 @@
                     * as exits. */
   char *EntryNodes; /**< Comma-separated list of nicknames of ORs to consider
                      * as entry points. */
+  int StrictExitNodes; /**< Boolean: When none of our ExitNodes are up, do we
+                        * stop building circuits? */
+  int StrictEntryNodes; /**< Boolean: When none of our EntryNodes are up, do we
+                         * stop building circuits? */
   char *ExcludeNodes; /**< Comma-separated list of nicknames of ORs not to
                        * use in circuits. */
 
@@ -1381,7 +1385,8 @@
 int router_nickname_matches(routerinfo_t *router, const char *nickname);
 routerinfo_t *router_choose_random_node(char *preferred, char *excluded,
                                         struct smartlist_t *excludedsmartlist,
-                                        int preferuptime, int preferbandwidth);
+                                        int preferuptime, int preferbandwidth,
+                                        int strict);
 routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port);
 routerinfo_t *router_get_by_nickname(const char *nickname);
 routerinfo_t *router_get_by_hexdigest(const char *hexdigest);



More information about the tor-commits mailing list