Repository navigation
Let a gateway serve through a relay (part R2a of #266) - #800
Conversation
A gateway with native.relay set registers with the relay under its own key, keeps the registration with a doubling backoff, drops it after two silent ping intervals, and accepts each reader the relay announces on a relay permit from a pool of four. Joined readers reach the native listener as a second source in its one listening socket, so a relay fault never ends the listener and relayed readers never take the permits direct readers need. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EL5rzp9FLsixdtkMSbgffp
…s waits (part R2a of #266) A dial that fails with InvalidInput (a host name that resolves to nothing) is now retried like any failure; only the key's own proof stops registering. A dropped stop sender is a stop, as for the listener, and a Pong write no longer holds up stop. Tests now cover the backoff starting over after a lasting registration, a refused dial being retried, the relay pool apart from a full connection pool, and a relay out of reach leaving direct readers served. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EL5rzp9FLsixdtkMSbgffp
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EL5rzp9FLsixdtkMSbgffp
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a90f5025ad
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…irly (part R2a of #266) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EL5rzp9FLsixdtkMSbgffp
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
Before: the relay from R1 (#788) runs, but no gateway uses it. A gateway can only be reached by dialing its native listener directly.
After: a gateway with
native.relay: "host:port"inconfig.jsonregisters with that relay under its own key and stays registered. Each reader the relay joins to it is served exactly as a direct reader would be: the same TLS pinned to the gateway's key, which the relay cannot read. Relayed readers come in on four permits of their own, so however many a relay sends, direct readers are still admitted. Readers don't dial the relay yet. That is R2b.How.
relay/gateway/application.rs(ThroughRelay) keeps the registration:Incoming{t}it takes a relay permit, dialsAccept{K, t}, and hands the stream on only afterJoined. With no permit free, nothing is dialed, and the relay answers that readerNoAnswer.Timer. A key that can't make its proof stops registering, because trying again can't change that.relay/gateway/infrastructure.rsholds the concrete pieces:TcpRelayDial, with nodelay and keepalive.IdentityKey, which wraps the native identity.RelayedAccept, the listener's oneEnrollmentAccept. It selects over the TCP accept and the joined readers' channel, and both branches are cancel-safe. With no relay configured the channel is closed, and that branch is disabled.NativeEnrollmentConnectionsgains a relayPoolof 4:relay_permit()hands out a permit, andstart_relayedadmits a connection on it in place of a connection permit.close, the wake sweep (relay_wake_report) andshutdowncover the new pool. A permit held by an accept still under way wakes the drain when it is dropped.Accepted::Relayed(stream, permit)is the new accept outcome. It leaves the accept backoff alone, because it says nothing about the listening socket.RelayAddressvalidateshost:port: an IPv6 host goes in brackets, and the whole is at most 255 bytes. UnlikelistenAddress, it may be a host name, looked up at each dial.signal_stop.joinwaits for it before the listener's drain.read_frame,next_frameandwrite_framemove torelay/wire.rs, which the relay and the gateway share.redialis not reused, because env_serve builds only on Unix and the gateway runs everywhere.sequenceDiagram participant L as Native listener participant G as Gateway relay task participant R as Relay participant P as Reader G->>R: Serve K, then Proof over the challenge R->>G: Registered P->>R: Connect K R->>G: Incoming t G->>G: take a relay permit, else drop t G->>R: Accept K t on a new connection R->>G: Joined G->>L: the stream and its relay permit P->>L: TLS pinned to K, served as a direct reader loop every ping interval R->>G: Ping G->>R: Pong endThe design doc's slice table now splits R2 into R2a (this PR), R2b (the reader's race of direct and relay, plus
peer.relay) and R2c (end to end). New rows RL15 to RL17 cover the gateway's side.Tests
tests/relay/gateway.rs(8 tests, manual timer), against the real R1 relay and a scripted one:Joined, and the bytes after it stay on the stream.native_listener_serves_relayed_connections_on_their_own_permits:a_gateway_with_a_relay_answers_a_reader_that_reaches_only_the_relay: a real relay over TCP, a real gateway started by composition, and a reader that completes TLS pinned to the gateway's key through the relay and is answered.native_relay_is_host_and_port: which relay values are accepted and which refused.cargo fmt --all, clippy with-D warningsfor nessa-server on Linux and for the six crates onx86_64-pc-windows-gnu, andnode scripts/check-architecture.mjs.Scripted gateway checks
Not applicable. This changes no UI, ACP or MCP behavior, and the gateway behaves as before unless
native.relayis set.Part of #266.
🤖 Generated with Claude Code
https://claude.ai/code/session_01EL5rzp9FLsixdtkMSbgffp
Generated by Claude Code
Summary by CodeRabbit