Skip to content

fix(helper): a silent relay no longer holds back a working direct route - #66

Merged
TheAnimatrix merged 2 commits into
mainfrom
relay-silent-fallback
Dec 1, 2026
Merged

TheAnimatrix merged 2 commits into
mainfrom
relay-silent-fallback

Conversation

@TheAnimatrix

@TheAnimatrix TheAnimatrix commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

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 new RELAY_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 sends HELLO. The other side's tries are closed before that.

What changed

  • Caller (net-io) gets step1 / dial_passed and search_step1 / search_passed: the existing dial and search, cut at step 1. dial and search now run both halves in a row, so their behavior does not change. Renewals still use the full race.
  • Helper relay.rs: dial_route and reach are built from RouteTries / RelayTries (routes and addresses in the same order, each up to step 1) plus admit. Step 1, HELLO and the host's answer still share one VIA_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 a GOAWAY inside the peer TLS with NOT_AUTHORIZED, GRANT_REVOKED or UNSUPPORTED_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's dial_route is unchanged.
  • Helper paths.rs: reach races them in relay_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:

  • The relay passes step 1 and is not let in (other than a refusal): the relay tries its next address, and the search starts again at once.
  • The search passes step 1 and is not let in (other than a refusal): the race ends, and the relay routes are tried afterwards, as before.
  • A refusal by the pinned host on either side ends the dial at once. On the relay side that is 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.
  • The search fails while the relay is still trying: the race waits for the relay. If the relay fails too, the search's error is the answer, and the search is not run a second time (before, it ran once, after the relay).

Host side: a losing attempt is a TLS connection that closes before HELLO. The host announces an inbound connection only after its caller's HELLO (inbound_on, caller_hello), so a losing attempt never appears as a host conn.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 hello answer to its first outbound conn.up. 5 runs each:

main (7ea2937) this branch
Relay accepts and never answers (direct conn.up) 10048–10066 ms, median 10051 1041–1063 ms, median 1048
Healthy relay (relay conn.up) 70–75 ms, median 74 69–85 ms, median 73

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 no conn.up within 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 with not_authorized and 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 peer INTERNAL_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 existing a_host_with_a_relay_route_is_reached_through_the_relay_first fails because the direct route wins. The head start is what keeps the relay preference.

Verification

Head 6e0aa9c, on main 7ea2937. Local checks on Windows:

  • On 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_refusals all pass (125 unit, 15, 8, 1 + 2 ignored, 7, 18, 20, 2).
  • On 6e0aa9c: cargo fmt --all --check passes, and cargo clippy -p mousse-helper --all-targets --all-features -- -D warnings -A clippy::missing_const_for_thread_local passes.
  • On 39ef80e: cargo clippy --workspace --all-targets --all-features -- -D warnings stops only at the known Windows missing_const_for_thread_local in crates/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.
  • On 39ef80e: cargo test --workspace --locked passes, 1310 tests in 70 suites, none failed.
  • On 39ef80e: cargo check -p mousse-net-core --target wasm32-unknown-unknown passes.

No issue. Refs mousse-agent/mousse#1510.

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.
@TheAnimatrix
TheAnimatrix merged commit eb19693 into main Dec 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant