[tor-commits] [tor/master] circuitbuild: Do node checks when counting nodes

nickm at torproject.org nickm at torproject.org
Tue Jun 9 19:45:23 UTC 2020


commit e46c3d95f4257fd1292c721a5d737af0f74f2f83
Author: teor <teor at riseup.net>
Date:   Wed May 13 13:23:39 2020 +1000

    circuitbuild: Do node checks when counting nodes
    
    Use the node check function to check that there are enough nodes to
    select a circuit path.
    
    Adds these checks, which are implied by other code:
    * supports EXTEND2 cells,
    * does not allow single-hop exits,
    
    Adds these extra checks:
    * has a general-purpose routerinfo,
    * if it is a direct connection, check reachable addresses.
    These checks reduce the node count, but they will never under-count
    nodes.
    
    Bridge nodes aren't handled correctly, we'll fix that in the next
    commit.
    
    Part of 34200.
---
 src/core/or/circuitbuild.c | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/src/core/or/circuitbuild.c b/src/core/or/circuitbuild.c
index bac82eb9f..233ea9bd0 100644
--- a/src/core/or/circuitbuild.c
+++ b/src/core/or/circuitbuild.c
@@ -2103,32 +2103,27 @@ circuit_extend_to_new_exit(origin_circuit_t *circ, extend_info_t *exit_ei)
   return 0;
 }
 
-/** Return the number of routers in <b>routers</b> that are currently up
- * and available for building circuits through.
+/** Return the number of routers in <b>nodes</b> that are currently up and
+ * available for building circuits through.
  *
- * (Note that this function may overcount or undercount, if we have
- * descriptors that are not the type we would prefer to use for some
- * particular router. See bug #25885.)
+ * If <b>direct</b> is true, only count nodes that are suitable for direct
+ * connections. Counts nodes regardless of whether their addresses are
+ * preferred.
  */
 MOCK_IMPL(STATIC int,
 count_acceptable_nodes, (const smartlist_t *nodes, int direct))
 {
   int num=0;
+  int flags = CRN_NEED_DESC;
+
+  if (direct)
+    flags |= CRN_DIRECT_CONN;
 
   SMARTLIST_FOREACH_BEGIN(nodes, const node_t *, node) {
     //    log_debug(LD_CIRC,
-//              "Contemplating whether router %d (%s) is a new option.",
-//              i, r->nickname);
-    if (! node->is_running)
-//      log_debug(LD_CIRC,"Nope, the directory says %d is not running.",i);
-      continue;
-    if (! node->is_valid)
-//      log_debug(LD_CIRC,"Nope, the directory says %d is not valid.",i);
-      continue;
-    if (! node_has_preferred_descriptor(node, direct))
-      continue;
-    /* The node has a descriptor, so we can just check the ntor key directly */
-    if (!node_has_curve25519_onion_key(node))
+    //              "Contemplating whether router %d (%s) is a new option.",
+    //              i, r->nickname);
+    if (!router_can_choose_node(node, flags))
       continue;
     ++num;
   } SMARTLIST_FOREACH_END(node);





More information about the tor-commits mailing list