Skip to content

Commit

Permalink
*: Fix various clippy warnings (#2900)
Browse files Browse the repository at this point in the history
  • Loading branch information
umgefahren committed Sep 16, 2022
1 parent 2c739e9 commit c81b06a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 30 deletions.
19 changes: 8 additions & 11 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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),
Expand Down
18 changes: 2 additions & 16 deletions protocols/kad/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions protocols/mdns/src/behaviour/iface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {
Expand All @@ -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))?
}
};
Expand Down
2 changes: 1 addition & 1 deletion protocols/mdns/src/behaviour/iface/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ fn query_response_packet(id: u16, peer_id: &[u8], records: &[Vec<u8>], 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
}

Expand Down

0 comments on commit c81b06a

Please sign in to comment.