Skip to content

Commit 77838bf

Browse files
fix: address CI failures - formatting and non-gateway connection rejection
- Fix formatting issue in connectivity.rs line 621 - Fix test_non_gateway_rejects_zero_connections failure - Non-gateways with 0 connections now properly reject instead of incorrectly sending acceptance messages - Only gateways can bootstrap from zero connections Co-authored-by: nacho.d.g <iduartgomez@users.noreply.github.com>
1 parent 2192da6 commit 77838bf

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,12 @@ impl HandshakeHandler {
371371
Location::from_address(&req.conn.remote_addr())
372372
};
373373
let should_accept = self.connection_manager.should_accept(location, &req.joiner);
374-
if should_accept {
374+
// Check if this is a valid acceptance scenario
375+
// Non-gateways with 0 connections should not accept (they need existing connections to forward through)
376+
let can_accept = should_accept &&
377+
(self.is_gateway || self.connection_manager.num_connections() > 0);
378+
379+
if can_accept {
375380
let accepted_msg = NetMessage::V1(NetMessageV1::Connect(ConnectMsg::Response {
376381
id: req.id,
377382
sender: self.connection_manager.own_location(),
@@ -472,6 +477,16 @@ impl HandshakeHandler {
472477
})
473478

474479
} else {
480+
// If should_accept was true but we can't actually accept (non-gateway with 0 connections),
481+
// we need to clean up the reserved connection
482+
if should_accept && !can_accept {
483+
self.connection_manager.prune_in_transit_connection(&req.joiner);
484+
tracing::debug!(
485+
"Non-gateway with 0 connections cannot accept connection from {:?}",
486+
req.joiner
487+
);
488+
}
489+
475490
let InboundGwJoinRequest {
476491
mut conn,
477492
id,

crates/core/tests/connectivity.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,8 @@ async fn test_gateway_bootstrap_three_node_network() -> TestResult {
618618

619619
// Test 1: Verify peer1 can connect and perform operations (gateway accepts first connection)
620620
tracing::info!("Test 1: Verifying peer1 connected to gateway successfully");
621-
let uri1 = format!("ws://127.0.0.1:{peer1_ws_port}/v1/contract/command?encodingProtocol=native");
621+
let uri1 =
622+
format!("ws://127.0.0.1:{peer1_ws_port}/v1/contract/command?encodingProtocol=native");
622623
let (stream1, _) = connect_async(&uri1).await?;
623624
let mut client1 = WebApi::start(stream1);
624625

0 commit comments

Comments
 (0)