aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2010-03-04 00:13:23 -0500
committerNick Mathewson <nickm@torproject.org>2010-03-04 00:13:23 -0500
commitb3ec39af8ff595b9490a330a356366b05c4750b9 (patch)
tree036540c711165d3002218c14600ead7262175fea
parentf3003d588fb379fae9a99568aa58d445ee7e2f0d (diff)
parent2b5e1d363640e34ec803044f0f8d086dfdd40a6b (diff)
downloadtor-b3ec39af8ff595b9490a330a356366b05c4750b9.tar.gz
tor-b3ec39af8ff595b9490a330a356366b05c4750b9.zip
Merge remote branch 'mikeperry/bwweight-smartlistfix'
-rw-r--r--src/or/routerlist.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index f0ae53abe0..0173c27e4e 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -1574,6 +1574,13 @@ smartlist_choose_by_bandwidth_weights(smartlist_t *sl,
rule == WEIGHT_FOR_MID ||
rule == WEIGHT_FOR_DIR);
+ if (smartlist_len(sl) == 0) {
+ log_info(LD_CIRC,
+ "Empty routerlist passed in to consensus weight node "
+ "selection for rule %d", rule);
+ return NULL;
+ }
+
weight_scale = networkstatus_get_param(NULL, "bwweightscale",
BW_WEIGHT_SCALE);
@@ -1692,6 +1699,15 @@ smartlist_choose_by_bandwidth_weights(smartlist_t *sl,
"Wg=%lf Wm=%lf We=%lf Wd=%lf with total bw %lf", rule,
Wg, Wm, We, Wd, weighted_bw);
+ /* If there is no bandwidth, choose at random */
+ if (DBL_TO_U64(weighted_bw) == 0) {
+ log_warn(LD_CIRC,
+ "Weighted bandwidth is %lf in node selection for rule %d",
+ weighted_bw, rule);
+ tor_free(bandwidths);
+ return smartlist_choose(sl);
+ }
+
rand_bw = crypto_rand_uint64(DBL_TO_U64(weighted_bw));
rand_bw++; /* crypto_rand_uint64() counts from 0, and we need to count
* from 1 below. See bug 1203 for details. */
@@ -1765,6 +1781,13 @@ smartlist_choose_by_bandwidth(smartlist_t *sl, bandwidth_weight_rule_t rule,
rule == WEIGHT_FOR_EXIT ||
rule == WEIGHT_FOR_GUARD);
+ if (smartlist_len(sl) == 0) {
+ log_info(LD_CIRC,
+ "Empty routerlist passed in to old node selection for rule %d",
+ rule);
+ return NULL;
+ }
+
/* First count the total bandwidth weight, and make a list
* of each value. <0 means "unknown; no routerinfo." We use the
* bits of negative values to remember whether the router was fast (-x)&1