summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-02-04 10:22:45 -0500
committerNick Mathewson <nickm@torproject.org>2013-02-04 10:22:45 -0500
commit8be7f69f8d2bdf074e5e90279dd42e182562ba7d (patch)
tree364a0b872e05ef743367175a42e4c6da4e9e41e8
parent40c13240c08349b94d39a1af320f61a1f7a4fda0 (diff)
downloadtor-8be7f69f8d2bdf074e5e90279dd42e182562ba7d.tar.gz
tor-8be7f69f8d2bdf074e5e90279dd42e182562ba7d.zip
Refactor should-count-towards-thresholds test into new function
-rw-r--r--src/or/dirserv.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 320b8e00d3..6c4b119e43 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -1884,6 +1884,16 @@ dirserv_thinks_router_is_hs_dir(const routerinfo_t *router,
node->is_running);
}
+/** Helper for dirserv_compute_performance_thresholds(): Decide whether to
+ * include a router in our calculations, and return true iff we should. */
+static int
+router_counts_toward_thresholds(const node_t *node, time_t now,
+ const digestmap_t *omit_as_sybil)
+{
+ return node->ri && router_is_active(node->ri, node, now) &&
+ !digestmap_get(omit_as_sybil, node->ri->cache_info.identity_digest);
+}
+
/** Look through the routerlist, the Mean Time Between Failure history, and
* the Weighted Fractional Uptime history, and use them to set thresholds for
* the Stable, Fast, and Guard flags. Update the fields stable_uptime,
@@ -1935,9 +1945,8 @@ dirserv_compute_performance_thresholds(routerlist_t *rl,
/* Now, fill in the arrays. */
SMARTLIST_FOREACH_BEGIN(nodelist_get_list(), node_t *, node) {
- routerinfo_t *ri = node->ri;
- if (ri && router_is_active(ri, node, now) &&
- !digestmap_get(omit_as_sybil, ri->cache_info.identity_digest)) {
+ if (router_counts_toward_thresholds(node, now, omit_as_sybil)) {
+ routerinfo_t *ri = node->ri;
const char *id = ri->cache_info.identity_digest;
uint32_t bw;
node->is_exit = (!router_exit_policy_rejects_all(ri) &&
@@ -1998,9 +2007,8 @@ dirserv_compute_performance_thresholds(routerlist_t *rl,
n_familiar = 0;
SMARTLIST_FOREACH_BEGIN(nodelist_get_list(), node_t *, node) {
- routerinfo_t *ri = node->ri;
- if (ri && router_is_active(ri, node, now) &&
- !digestmap_get(omit_as_sybil, ri->cache_info.identity_digest)) {
+ if (router_counts_toward_thresholds(node, now, omit_as_sybil)) {
+ routerinfo_t *ri = node->ri;
const char *id = ri->cache_info.identity_digest;
long tk = rep_hist_get_weighted_time_known(id, now);
if (tk < guard_tk)