aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2006-01-05 10:59:46 +0000
committerRoger Dingledine <arma@torproject.org>2006-01-05 10:59:46 +0000
commit6aaa92f736c9b876defcce9c40898acbd29a5bc3 (patch)
tree1d44e2c4dbd1896bff1c3256cb17fd9be02e50a8
parent1107c40dc0abec7c64e3a6bc86e7e833bafbd43d (diff)
downloadtor-6aaa92f736c9b876defcce9c40898acbd29a5bc3.tar
tor-6aaa92f736c9b876defcce9c40898acbd29a5bc3.tar.gz
short-circuit half the cost of node-picking in the general case.
svn:r5732
-rw-r--r--src/or/routerlist.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 16c69284b..9c0433c91 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -809,20 +809,22 @@ router_choose_random_node(const char *preferred,
int allow_unverified, int strict)
{
smartlist_t *sl, *excludednodes;
- routerinfo_t *choice;
+ routerinfo_t *choice = NULL;
excludednodes = smartlist_create();
add_nickname_list_to_smartlist(excludednodes,excluded,0,0,1);
/* Try the preferred nodes first. Ignore need_uptime and need_capacity,
* since the user explicitly asked for these nodes. */
- sl = smartlist_create();
- add_nickname_list_to_smartlist(sl,preferred,1,1,1);
- smartlist_subtract(sl,excludednodes);
- if (excludedsmartlist)
- smartlist_subtract(sl,excludedsmartlist);
- choice = smartlist_choose(sl);
- smartlist_free(sl);
+ if (preferred) {
+ sl = smartlist_create();
+ add_nickname_list_to_smartlist(sl,preferred,1,1,1);
+ smartlist_subtract(sl,excludednodes);
+ if (excludedsmartlist)
+ smartlist_subtract(sl,excludedsmartlist);
+ choice = smartlist_choose(sl);
+ smartlist_free(sl);
+ }
if (!choice && !strict) {
/* Then give up on our preferred choices: any node
* will do that has the required attributes. */