fix: register unknown channels on the fly for hole-punched connections#58
fix: register unknown channels on the fly for hole-punched connections#58jacderida wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent PeerNotFound when sending over newly hole-punched connections by auto-registering unknown transport channels in TransportHandle::peers during the first send, and updates the saorsa-transport dependency to a NAT-traversal-related branch.
Changes:
- Register missing
channel_identries inTransportHandle::peersinsidesend_on_channelinstead of returningPeerNotFound. - Update
saorsa-transportdependency from crates.io to a git branch (feat-nat_traversal_attempts). - Update
Cargo.lockto reflect the new git-sourced transport dependency.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/transport_handle.rs |
Adds on-the-fly channel registration in send_on_channel to avoid early PeerNotFound during hole-punch flows. |
Cargo.toml |
Switches saorsa-transport dependency to a git branch for NAT traversal wiring fixes. |
Cargo.lock |
Locks saorsa-transport to a specific git commit from the configured branch. |
febbe27 to
4216376
Compare
Hole-punched connections may not have their channels registered in TransportHandle::peers when the first DHT response is attempted. Instead of returning PeerNotFound, register the channel immediately so the send can proceed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
4216376 to
04980ec
Compare
|
|
||
| # Networking | ||
| saorsa-transport = "0.28" | ||
| saorsa-transport = { git = "https://github.com/jacderida/saorsa-transport.git", branch = "feat-nat_traversal_attempts" } |
There was a problem hiding this comment.
saorsa-transport is pulled from a personal fork (jacderida/saorsa-transport) and a moving branch, which increases supply-chain risk and makes downstream builds non-reproducible (downstream users won’t use this repo’s Cargo.lock). Please switch to the saorsa-labs/saorsa-transport repo and pin an immutable rev (or a crates.io release/tag) before merging, especially if saorsa-core is intended to be publishable on crates.io (git deps generally block publishing).
| saorsa-transport = { git = "https://github.com/jacderida/saorsa-transport.git", branch = "feat-nat_traversal_attempts" } | |
| saorsa-transport = "0.27" |
|
Work is part of #62 |
Summary
Hole-punched connections are accepted at the transport layer and registered in
P2pEndpoint::connected_peers, but the event chain to populateTransportHandle::peersmay not have completed when the first DHT response is attempted. Instead of returningPeerNotFound, register the channel immediately so the send can proceed.Also updates
saorsa-transportdependency to thefeat-nat_traversal_attemptsbranch which contains the NAT traversal wiring fixes (WithAutonomi/saorsa-transport#25).Test plan
PeerNotFounderrors🤖 Generated with Claude Code
Greptile Summary
This PR fixes a
PeerNotFounderror that occurred when a hole-punched connection attempted its first DHT response before theConnectionEvent::Establishedhandler had finished populatingTransportHandle::peers. The fix registers a minimalPeerInfoentry on the fly insidesend_on_channel, unblocking the send while relying on the subsequent event to backfill the full metadata (addresses, protocols).src/transport_handle.rs: Instead of returningPeerNotFound,send_on_channelnow inserts a skeletonPeerInfo(empty addresses, no protocols) when the channel is missing fromself.peers. The send then proceeds through the existingis_connection_activeguard, which requires the channel to already be inactive_connections— an implicit assumption that holds becauseactive_connectionsis populated first in the same event handler.Cargo.toml/Cargo.lock: Bumpssaorsa-transportfrom the0.28crates.io release to thefeat-nat_traversal_attemptsbranch on a personal fork (jacderida/saorsa-transport). This should be updated to point to thesaorsa-labsorg repository or a versioned release before this lands inmain.entry().or_insert_with()idiom, leaving a small TOCTOU window where a racing event handler could insert a fullerPeerInfothat gets overwritten with the empty skeleton.Confidence Score: 4/5
Important Files Changed
Sequence Diagram
sequenceDiagram participant T as saorsa-transport participant EH as ConnectionEvent Handler participant AC as active_connections participant P as peers (TransportHandle) participant SC as send_on_channel T->>EH: ConnectionEvent::Established (hole-punch) EH->>AC: write().insert(channel_id) Note over EH,P: await point — another task can run here EH->>P: write().insert(PeerInfo { addresses, protocols, ... }) Note over SC: DHT response arrives before EH reaches peers.insert SC->>P: read().contains_key(channel_id) → false SC->>P: write().insert(PeerInfo { addresses: [], protocols: [] }) SC->>AC: is_connection_active? → true (already inserted above) SC->>T: send_to_peer_optimized(addr, data) ✓Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix: register unknown channels on the fl..." | Re-trigger Greptile