aboutsummaryrefslogtreecommitdiff
path: root/src/feature/nodelist
diff options
context:
space:
mode:
authorteor <teor@riseup.net>2020-05-11 17:00:25 +1000
committerteor <teor@riseup.net>2020-05-11 17:00:25 +1000
commit1c1faf586ab7083221e02da4315679c5cf13d151 (patch)
tree98780850692bd2eda6c0cd91b2eeaf37bea472a8 /src/feature/nodelist
parent9e7f51e469cd275ef519498945124fe5addc889f (diff)
downloadtor-1c1faf586ab7083221e02da4315679c5cf13d151.tar.gz
tor-1c1faf586ab7083221e02da4315679c5cf13d151.zip
routerlist: Choose nodes that can initiate IPv6 extends
Part of 33226.
Diffstat (limited to 'src/feature/nodelist')
-rw-r--r--src/feature/nodelist/node_select.c49
-rw-r--r--src/feature/nodelist/node_select.h2
-rw-r--r--src/feature/nodelist/routerlist.c9
-rw-r--r--src/feature/nodelist/routerlist.h3
4 files changed, 39 insertions, 24 deletions
diff --git a/src/feature/nodelist/node_select.c b/src/feature/nodelist/node_select.c
index 40d0f2a5b0..8e7da1ae2b 100644
--- a/src/feature/nodelist/node_select.c
+++ b/src/feature/nodelist/node_select.c
@@ -930,25 +930,33 @@ nodelist_subtract(smartlist_t *sl, const smartlist_t *excluded)
bitarray_free(excluded_idx);
}
-/** Return a random running node from the nodelist. Never
- * pick a node that is in
- * <b>excludedsmartlist</b>, or which matches <b>excludedset</b>,
- * even if they are the only nodes available.
- * If <b>CRN_NEED_UPTIME</b> is set in flags and any router has more than
- * a minimum uptime, return one of those.
- * If <b>CRN_NEED_CAPACITY</b> is set in flags, weight your choice by the
- * advertised capacity of each router.
- * If <b>CRN_NEED_GUARD</b> is set in flags, consider only Guard routers.
- * If <b>CRN_WEIGHT_AS_EXIT</b> is set in flags, we weight bandwidths as if
- * picking an exit node, otherwise we weight bandwidths for picking a relay
- * node (that is, possibly discounting exit nodes).
- * If <b>CRN_NEED_DESC</b> is set in flags, we only consider nodes that
- * have a routerinfo or microdescriptor -- that is, enough info to be
- * used to build a circuit.
- * If <b>CRN_PREF_ADDR</b> is set in flags, we only consider nodes that
- * have an address that is preferred by the ClientPreferIPv6ORPort setting
- * (regardless of this flag, we exclude nodes that aren't allowed by the
- * firewall, including ClientUseIPv4 0 and fascist_firewall_use_ipv6() == 0).
+/** Return a random running node from the nodelist. Never pick a node that is
+ * in <b>excludedsmartlist</b>, or which matches <b>excludedset</b>, even if
+ * they are the only nodes available.
+ *
+ * If the following <b>flags</b> are set:
+ * - <b>CRN_NEED_UPTIME</b>: if any router has more than a minimum uptime,
+ * return one of those;
+ * - <b>CRN_NEED_CAPACITY</b>: weight your choice by the advertised capacity
+ * of each router;
+ * - <b>CRN_NEED_GUARD</b>: only consider Guard routers;
+ * - <b>CRN_WEIGHT_AS_EXIT</b>: we weight bandwidths as if picking an exit
+ * node, otherwise we weight bandwidths for
+ * picking a relay node (that is, possibly
+ * discounting exit nodes);
+ * - <b>CRN_NEED_DESC</b>: only consider nodes that have a routerinfo or
+ * microdescriptor -- that is, enough info to be
+ * used to build a circuit;
+ * - <b>CRN_DIRECT_CONN</b>: only consider nodes that are suitable for direct
+ * connections. Check ReachableAddresses,
+ * ClientUseIPv4 0, and
+ * fascist_firewall_use_ipv6() == 0);
+ * - <b>CRN_PREF_ADDR</b>: only consider nodes that have an address that is
+ * preferred by the ClientPreferIPv6ORPort setting.
+ * - <b>CRN_RENDEZVOUS_V3</b>: only consider nodes that can become v3 onion
+ * service rendezvous points.
+ * - <b>CRN_INITIATE_IPV6_EXTEND</b>: only consider routers than can initiate
+ * IPv6 extends.
*/
const node_t *
router_choose_random_node(smartlist_t *excludedsmartlist,
@@ -963,6 +971,7 @@ router_choose_random_node(smartlist_t *excludedsmartlist,
const int pref_addr = (flags & CRN_PREF_ADDR) != 0;
const int direct_conn = (flags & CRN_DIRECT_CONN) != 0;
const int rendezvous_v3 = (flags & CRN_RENDEZVOUS_V3) != 0;
+ const bool initiate_ipv6_extend = (flags & CRN_INITIATE_IPV6_EXTEND) != 0;
const smartlist_t *node_list = nodelist_get_list();
smartlist_t *sl=smartlist_new(),
@@ -997,7 +1006,7 @@ router_choose_random_node(smartlist_t *excludedsmartlist,
router_add_running_nodes_to_smartlist(sl, need_uptime, need_capacity,
need_guard, need_desc, pref_addr,
- direct_conn);
+ direct_conn, initiate_ipv6_extend);
log_debug(LD_CIRC,
"We found %d running nodes.",
smartlist_len(sl));
diff --git a/src/feature/nodelist/node_select.h b/src/feature/nodelist/node_select.h
index 2e67f990f6..29b6e6f2c8 100644
--- a/src/feature/nodelist/node_select.h
+++ b/src/feature/nodelist/node_select.h
@@ -28,6 +28,8 @@ typedef enum router_crn_flags_t {
/* On clients, only provide nodes with HSRend >= 2 protocol version which
* is required for hidden service version >= 3. */
CRN_RENDEZVOUS_V3 = 1<<9,
+ /* On clients, only provide nodes that can initiate IPv6 extends. */
+ CRN_INITIATE_IPV6_EXTEND = 1<<10,
} router_crn_flags_t;
/** Possible ways to weight routers when choosing one randomly. See
diff --git a/src/feature/nodelist/routerlist.c b/src/feature/nodelist/routerlist.c
index e511256268..0d3d1bea3e 100644
--- a/src/feature/nodelist/routerlist.c
+++ b/src/feature/nodelist/routerlist.c
@@ -512,13 +512,15 @@ routers_have_same_or_addrs(const routerinfo_t *r1, const routerinfo_t *r2)
}
/** Add every suitable node from our nodelist to <b>sl</b>, so that
- * we can pick a node for a circuit.
+ * we can pick a node for a circuit. See router_choose_random_node()
+ * for details.
*/
void
router_add_running_nodes_to_smartlist(smartlist_t *sl, int need_uptime,
int need_capacity, int need_guard,
int need_desc, int pref_addr,
- int direct_conn)
+ int direct_conn,
+ bool initiate_ipv6_extend)
{
const int check_reach = !router_or_conn_should_skip_reachable_address_check(
get_options(),
@@ -545,7 +547,8 @@ router_add_running_nodes_to_smartlist(smartlist_t *sl, int need_uptime,
FIREWALL_OR_CONNECTION,
pref_addr))
continue;
-
+ if (initiate_ipv6_extend && !node_supports_initiating_ipv6_extends(node))
+ continue;
smartlist_add(sl, (void *)node);
} SMARTLIST_FOREACH_END(node);
}
diff --git a/src/feature/nodelist/routerlist.h b/src/feature/nodelist/routerlist.h
index 401ce5e35a..1297bb4b65 100644
--- a/src/feature/nodelist/routerlist.h
+++ b/src/feature/nodelist/routerlist.h
@@ -61,7 +61,8 @@ int routers_have_same_or_addrs(const routerinfo_t *r1, const routerinfo_t *r2);
void router_add_running_nodes_to_smartlist(smartlist_t *sl, int need_uptime,
int need_capacity, int need_guard,
int need_desc, int pref_addr,
- int direct_conn);
+ int direct_conn,
+ bool initiate_ipv6_extend);
const routerinfo_t *routerlist_find_my_routerinfo(void);
uint32_t router_get_advertised_bandwidth(const routerinfo_t *router);