[tor-commits] [tor/maint-0.3.2] Use node counts in networks with all zero-bandwidths
nickm at torproject.org
nickm at torproject.org
Wed Nov 8 16:02:56 UTC 2017
commit 14b0bba06e65a1dfca6a2f15f3016cb36409183f
Author: teor <teor2345 at gmail.com>
Date: Wed Nov 8 14:09:50 2017 +1100
Use node counts in networks with all zero-bandwidths
When calculating the fraction of nodes that have descriptors, and all
all nodes in the network have zero bandwidths, count the number of nodes
instead.
Fixes bug 23318; bugfix on 0.2.4.10-alpha.
---
changes/bug23318 | 4 ++++
src/or/routerlist.c | 28 ++++++++++++++++++++--------
2 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/changes/bug23318 b/changes/bug23318
index 32c85eb19..7fcb8d448 100644
--- a/changes/bug23318
+++ b/changes/bug23318
@@ -5,3 +5,7 @@
integer. This had the biggest effect when a relay's weight adjustments
should have given it weight 0, but it got weight 1 instead.
Fixes bug 23318; bugfix on 0.2.4.3-alpha.
+ - When calculating the fraction of nodes that have descriptors, and all
+ all nodes in the network have zero bandwidths, count the number of nodes
+ instead.
+ Fixes bug 23318; bugfix on 0.2.4.10-alpha.
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index faf2eeda5..d6347c49f 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -149,7 +149,8 @@ typedef struct cert_list_t cert_list_t;
/* static function prototypes */
static int compute_weighted_bandwidths(const smartlist_t *sl,
bandwidth_weight_rule_t rule,
- double **bandwidths_out);
+ double **bandwidths_out,
+ double *total_bandwidth_out);
static const routerstatus_t *router_pick_trusteddirserver_impl(
const smartlist_t *sourcelist, dirinfo_type_t auth,
int flags, int *n_busy_out);
@@ -2513,7 +2514,7 @@ smartlist_choose_node_by_bandwidth_weights(const smartlist_t *sl,
double *bandwidths_dbl=NULL;
uint64_t *bandwidths_u64=NULL;
- if (compute_weighted_bandwidths(sl, rule, &bandwidths_dbl) < 0)
+ if (compute_weighted_bandwidths(sl, rule, &bandwidths_dbl, NULL) < 0)
return NULL;
bandwidths_u64 = tor_calloc(smartlist_len(sl), sizeof(uint64_t));
@@ -2533,11 +2534,14 @@ smartlist_choose_node_by_bandwidth_weights(const smartlist_t *sl,
* smartlist_choose_node_by_bandwidth_weights, compute weighted bandwidth
* values for each node and store them in a freshly allocated
* *<b>bandwidths_out</b> of the same length as <b>sl</b>, and holding results
- * as doubles. Return 0 on success, -1 on failure. */
+ * as doubles. If <b>total_bandwidth_out</b> is non-NULL, set it to the total
+ * of all the bandwidths.
+ * Return 0 on success, -1 on failure. */
static int
compute_weighted_bandwidths(const smartlist_t *sl,
bandwidth_weight_rule_t rule,
- double **bandwidths_out)
+ double **bandwidths_out,
+ double *total_bandwidth_out)
{
int64_t weight_scale;
double Wg = -1, Wm = -1, We = -1, Wd = -1;
@@ -2545,6 +2549,7 @@ compute_weighted_bandwidths(const smartlist_t *sl,
uint64_t weighted_bw = 0;
guardfraction_bandwidth_t guardfraction_bw;
double *bandwidths;
+ double total_bandwidth = 0.0;
/* Can't choose exit and guard at same time */
tor_assert(rule == NO_WEIGHTING ||
@@ -2553,6 +2558,10 @@ compute_weighted_bandwidths(const smartlist_t *sl,
rule == WEIGHT_FOR_MID ||
rule == WEIGHT_FOR_DIR);
+ if (total_bandwidth_out) {
+ *total_bandwidth_out = 0.0;
+ }
+
if (smartlist_len(sl) == 0) {
log_info(LD_CIRC,
"Empty routerlist passed in to consensus weight node "
@@ -2714,6 +2723,7 @@ compute_weighted_bandwidths(const smartlist_t *sl,
}
bandwidths[node_sl_idx] = final_weight;
+ total_bandwidth += final_weight;
} SMARTLIST_FOREACH_END(node);
log_debug(LD_CIRC, "Generated weighted bandwidths for rule %s based "
@@ -2724,6 +2734,10 @@ compute_weighted_bandwidths(const smartlist_t *sl,
*bandwidths_out = bandwidths;
+ if (total_bandwidth_out) {
+ *total_bandwidth_out = total_bandwidth;
+ }
+
return 0;
}
@@ -2740,7 +2754,8 @@ frac_nodes_with_descriptors(const smartlist_t *sl,
if (smartlist_len(sl) == 0)
return 0.0;
- if (compute_weighted_bandwidths(sl, rule, &bandwidths) < 0) {
+ if (compute_weighted_bandwidths(sl, rule, &bandwidths, &total) < 0 ||
+ total <= 0.0) {
int n_with_descs = 0;
SMARTLIST_FOREACH(sl, const node_t *, node, {
if (node_has_descriptor(node))
@@ -2759,9 +2774,6 @@ frac_nodes_with_descriptors(const smartlist_t *sl,
tor_free(bandwidths);
- if (total < 1.0)
- return 0;
-
return present / total;
}
More information about the tor-commits
mailing list