Skip to content

Commit 2916606

Browse files
sanityclaude
andcommitted
fix: route connect messages through upstream for NAT relay
ObservedAddress and ConnectResponse messages must route through the upstream connection (source_addr) rather than directly to target addresses, since relay peers may not have direct connections to joiners. This mirrors the fix from PR #2171 that addressed the same NAT routing issue for different message types. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b428f92 commit 2916606

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

crates/core/src/operations/connect.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ impl Operation for ConnectOp {
886886
network_bridge: &'a mut NB,
887887
op_manager: &'a OpManager,
888888
msg: &'a Self::Message,
889-
_source_addr: Option<ObservedAddr>,
889+
source_addr: Option<ObservedAddr>,
890890
) -> std::pin::Pin<
891891
Box<dyn std::future::Future<Output = Result<OperationResult, OpError>> + Send + 'a>,
892892
> {
@@ -907,9 +907,16 @@ impl Operation for ConnectOp {
907907
target: target.clone(),
908908
address,
909909
};
910-
network_bridge
911-
.send(target.addr(), NetMessage::V1(NetMessageV1::Connect(msg)))
912-
.await?;
910+
// Route through upstream (where the request came from) since we may
911+
// not have a direct connection to the target
912+
if let Some(upstream) = &source_addr {
913+
network_bridge
914+
.send(
915+
upstream.socket_addr(),
916+
NetMessage::V1(NetMessageV1::Connect(msg)),
917+
)
918+
.await?;
919+
}
913920
}
914921

915922
if let Some(peer) = actions.expect_connection_from {
@@ -947,10 +954,17 @@ impl Operation for ConnectOp {
947954
target: response_target,
948955
payload: response,
949956
};
950-
return Ok(store_operation_state_with_msg(
951-
&mut self,
952-
Some(response_msg),
953-
));
957+
// Route the response through upstream (where the request came from)
958+
// since we may not have a direct connection to the joiner
959+
if let Some(upstream) = &source_addr {
960+
network_bridge
961+
.send(
962+
upstream.socket_addr(),
963+
NetMessage::V1(NetMessageV1::Connect(response_msg)),
964+
)
965+
.await?;
966+
}
967+
return Ok(store_operation_state(&mut self));
954968
}
955969

956970
Ok(store_operation_state(&mut self))

0 commit comments

Comments
 (0)