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 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/CHANGELOG.md
Expand Up @@ -4,8 +4,11 @@

- Hide `prost::Error` from public API in `FromEnvelopeError::InvalidPeerRecord` and `signed_envelope::DecodingError`. See [PR 3058].

- Fixed minor clippy issue. See [PR 3106].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to announce clippy improvements in the CHANGELOG.md if they don't affect the public API, see here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, lets not clutter the changelog with such details.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the changes from the changelog.


[PR 3031]: https://github.com/libp2p/rust-libp2p/pull/3031
[PR 3058]: https://github.com/libp2p/rust-libp2p/pull/3058
[PR 3106]: https://github.com/libp2p/rust-libp2p/pull/3106

# 0.37.0

Expand Down
2 changes: 1 addition & 1 deletion core/src/identity/ecdsa.rs
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
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
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
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
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
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
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
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
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
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
4 changes: 4 additions & 0 deletions muxers/mplex/CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

- Update to `libp2p-core` `v0.38.0`.

- Fixed minor clippy issue. See [PR 3106].

[PR 3106]: https://github.com/libp2p/rust-libp2p/pull/3106

# 0.37.0

- Bump rand to 0.8 and quickcheck to 1. See [PR 2857].
Expand Down
2 changes: 1 addition & 1 deletion muxers/mplex/src/codec.rs
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
3 changes: 3 additions & 0 deletions protocols/gossipsub/CHANGELOG.md
Expand Up @@ -8,7 +8,10 @@

- Refactoring GossipsubCodec to use common protobuf Codec. See [PR 3070].

- Fixed minor clippy issue. See [PR 3106].

[PR 3070]: https://github.com/libp2p/rust-libp2p/pull/3070
[PR 3106]: https://github.com/libp2p/rust-libp2p/pull/3106

# 0.42.0

Expand Down
4 changes: 2 additions & 2 deletions protocols/gossipsub/src/behaviour.rs
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
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
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
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: 4 additions & 0 deletions protocols/kad/CHANGELOG.md
Expand Up @@ -4,6 +4,10 @@

- Update to `libp2p-swarm` `v0.41.0`.

- Fixed minor clippy issue. See [PR 3106].

[PR 3106]: https://github.com/libp2p/rust-libp2p/pull/3106

# 0.41.0

- Remove deprecated `set_protocol_name()` from `KademliaConfig` & `KademliaProtocolConfig`.
Expand Down