From cb64ddb3c811e175d774dc615e0d3d63ccddf944 Mon Sep 17 00:00:00 2001
From: Mahmoud Mazouz <hello@fuzzypixelz.com>
Date: Thu, 12 Sep 2024 12:24:32 +0200
Subject: [PATCH] Don't auto-connect to configured connect endpoints (#1396)

---
 zenoh/src/net/runtime/orchestrator.rs | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/zenoh/src/net/runtime/orchestrator.rs b/zenoh/src/net/runtime/orchestrator.rs
index fee4c86c1d..6bff4e75be 100644
--- a/zenoh/src/net/runtime/orchestrator.rs
+++ b/zenoh/src/net/runtime/orchestrator.rs
@@ -12,6 +12,7 @@
 //   ZettaScale Zenoh Team, <zenoh@zettascale.tech>
 //
 use std::{
+    collections::HashSet,
     net::{IpAddr, Ipv6Addr, SocketAddr},
     time::Duration,
 };
@@ -911,8 +912,23 @@ impl Runtime {
     }
 
     #[must_use]
-    async fn connect(&self, zid: &ZenohIdProto, locators: &[Locator]) -> bool {
-        const ERR: &str = "Unable to connect to newly scouted peer ";
+    async fn connect(&self, zid: &ZenohIdProto, scouted_locators: &[Locator]) -> bool {
+        const ERR: &str = "Unable to connect to newly scouted peer";
+
+        let configured_locators = self
+            .state
+            .config
+            .lock()
+            .connect()
+            .endpoints()
+            .get(self.whatami())
+            .iter()
+            .flat_map(|e| e.iter().map(EndPoint::to_locator))
+            .collect::<HashSet<_>>();
+
+        let locators = scouted_locators
+            .iter()
+            .filter(|l| !configured_locators.contains(l));
 
         let inspector = LocatorInspector::default();
         for locator in locators {
@@ -968,7 +984,7 @@ impl Runtime {
             tracing::warn!(
                 "Unable to connect to any locator of scouted peer {}: {:?}",
                 zid,
-                locators
+                scouted_locators
             );
         } else {
             tracing::trace!(