diff options
author | Roger Dingledine <arma@torproject.org> | 2004-04-02 22:30:39 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2004-04-02 22:30:39 +0000 |
commit | fc3d7383e75499ccd78afbbadeda39c7b5c3012f (patch) | |
tree | 607ab261b065f907a74427c76c8138bae10e3fb6 /src/or/routerlist.c | |
parent | f34e6da3e75ad5b681c68e6c0a50d65d4566f9cf (diff) | |
download | tor-fc3d7383e75499ccd78afbbadeda39c7b5c3012f.tar tor-fc3d7383e75499ccd78afbbadeda39c7b5c3012f.tar.gz |
router_choose_random_node can take a smartlist of nodes to exclude
svn:r1442
Diffstat (limited to 'src/or/routerlist.c')
-rw-r--r-- | src/or/routerlist.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/or/routerlist.c b/src/or/routerlist.c index b913f9171..048dc4947 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -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); } |