diff options
author | Alex Auvolat <alex@adnab.me> | 2021-10-22 15:20:07 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-10-22 15:20:07 +0200 |
commit | 9b64c27da68f7ac9049e02e26da918e871a63f07 (patch) | |
tree | 9887cbd4f485fd46f7c00df300ee3c9f222459c3 /src/peering/fullmesh.rs | |
parent | 57327f10e2536a89004f3a1def83ed16243c1a3e (diff) | |
download | netapp-9b64c27da68f7ac9049e02e26da918e871a63f07.tar.gz netapp-9b64c27da68f7ac9049e02e26da918e871a63f07.zip |
clippy & fmt
Diffstat (limited to 'src/peering/fullmesh.rs')
-rw-r--r-- | src/peering/fullmesh.rs | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/peering/fullmesh.rs b/src/peering/fullmesh.rs index 04318a3..cf10279 100644 --- a/src/peering/fullmesh.rs +++ b/src/peering/fullmesh.rs @@ -1,4 +1,4 @@ -use std::collections::{HashMap, VecDeque}; +use std::collections::{hash_map::Entry::Vacant, HashMap, VecDeque}; use std::net::SocketAddr; use std::sync::atomic::{self, AtomicU64}; use std::sync::{Arc, RwLock}; @@ -432,10 +432,8 @@ impl FullMeshPeeringStrategy { fn on_connected(self: Arc<Self>, id: NodeID, addr: SocketAddr, is_incoming: bool) { if is_incoming { let mut known_hosts = self.known_hosts.write().unwrap(); - if !known_hosts.list.contains_key(&id) { - known_hosts - .list - .insert(id, self.new_peer(&id, addr)); + if let Vacant(entry) = known_hosts.list.entry(id) { + entry.insert(self.new_peer(&id, addr)); known_hosts.update_hash(); self.update_public_peer_list(&known_hosts); } @@ -446,12 +444,15 @@ impl FullMeshPeeringStrategy { host.state = PeerConnState::Connected; host.addr = addr; } else { - known_hosts.list.insert(id, PeerInfoInternal{ - state: PeerConnState::Connected, - addr, - last_seen: None, - ping: VecDeque::new(), - }); + known_hosts.list.insert( + id, + PeerInfoInternal { + state: PeerConnState::Connected, + addr, + last_seen: None, + ping: VecDeque::new(), + }, + ); } known_hosts.update_hash(); self.update_public_peer_list(&known_hosts); |