diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 954c68ae..21dd7756 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -649,7 +649,7 @@ where set.iter() .filter(|p| { self.explicit_peers.contains(*p) - || !self.score_below_threshold(*p, |ts| ts.publish_threshold).0 + || !self.score_below_threshold(p, |ts| ts.publish_threshold).0 }) .cloned(), ); @@ -946,14 +946,11 @@ where ); // remove explicit peers, peers with negative scores, and backoffed peers - peers = peers - .into_iter() - .filter(|p| { - !self.explicit_peers.contains(p) - && !self.score_below_threshold(p, |_| 0.0).0 - && !self.backoffs.is_backoff_with_slack(topic_hash, p) - }) - .collect(); + peers.retain(|p| { + !self.explicit_peers.contains(p) + && !self.score_below_threshold(p, |_| 0.0).0 + && !self.backoffs.is_backoff_with_slack(topic_hash, p) + }); // Add up to mesh_n of them them to the mesh // NOTE: These aren't randomly added, currently FIFO @@ -1625,7 +1622,7 @@ where // //TODO: Once signed records are spec'd: Can we use peerInfo without any IDs if they have a // signed peer record? - px = px.into_iter().filter(|p| p.peer_id.is_some()).collect(); + px.retain(|p| p.peer_id.is_some()); if px.len() > n { // only use at most prune_peers many random peers let mut rng = thread_rng(); @@ -3204,7 +3201,7 @@ where debug!("Peer disconnected: {}", peer_id); { let topics = match self.peer_topics.get(peer_id) { - Some(topics) => (topics), + Some(topics) => topics, None => { debug_assert!( self.blacklisted_peers.contains(peer_id), diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index bcadb57f..5be9ae17 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -658,14 +658,7 @@ where let pos = self .inbound_substreams .iter() - .position(|state| match state { - InboundSubstreamState::WaitingUser(ref conn_id, _) - if conn_id == &request_id.connec_unique_id => - { - true - } - _ => false, - }); + .position(|state| matches!(state, InboundSubstreamState::WaitingUser(ref conn_id, _) if conn_id == &request_id.connec_unique_id)); if let Some(pos) = pos { let (conn_id, substream) = match self.inbound_substreams.remove(pos) { @@ -737,14 +730,7 @@ where let pos = self .inbound_substreams .iter() - .position(|state| match state { - InboundSubstreamState::WaitingUser(ref conn_id, _) - if conn_id == &request_id.connec_unique_id => - { - true - } - _ => false, - }); + .position(|state| matches!(state, InboundSubstreamState::WaitingUser(ref conn_id, _) if conn_id == &request_id.connec_unique_id)); if let Some(pos) = pos { let (conn_id, substream) = match self.inbound_substreams.remove(pos) { diff --git a/protocols/mdns/src/behaviour/iface.rs b/protocols/mdns/src/behaviour/iface.rs index c5bacced..b2d0506b 100644 --- a/protocols/mdns/src/behaviour/iface.rs +++ b/protocols/mdns/src/behaviour/iface.rs @@ -85,7 +85,7 @@ where socket.bind(&SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 5353).into())?; socket.set_multicast_loop_v4(true)?; socket.set_multicast_ttl_v4(255)?; - socket.join_multicast_v4(&*crate::IPV4_MDNS_MULTICAST_ADDRESS, &addr)?; + socket.join_multicast_v4(&crate::IPV4_MDNS_MULTICAST_ADDRESS, &addr)?; U::from_std(UdpSocket::from(socket))? } IpAddr::V6(_) => { @@ -96,7 +96,7 @@ where socket.bind(&SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), 5353).into())?; socket.set_multicast_loop_v6(true)?; // TODO: find interface matching addr. - socket.join_multicast_v6(&*crate::IPV6_MDNS_MULTICAST_ADDRESS, 0)?; + socket.join_multicast_v6(&crate::IPV6_MDNS_MULTICAST_ADDRESS, 0)?; U::from_std(UdpSocket::from(socket))? } }; diff --git a/protocols/mdns/src/behaviour/iface/dns.rs b/protocols/mdns/src/behaviour/iface/dns.rs index 5bb190f4..4590e1e2 100644 --- a/protocols/mdns/src/behaviour/iface/dns.rs +++ b/protocols/mdns/src/behaviour/iface/dns.rs @@ -246,7 +246,7 @@ fn query_response_packet(id: u16, peer_id: &[u8], records: &[Vec], ttl: u32) fn duration_to_secs(duration: Duration) -> u32 { let secs = duration .as_secs() - .saturating_add(if duration.subsec_nanos() > 0 { 1 } else { 0 }); + .saturating_add(u64::from(duration.subsec_nanos() > 0)); cmp::min(secs, From::from(u32::max_value())) as u32 }