]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
router_choose_random_node can take a smartlist of nodes to exclude
authorRoger Dingledine <arma@torproject.org>
Fri, 2 Apr 2004 22:30:39 +0000 (22:30 +0000)
committerRoger Dingledine <arma@torproject.org>
Fri, 2 Apr 2004 22:30:39 +0000 (22:30 +0000)
svn:r1442

src/or/onion.c
src/or/or.h
src/or/routerlist.c

index 36f76415a688467e3311ecde278266ae76dfe8e9..44e32c44fb7144cbfeece401f4ab0e862761f57f 100644 (file)
@@ -334,7 +334,7 @@ static routerinfo_t *choose_good_exit_server(uint8_t purpose, routerlist_t *dir)
   if(purpose == CIRCUIT_PURPOSE_C_GENERAL)
     return choose_good_exit_server_general(dir);
   else
-    return router_choose_random_node(dir, options.RendNodes, options.RendExcludeNodes);
+    return router_choose_random_node(dir, options.RendNodes, options.RendExcludeNodes, NULL);
 }
 
 cpath_build_state_t *onion_new_cpath_build_state(uint8_t purpose,
index 41836c7b004d53dc4133790cca1cb1f093ce19cf..83c06ab8ca07ae71e14e974b4a83de061e27ffd4 100644 (file)
@@ -975,7 +975,9 @@ int router_dump_router_to_string(char *s, int maxlen, routerinfo_t *router,
 /********************************* routerlist.c ***************************/
 
 routerinfo_t *router_pick_directory_server(void);
-routerinfo_t *router_choose_random_node(routerlist_t *dir, char *preferred, char *excluded);
+routerinfo_t *router_choose_random_node(routerlist_t *dir,
+                                        char *preferred, char *excluded,
+                                        smartlist_t *excludedsmartlist);
 routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port);
 routerinfo_t *router_get_by_link_pk(crypto_pk_env_t *pk);
 routerinfo_t *router_get_by_nickname(char *nickname);
index b913f917184ed8d5a0d304b293470fe8f465fde4..048dc49475f790fd66201766a2b6cf82de291781 100644 (file)
@@ -233,7 +233,13 @@ void router_add_running_routers_to_smartlist(smartlist_t *sl) {
   }
 }
 
-routerinfo_t *router_choose_random_node(routerlist_t *dir, char *preferred, char *excluded)
+/* Pick a random node from preferred if possible, else from all of dir.
+ * Never pick a node in excluded.
+ * If excludedsmartlist is defined, never pick a node in it either.
+ */
+routerinfo_t *router_choose_random_node(routerlist_t *dir,
+                                        char *preferred, char *excluded,
+                                        smartlist_t *excludedsmartlist)
 {
   smartlist_t *sl, *excludednodes;
   routerinfo_t *choice;
@@ -245,12 +251,16 @@ routerinfo_t *router_choose_random_node(routerlist_t *dir, char *preferred, char
   sl = smartlist_create();
   add_nickname_list_to_smartlist(sl,preferred);
   smartlist_subtract(sl,excludednodes);
+  if(excludedsmartlist)
+    smartlist_subtract(sl,excludedsmartlist);
   choice = smartlist_choose(sl);
   smartlist_free(sl);
   if(!choice) {
     sl = smartlist_create();
     router_add_running_routers_to_smartlist(sl);
     smartlist_subtract(sl,excludednodes);
+    if(excludedsmartlist)
+      smartlist_subtract(sl,excludedsmartlist);
     choice = smartlist_choose(sl);
     smartlist_free(sl);
   }