mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-29 02:31:20 +00:00
*: Fix various clippy warnings (#2900)
This commit is contained in:
parent
2c739e9bdb
commit
c81b06a9b2
@ -649,7 +649,7 @@ where
|
|||||||
set.iter()
|
set.iter()
|
||||||
.filter(|p| {
|
.filter(|p| {
|
||||||
self.explicit_peers.contains(*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(),
|
.cloned(),
|
||||||
);
|
);
|
||||||
@ -946,14 +946,11 @@ where
|
|||||||
);
|
);
|
||||||
|
|
||||||
// remove explicit peers, peers with negative scores, and backoffed peers
|
// remove explicit peers, peers with negative scores, and backoffed peers
|
||||||
peers = peers
|
peers.retain(|p| {
|
||||||
.into_iter()
|
!self.explicit_peers.contains(p)
|
||||||
.filter(|p| {
|
&& !self.score_below_threshold(p, |_| 0.0).0
|
||||||
!self.explicit_peers.contains(p)
|
&& !self.backoffs.is_backoff_with_slack(topic_hash, p)
|
||||||
&& !self.score_below_threshold(p, |_| 0.0).0
|
});
|
||||||
&& !self.backoffs.is_backoff_with_slack(topic_hash, p)
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
// Add up to mesh_n of them them to the mesh
|
// Add up to mesh_n of them them to the mesh
|
||||||
// NOTE: These aren't randomly added, currently FIFO
|
// 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
|
//TODO: Once signed records are spec'd: Can we use peerInfo without any IDs if they have a
|
||||||
// signed peer record?
|
// 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 {
|
if px.len() > n {
|
||||||
// only use at most prune_peers many random peers
|
// only use at most prune_peers many random peers
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
@ -3204,7 +3201,7 @@ where
|
|||||||
debug!("Peer disconnected: {}", peer_id);
|
debug!("Peer disconnected: {}", peer_id);
|
||||||
{
|
{
|
||||||
let topics = match self.peer_topics.get(peer_id) {
|
let topics = match self.peer_topics.get(peer_id) {
|
||||||
Some(topics) => (topics),
|
Some(topics) => topics,
|
||||||
None => {
|
None => {
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
self.blacklisted_peers.contains(peer_id),
|
self.blacklisted_peers.contains(peer_id),
|
||||||
|
@ -658,14 +658,7 @@ where
|
|||||||
let pos = self
|
let pos = self
|
||||||
.inbound_substreams
|
.inbound_substreams
|
||||||
.iter()
|
.iter()
|
||||||
.position(|state| match state {
|
.position(|state| matches!(state, InboundSubstreamState::WaitingUser(ref conn_id, _) if conn_id == &request_id.connec_unique_id));
|
||||||
InboundSubstreamState::WaitingUser(ref conn_id, _)
|
|
||||||
if conn_id == &request_id.connec_unique_id =>
|
|
||||||
{
|
|
||||||
true
|
|
||||||
}
|
|
||||||
_ => false,
|
|
||||||
});
|
|
||||||
|
|
||||||
if let Some(pos) = pos {
|
if let Some(pos) = pos {
|
||||||
let (conn_id, substream) = match self.inbound_substreams.remove(pos) {
|
let (conn_id, substream) = match self.inbound_substreams.remove(pos) {
|
||||||
@ -737,14 +730,7 @@ where
|
|||||||
let pos = self
|
let pos = self
|
||||||
.inbound_substreams
|
.inbound_substreams
|
||||||
.iter()
|
.iter()
|
||||||
.position(|state| match state {
|
.position(|state| matches!(state, InboundSubstreamState::WaitingUser(ref conn_id, _) if conn_id == &request_id.connec_unique_id));
|
||||||
InboundSubstreamState::WaitingUser(ref conn_id, _)
|
|
||||||
if conn_id == &request_id.connec_unique_id =>
|
|
||||||
{
|
|
||||||
true
|
|
||||||
}
|
|
||||||
_ => false,
|
|
||||||
});
|
|
||||||
|
|
||||||
if let Some(pos) = pos {
|
if let Some(pos) = pos {
|
||||||
let (conn_id, substream) = match self.inbound_substreams.remove(pos) {
|
let (conn_id, substream) = match self.inbound_substreams.remove(pos) {
|
||||||
|
@ -85,7 +85,7 @@ where
|
|||||||
socket.bind(&SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 5353).into())?;
|
socket.bind(&SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 5353).into())?;
|
||||||
socket.set_multicast_loop_v4(true)?;
|
socket.set_multicast_loop_v4(true)?;
|
||||||
socket.set_multicast_ttl_v4(255)?;
|
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))?
|
U::from_std(UdpSocket::from(socket))?
|
||||||
}
|
}
|
||||||
IpAddr::V6(_) => {
|
IpAddr::V6(_) => {
|
||||||
@ -96,7 +96,7 @@ where
|
|||||||
socket.bind(&SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), 5353).into())?;
|
socket.bind(&SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), 5353).into())?;
|
||||||
socket.set_multicast_loop_v6(true)?;
|
socket.set_multicast_loop_v6(true)?;
|
||||||
// TODO: find interface matching addr.
|
// 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))?
|
U::from_std(UdpSocket::from(socket))?
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -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 {
|
fn duration_to_secs(duration: Duration) -> u32 {
|
||||||
let secs = duration
|
let secs = duration
|
||||||
.as_secs()
|
.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
|
cmp::min(secs, From::from(u32::max_value())) as u32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user