Skip to content

fix(relay): prevent cross-relay aliasing on home_on_every_relay and isolate relay_slow - #26

Merged
CommaBot merged 1 commit into
stillfailfrom
ember/no-cross-relay-alias
Nov 20, 2026
Merged

CommaBot merged 1 commit into
stillfailfrom
ember/no-cross-relay-alias

Conversation

@CommaBot

@CommaBot CommaBot commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  1. iroh/tests/relay_slow.rs:73, 183 (presets::N0 → presets::Minimal): Stops relay_slow tests (which bind deterministic keys [1; 32] / [2; 32]) from querying or publishing to public N0 Pkarr/DNS while preserving all transport, path-selector, 600 ms slow-relay switch, new-connection race, and 17-peer zero-loss assertions.
  2. Explicit synchronization in concurrent_insert_and_remove_relay_keeps_removed_tombstone_consistent (iroh/src/endpoint.rs, iroh/src/socket.rs): Replaces the 8× yield_now loop with a test-only Notify (notify_next_relay_remove_queued) fired once ActorMessage::RelayRemoved is enqueued on actor_sender behind the paused RelayInserted.
  3. No cross-relay borrowing on Builder::home_on_every_relay + non-home idle cleanup (iroh/src/socket/transports/relay/actor.rs):
    • Previously, when an endpoint with home_on_every_relay sent to a relay URL R_extra that owned no single-relay transport, TransportsSender (transports.rs:1347) routed it to relay[0] via unwrap_or(0), and RelayActor::active_relay_handle_for_endpoint (actor.rs:1866-1884) saw the peer in relay[0]'s endpoints_present and sent R_extra's packets over relay[0]'s WebSocket—establishing a path named Relay(R_extra) whose traffic and RTT actually belonged to relay[0].
    • TransportsSender's unwrap_or(0) is intentionally preserved so legitimate unowned allowed URLs (native allowPublicRelays emergency fallback when ours are down, and workspace custom relays #theirs on the main endpoint) still reach relay[0]; RelayActor::active_relay_handle_for_endpoint now skips the endpoints_present cross-URL shortcut when home_on_every_relay is enabled and dials R_extra directly (is_home_relay = false).
    • Non-home blackhole / idle cleanup fix: Previously, ActiveRelayActor::run_dialing reset inactive_timeout on every 3 s UNDELIVERABLE_DATAGRAM_TIMEOUT tick even when the outgoing queue was empty, and sleep_backoff did not poll inactive_timeout at all—allowing a blackholed non-home relay whose handshake kept timing out at 10 s to retry forever until endpoint shutdown even after QUIC exhausted its 2 / 6 path budget. flush_undeliverable_datagrams now extends inactive_deadline (RELAY_INACTIVE_CLEANUP_TIME = 60 s) only when outgoing datagrams were actually queued, and both run_dialing and sleep_backoff exit promptly once inactive_timeout elapses with nothing new queued.
    • Single-home endpoints (home_on_every_relay == false, including inner LeafLinks scope endpoints and route_lookup_reads_endpoints_present_and_asks_no_actor) retain upstream's endpoints_present shortcut unchanged.

Product Behavior Change: Workspace Custom Relays (#theirs) on the Main Endpoint

  • Before this PR: Whenever relay[0] already had a station in endpoints_present (e.g. after exchanging traffic over an official ours relay first and then learning #theirs via setWays → addAddr, or on subsequent connections to that station), packets addressed to #theirs on the main endpoint were borrowed onto relay[0]'s official WebSocket rather than opening a connection to #theirs.
    • Evidence boundary: That home_on_every_relay borrowed relay[0] (sent(&relay_d) == 0 while opening a path named Relay(url_d)) once endpoints_present contained the peer is runtime-verified by the pre-fix failure of endpoint::tests::home_on_every_relay_does_not_borrow_another_relay_for_unowned_urls. How product Mesh feeds #theirs and relayAllowlist to the main endpoint (client/core-ts/src/mesh.ts:969, 993-996, 1431, 1472-1474, 1607, client/shell/src/iroh_ops.rs:345-349, client/iroh-wasm/src/lib.rs:98-102) is a code-reading deduction (note: on a cold first connect before endpoints_present was populated, an allowed #theirs URL could already be dialed on relay[0]; and on web, #theirs enters the main endpoint's relayAllowlist only after #rebind at mesh.ts:1431).
  • After this PR: Whenever #theirs is permitted by the main endpoint's allowlist and outgoing packets are addressed to it, relay[0] genuinely connects to #theirs via a non-home ActiveRelayActor (is_home_relay = false):
    1. Extra connections: At most 1 WebSocket/TCP connection per distinct #theirs URL on the main endpoint (relay[0]), shared across all QUIC connections/peers on that endpoint.
    2. Identity exposed to custom relay: The workspace's custom relay sees the device's main EndpointId (Mesh.#secret), distinct from the per-relay derived key (pinnedKey(secret, relay)) used by single-relay #explore endpoints (mesh.ts:2638).
    3. When reclaimed: While an open QUIC path over #theirs sends keepalives/ACKs, each outgoing datagram extends RELAY_INACTIVE_CLEANUP_TIME (60 s). Once no outgoing datagrams are queued for #theirs (connection closed, #theirs disabled via set_disabled_relays / Hot Relays narrowing, peer absent after RELAY_PATH_LOST_MAX = 2, or handshake blackholed), the non-home ActiveRelayActor exits and is reaped after 60 s.

Verification

  • socket::transports::relay::actor::tests::non_home_blackhole_relay_exits_after_inactive_cleanup_time (paused-clock regression: confirmed runtime failure when empty 3 s flushes extend inactive_deadline; passes with fix, verifying 5× 10 s blackhole dial timeouts + backoffs exit and reap by t=62 s with 0 dials across +105 s afterwards, while a connected extra non-home relay carrying periodic traffic stays active past t=102 s and exits after 60 s idle).
  • endpoint::tests::home_on_every_relay_does_not_borrow_another_relay_for_unowned_urls (strict sent(&relay_c) > c_before + direct relay_loss_stats == Some((0, 2, 2)) assertion for RELAY_PATH_LOST_MAX exhaustion + > RELAY_REOPEN silence check).
  • endpoint::tests::concurrent_insert_and_remove_relay_keeps_removed_tombstone_consistent
  • socket::transports::relay:: full unit suite (24/24), iroh-relay unit suite (16/16), relay_slow integration suite (3/3), and wasm32-unknown-unknown checks (tls-ring and tls-ring,unstable-custom-transports).

…eclaim idle non-home dials

- Replace `presets::N0` with `presets::Minimal` in `iroh/tests/relay_slow.rs` so deterministic secret keys do not publish to or pull foreign relay addresses from public Pkarr/DNS.
- Replace the 8x `yield_now` wait in `concurrent_insert_and_remove_relay_keeps_removed_tombstone_consistent` with explicit `Notify` synchronization once `ActorMessage::RelayRemoved` is queued on `actor_sender` behind the paused `RelayInserted`.
- Disable `RelayActor::active_relay_handle_for_endpoint`'s `endpoints_present` cross-relay shortcut when `Builder::home_on_every_relay` is set while keeping `TransportsSender`'s `unwrap_or(0)` fallback intact: unowned allowed relays dial their own relay URL genuinely on `relay[0]`, whereas absent foreign relays fail QUIC path validation (`RELAY_PATH_LOST_MAX = 2`) without borrowing another relay's connection or establishing a misnamed path.
- Extend `ActiveRelayActor`'s 60 s `RELAY_INACTIVE_CLEANUP_TIME` deadline during disconnected undeliverable flushes only when outgoing datagrams were actually queued, and honor that idle deadline across both `run_dialing` and `sleep_backoff` so a blackholed non-home relay exits and is reaped instead of retrying until endpoint shutdown.

Co-authored-by: darksky <darksky@cue.surf>
@CommaBot
CommaBot force-pushed the ember/no-cross-relay-alias branch from f5102d3 to fdb906b Compare November 20, 2026 20:22
@CommaBot
CommaBot merged commit 0d8d64f into stillfail Nov 20, 2026
4 checks passed
CommaBot pushed a commit to AFK-surf/monoid that referenced this pull request Nov 20, 2026
Pin iroh and iroh-relay across client, mesh-transport, station mesh addon, and load tools to 0d8d64f82289a6726cd7edb1671d38a1ce56d0fc (zzj3720/iroh#26).

Co-authored-by: darksky <darksky@cue.surf>
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