mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-13 01:51:23 +00:00
*: Fix newly raised clippy warnings (#3106)
Fixed minor issues raised by clippy to improve correctness and readablitity.
This commit is contained in:
@ -1265,9 +1265,9 @@ where
|
||||
// Ask in random order
|
||||
let mut iwant_ids_vec: Vec<_> = iwant_ids.into_iter().collect();
|
||||
let mut rng = thread_rng();
|
||||
iwant_ids_vec.partial_shuffle(&mut rng, iask as usize);
|
||||
iwant_ids_vec.partial_shuffle(&mut rng, iask);
|
||||
|
||||
iwant_ids_vec.truncate(iask as usize);
|
||||
iwant_ids_vec.truncate(iask);
|
||||
*iasked += iask;
|
||||
|
||||
for message_id in &iwant_ids_vec {
|
||||
|
@ -253,7 +253,7 @@ impl PeerScore {
|
||||
|
||||
// P2: first message deliveries
|
||||
let p2 = {
|
||||
let v = topic_stats.first_message_deliveries as f64;
|
||||
let v = topic_stats.first_message_deliveries;
|
||||
if v < topic_params.first_message_deliveries_cap {
|
||||
v
|
||||
} else {
|
||||
|
@ -890,7 +890,7 @@ fn test_score_ip_colocation() {
|
||||
let n_shared = 3.0;
|
||||
let ip_surplus = n_shared - ip_colocation_factor_threshold;
|
||||
let penalty = ip_surplus * ip_surplus;
|
||||
let expected = ip_colocation_factor_weight * penalty as f64;
|
||||
let expected = ip_colocation_factor_weight * penalty;
|
||||
|
||||
assert_eq!(score_b, expected, "Peer B should have expected score");
|
||||
assert_eq!(score_c, expected, "Peer C should have expected score");
|
||||
|
@ -50,7 +50,7 @@ pub trait TopicSubscriptionFilter {
|
||||
}
|
||||
}
|
||||
self.filter_incoming_subscription_set(
|
||||
filtered_subscriptions.into_iter().map(|(_, v)| v).collect(),
|
||||
filtered_subscriptions.into_values().collect(),
|
||||
currently_subscribed_topics,
|
||||
)
|
||||
}
|
||||
|
@ -94,14 +94,14 @@ impl<T> From<Key<T>> for KeyBytes {
|
||||
|
||||
impl From<Multihash> for Key<Multihash> {
|
||||
fn from(m: Multihash) -> Self {
|
||||
let bytes = KeyBytes(Sha256::digest(&m.to_bytes()));
|
||||
let bytes = KeyBytes(Sha256::digest(m.to_bytes()));
|
||||
Key { preimage: m, bytes }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PeerId> for Key<PeerId> {
|
||||
fn from(p: PeerId) -> Self {
|
||||
let bytes = KeyBytes(Sha256::digest(&p.to_bytes()));
|
||||
let bytes = KeyBytes(Sha256::digest(p.to_bytes()));
|
||||
Key { preimage: p, bytes }
|
||||
}
|
||||
}
|
||||
|
@ -732,9 +732,7 @@ mod tests {
|
||||
|
||||
impl std::fmt::Debug for Graph {
|
||||
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
fmt.debug_list()
|
||||
.entries(self.0.iter().map(|(id, _)| id))
|
||||
.finish()
|
||||
fmt.debug_list().entries(self.0.keys()).finish()
|
||||
}
|
||||
}
|
||||
|
||||
@ -796,8 +794,8 @@ mod tests {
|
||||
fn get_closest_peer(&self, target: &KeyBytes) -> PeerId {
|
||||
*self
|
||||
.0
|
||||
.iter()
|
||||
.map(|(peer_id, _)| (target.distance(&Key::from(*peer_id)), peer_id))
|
||||
.keys()
|
||||
.map(|peer_id| (target.distance(&Key::from(*peer_id)), peer_id))
|
||||
.fold(None, |acc, (distance_b, peer_id_b)| match acc {
|
||||
None => Some((distance_b, peer_id_b)),
|
||||
Some((distance_a, peer_id_a)) => {
|
||||
|
@ -298,8 +298,8 @@ impl NetworkBehaviour for Relay {
|
||||
// Deny if it exceeds `max_reservations`.
|
||||
|| self
|
||||
.reservations
|
||||
.iter()
|
||||
.map(|(_, cs)| cs.len())
|
||||
.values()
|
||||
.map(|cs| cs.len())
|
||||
.sum::<usize>()
|
||||
>= self.config.max_reservations
|
||||
// Deny if it exceeds the allowed rate of reservations.
|
||||
|
@ -310,7 +310,7 @@ fn handle_outbound_event(
|
||||
expiring_registrations.extend(registrations.iter().cloned().map(|registration| {
|
||||
async move {
|
||||
// if the timer errors we consider it expired
|
||||
futures_timer::Delay::new(Duration::from_secs(registration.ttl as u64)).await;
|
||||
futures_timer::Delay::new(Duration::from_secs(registration.ttl)).await;
|
||||
|
||||
(registration.record.peer_id(), registration.namespace)
|
||||
}
|
||||
|
@ -381,7 +381,7 @@ impl Registrations {
|
||||
self.registrations
|
||||
.insert(registration_id, registration.clone());
|
||||
|
||||
let next_expiry = futures_timer::Delay::new(Duration::from_secs(ttl as u64))
|
||||
let next_expiry = futures_timer::Delay::new(Duration::from_secs(ttl))
|
||||
.map(move |_| registration_id)
|
||||
.boxed();
|
||||
|
||||
|
Reference in New Issue
Block a user