From df405712f67d0c73b98b3ce38408186254f1f8a9 Mon Sep 17 00:00:00 2001 From: OlivierHecart Date: Thu, 26 Sep 2024 21:38:18 +0200 Subject: [PATCH 1/4] connect_peers returns false if not connected to avoid wrong start_contitions notif --- zenoh/src/net/routing/hat/p2p_peer/gossip.rs | 2 +- zenoh/src/net/runtime/orchestrator.rs | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/zenoh/src/net/routing/hat/p2p_peer/gossip.rs b/zenoh/src/net/routing/hat/p2p_peer/gossip.rs index b3216c6b8c..d69eb74cc7 100644 --- a/zenoh/src/net/routing/hat/p2p_peer/gossip.rs +++ b/zenoh/src/net/routing/hat/p2p_peer/gossip.rs @@ -427,8 +427,8 @@ impl Network { .get_transport_unicast(&zid) .await .is_none() + && runtime.connect_peer(&zid, &locators).await { - runtime.connect_peer(&zid, &locators).await; runtime .start_conditions() .terminate_peer_connector_zid(zid) diff --git a/zenoh/src/net/runtime/orchestrator.rs b/zenoh/src/net/runtime/orchestrator.rs index faadf5eb5c..2f0a54ea71 100644 --- a/zenoh/src/net/runtime/orchestrator.rs +++ b/zenoh/src/net/runtime/orchestrator.rs @@ -1024,7 +1024,7 @@ impl Runtime { } } - pub async fn connect_peer(&self, zid: &ZenohIdProto, locators: &[Locator]) { + pub async fn connect_peer(&self, zid: &ZenohIdProto, locators: &[Locator]) -> bool { let manager = self.manager(); if zid != &manager.zid() { let has_unicast = manager.get_transport_unicast(zid).await.is_some(); @@ -1042,10 +1042,13 @@ impl Runtime { if !has_unicast && !has_multicast { tracing::debug!("Try to connect to peer {} via any of {:?}", zid, locators); - let _ = self.connect(zid, locators).await; + self.connect(zid, locators).await } else { tracing::trace!("Already connected scouted peer: {}", zid); + true } + } else { + true } } @@ -1089,7 +1092,7 @@ impl Runtime { ) { Runtime::scout(ucast_sockets, what, addr, move |hello| async move { if !hello.locators.is_empty() { - self.connect_peer(&hello.zid, &hello.locators).await + self.connect_peer(&hello.zid, &hello.locators).await; } else { tracing::warn!("Received Hello with no locators: {:?}", hello); } From 24149efac81bfe587eb73ea704c515e506d8755f Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Fri, 27 Sep 2024 09:30:39 +0000 Subject: [PATCH 2/4] Document `connect` and `connect_peer` --- zenoh/src/net/runtime/orchestrator.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zenoh/src/net/runtime/orchestrator.rs b/zenoh/src/net/runtime/orchestrator.rs index 2f0a54ea71..d3e234c038 100644 --- a/zenoh/src/net/runtime/orchestrator.rs +++ b/zenoh/src/net/runtime/orchestrator.rs @@ -911,7 +911,7 @@ impl Runtime { } } - /// Returns `true` if a new Transport instance has been opened with `zid`. + /// Returns `true` if a new Transport instance exists between us and `zid`. #[must_use] async fn connect(&self, zid: &ZenohIdProto, scouted_locators: &[Locator]) -> bool { if !self.insert_pending_connection(*zid).await { @@ -1024,6 +1024,7 @@ impl Runtime { } } + /// Returns `true` if a new Transport instance exists between us and `zid`. pub async fn connect_peer(&self, zid: &ZenohIdProto, locators: &[Locator]) -> bool { let manager = self.manager(); if zid != &manager.zid() { From d907eadc4c326866ba9c66eae70a7e0148e58089 Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Fri, 27 Sep 2024 09:42:38 +0000 Subject: [PATCH 3/4] Clarify comments --- zenoh/src/net/runtime/orchestrator.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zenoh/src/net/runtime/orchestrator.rs b/zenoh/src/net/runtime/orchestrator.rs index d3e234c038..1a3ada13c5 100644 --- a/zenoh/src/net/runtime/orchestrator.rs +++ b/zenoh/src/net/runtime/orchestrator.rs @@ -911,7 +911,7 @@ impl Runtime { } } - /// Returns `true` if a new Transport instance exists between us and `zid`. + /// Returns `true` if a new Transport instance is established between us and `zid` or had already been established. #[must_use] async fn connect(&self, zid: &ZenohIdProto, scouted_locators: &[Locator]) -> bool { if !self.insert_pending_connection(*zid).await { @@ -1024,7 +1024,7 @@ impl Runtime { } } - /// Returns `true` if a new Transport instance exists between us and `zid`. + /// Returns `true` if a new Transport instance is established between us and `zid` or had already been established. pub async fn connect_peer(&self, zid: &ZenohIdProto, locators: &[Locator]) -> bool { let manager = self.manager(); if zid != &manager.zid() { From 0301cdc8b24ba94343c63d45d5e0c03edf156f63 Mon Sep 17 00:00:00 2001 From: OlivierHecart Date: Fri, 27 Sep 2024 11:51:59 +0200 Subject: [PATCH 4/4] Update comments --- zenoh/src/net/runtime/orchestrator.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zenoh/src/net/runtime/orchestrator.rs b/zenoh/src/net/runtime/orchestrator.rs index 1a3ada13c5..c95f47a970 100644 --- a/zenoh/src/net/runtime/orchestrator.rs +++ b/zenoh/src/net/runtime/orchestrator.rs @@ -911,7 +911,7 @@ impl Runtime { } } - /// Returns `true` if a new Transport instance is established between us and `zid` or had already been established. + /// Returns `true` if a new Transport instance is established with `zid` or had already been established. #[must_use] async fn connect(&self, zid: &ZenohIdProto, scouted_locators: &[Locator]) -> bool { if !self.insert_pending_connection(*zid).await { @@ -1024,7 +1024,7 @@ impl Runtime { } } - /// Returns `true` if a new Transport instance is established between us and `zid` or had already been established. + /// Returns `true` if a new Transport instance is established with `zid` or had already been established. pub async fn connect_peer(&self, zid: &ZenohIdProto, locators: &[Locator]) -> bool { let manager = self.manager(); if zid != &manager.zid() {