[tor-commits] [tor/master] Refactor should-count-towards-thresholds test into new function

nickm at torproject.org nickm at torproject.org
Mon Feb 4 17:39:03 UTC 2013


commit 8be7f69f8d2bdf074e5e90279dd42e182562ba7d
Author: Nick Mathewson <nickm at torproject.org>
Date:   Mon Feb 4 10:22:45 2013 -0500

    Refactor should-count-towards-thresholds test into new function
---
 src/or/dirserv.c |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 320b8e0..6c4b119 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)





More information about the tor-commits mailing list