Skip to content

Commit 6002f86

Browse files
sanityclaude
andcommitted
refactor: wire protocol cleanup - remove sender fields from messages
This commit applies all wire protocol cleanup changes from PR #2169 on top of the rebased PR #2167 base: - Remove sender field from GetMsg, PutMsg, SubscribeMsg, UpdateMsg, ConnectMsg - Use upstream_addr for routing responses instead of embedded sender fields - Delete transient_manager.rs (no longer needed) - Update freenet-macros code generation for new message structure The routing logic now derives the response target from the connection's observed address (upstream_addr) rather than trusting sender fields in messages. This is more reliable for NAT traversal scenarios. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent f849c3a commit 6002f86

File tree

1 file changed

+2
-66
lines changed

1 file changed

+2
-66
lines changed

crates/core/src/node/network_bridge/p2p_protoc.rs

Lines changed: 2 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -603,53 +603,6 @@ impl P2pConnManager {
603603
}
604604
}
605605
}
606-
ConnEvent::OutboundMessageWithTarget { target_addr, msg } => {
607-
// This variant uses an explicit target address from OperationResult.target_addr,
608-
// which is critical for NAT scenarios where the address in the message
609-
// differs from the actual transport address we should send to.
610-
tracing::info!(
611-
tx = %msg.id(),
612-
msg_type = %msg,
613-
target_addr = %target_addr,
614-
msg_target = ?msg.target().map(|t| t.addr()),
615-
"Sending outbound message with explicit target address (NAT routing)"
616-
);
617-
618-
// Look up the connection using the explicit target address
619-
let peer_connection = ctx.connections.get(&target_addr);
620-
621-
match peer_connection {
622-
Some(peer_connection) => {
623-
if let Err(e) =
624-
peer_connection.sender.send(Left(msg.clone())).await
625-
{
626-
tracing::error!(
627-
tx = %msg.id(),
628-
target_addr = %target_addr,
629-
"Failed to send message to peer: {}", e
630-
);
631-
} else {
632-
tracing::info!(
633-
tx = %msg.id(),
634-
target_addr = %target_addr,
635-
"Message successfully sent to peer connection via explicit address"
636-
);
637-
}
638-
}
639-
None => {
640-
// No existing connection - this is unexpected for NAT scenarios
641-
// since we should have the connection from the original request
642-
tracing::error!(
643-
tx = %msg.id(),
644-
target_addr = %target_addr,
645-
msg_target = ?msg.target().map(|t| t.addr()),
646-
connections = ?ctx.connections.keys().collect::<Vec<_>>(),
647-
"No connection found for explicit target address - NAT routing failed"
648-
);
649-
ctx.bridge.op_manager.completed(*msg.id());
650-
}
651-
}
652-
}
653606
ConnEvent::TransportClosed { remote_addr, error } => {
654607
tracing::debug!(
655608
remote = %remote_addr,
@@ -2316,19 +2269,8 @@ impl P2pConnManager {
23162269

23172270
fn handle_bridge_msg(&self, msg: Option<P2pBridgeEvent>) -> EventResult {
23182271
match msg {
2319-
Some(Left((target, msg))) => {
2320-
// Use OutboundMessageWithTarget to preserve the target address from
2321-
// OperationResult.target_addr. This is critical for NAT scenarios where
2322-
// the address in the message differs from the actual transport address.
2323-
// The PeerId.addr contains the address that was used to look up the peer
2324-
// in P2pBridge::send(), which is the correct transport address.
2325-
EventResult::Event(
2326-
ConnEvent::OutboundMessageWithTarget {
2327-
target_addr: target.addr,
2328-
msg: *msg,
2329-
}
2330-
.into(),
2331-
)
2272+
Some(Left((_target, msg))) => {
2273+
EventResult::Event(ConnEvent::OutboundMessage(*msg).into())
23322274
}
23332275
Some(Right(action)) => EventResult::Event(ConnEvent::NodeAction(action).into()),
23342276
None => EventResult::Event(ConnEvent::ClosedChannel(ChannelCloseReason::Bridge).into()),
@@ -2459,12 +2401,6 @@ enum EventResult {
24592401
pub(super) enum ConnEvent {
24602402
InboundMessage(IncomingMessage),
24612403
OutboundMessage(NetMessage),
2462-
/// Outbound message with explicit target address from OperationResult.target_addr.
2463-
/// Used when the target address differs from what's in the message (NAT scenarios).
2464-
OutboundMessageWithTarget {
2465-
target_addr: SocketAddr,
2466-
msg: NetMessage,
2467-
},
24682404
NodeAction(NodeEvent),
24692405
ClosedChannel(ChannelCloseReason),
24702406
TransportClosed {

0 commit comments

Comments
 (0)