From 03d6995d0ef689bc9951e603d09939c449d9c159 Mon Sep 17 00:00:00 2001 From: Mike Perry Date: Fri, 26 Feb 2010 16:17:09 -0800 Subject: [PATCH 1/3] Check for empty smartlists and no bandwidth during node selection. --- src/or/routerlist.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 80229f2141..4daf1e6abd 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -1576,6 +1576,13 @@ smartlist_choose_by_bandwidth_weights(smartlist_t *sl, rule == WEIGHT_FOR_MID || rule == WEIGHT_FOR_DIR); + if (!sl || smartlist_len(sl) == 0) { + log_warn(LD_CIRC, + "Empty routerlist passed in to node selection for rule %d", + rule); + return NULL; + } + weight_scale = networkstatus_get_param(NULL, "bwweightscale", BW_WEIGHT_SCALE); @@ -1694,6 +1701,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. */ @@ -1767,6 +1783,13 @@ smartlist_choose_by_bandwidth(smartlist_t *sl, bandwidth_weight_rule_t rule, rule == WEIGHT_FOR_EXIT || rule == WEIGHT_FOR_GUARD); + if (!sl || smartlist_len(sl) == 0) { + log_warn(LD_CIRC, + "Empty routerlist passed in to 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 From 97eec84f4bcc4908e47ebcb51f1eb1d3a782b42b Mon Sep 17 00:00:00 2001 From: Mike Perry Date: Wed, 3 Mar 2010 17:35:06 -0800 Subject: [PATCH 2/3] Demote warn to info, since it can happen. I still feel like we should investigate this case. It seems odd. --- src/or/routerlist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 4daf1e6abd..392588cef4 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -1577,7 +1577,7 @@ smartlist_choose_by_bandwidth_weights(smartlist_t *sl, rule == WEIGHT_FOR_DIR); if (!sl || smartlist_len(sl) == 0) { - log_warn(LD_CIRC, + log_info(LD_CIRC, "Empty routerlist passed in to node selection for rule %d", rule); return NULL; From 2b5e1d363640e34ec803044f0f8d086dfdd40a6b Mon Sep 17 00:00:00 2001 From: Mike Perry Date: Wed, 3 Mar 2010 21:02:01 -0800 Subject: [PATCH 3/3] Woops, forgot the second warn. Also, differentiate the two log messages. --- src/or/routerlist.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 392588cef4..a67703ca4b 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -1576,10 +1576,10 @@ smartlist_choose_by_bandwidth_weights(smartlist_t *sl, rule == WEIGHT_FOR_MID || rule == WEIGHT_FOR_DIR); - if (!sl || smartlist_len(sl) == 0) { + if (smartlist_len(sl) == 0) { log_info(LD_CIRC, - "Empty routerlist passed in to node selection for rule %d", - rule); + "Empty routerlist passed in to consensus weight node " + "selection for rule %d", rule); return NULL; } @@ -1783,9 +1783,9 @@ smartlist_choose_by_bandwidth(smartlist_t *sl, bandwidth_weight_rule_t rule, rule == WEIGHT_FOR_EXIT || rule == WEIGHT_FOR_GUARD); - if (!sl || smartlist_len(sl) == 0) { - log_warn(LD_CIRC, - "Empty routerlist passed in to node selection for rule %d", + if (smartlist_len(sl) == 0) { + log_info(LD_CIRC, + "Empty routerlist passed in to old node selection for rule %d", rule); return NULL; }