diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 0c242507bc..bb554c0d16 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -1808,13 +1808,10 @@ routerstatus_sl_choose_by_bandwidth(smartlist_t *sl)
return smartlist_choose_by_bandwidth(sl, NO_WEIGHTING, 1);
}
-/** Return a random running router from the routerlist. If any node
- * named in preferred is available, pick one of those. Never
+/** Return a random running router from the routerlist. Never
* pick a node whose routerinfo is in
* excludedsmartlist, or whose routerinfo matches excludedset,
- * even if they are the only nodes
- * available. If CRN_STRICT_PREFERRED is set in flags, never pick
- * any node besides those in preferred.
+ * even if they are the only nodes available.
* If CRN_NEED_UPTIME is set in flags and any router has more than
* a minimum uptime, return one of those.
* If CRN_NEED_CAPACITY is set in flags, weight your choice by the
@@ -1837,7 +1834,8 @@ router_choose_random_node(smartlist_t *excludedsmartlist,
const int allow_invalid = (flags & CRN_ALLOW_INVALID) != 0;
const int weight_for_exit = (flags & CRN_WEIGHT_AS_EXIT) != 0;
- smartlist_t *sl, *excludednodes;
+ smartlist_t *sl=smartlist_create(),
+ *excludednodes=smartlist_create();
routerinfo_t *choice = NULL, *r;
bandwidth_weight_rule_t rule;
@@ -1845,8 +1843,6 @@ router_choose_random_node(smartlist_t *excludedsmartlist,
rule = weight_for_exit ? WEIGHT_FOR_EXIT :
(need_guard ? WEIGHT_FOR_GUARD : NO_WEIGHTING);
- excludednodes = smartlist_create();
-
/* Exclude relays that allow single hop exit circuits, if the user
* wants to (such relays might be risky) */
if (get_options()->ExcludeSingleHopRelays) {
@@ -1862,35 +1858,32 @@ router_choose_random_node(smartlist_t *excludedsmartlist,
routerlist_add_family(excludednodes, r);
}
- { /* XXX021 reformat */
- sl = smartlist_create();
- router_add_running_routers_to_smartlist(sl, allow_invalid,
- need_uptime, need_capacity,
- need_guard);
- smartlist_subtract(sl,excludednodes);
- if (excludedsmartlist)
- smartlist_subtract(sl,excludedsmartlist);
- if (excludedset)
- routerset_subtract_routers(sl,excludedset);
+ router_add_running_routers_to_smartlist(sl, allow_invalid,
+ need_uptime, need_capacity,
+ need_guard);
+ smartlist_subtract(sl,excludednodes);
+ if (excludedsmartlist)
+ smartlist_subtract(sl,excludedsmartlist);
+ if (excludedset)
+ routerset_subtract_routers(sl,excludedset);
- if (need_capacity || need_guard)
- choice = routerlist_sl_choose_by_bandwidth(sl, rule);
- else
- choice = smartlist_choose(sl);
+ if (need_capacity || need_guard)
+ choice = routerlist_sl_choose_by_bandwidth(sl, rule);
+ else
+ choice = smartlist_choose(sl);
- smartlist_free(sl);
- if (!choice && (need_uptime || need_capacity || need_guard)) {
- /* try once more -- recurse but with fewer restrictions. */
- log_info(LD_CIRC,
- "We couldn't find any live%s%s%s routers; falling back "
- "to list of all routers.",
- need_capacity?", fast":"",
- need_uptime?", stable":"",
- need_guard?", guard":"");
- flags &= ~ (CRN_NEED_UPTIME|CRN_NEED_CAPACITY|CRN_NEED_GUARD);
- choice = router_choose_random_node(
- excludedsmartlist, excludedset, flags);
- }
+ smartlist_free(sl);
+ if (!choice && (need_uptime || need_capacity || need_guard)) {
+ /* try once more -- recurse but with fewer restrictions. */
+ log_info(LD_CIRC,
+ "We couldn't find any live%s%s%s routers; falling back "
+ "to list of all routers.",
+ need_capacity?", fast":"",
+ need_uptime?", stable":"",
+ need_guard?", guard":"");
+ flags &= ~ (CRN_NEED_UPTIME|CRN_NEED_CAPACITY|CRN_NEED_GUARD);
+ choice = router_choose_random_node(
+ excludedsmartlist, excludedset, flags);
}
smartlist_free(excludednodes);
if (!choice) {
@@ -5184,9 +5177,13 @@ routerset_get_all_routers(smartlist_t *out, const routerset_t *routerset,
}
}
-/** Add to target every routerinfo_t from source that is in
- * include, but not excluded in a more specific fashion by
- * exclude. If running_only, only include running routers.
+/** Add to target every routerinfo_t from source except:
+ *
+ * 1) Don't add it if include is non-empty and the relay isn't in
+ * include; and
+ * 2) Don't add it if exclude is non-empty and the relay is
+ * excluded in a more specific fashion by exclude.
+ * 3) If running_only, don't add non-running routers.
*/
void
routersets_get_disjunction(smartlist_t *target,