mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-23 16:11:19 +00:00
*: Fix newly raised clippy warnings (#3106)
Fixed minor issues raised by clippy to improve correctness and readablitity.
This commit is contained in:
parent
90df86d9e7
commit
c32f03c317
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
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<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
|
||||
@ -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!(
|
||||
|
@ -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?;
|
||||
@ -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
|
||||
@ -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)
|
||||
|
@ -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 {
|
||||
@ -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 {
|
||||
@ -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!(
|
||||
@ -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!(
|
||||
@ -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:?}");
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
@ -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.
|
||||
@ -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:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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?;
|
||||
@ -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);
|
||||
}
|
||||
},
|
||||
|
@ -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!
|
||||
@ -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.
|
||||
|
@ -131,7 +131,7 @@ 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()?;
|
||||
@ -139,7 +139,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!("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<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)
|
||||
};
|
||||
@ -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
|
||||
@ -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,
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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?;
|
||||
@ -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}");
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
@ -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?;
|
||||
|
||||
@ -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:?}"),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user