feat: fast CONNECT recovery for NATed peers via TTL=0 gateway fallback#2998
Closed
feat: fast CONNECT recovery for NATed peers via TTL=0 gateway fallback#2998
Conversation
After suspend/resume, a NATed peer reconnects via initial_join_procedure. The gateway routes CONNECT to ring peers, but if those are also behind NAT, hole punching fails. Each attempt takes ~10s (transport timeout) before the bloom filter updates, so convergence is very slow. When the joiner has zero ring connections, send one CONNECT request with TTL=0 alongside normal requests. TTL=0 forces the gateway to accept directly (no forwarding), using the existing transient connection — no NAT traversal needed. If the gateway rejects (at capacity), normal routing still works as fallback. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
Author
|
Superseded by PR #3015 (merged Feb 16) which solved the root cause with TTL-aware reservation cleanup. The TTL=0 gateway workaround is no longer needed. [AI-assisted - Claude] |
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.
Problem
After suspend/resume (or any isolation event), a NATed peer tries to reconnect via
initial_join_procedure. The gateway routes CONNECT requests to ring peers, but if those peers are also behind NAT, the joiner can't reach them (NAT-to-NAT hole punching fails). Each failed attempt takes ~10s (transport handshake timeout) before the bloom filter is updated. With many NATed peers in the gateway's ring, reconnection can take many minutes.Observed on technic: Zero ring connections after suspend, stuck in isolation loop with NAT traversal failing to all acceptor peers routed by the gateway.
Approach
When the joiner has zero ring connections, include one CONNECT request with TTL=0 alongside normal requests. TTL=0 forces the gateway to accept directly (no forwarding to potentially NATed acceptors). Since the joiner already has a transient connection to the gateway, no NAT traversal is needed.
Why TTL=0 works
ConnectRequest { ttl: 0 }can_forward = self.forwarded_to.is_none() && self.request.ttl > 0→falseis_terminus = true→ gateway checksshould_accept()→ accepts (has capacity)ConnectResponsewith gateway as acceptorConnectPeer { is_gw: false }→ promotes existing transient connection to ringKey design decisions
open_conns == 0: Normal topology optimization continues for non-isolated peers.should_accept()andhandle_connect_peer()have idempotent guards.Changes
join_ring_request(): Addedttl_override: Option<u8>parameter to allow callers to override the default TTLinitial_join_procedure(): Whenopen_conns == 0, first gateway request uses TTL=0 for fast direct bootstraphandle_aborted_op(): Updated two call sites to passNone(no TTL override)Testing
cargo fmt && cargo clippy --all-targets— cleancargo test -p freenet)test_multiple_clients_subscriptionfails on unmodified main too (pre-existing, unrelated)[AI-assisted - Claude]