Skip to content

Commit

Permalink
Sleep for scouting/delay in router and linkstate peer modes
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierHecart committed May 14, 2024
1 parent ad0362c commit 70b9cb7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions zenoh/src/net/runtime/orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl Runtime {
}

async fn start_peer(&self) -> ZResult<()> {
let (listeners, peers, scouting, listen, autoconnect, addr, ifaces, delay) = {
let (listeners, peers, scouting, listen, autoconnect, addr, ifaces, delay, linkstate) = {
let guard = &self.state.config.lock();
let listeners = if guard.listen().endpoints().is_empty() {
let endpoint: EndPoint = PEER_DEFAULT_LISTENER.parse().unwrap();
Expand Down Expand Up @@ -194,6 +194,7 @@ impl Runtime {
unwrap_or_default!(guard.scouting().multicast().address()),
unwrap_or_default!(guard.scouting().multicast().interface()),
Duration::from_millis(unwrap_or_default!(guard.scouting().delay())),
unwrap_or_default!(guard.routing().peer().mode()) == *"linkstate",
)
};

Expand All @@ -205,7 +206,9 @@ impl Runtime {
self.start_scout(listen, autoconnect, addr, ifaces).await?;
}

if (scouting || !peers.is_empty())
if linkstate {
tokio::time::sleep(delay).await;
} else if (scouting || !peers.is_empty())
&& tokio::time::timeout(delay, self.state.start_conditions.notified())
.await
.is_err()
Expand All @@ -217,7 +220,7 @@ impl Runtime {
}

async fn start_router(&self) -> ZResult<()> {
let (listeners, peers, scouting, listen, autoconnect, addr, ifaces) = {
let (listeners, peers, scouting, listen, autoconnect, addr, ifaces, delay) = {
let guard = self.state.config.lock();
let listeners = if guard.listen().endpoints().is_empty() {
let endpoint: EndPoint = ROUTER_DEFAULT_LISTENER.parse().unwrap();
Expand Down Expand Up @@ -245,6 +248,7 @@ impl Runtime {
*unwrap_or_default!(guard.scouting().multicast().autoconnect().router()),
unwrap_or_default!(guard.scouting().multicast().address()),
unwrap_or_default!(guard.scouting().multicast().interface()),
Duration::from_millis(unwrap_or_default!(guard.scouting().delay())),
)
};

Expand All @@ -256,6 +260,7 @@ impl Runtime {
self.start_scout(listen, autoconnect, addr, ifaces).await?;
}

tokio::time::sleep(delay).await;
Ok(())
}

Expand Down

0 comments on commit 70b9cb7

Please sign in to comment.