diff options
author | teor <teor@riseup.net> | 2020-05-14 22:06:14 +1000 |
---|---|---|
committer | teor <teor@riseup.net> | 2020-05-14 22:06:14 +1000 |
commit | 5f577b0f25393187ec60e5a027ba5bebaddfadf5 (patch) | |
tree | f761570d53f4504fce2fc4ad7036f131597b1771 /src/core | |
parent | 2e41d82cc5aa30ab0dfebaa2bfd04fcb1f6a7c69 (diff) | |
download | tor-5f577b0f25393187ec60e5a027ba5bebaddfadf5.tar.gz tor-5f577b0f25393187ec60e5a027ba5bebaddfadf5.zip |
circuitbuild: Refactor IPv6 extend node selection
Move this complex check into its own function.
Part of 33222.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/or/circuitbuild.c | 25 | ||||
-rw-r--r-- | src/core/or/circuitbuild.h | 3 |
2 files changed, 24 insertions, 4 deletions
diff --git a/src/core/or/circuitbuild.c b/src/core/or/circuitbuild.c index 42ec79a9ba..4dc3067a76 100644 --- a/src/core/or/circuitbuild.c +++ b/src/core/or/circuitbuild.c @@ -1999,6 +1999,26 @@ cpath_build_state_to_crn_flags(const cpath_build_state_t *state) return flags; } +/* Return the CRN_INITIATE_IPV6_EXTEND flag, based on <b>state</b> and + * <b>cur_len</b>. + * + * Only called for middle nodes (for now). Must not be called on single-hop + * circuits. */ +STATIC int +cpath_build_state_to_crn_ipv6_extend_flag(const cpath_build_state_t *state, + int cur_len) +{ + IF_BUG_ONCE(state->desired_path_len < 2) + return 0; + + /* The last node is the relay doing the self-test. So we want to extend over + * IPv6 from the second-last node. */ + if (state->is_ipv6_selftest && cur_len == state->desired_path_len - 2) + return CRN_INITIATE_IPV6_EXTEND; + else + return 0; +} + /** Decide a suitable length for circ's cpath, and pick an exit * router (or use <b>exit</b> if provided). Store these in the * cpath. @@ -2320,10 +2340,7 @@ choose_good_middle_server(uint8_t purpose, excluded = build_middle_exclude_list(purpose, state, head, cur_len); flags |= cpath_build_state_to_crn_flags(state); - /* Picking the second-last node. (The last node is the relay doing the - * self-test.) */ - if (state->is_ipv6_selftest && cur_len == state->desired_path_len - 2) - flags |= CRN_INITIATE_IPV6_EXTEND; + flags |= cpath_build_state_to_crn_ipv6_extend_flag(state, cur_len); /** If a hidden service circuit wants a specific middle node, pin it. */ if (middle_node_must_be_vanguard(options, purpose, cur_len)) { diff --git a/src/core/or/circuitbuild.h b/src/core/or/circuitbuild.h index e62048f68c..565be09975 100644 --- a/src/core/or/circuitbuild.h +++ b/src/core/or/circuitbuild.h @@ -98,6 +98,9 @@ STATIC int onion_pick_cpath_exit(origin_circuit_t *circ, extend_info_t *exit_ei, int is_hs_v3_rp_circuit); STATIC int cpath_build_state_to_crn_flags(const cpath_build_state_t *state); +STATIC int cpath_build_state_to_crn_ipv6_extend_flag( + const cpath_build_state_t *state, + int cur_len); #endif /* defined(CIRCUITBUILD_PRIVATE) */ |