refactor!: remove dead NatTraversalEndpoint hole-punch chain#41
Merged
Conversation
Deletes the unused duplicate connect_with_fallback on
NatTraversalEndpoint plus its supporting "PATH_CHALLENGE hole-punch"
chain (attempt_hole_punching, attempt_quic_hole_punching,
get_candidate_pairs_for_addr, calculate_candidate_pair_priority,
create_path_challenge_packet, store_successful_candidate_pair,
get_successful_candidate_address) and the orphaned
successful_candidates DashMap field.
The deleted code was reachable only from the duplicate
connect_with_fallback (also removed). The actual production hole-punch
path lives in P2pEndpoint::connect_with_fallback_inner, which is what
LinkTransport::dial_addr (link_transport_impl.rs) and the
saorsa-transport example bin both call. The duplicate had no in-tree
or downstream consumers — verified across this crate, saorsa-core,
and ant-node.
The deleted hole-punch implementation could not have worked even if
it had been wired in:
1. attempt_quic_hole_punching bound a fresh std::net::UdpSocket to
the local candidate address — always fails on a real node because
Quinn already owns the port (UDP binds are exclusive).
2. The "QUIC packet" it sent was a hand-rolled byte sequence
(0x40 [0,0,0,1] 0x1a <8 random>) that is not a valid encrypted
QUIC packet, so any receiving Quinn endpoint silently dropped it
during connection-id lookup.
3. The success branch then waited 100 ms blocking on recv_from for
a "response" no compliant peer would ever send.
The #[allow(dead_code)] markers on every function in the chain
disguised that nothing in the path could ever succeed, actively
misleading anyone debugging hole-punch issues via grep. Comment blocks
left in place point readers at the production path.
Also fixes a pre-existing nonminimal_bool clippy warning in the same
file (`!target_peer_id.is_some()` -> `target_peer_id.is_none()`) so the
file now passes `cargo clippy --lib -- -D warnings`. The fix is a
single character but is called out here so it isn't hidden inside the
bulk deletion.
The `!` indicates removal of a `pub fn`. No in-tree or downstream
consumer depended on it, but the public API surface is technically
narrower.
Verified:
cargo test --lib 1459/1459 passed (3 ignored, unchanged)
cargo clippy --lib -- -D warnings clean
rustfmt --edition 2024 --check clean
Downstream saorsa-core test suite still green
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Comment on lines
5651
to
5660
| info!( | ||
| "Sending PUNCH_ME_NOW coordination request for {} to coordinator {} (wire_id={}, from_peer_id={}, from_addr={})", | ||
| target_addr, coordinator, | ||
| target_addr, | ||
| coordinator, | ||
| hex::encode(&target_wire_id[..8]), | ||
| target_peer_id.map(|p| hex::encode(&p[..8])).unwrap_or_else(|| "none".to_string()), | ||
| !target_peer_id.is_some(), | ||
| target_peer_id | ||
| .map(|p| hex::encode(&p[..8])) | ||
| .unwrap_or_else(|| "none".to_string()), | ||
| target_peer_id.is_none(), | ||
| ); |
There was a problem hiding this comment.
Misleading
from_addr log label
The from_addr={} format slot receives target_peer_id.is_none() — a bool — so the log line always prints from_addr=true or from_addr=false rather than an actual address. This pre-existed the PR (!target_peer_id.is_some() had identical semantics), but since this line is touched by the clippy fix, it's a good opportunity to rename the label to match what is actually logged.
Suggested change
| info!( | |
| "Sending PUNCH_ME_NOW coordination request for {} to coordinator {} (wire_id={}, from_peer_id={}, from_addr={})", | |
| target_addr, coordinator, | |
| target_addr, | |
| coordinator, | |
| hex::encode(&target_wire_id[..8]), | |
| target_peer_id.map(|p| hex::encode(&p[..8])).unwrap_or_else(|| "none".to_string()), | |
| !target_peer_id.is_some(), | |
| target_peer_id | |
| .map(|p| hex::encode(&p[..8])) | |
| .unwrap_or_else(|| "none".to_string()), | |
| target_peer_id.is_none(), | |
| ); | |
| "Sending PUNCH_ME_NOW coordination request for {} to coordinator {} (wire_id={}, from_peer_id={}, peer_id_missing={})", |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/nat_traversal_api.rs
Line: 5651-5660
Comment:
**Misleading `from_addr` log label**
The `from_addr={}` format slot receives `target_peer_id.is_none()` — a `bool` — so the log line always prints `from_addr=true` or `from_addr=false` rather than an actual address. This pre-existed the PR (`!target_peer_id.is_some()` had identical semantics), but since this line is touched by the clippy fix, it's a good opportunity to rename the label to match what is actually logged.
```suggestion
"Sending PUNCH_ME_NOW coordination request for {} to coordinator {} (wire_id={}, from_peer_id={}, peer_id_missing={})",
```
How can I resolve this? If you propose a fix, please make it concise.Removes `pub struct CandidatePair` and `pub enum CandidatePairState` from `nat_traversal_api.rs`. They were only ever used by the dead hole-punch chain deleted in 5280123, and `connection/nat_traversal.rs` defines its own unrelated `pub(super) CandidatePair` for the live coordinator path. With the chain gone, both types are orphans in the public API surface. Also tightens the two tombstone comments — drops the box-drawing borders, fixes the misleading "implemented elsewhere in this file" phrasing (the production flow spans `p2p_endpoint.rs` and the PUNCH_ME_NOW helpers later in this file), and cross-links them. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Pre-existing formatting drift caught by `cargo fmt --all -- --check` on this branch but unrelated to the hole-punch chain removal: - `src/endpoint.rs:387` — collapse a `.as_ref().map(...)` chain that rustfmt now wants on one line. - `src/p2p_endpoint.rs:1822` — split a multi-arg `info!` so each positional argument sits on its own line. No semantic change. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
jacderida
approved these changes
Apr 6, 2026
mickvandijke
added a commit
that referenced
this pull request
Apr 6, 2026
PR #41 removed the dead `NatTraversalEndpoint::attempt_hole_punching` chain (`get_candidate_pairs_for_addr`, `calculate_candidate_pair_priority`, `attempt_quic_hole_punching`, `create_path_challenge_packet`, `store_successful_candidate_pair`, `get_successful_candidate_address`) as unreachable code gated behind `#[allow(dead_code)]` that could not have worked in production. PR #40 had added `CandidateSource::PortMapped` handling inside two of those exact functions (`is_local_side` in `get_candidate_pairs_for_addr` and a type-preference slot in `calculate_candidate_pair_priority`). Those additions patched dead code and are safely dropped — the live production pairing path in `P2pEndpoint::connect_with_fallback_inner` drives the coordinator-mediated PUNCH_ME_NOW flow and consumes priorities from `crate::connection::nat_traversal::calculate_candidate_priority`, which works off `CandidateType`, not `CandidateSource`. The mapping `CandidateSource::PortMapped -> CandidateType::ServerReflexive` in `classify_candidate_type` at `src/connection/nat_traversal.rs:307` (introduced by PR #40 and untouched by PR #41) is what carries the PortMapped variant through the production pairing formula. No further plumbing is required. Extended PR #41's tombstone comment with a note explaining why PortMapped needs no replacement pairing logic at this site, so the next person grepping for `PortMapped` in `nat_traversal_api.rs` lands on the explanation directly. Validation: - cargo fmt --all -- --check clean - cargo clippy --features upnp --all-targets -- -D warnings clean - cargo clippy --no-default-features --features platform-verifier,network-discovery --all-targets -- -D warnings clean - cargo nextest run --features upnp --lib: 1470/1470 passed Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
connect_with_fallbackonNatTraversalEndpointand its supporting "PATH_CHALLENGE hole-punch" chain (attempt_hole_punching,attempt_quic_hole_punching,get_candidate_pairs_for_addr,calculate_candidate_pair_priority,create_path_challenge_packet,store_successful_candidate_pair,get_successful_candidate_address) plus the orphanedsuccessful_candidatesDashMap field.connect_with_fallback(also removed). The production hole-punch path lives inP2pEndpoint::connect_with_fallback_inner, which is whatLinkTransport::dial_addrand thesaorsa-transportexample bin both call. Verified no in-tree or downstream consumers across this crate, saorsa-core, and ant-node.nonminimal_boolclippy warning in the same file (!target_peer_id.is_some()→target_peer_id.is_none()).Why this is dead code, not just unused
The deleted hole-punch implementation could not have worked even if it had been wired in:
attempt_quic_hole_punchingbound a freshstd::net::UdpSocketto the local candidate address — always fails on a real node because Quinn already owns the port (UDP binds are exclusive).0x40 [0,0,0,1] 0x1a <8 random>) that is not a valid encrypted QUIC packet, so any receiving Quinn endpoint silently dropped it during connection-id lookup.recv_fromfor a "response" no compliant peer would ever send.The
#[allow(dead_code)]markers on every function in the chain disguised that nothing in the path could ever succeed, actively misleading anyone debugging hole-punch issues via grep. Comment blocks left in place point readers at the production path.Breaking change
The
!indicates removal of apub fn. No in-tree or downstream consumer depended on it, but the public API surface is technically narrower.Test plan
cargo test --lib— 1459/1459 passed (3 ignored, unchanged)cargo clippy --lib -- -D warnings— cleanrustfmt --edition 2024 --check— clean🤖 Generated with Claude Code
Greptile Summary
Removes an unreachable
NatTraversalEndpoint::connect_with_fallbackduplicate and its seven supporting helper functions (plus the orphanedsuccessful_candidatesDashMap field) that were gated behind#[allow(dead_code)]and could not have worked — the innerUdpSocketbind races Quinn for the port, and the hand-rolled byte sequence is not a valid QUIC packet. The production hole-punch path inP2pEndpoint::connect_with_fallback_inneris untouched. All call-site verification confirms no in-tree consumer used the removed API.Confidence Score: 5/5
Safe to merge — removes provably unreachable code with no in-tree callsites and adds tombstone comments.
All changed code is dead-code removal confirmed by grepping every call site. The single P2 finding (misleading log label touched by the clippy fix) does not affect correctness or runtime behaviour.
No files require special attention.
Important Files Changed
successful_candidatesfield; adds tombstone comments; fixes a clippynonminimal_boolwarning.Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[dial_addr / saorsa-transport bin] --> B[P2pEndpoint::connect_with_fallback] B --> C[P2pEndpoint::connect_with_fallback_inner] C --> D[PUNCH_ME_NOW coordinator flow] D --> E[Hole-punch attempt] E --> F[Connection established] G[NatTraversalEndpoint::connect_with_fallback REMOVED] G -.->|deleted chain| H[attempt_hole_punching attempt_quic_hole_punching get_candidate_pairs_for_addr create_path_challenge_packet store_successful_candidate_pair ALL REMOVED] style G fill:#f99,stroke:#c33 style H fill:#f99,stroke:#c33Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "refactor!: remove dead NatTraversalEndpo..." | Re-trigger Greptile