Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: Fix newly raised clippy warnings #3106

Merged
merged 6 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/identity/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/chat-tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
// 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);
jxs marked this conversation as resolved.
Show resolved Hide resolved
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.
Expand Down Expand Up @@ -119,7 +119,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
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
Expand All @@ -138,7 +138,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
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!(
Expand Down
6 changes: 3 additions & 3 deletions examples/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
// 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?;
Expand Down Expand Up @@ -122,7 +122,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
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
Expand All @@ -140,7 +140,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
.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)
Expand Down
10 changes: 5 additions & 5 deletions examples/distributed-key-value-store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
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 {
Expand All @@ -133,7 +133,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
}
}
QueryResult::GetProviders(Err(err)) => {
eprintln!("Failed to get providers: {:?}", err);
eprintln!("Failed to get providers: {err:?}");
}
QueryResult::GetRecord(Ok(ok)) => {
for PeerRecord {
Expand All @@ -149,7 +149,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
}
}
QueryResult::GetRecord(Err(err)) => {
eprintln!("Failed to get record: {:?}", err);
eprintln!("Failed to get record: {err:?}");
}
QueryResult::PutRecord(Ok(PutRecordOk { key })) => {
println!(
Expand All @@ -158,7 +158,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
);
}
QueryResult::PutRecord(Err(err)) => {
eprintln!("Failed to put record: {:?}", err);
eprintln!("Failed to put record: {err:?}");
}
QueryResult::StartProviding(Ok(AddProviderOk { key })) => {
println!(
Expand All @@ -167,7 +167,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
);
}
QueryResult::StartProviding(Err(err)) => {
eprintln!("Failed to put provider record: {:?}", err);
eprintln!("Failed to put provider record: {err:?}");
}
_ => {}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/file-sharing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
// 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.
Expand Down Expand Up @@ -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:?}"),
}
}

Expand Down
8 changes: 4 additions & 4 deletions examples/gossipsub-chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
// 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?;
Expand Down Expand Up @@ -127,19 +127,19 @@ async fn main() -> Result<(), Box<dyn Error>> {
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);
}
},
Expand Down
4 changes: 2 additions & 2 deletions examples/ipfs-kad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
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!
Expand All @@ -102,7 +102,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
}
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.
Expand Down
16 changes: 8 additions & 8 deletions examples/ipfs-private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ async fn main() -> Result<(), Box<dyn Error>> {
env_logger::init();

let ipfs_path = get_ipfs_path();
println!("using IPFS_PATH {:?}", ipfs_path);
println!("using IPFS_PATH {ipfs_path:?}");
let psk: Option<PreSharedKey> = get_psk(&ipfs_path)?
.map(|text| PreSharedKey::from_str(&text))
.transpose()?;

// 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());
}
Expand Down Expand Up @@ -202,7 +202,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
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)
};
Expand All @@ -211,7 +211,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
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
Expand All @@ -229,16 +229,16 @@ async fn main() -> Result<(), Box<dyn Error>> {
.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,
Expand Down Expand Up @@ -286,7 +286,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
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());
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/mdns-passive-discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
// 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?;
Expand All @@ -52,12 +52,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
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}");
}
}
_ => {}
Expand Down
8 changes: 4 additions & 4 deletions examples/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use std::error::Error;
async fn main() -> Result<(), Box<dyn Error>> {
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?;

Expand All @@ -65,13 +65,13 @@ async fn main() -> Result<(), Box<dyn Error>> {
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:?}"),
_ => {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion muxers/mplex/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion protocols/gossipsub/src/peer_score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion protocols/gossipsub/src/peer_score/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion protocols/gossipsub/src/subscription_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
Expand Down
4 changes: 2 additions & 2 deletions protocols/kad/src/kbucket/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
Expand Down
8 changes: 3 additions & 5 deletions protocols/kad/src/query/peers/closest/disjoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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)) => {
Expand Down
4 changes: 2 additions & 2 deletions protocols/relay/src/v2/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion protocols/rendezvous/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading