summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorteor <teor@riseup.net>2020-05-13 13:23:39 +1000
committerteor <teor@riseup.net>2020-05-18 21:53:52 +1000
commite46c3d95f4257fd1292c721a5d737af0f74f2f83 (patch)
tree8008f6bcbdbb8d6bffdd1f7508b00b878e561133 /src
parent766fc86df46ff88364610b18e28904c3b45f98f1 (diff)
downloadtor-e46c3d95f4257fd1292c721a5d737af0f74f2f83.tar.gz
tor-e46c3d95f4257fd1292c721a5d737af0f74f2f83.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/core/or/circuitbuild.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/src/core/or/circuitbuild.c b/src/core/or/circuitbuild.c
index bac82eb9f5..233ea9bd08 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);