diff options
author | Alex Auvolat <alex@adnab.me> | 2021-10-12 13:44:42 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-10-12 13:44:42 +0200 |
commit | b14515a422a04fa008e6c67f6465ead927c7b8ad (patch) | |
tree | a87e7c3ca8f28703fe714a6d700b0d0d95f82d85 /src/peering/fullmesh.rs | |
parent | 50806b54b715a1d4450d037191c6cc812edb8e59 (diff) | |
download | netapp-b14515a422a04fa008e6c67f6465ead927c7b8ad.tar.gz netapp-b14515a422a04fa008e6c67f6465ead927c7b8ad.zip |
Rewrite because clippy didn't understand drop
Diffstat (limited to 'src/peering/fullmesh.rs')
-rw-r--r-- | src/peering/fullmesh.rs | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/src/peering/fullmesh.rs b/src/peering/fullmesh.rs index b0bbe45..8b1c802 100644 --- a/src/peering/fullmesh.rs +++ b/src/peering/fullmesh.rs @@ -187,32 +187,34 @@ impl FullMeshPeeringStrategy { pub async fn run(self: Arc<Self>) { loop { // 1. Read current state: get list of connected peers (ping them) - let known_hosts = self.known_hosts.read().unwrap(); - debug!("known_hosts: {} peers", known_hosts.list.len()); - - let mut to_ping = vec![]; - let mut to_retry = vec![]; - for (id, info) in known_hosts.list.iter() { - debug!("{}, {:?}", hex::encode(id), info); - match info.state { - PeerConnState::Connected => { - let must_ping = match info.last_seen { - None => true, - Some(t) => Instant::now() - t > PING_INTERVAL, - }; - if must_ping { - to_ping.push(*id); + let (to_ping, to_retry) = { + let known_hosts = self.known_hosts.read().unwrap(); + debug!("known_hosts: {} peers", known_hosts.list.len()); + + let mut to_ping = vec![]; + let mut to_retry = vec![]; + for (id, info) in known_hosts.list.iter() { + debug!("{}, {:?}", hex::encode(id), info); + match info.state { + PeerConnState::Connected => { + let must_ping = match info.last_seen { + None => true, + Some(t) => Instant::now() - t > PING_INTERVAL, + }; + if must_ping { + to_ping.push(*id); + } } - } - PeerConnState::Waiting(_, t) => { - if Instant::now() >= t { - to_retry.push(*id); + PeerConnState::Waiting(_, t) => { + if Instant::now() >= t { + to_retry.push(*id); + } } + _ => (), } - _ => (), } - } - drop(known_hosts); + (to_ping, to_retry) + }; // 2. Dispatch ping to hosts trace!("to_ping: {} peers", to_retry.len()); |