Repository navigation
fix(helper): a silent relay no longer holds back a working direct route - #66
Merged
Merged
Conversation
A host with a relay route is still dialled through the relay first. After RELAY_HEAD_START_MS (1000 ms) the host's own routes race the relay up to step 1, pinned to the host; only the first to pass it is admitted and sends HELLO, and the other's tries are closed first. Caller gains step1/dial_passed and search_step1/search_passed so the race stops before any path is admitted.
…t once A relayed pipe that passed step 1 and got GOAWAY NOT_AUTHORIZED, GRANT_REVOKED or UNSUPPORTED_VERSION (or a version refusal) now ends the relay tries and the relay-first race at once: no direct search starts again and no later relay address replaces it. A pipe that ended, a local close, a timeout or a relay failure still moves on to the next try.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A host with a relay route is still dialled through the relay first. Previously, a relay that accepted the connection but never answered held B's dial for the full
VIA_RELAY_DIAL_MS(10 s) before any direct route was tried. Now, if the relay has not passed step 1 (the pinned peer TLS) within the newRELAY_HEAD_START_MS(1000 ms by default), the host's own routes start too, with the usual search. Both sides stop at step 1. The first to pass is the only path admitted into the caller's session and the only one that sendsHELLO. The other side's tries are closed before that.What changed
Caller(net-io) getsstep1/dial_passedandsearch_step1/search_passed: the existing dial and search, cut at step 1.dialandsearchnow run both halves in a row, so their behavior does not change. Renewals still use the full race.relay.rs:dial_routeandreachare built fromRouteTries/RelayTries(routes and addresses in the same order, each up to step 1) plusadmit. Step 1,HELLOand the host's answer still share oneVIA_RELAY_DIAL_MS. A relayed pipe that passed step 1 and is refused by the pinned host itself ends the relay tries at once (host_refused). That covers aGOAWAYinside the peer TLS withNOT_AUTHORIZED,GRANT_REVOKEDorUNSUPPORTED_VERSION, and a version refusal. Before, only a version refusal did: a host refusal waited for the end of its route, and a later address's error could replace it. A pipe that ended, a local close, a timeout or a relay failure still moves on to the next address and route. The bulk companion'sdial_routeis unchanged.paths.rs:reachraces them inrelay_first, keeping the relay on a tie.What stays the same: the per-host dial lock, the peer generation check when the path is added, the search's route generation, LAN-first tiers and head starts inside the search, pin checks, relay approval checks on every dial, and the relay-to-direct upgrade after a relayed path comes up. No wire, spec or host change.
How the race ends in each case:
host_refused, so no direct search starts again and no later relay address replaces it. A relayed pipe that just closed is not a refusal: the race goes on.Host side: a losing attempt is a TLS connection that closes before
HELLO. The host announces an inbound connection only after its caller'sHELLO(inbound_on,caller_hello), so a losing attempt never appears as a hostconn.up. Losing search tries already behave this way today.Result
Both columns use the same fixture: paired helpers on Windows loopback, with A enrolled on a test relay and B holding the approved relay route plus one working LAN-class direct route through a loopback proxy. B restarts, and the time is measured from B's
helloanswer to its first outboundconn.up. 5 runs each:conn.up)conn.up)The remaining ~1 s is the head start, kept on purpose. Limits: loopback only. A real relay adds round trips, so a relay that takes longer than 1 s to pass step 1 can now lose to a direct route; that direct path is then used straight away, without the relay-then-upgrade step. This was not measured on real remote relays. The measurement harness is not part of this PR.
Tests
New tests in
crates/mousse-helper/tests/app_relay_first.rs:a_silent_relay_does_not_hold_back_a_working_direct_route: the relay takes B's circuit and never answers. The direct route comes up, carries a stream, and is B's only path. It fails on main: there is noconn.upwithin the 20 s wait, because the relay holds the dial.the_hosts_refusal_on_the_direct_route_ends_the_dial_past_a_silent_relay: A removed B's grant and the relay is silent. B's dial ends withnot_authorizedand the host is parked. It fails on main for the same reason.a_relay_that_passes_step_1_first_ends_the_search_it_raced: with no head start and a slow direct route, the relay passes step 1 while the search is still running. The relayed path is let in, the upgrade later moves to the direct route, and there are exactly two paths in all. It passes on main too and guards the new interleaving.Also new, in
relay.rs:only_the_hosts_own_refusal_ends_the_relay_tries, a table of the errors a relayed pipe can end with after step 1. Only the host's own refusals end the tries; pipe closed, I/O error, unresponsive, a local close, a peerINTERNAL_ERROR, a timeout and a relay failure move on. It fails with the earlier version-only check.Control: with
MOUSSE_NET_RELAY_HEAD_START_MS=0, the existinga_host_with_a_relay_route_is_reached_through_the_relay_firstfails because the direct route wins. The head start is what keeps the relay preference.Verification
Head
6e0aa9c, on main7ea2937. Local checks on Windows:6e0aa9c:cargo test -p mousse-helper --bins --test app_relay_first --test app_relay --test app_relay_remote --test app_relay_rotation --test app_relay_completion --test app_paths --test app_version_refusalsall pass (125 unit, 15, 8, 1 + 2 ignored, 7, 18, 20, 2).6e0aa9c:cargo fmt --all --checkpasses, andcargo clippy -p mousse-helper --all-targets --all-features -- -D warnings -A clippy::missing_const_for_thread_localpasses.39ef80e:cargo clippy --workspace --all-targets --all-features -- -D warningsstops only at the known Windowsmissing_const_for_thread_localincrates/mousse-helper/src/app/out.rs:53, which this PR does not touch (also noted on fix(caller): a slow unrelated name holds a ready tailnet candidate back for the LAN head start only #64). With that one lint allowed (-A clippy::missing_const_for_thread_local), it passes.39ef80e:cargo test --workspace --lockedpasses, 1310 tests in 70 suites, none failed.39ef80e:cargo check -p mousse-net-core --target wasm32-unknown-unknownpasses.No issue. Refs mousse-agent/mousse#1510.