Rewrite because clippy didn't understand drop

This commit is contained in:
Alex 2021-10-12 13:44:42 +02:00
parent 50806b54b7
commit b14515a422
No known key found for this signature in database
GPG key ID: EDABF9711E244EB1

View file

@ -187,32 +187,34 @@ impl FullMeshPeeringStrategy {
pub async fn run(self: Arc<Self>) { pub async fn run(self: Arc<Self>) {
loop { loop {
// 1. Read current state: get list of connected peers (ping them) // 1. Read current state: get list of connected peers (ping them)
let known_hosts = self.known_hosts.read().unwrap(); let (to_ping, to_retry) = {
debug!("known_hosts: {} peers", known_hosts.list.len()); let known_hosts = self.known_hosts.read().unwrap();
debug!("known_hosts: {} peers", known_hosts.list.len());
let mut to_ping = vec![]; let mut to_ping = vec![];
let mut to_retry = vec![]; let mut to_retry = vec![];
for (id, info) in known_hosts.list.iter() { for (id, info) in known_hosts.list.iter() {
debug!("{}, {:?}", hex::encode(id), info); debug!("{}, {:?}", hex::encode(id), info);
match info.state { match info.state {
PeerConnState::Connected => { PeerConnState::Connected => {
let must_ping = match info.last_seen { let must_ping = match info.last_seen {
None => true, None => true,
Some(t) => Instant::now() - t > PING_INTERVAL, Some(t) => Instant::now() - t > PING_INTERVAL,
}; };
if must_ping { if must_ping {
to_ping.push(*id); to_ping.push(*id);
}
} }
} PeerConnState::Waiting(_, t) => {
PeerConnState::Waiting(_, t) => { if Instant::now() >= t {
if Instant::now() >= t { to_retry.push(*id);
to_retry.push(*id); }
} }
_ => (),
} }
_ => (),
} }
} (to_ping, to_retry)
drop(known_hosts); };
// 2. Dispatch ping to hosts // 2. Dispatch ping to hosts
trace!("to_ping: {} peers", to_retry.len()); trace!("to_ping: {} peers", to_retry.len());