diff --git a/core/src/identity/ecdsa.rs b/core/src/identity/ecdsa.rs index 88411b23..4accdde2 100644 --- a/core/src/identity/ecdsa.rs +++ b/core/src/identity/ecdsa.rs @@ -209,7 +209,7 @@ impl PublicKey { } let key_len = bitstr_head[1].checked_sub(1)? as usize; - let key_buf = asn1_buf.get(4 + oids_len + 3..4 + oids_len + 3 + key_len as usize)?; + let key_buf = asn1_buf.get(4 + oids_len + 3..4 + oids_len + 3 + key_len)?; Some(key_buf) } } diff --git a/examples/chat-tokio.rs b/examples/chat-tokio.rs index d2e5b63a..6bd77bd1 100644 --- a/examples/chat-tokio.rs +++ b/examples/chat-tokio.rs @@ -53,7 +53,7 @@ async fn main() -> Result<(), Box> { // Create a random PeerId let id_keys = identity::Keypair::generate_ed25519(); let peer_id = PeerId::from(id_keys.public()); - println!("Local peer id: {:?}", peer_id); + println!("Local peer id: {peer_id:?}"); // Create a tokio-based TCP transport use noise for authenticated // encryption and Mplex for multiplexing of substreams on a TCP stream. @@ -119,7 +119,7 @@ async fn main() -> Result<(), Box> { if let Some(to_dial) = std::env::args().nth(1) { let addr: Multiaddr = to_dial.parse()?; swarm.dial(addr)?; - println!("Dialed {:?}", to_dial); + println!("Dialed {to_dial:?}"); } // Read full lines from stdin @@ -138,7 +138,7 @@ async fn main() -> Result<(), Box> { event = swarm.select_next_some() => { match event { SwarmEvent::NewListenAddr { address, .. } => { - println!("Listening on {:?}", address); + println!("Listening on {address:?}"); } SwarmEvent::Behaviour(MyBehaviourEvent::Floodsub(FloodsubEvent::Message(message))) => { println!( diff --git a/examples/chat.rs b/examples/chat.rs index e5368b49..cf1b84d1 100644 --- a/examples/chat.rs +++ b/examples/chat.rs @@ -70,7 +70,7 @@ async fn main() -> Result<(), Box> { // Create a random PeerId let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); - println!("Local peer id: {:?}", local_peer_id); + println!("Local peer id: {local_peer_id:?}"); // Set up an encrypted DNS-enabled TCP Transport over the Mplex and Yamux protocols let transport = libp2p::development_transport(local_key).await?; @@ -122,7 +122,7 @@ async fn main() -> Result<(), Box> { if let Some(to_dial) = std::env::args().nth(1) { let addr: Multiaddr = to_dial.parse()?; swarm.dial(addr)?; - println!("Dialed {:?}", to_dial) + println!("Dialed {to_dial:?}") } // Read full lines from stdin @@ -140,7 +140,7 @@ async fn main() -> Result<(), Box> { .publish(floodsub_topic.clone(), line.expect("Stdin not to close").as_bytes()), event = swarm.select_next_some() => match event { SwarmEvent::NewListenAddr { address, .. } => { - println!("Listening on {:?}", address); + println!("Listening on {address:?}"); } SwarmEvent::Behaviour(OutEvent::Floodsub( FloodsubEvent::Message(message) diff --git a/examples/distributed-key-value-store.rs b/examples/distributed-key-value-store.rs index 2f90b4c4..3323cc91 100644 --- a/examples/distributed-key-value-store.rs +++ b/examples/distributed-key-value-store.rs @@ -114,7 +114,7 @@ async fn main() -> Result<(), Box> { line = stdin.select_next_some() => handle_input_line(&mut swarm.behaviour_mut().kademlia, line.expect("Stdin not to close")), event = swarm.select_next_some() => match event { SwarmEvent::NewListenAddr { address, .. } => { - println!("Listening in {:?}", address); + println!("Listening in {address:?}"); }, SwarmEvent::Behaviour(MyBehaviourEvent::Mdns(MdnsEvent::Discovered(list))) => { for (peer_id, multiaddr) in list { @@ -133,7 +133,7 @@ async fn main() -> Result<(), Box> { } } QueryResult::GetProviders(Err(err)) => { - eprintln!("Failed to get providers: {:?}", err); + eprintln!("Failed to get providers: {err:?}"); } QueryResult::GetRecord(Ok(ok)) => { for PeerRecord { @@ -149,7 +149,7 @@ async fn main() -> Result<(), Box> { } } QueryResult::GetRecord(Err(err)) => { - eprintln!("Failed to get record: {:?}", err); + eprintln!("Failed to get record: {err:?}"); } QueryResult::PutRecord(Ok(PutRecordOk { key })) => { println!( @@ -158,7 +158,7 @@ async fn main() -> Result<(), Box> { ); } QueryResult::PutRecord(Err(err)) => { - eprintln!("Failed to put record: {:?}", err); + eprintln!("Failed to put record: {err:?}"); } QueryResult::StartProviding(Ok(AddProviderOk { key })) => { println!( @@ -167,7 +167,7 @@ async fn main() -> Result<(), Box> { ); } QueryResult::StartProviding(Err(err)) => { - eprintln!("Failed to put provider record: {:?}", err); + eprintln!("Failed to put provider record: {err:?}"); } _ => {} } diff --git a/examples/file-sharing.rs b/examples/file-sharing.rs index 4e3cad3f..d8600815 100644 --- a/examples/file-sharing.rs +++ b/examples/file-sharing.rs @@ -149,7 +149,7 @@ async fn main() -> Result<(), Box> { // Locate all nodes providing the file. let providers = network_client.get_providers(name.clone()).await; if providers.is_empty() { - return Err(format!("Could not find provider for file {}.", name).into()); + return Err(format!("Could not find provider for file {name}.").into()); } // Request the content of the file from each node. @@ -506,8 +506,8 @@ mod network { } } SwarmEvent::IncomingConnectionError { .. } => {} - SwarmEvent::Dialing(peer_id) => eprintln!("Dialing {}", peer_id), - e => panic!("{:?}", e), + SwarmEvent::Dialing(peer_id) => eprintln!("Dialing {peer_id}"), + e => panic!("{e:?}"), } } diff --git a/examples/gossipsub-chat.rs b/examples/gossipsub-chat.rs index 1bf9ce27..e293b25b 100644 --- a/examples/gossipsub-chat.rs +++ b/examples/gossipsub-chat.rs @@ -68,7 +68,7 @@ async fn main() -> Result<(), Box> { // Create a random PeerId let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); - println!("Local peer id: {}", local_peer_id); + println!("Local peer id: {local_peer_id}"); // Set up an encrypted DNS-enabled TCP Transport over the Mplex protocol. let transport = libp2p::development_transport(local_key.clone()).await?; @@ -127,19 +127,19 @@ async fn main() -> Result<(), Box> { if let Err(e) = swarm .behaviour_mut().gossipsub .publish(topic.clone(), line.expect("Stdin not to close").as_bytes()) { - println!("Publish error: {:?}", e); + println!("Publish error: {e:?}"); } }, event = swarm.select_next_some() => match event { SwarmEvent::Behaviour(MyBehaviourEvent::Mdns(MdnsEvent::Discovered(list))) => { for (peer_id, _multiaddr) in list { - println!("mDNS discovered a new peer: {}", peer_id); + println!("mDNS discovered a new peer: {peer_id}"); swarm.behaviour_mut().gossipsub.add_explicit_peer(&peer_id); } }, SwarmEvent::Behaviour(MyBehaviourEvent::Mdns(MdnsEvent::Expired(list))) => { for (peer_id, _multiaddr) in list { - println!("mDNS discover peer has expired: {}", peer_id); + println!("mDNS discover peer has expired: {peer_id}"); swarm.behaviour_mut().gossipsub.remove_explicit_peer(&peer_id); } }, diff --git a/examples/ipfs-kad.rs b/examples/ipfs-kad.rs index a36ed977..659cd49b 100644 --- a/examples/ipfs-kad.rs +++ b/examples/ipfs-kad.rs @@ -78,7 +78,7 @@ async fn main() -> Result<(), Box> { identity::Keypair::generate_ed25519().public().into() }; - println!("Searching for the closest peers to {:?}", to_search); + println!("Searching for the closest peers to {to_search:?}"); swarm.behaviour_mut().get_closest_peers(to_search); // Kick it off! @@ -102,7 +102,7 @@ async fn main() -> Result<(), Box> { } Err(GetClosestPeersError::Timeout { peers, .. }) => { if !peers.is_empty() { - println!("Query timed out with closest peers: {:#?}", peers) + println!("Query timed out with closest peers: {peers:#?}") } else { // The example is considered failed as there // should always be at least 1 reachable peer. diff --git a/examples/ipfs-private.rs b/examples/ipfs-private.rs index 6771a160..1f6aec90 100644 --- a/examples/ipfs-private.rs +++ b/examples/ipfs-private.rs @@ -131,7 +131,7 @@ async fn main() -> Result<(), Box> { env_logger::init(); let ipfs_path = get_ipfs_path(); - println!("using IPFS_PATH {:?}", ipfs_path); + println!("using IPFS_PATH {ipfs_path:?}"); let psk: Option = get_psk(&ipfs_path)? .map(|text| PreSharedKey::from_str(&text)) .transpose()?; @@ -139,7 +139,7 @@ async fn main() -> Result<(), Box> { // Create a random PeerId let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); - println!("using random peer id: {:?}", local_peer_id); + println!("using random peer id: {local_peer_id:?}"); if let Some(psk) = psk { println!("using swarm key with fingerprint: {}", psk.fingerprint()); } @@ -202,7 +202,7 @@ async fn main() -> Result<(), Box> { ping: ping::Behaviour::new(ping::Config::new()), }; - println!("Subscribing to {:?}", gossipsub_topic); + println!("Subscribing to {gossipsub_topic:?}"); behaviour.gossipsub.subscribe(&gossipsub_topic).unwrap(); Swarm::new(transport, behaviour, local_peer_id) }; @@ -211,7 +211,7 @@ async fn main() -> Result<(), Box> { for to_dial in std::env::args().skip(1) { let addr: Multiaddr = parse_legacy_multiaddr(&to_dial)?; swarm.dial(addr)?; - println!("Dialed {:?}", to_dial) + println!("Dialed {to_dial:?}") } // Read full lines from stdin @@ -229,16 +229,16 @@ async fn main() -> Result<(), Box> { .gossipsub .publish(gossipsub_topic.clone(), line.expect("Stdin not to close").as_bytes()) { - println!("Publish error: {:?}", e); + println!("Publish error: {e:?}"); } }, event = swarm.select_next_some() => { match event { SwarmEvent::NewListenAddr { address, .. } => { - println!("Listening on {:?}", address); + println!("Listening on {address:?}"); } SwarmEvent::Behaviour(MyBehaviourEvent::Identify(event)) => { - println!("identify: {:?}", event); + println!("identify: {event:?}"); } SwarmEvent::Behaviour(MyBehaviourEvent::Gossipsub(GossipsubEvent::Message { propagation_source: peer_id, @@ -286,7 +286,7 @@ async fn main() -> Result<(), Box> { peer, result: Result::Err(ping::Failure::Other { error }), } => { - println!("ping: ping::Failure with {}: {}", peer.to_base58(), error); + println!("ping: ping::Failure with {}: {error}", peer.to_base58()); } } } diff --git a/examples/mdns-passive-discovery.rs b/examples/mdns-passive-discovery.rs index 9ac7e1a4..8231d888 100644 --- a/examples/mdns-passive-discovery.rs +++ b/examples/mdns-passive-discovery.rs @@ -34,7 +34,7 @@ async fn main() -> Result<(), Box> { // Create a random PeerId. let id_keys = identity::Keypair::generate_ed25519(); let peer_id = PeerId::from(id_keys.public()); - println!("Local peer id: {:?}", peer_id); + println!("Local peer id: {peer_id:?}"); // Create a transport. let transport = libp2p::development_transport(id_keys).await?; @@ -52,12 +52,12 @@ async fn main() -> Result<(), Box> { match swarm.select_next_some().await { SwarmEvent::Behaviour(MdnsEvent::Discovered(peers)) => { for (peer, addr) in peers { - println!("discovered {} {}", peer, addr); + println!("discovered {peer} {addr}"); } } SwarmEvent::Behaviour(MdnsEvent::Expired(expired)) => { for (peer, addr) in expired { - println!("expired {} {}", peer, addr); + println!("expired {peer} {addr}"); } } _ => {} diff --git a/examples/ping.rs b/examples/ping.rs index 9be23419..5d7443b8 100644 --- a/examples/ping.rs +++ b/examples/ping.rs @@ -50,7 +50,7 @@ use std::error::Error; async fn main() -> Result<(), Box> { let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); - println!("Local peer id: {:?}", local_peer_id); + println!("Local peer id: {local_peer_id:?}"); let transport = libp2p::development_transport(local_key).await?; @@ -65,13 +65,13 @@ async fn main() -> Result<(), Box> { if let Some(addr) = std::env::args().nth(1) { let remote: Multiaddr = addr.parse()?; swarm.dial(remote)?; - println!("Dialed {}", addr) + println!("Dialed {addr}") } loop { match swarm.select_next_some().await { - SwarmEvent::NewListenAddr { address, .. } => println!("Listening on {:?}", address), - SwarmEvent::Behaviour(event) => println!("{:?}", event), + SwarmEvent::NewListenAddr { address, .. } => println!("Listening on {address:?}"), + SwarmEvent::Behaviour(event) => println!("{event:?}"), _ => {} } } diff --git a/muxers/mplex/src/codec.rs b/muxers/mplex/src/codec.rs index 3867cd27..f7d986a8 100644 --- a/muxers/mplex/src/codec.rs +++ b/muxers/mplex/src/codec.rs @@ -226,7 +226,7 @@ impl Decoder for Codec { } let buf = src.split_to(len); - let num = (header >> 3) as u64; + let num = header >> 3; let out = match header & 7 { 0 => Frame::Open { stream_id: RemoteStreamId::dialer(num), diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 43f2f794..8fe6fc94 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -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 { diff --git a/protocols/gossipsub/src/peer_score.rs b/protocols/gossipsub/src/peer_score.rs index 4c7a09bb..fc87253d 100644 --- a/protocols/gossipsub/src/peer_score.rs +++ b/protocols/gossipsub/src/peer_score.rs @@ -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 { diff --git a/protocols/gossipsub/src/peer_score/tests.rs b/protocols/gossipsub/src/peer_score/tests.rs index c457ffe0..3616452a 100644 --- a/protocols/gossipsub/src/peer_score/tests.rs +++ b/protocols/gossipsub/src/peer_score/tests.rs @@ -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"); diff --git a/protocols/gossipsub/src/subscription_filter.rs b/protocols/gossipsub/src/subscription_filter.rs index 600a02c7..ca4204cc 100644 --- a/protocols/gossipsub/src/subscription_filter.rs +++ b/protocols/gossipsub/src/subscription_filter.rs @@ -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, ) } diff --git a/protocols/kad/src/kbucket/key.rs b/protocols/kad/src/kbucket/key.rs index 00a15765..62401c46 100644 --- a/protocols/kad/src/kbucket/key.rs +++ b/protocols/kad/src/kbucket/key.rs @@ -94,14 +94,14 @@ impl From> for KeyBytes { impl From for Key { 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 for Key { 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 } } } diff --git a/protocols/kad/src/query/peers/closest/disjoint.rs b/protocols/kad/src/query/peers/closest/disjoint.rs index 2272b8e4..6a818713 100644 --- a/protocols/kad/src/query/peers/closest/disjoint.rs +++ b/protocols/kad/src/query/peers/closest/disjoint.rs @@ -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)) => { diff --git a/protocols/relay/src/v2/relay.rs b/protocols/relay/src/v2/relay.rs index 5b1eb810..a53024b3 100644 --- a/protocols/relay/src/v2/relay.rs +++ b/protocols/relay/src/v2/relay.rs @@ -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::() >= self.config.max_reservations // Deny if it exceeds the allowed rate of reservations. diff --git a/protocols/rendezvous/src/client.rs b/protocols/rendezvous/src/client.rs index 5ceb945a..1eed9831 100644 --- a/protocols/rendezvous/src/client.rs +++ b/protocols/rendezvous/src/client.rs @@ -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) } diff --git a/protocols/rendezvous/src/server.rs b/protocols/rendezvous/src/server.rs index dd4731d8..4dfad583 100644 --- a/protocols/rendezvous/src/server.rs +++ b/protocols/rendezvous/src/server.rs @@ -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();