-
-
Notifications
You must be signed in to change notification settings - Fork 107
fix: use upstream_addr for subscribe operation NAT routing #2171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sanity
merged 16 commits into
refactor/wire-protocol-cleanup-2164
from
fix/subscribe-nat-routing-2164
Dec 2, 2025
+124
−49
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
edd79da
ci: trigger workflow
sanity 1b6e365
ci: trigger workflow
sanity fba6604
ci: trigger workflow
sanity ed5586f
refactor(ring): restructure PeerKeyLocation to separate identity from…
sanity 104a03f
ci: trigger workflow
sanity 3f9a6f3
refactor: wire protocol cleanup - remove sender fields from messages
sanity 522a964
refactor: migrate PeerKeyLocation field accesses to use new methods
sanity 3d473ed
refactor(ring): restructure PeerKeyLocation to separate identity from…
sanity 4aae58d
refactor: use ObservedAddr newtype for source_addr throughout
sanity 2e57361
ci: trigger workflow
sanity 0ef40bc
fix: resolve post-rebase compilation errors
sanity 76d75c6
refactor: wire protocol cleanup - remove sender fields from messages
sanity 7f6ad28
fix: use upstream_addr for subscribe operation NAT routing
sanity 31a6d9a
fix: route connect responses through upstream_addr
sanity 74f4e77
fix: handle Unknown addresses in get.rs to avoid panics
sanity d1bf045
fix: resolve compilation errors after rebase
sanity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -603,6 +603,53 @@ impl P2pConnManager { | |
| } | ||
| } | ||
| } | ||
| ConnEvent::OutboundMessageWithTarget { target_addr, msg } => { | ||
| // This variant uses an explicit target address from OperationResult.target_addr, | ||
| // which is critical for NAT scenarios where the address in the message | ||
| // differs from the actual transport address we should send to. | ||
| tracing::info!( | ||
| tx = %msg.id(), | ||
| msg_type = %msg, | ||
| target_addr = %target_addr, | ||
| msg_target = ?msg.target().map(|t| t.addr()), | ||
| "Sending outbound message with explicit target address (NAT routing)" | ||
| ); | ||
|
|
||
| // Look up the connection using the explicit target address | ||
| let peer_connection = ctx.connections.get(&target_addr); | ||
|
|
||
| match peer_connection { | ||
| Some(peer_connection) => { | ||
| if let Err(e) = | ||
| peer_connection.sender.send(Left(msg.clone())).await | ||
| { | ||
| tracing::error!( | ||
| tx = %msg.id(), | ||
| target_addr = %target_addr, | ||
| "Failed to send message to peer: {}", e | ||
| ); | ||
| } else { | ||
| tracing::info!( | ||
| tx = %msg.id(), | ||
| target_addr = %target_addr, | ||
| "Message successfully sent to peer connection via explicit address" | ||
| ); | ||
| } | ||
| } | ||
| None => { | ||
| // No existing connection - this is unexpected for NAT scenarios | ||
| // since we should have the connection from the original request | ||
| tracing::error!( | ||
| tx = %msg.id(), | ||
| target_addr = %target_addr, | ||
| msg_target = ?msg.target().map(|t| t.addr()), | ||
| connections = ?ctx.connections.keys().collect::<Vec<_>>(), | ||
| "No connection found for explicit target address - NAT routing failed" | ||
| ); | ||
| ctx.bridge.op_manager.completed(*msg.id()); | ||
| } | ||
| } | ||
| } | ||
| ConnEvent::TransportClosed { remote_addr, error } => { | ||
| tracing::debug!( | ||
| remote = %remote_addr, | ||
|
|
@@ -2266,8 +2313,19 @@ impl P2pConnManager { | |
|
|
||
| fn handle_bridge_msg(&self, msg: Option<P2pBridgeEvent>) -> EventResult { | ||
| match msg { | ||
| Some(Left((_target, msg))) => { | ||
| EventResult::Event(ConnEvent::OutboundMessage(*msg).into()) | ||
| Some(Left((target, msg))) => { | ||
| // Use OutboundMessageWithTarget to preserve the target address from | ||
| // OperationResult.target_addr. This is critical for NAT scenarios where | ||
| // the address in the message differs from the actual transport address. | ||
| // The PeerId.addr contains the address that was used to look up the peer | ||
| // in P2pBridge::send(), which is the correct transport address. | ||
| EventResult::Event( | ||
| ConnEvent::OutboundMessageWithTarget { | ||
| target_addr: target.addr, | ||
| msg: *msg, | ||
| } | ||
| .into(), | ||
| ) | ||
| } | ||
| Some(Right(action)) => EventResult::Event(ConnEvent::NodeAction(action).into()), | ||
| None => EventResult::Event(ConnEvent::ClosedChannel(ChannelCloseReason::Bridge).into()), | ||
|
|
@@ -2398,6 +2456,12 @@ enum EventResult { | |
| pub(super) enum ConnEvent { | ||
| InboundMessage(IncomingMessage), | ||
| OutboundMessage(NetMessage), | ||
| /// Outbound message with explicit target address from OperationResult.target_addr. | ||
| /// Used when the target address differs from what's in the message (NAT scenarios). | ||
| OutboundMessageWithTarget { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we were doing things correctly this variant wouldn't be needed cause we wouldn't be ever leaking out the internal address to other peers. |
||
| target_addr: SocketAddr, | ||
| msg: NetMessage, | ||
| }, | ||
| NodeAction(NodeEvent), | ||
| ClosedChannel(ChannelCloseReason), | ||
| TransportClosed { | ||
|
|
||
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when would that happen?