From 4ab0ce7c69f3956d51e7abfcb13344b2e208a6fd Mon Sep 17 00:00:00 2001 From: Hubert Bugaj Date: Mon, 11 Apr 2022 22:16:13 +0200 Subject: [PATCH 1/5] fix some clippy issues --- core/src/identity/rsa.rs | 2 +- core/src/peer_id.rs | 2 +- core/src/peer_record.rs | 2 +- core/src/transport/memory.rs | 6 +++--- muxers/mplex/src/config.rs | 2 +- muxers/mplex/src/io.rs | 8 ++++---- muxers/yamux/src/lib.rs | 14 ++++++++------ swarm/src/behaviour/either.rs | 8 ++++---- swarm/src/connection/pool/concurrent_dial.rs | 6 +++--- swarm/src/lib.rs | 8 ++++---- transports/dns/src/lib.rs | 14 ++++++++------ transports/noise/src/protocol/x25519.rs | 6 ++++++ transports/noise/src/protocol/x25519_spec.rs | 6 ++++++ transports/tcp/src/lib.rs | 6 ++++++ transports/uds/src/lib.rs | 6 ++++++ transports/wasm-ext/src/lib.rs | 10 +++++----- 16 files changed, 67 insertions(+), 39 deletions(-) diff --git a/core/src/identity/rsa.rs b/core/src/identity/rsa.rs index 4175732ffb1..40a7ea6f144 100644 --- a/core/src/identity/rsa.rs +++ b/core/src/identity/rsa.rs @@ -263,7 +263,7 @@ impl DerDecodable<'_> for Asn1SubjectPublicKey { ))); } - let pk_der: Vec = object.value().into_iter().skip(1).cloned().collect(); + let pk_der: Vec = object.value().iter().skip(1).cloned().collect(); // We don't parse pk_der further as an ASN.1 RsaPublicKey, since // we only need the DER encoding for `verify`. Ok(Self(PublicKey(pk_der))) diff --git a/core/src/peer_id.rs b/core/src/peer_id.rs index d9525831c9b..d5e4e1496bd 100644 --- a/core/src/peer_id.rs +++ b/core/src/peer_id.rs @@ -94,7 +94,7 @@ impl PeerId { /// In case the given [`Multiaddr`] ends with `/p2p/`, this function /// will return the encapsulated [`PeerId`], otherwise it will return `None`. pub fn try_from_multiaddr(address: &Multiaddr) -> Option { - address.iter().last().map_or(None, |p| match p { + address.iter().last().and_then(|p| match p { Protocol::P2p(hash) => PeerId::from_multihash(hash).ok(), _ => None, }) diff --git a/core/src/peer_record.rs b/core/src/peer_record.rs index dc1a34297d4..f86df68f957 100644 --- a/core/src/peer_record.rs +++ b/core/src/peer_record.rs @@ -89,7 +89,7 @@ impl PeerRecord { }; let envelope = SignedEnvelope::new( - &key, + key, String::from(DOMAIN_SEP), PAYLOAD_TYPE.as_bytes().to_vec(), payload, diff --git a/core/src/transport/memory.rs b/core/src/transport/memory.rs index 2685ef72d06..02e21e7effa 100644 --- a/core/src/transport/memory.rs +++ b/core/src/transport/memory.rs @@ -358,9 +358,9 @@ impl Sink for Chan { } } -impl> Into>> for Chan { - fn into(self) -> RwStreamSink> { - RwStreamSink::new(self) +impl> From> for RwStreamSink> { + fn from(channel: Chan) -> RwStreamSink> { + RwStreamSink::new(channel) } } diff --git a/muxers/mplex/src/config.rs b/muxers/mplex/src/config.rs index b6166f827e5..587a4230480 100644 --- a/muxers/mplex/src/config.rs +++ b/muxers/mplex/src/config.rs @@ -21,7 +21,7 @@ use crate::codec::MAX_FRAME_SIZE; use std::cmp; -pub(crate) const DEFAULT_MPLEX_PROTOCOL_NAME: &'static [u8] = b"/mplex/6.7.0"; +pub(crate) const DEFAULT_MPLEX_PROTOCOL_NAME: &[u8] = b"/mplex/6.7.0"; /// Configuration for the multiplexer. #[derive(Debug, Clone)] diff --git a/muxers/mplex/src/io.rs b/muxers/mplex/src/io.rs index ec782439efe..bbb11943201 100644 --- a/muxers/mplex/src/io.rs +++ b/muxers/mplex/src/io.rs @@ -810,10 +810,10 @@ where /// Checks whether a substream is open for reading. fn can_read(&self, id: &LocalStreamId) -> bool { - match self.substreams.get(id) { - Some(SubstreamState::Open { .. }) | Some(SubstreamState::SendClosed { .. }) => true, - _ => false, - } + matches!( + self.substreams.get(id), + Some(SubstreamState::Open { .. }) | Some(SubstreamState::SendClosed { .. }) + ) } /// Sends pending frames, without flushing. diff --git a/muxers/yamux/src/lib.rs b/muxers/yamux/src/lib.rs index 45c77486009..2ce0b065345 100644 --- a/muxers/yamux/src/lib.rs +++ b/muxers/yamux/src/lib.rs @@ -252,17 +252,19 @@ impl YamuxConfig { /// Creates a new `YamuxConfig` in client mode, regardless of whether /// it will be used for an inbound or outbound upgrade. pub fn client() -> Self { - let mut cfg = Self::default(); - cfg.mode = Some(yamux::Mode::Client); - cfg + Self { + mode: Some(yamux::Mode::Client), + ..Default::default() + } } /// Creates a new `YamuxConfig` in server mode, regardless of whether /// it will be used for an inbound or outbound upgrade. pub fn server() -> Self { - let mut cfg = Self::default(); - cfg.mode = Some(yamux::Mode::Server); - cfg + Self { + mode: Some(yamux::Mode::Server), + ..Default::default() + } } /// Sets the size (in bytes) of the receive window per substream. diff --git a/swarm/src/behaviour/either.rs b/swarm/src/behaviour/either.rs index 6d837105d72..479534f6a8f 100644 --- a/swarm/src/behaviour/either.rs +++ b/swarm/src/behaviour/either.rs @@ -227,11 +227,11 @@ where ) -> Poll> { let event = match self { Either::Left(behaviour) => futures::ready!(behaviour.poll(cx, params)) - .map_out(|e| Either::Left(e)) - .map_handler_and_in(|h| IntoEitherHandler::Left(h), |e| Either::Left(e)), + .map_out(Either::Left) + .map_handler_and_in(IntoEitherHandler::Left, Either::Left), Either::Right(behaviour) => futures::ready!(behaviour.poll(cx, params)) - .map_out(|e| Either::Right(e)) - .map_handler_and_in(|h| IntoEitherHandler::Right(h), |e| Either::Right(e)), + .map_out(Either::Right) + .map_handler_and_in(IntoEitherHandler::Right, Either::Right), }; Poll::Ready(event) diff --git a/swarm/src/connection/pool/concurrent_dial.rs b/swarm/src/connection/pool/concurrent_dial.rs index 8f607ac7166..5ba71f54fd0 100644 --- a/swarm/src/connection/pool/concurrent_dial.rs +++ b/swarm/src/connection/pool/concurrent_dial.rs @@ -60,7 +60,7 @@ where let mut pending_dials = pending_dials.into_iter(); let dials = FuturesUnordered::new(); - while let Some(dial) = pending_dials.next() { + for dial in pending_dials.by_ref() { dials.push(dial); if dials.len() == concurrency_factor.get() as usize { break; @@ -95,7 +95,7 @@ where loop { match ready!(self.dials.poll_next_unpin(cx)) { Some((addr, Ok(output))) => { - let errors = std::mem::replace(&mut self.errors, vec![]); + let errors = std::mem::take(&mut self.errors); return Poll::Ready(Ok((addr, output, errors))); } Some((addr, Err(e))) => { @@ -105,7 +105,7 @@ where } } None => { - return Poll::Ready(Err(std::mem::replace(&mut self.errors, vec![]))); + return Poll::Ready(Err(std::mem::take(&mut self.errors))); } } } diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 0242f2b25a9..4c3a16fecda 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -514,7 +514,7 @@ where }; match dial { Ok(fut) => fut - .map(|r| (address, r.map_err(|e| TransportError::Other(e)))) + .map(|r| (address, r.map_err(TransportError::Other))) .boxed(), Err(err) => futures::future::ready((address, Err(err))).boxed(), } @@ -538,7 +538,7 @@ where Err((connection_limit, handler)) => { let error = DialError::ConnectionLimit(connection_limit); self.behaviour.inject_dial_failure(None, handler, &error); - return Err(error); + Err(error) } } } @@ -800,7 +800,7 @@ where .expect("n + 1 is always non-zero; qed"); let non_banned_established = other_established_connection_ids .into_iter() - .filter(|conn_id| !this.banned_peer_connections.contains(&conn_id)) + .filter(|conn_id| !this.banned_peer_connections.contains(conn_id)) .count(); log::debug!( @@ -896,7 +896,7 @@ where if conn_was_reported { let remaining_non_banned = remaining_established_connection_ids .into_iter() - .filter(|conn_id| !this.banned_peer_connections.contains(&conn_id)) + .filter(|conn_id| !this.banned_peer_connections.contains(conn_id)) .count(); this.behaviour.inject_connection_closed( &peer_id, diff --git a/transports/dns/src/lib.rs b/transports/dns/src/lib.rs index 7bdc9552688..c5b605720ea 100644 --- a/transports/dns/src/lib.rs +++ b/transports/dns/src/lib.rs @@ -264,12 +264,14 @@ where // dialing attempts as soon as there is another fully resolved // address. while let Some(addr) = unresolved.pop() { - if let Some((i, name)) = addr.iter().enumerate().find(|(_, p)| match p { - Protocol::Dns(_) - | Protocol::Dns4(_) - | Protocol::Dns6(_) - | Protocol::Dnsaddr(_) => true, - _ => false, + if let Some((i, name)) = addr.iter().enumerate().find(|(_, p)| { + matches!( + p, + Protocol::Dns(_) + | Protocol::Dns4(_) + | Protocol::Dns6(_) + | Protocol::Dnsaddr(_) + ) }) { if dns_lookups == MAX_DNS_LOOKUPS { log::debug!("Too many DNS lookups. Dropping unresolved {}.", addr); diff --git a/transports/noise/src/protocol/x25519.rs b/transports/noise/src/protocol/x25519.rs index 5268da24776..bc22dcc70b9 100644 --- a/transports/noise/src/protocol/x25519.rs +++ b/transports/noise/src/protocol/x25519.rs @@ -180,6 +180,12 @@ impl Keypair { } } +impl Default for Keypair { + fn default() -> Self { + Self::new() + } +} + /// Promote a X25519 secret key into a keypair. impl From> for Keypair { fn from(secret: SecretKey) -> Keypair { diff --git a/transports/noise/src/protocol/x25519_spec.rs b/transports/noise/src/protocol/x25519_spec.rs index 449831d8bb7..b0ae73d96e5 100644 --- a/transports/noise/src/protocol/x25519_spec.rs +++ b/transports/noise/src/protocol/x25519_spec.rs @@ -61,6 +61,12 @@ impl Keypair { } } +impl Default for Keypair { + fn default() -> Self { + Self::new() + } +} + /// Promote a X25519 secret key into a keypair. impl From> for Keypair { fn from(secret: SecretKey) -> Keypair { diff --git a/transports/tcp/src/lib.rs b/transports/tcp/src/lib.rs index cacf13bb7d5..6e6eb771d06 100644 --- a/transports/tcp/src/lib.rs +++ b/transports/tcp/src/lib.rs @@ -328,6 +328,12 @@ where } } +impl Default for GenTcpConfig { + fn default() -> Self { + Self::new() + } +} + impl Transport for GenTcpConfig where T: Provider + Send + 'static, diff --git a/transports/uds/src/lib.rs b/transports/uds/src/lib.rs index 6dd0852396c..472fd1c607c 100644 --- a/transports/uds/src/lib.rs +++ b/transports/uds/src/lib.rs @@ -63,6 +63,12 @@ impl $uds_config { } } +impl Default for $uds_config { + fn default() -> Self { + Self::new() + } +} + impl Transport for $uds_config { type Output = $unix_stream; type Error = io::Error; diff --git a/transports/wasm-ext/src/lib.rs b/transports/wasm-ext/src/lib.rs index 44f3dcbd54a..64deb877858 100644 --- a/transports/wasm-ext/src/lib.rs +++ b/transports/wasm-ext/src/lib.rs @@ -318,15 +318,15 @@ impl Stream for Listen { }; if let Some(addrs) = event.new_addrs() { - for addr in addrs.into_iter() { - let addr = js_value_to_addr(&addr)?; + for addr in addrs.iter() { + let addr = js_value_to_addr(addr)?; self.pending_events .push_back(ListenerEvent::NewAddress(addr)); } } if let Some(upgrades) = event.new_connections() { - for upgrade in upgrades.into_iter().cloned() { + for upgrade in upgrades.iter().cloned() { let upgrade: ffi::ConnectionEvent = upgrade.into(); self.pending_events.push_back(ListenerEvent::Upgrade { local_addr: upgrade.local_addr().parse()?, @@ -337,8 +337,8 @@ impl Stream for Listen { } if let Some(addrs) = event.expired_addrs() { - for addr in addrs.into_iter() { - match js_value_to_addr(&addr) { + for addr in addrs.iter() { + match js_value_to_addr(addr) { Ok(addr) => self .pending_events .push_back(ListenerEvent::NewAddress(addr)), From f19313e0e4a04ebca4fd33121cbccbf80023f946 Mon Sep 17 00:00:00 2001 From: Hubert Bugaj Date: Mon, 25 Apr 2022 20:08:53 +0200 Subject: [PATCH 2/5] enable and fix clippy style warnings --- .cargo/config.toml | 2 +- core/src/transport/memory.rs | 9 +++-- misc/metrics/src/gossipsub.rs | 7 ++-- protocols/gossipsub/src/behaviour.rs | 22 ++++++------ protocols/gossipsub/src/mcache.rs | 2 +- protocols/gossipsub/src/metrics.rs | 4 +-- protocols/gossipsub/src/peer_score.rs | 2 +- protocols/identify/src/identify.rs | 24 ++++++------- protocols/kad/src/addresses.rs | 1 + protocols/kad/src/behaviour.rs | 2 +- protocols/kad/src/jobs.rs | 1 + protocols/kad/src/kbucket/bucket.rs | 10 +++--- protocols/kad/src/kbucket/key.rs | 6 ++-- protocols/mdns/src/behaviour.rs | 4 +-- protocols/ping/src/handler.rs | 6 ++++ protocols/relay/src/v2/client.rs | 2 +- protocols/relay/src/v2/client/transport.rs | 8 ++--- .../relay/src/v2/protocol/inbound_hop.rs | 4 ++- .../relay/src/v2/protocol/inbound_stop.rs | 2 +- .../relay/src/v2/protocol/outbound_hop.rs | 34 +++++++++++++------ .../relay/src/v2/protocol/outbound_stop.rs | 14 +++++--- protocols/relay/src/v2/relay.rs | 2 +- protocols/rendezvous/src/codec.rs | 1 + protocols/rendezvous/src/handler/inbound.rs | 2 ++ protocols/rendezvous/src/handler/outbound.rs | 1 + protocols/rendezvous/src/substream_handler.rs | 1 + protocols/request-response/src/lib.rs | 2 +- swarm/src/connection.rs | 1 + swarm/src/lib.rs | 1 + 29 files changed, 104 insertions(+), 73 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 3f2c1e603f3..95976aaa800 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,3 +1,3 @@ [alias] # Temporary solution to have clippy config in a single place until https://github.com/rust-lang/rust-clippy/blob/master/doc/roadmap-2021.md#lintstoml-configuration is shipped. -custom-clippy = "clippy -- -A clippy::type_complexity -A clippy::pedantic -A clippy::style -D warnings" +custom-clippy = "clippy -- -A clippy::type_complexity -A clippy::pedantic -D warnings" diff --git a/core/src/transport/memory.rs b/core/src/transport/memory.rs index 02e21e7effa..40bc5d3da15 100644 --- a/core/src/transport/memory.rs +++ b/core/src/transport/memory.rs @@ -150,9 +150,12 @@ impl Future for DialFuture { .take() .expect("Future should not be polled again once complete"); let dial_port = self.dial_port; - match self.sender.start_send((channel_to_send, dial_port)) { - Err(_) => return Poll::Ready(Err(MemoryTransportError::Unreachable)), - Ok(()) => {} + if self + .sender + .start_send((channel_to_send, dial_port)) + .is_err() + { + return Poll::Ready(Err(MemoryTransportError::Unreachable)); } Poll::Ready(Ok(self diff --git a/misc/metrics/src/gossipsub.rs b/misc/metrics/src/gossipsub.rs index e2a567f99be..0bb6af5f452 100644 --- a/misc/metrics/src/gossipsub.rs +++ b/misc/metrics/src/gossipsub.rs @@ -42,11 +42,8 @@ impl Metrics { impl super::Recorder for super::Metrics { fn record(&self, event: &libp2p_gossipsub::GossipsubEvent) { - match event { - libp2p_gossipsub::GossipsubEvent::Message { .. } => { - self.gossipsub.messages.inc(); - } - _ => {} + if let libp2p_gossipsub::GossipsubEvent::Message { .. } = event { + self.gossipsub.messages.inc(); } } } diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 583af5ec1cb..ff7fa8c1504 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -1226,19 +1226,19 @@ where } for id in ids { - if !self.duplicate_cache.contains(&id) && !self.pending_iwant_msgs.contains(&id) { - if self + if !self.duplicate_cache.contains(&id) + && !self.pending_iwant_msgs.contains(&id) + && self .peer_score .as_ref() .map(|(_, _, _, promises)| !promises.contains(&id)) .unwrap_or(true) - { - // have not seen this message and are not currently requesting it - if iwant_ids.insert(id) { - // Register the IWANT metric - if let Some(metrics) = self.metrics.as_mut() { - metrics.register_iwant(&topic); - } + { + // have not seen this message and are not currently requesting it + if iwant_ids.insert(id) { + // Register the IWANT metric + if let Some(metrics) = self.metrics.as_mut() { + metrics.register_iwant(&topic); } } } @@ -1353,7 +1353,7 @@ where } else if let Some(m) = self.metrics.as_mut() { // Sending of messages succeeded, register them on the internal metrics. for topic in topics.iter() { - m.msg_sent(&topic, msg_bytes); + m.msg_sent(topic, msg_bytes); } } } @@ -2136,7 +2136,7 @@ where for peer_id in self.connected_peers.keys() { scores .entry(peer_id) - .or_insert_with(|| peer_score.metric_score(&peer_id, self.metrics.as_mut())); + .or_insert_with(|| peer_score.metric_score(peer_id, self.metrics.as_mut())); } } diff --git a/protocols/gossipsub/src/mcache.rs b/protocols/gossipsub/src/mcache.rs index 58f398ba9cc..6d1c0465a76 100644 --- a/protocols/gossipsub/src/mcache.rs +++ b/protocols/gossipsub/src/mcache.rs @@ -148,7 +148,7 @@ impl MessageCache { message.validated = true; // Clear the known peers list (after a message is validated, it is forwarded and we no // longer need to store the originating peers). - let originating_peers = std::mem::replace(known_peers, HashSet::new()); + let originating_peers = std::mem::take(known_peers); (&*message, originating_peers) }) } diff --git a/protocols/gossipsub/src/metrics.rs b/protocols/gossipsub/src/metrics.rs index e813140f759..eb33b54210c 100644 --- a/protocols/gossipsub/src/metrics.rs +++ b/protocols/gossipsub/src/metrics.rs @@ -517,9 +517,7 @@ impl Metrics { let metric = self .peers_per_protocol .get_or_create(&ProtocolLabel { protocol: kind }); - if metric.get() == 0 { - return; - } else { + if metric.get() != 0 { // decrement the counter metric.set(metric.get() - 1); } diff --git a/protocols/gossipsub/src/peer_score.rs b/protocols/gossipsub/src/peer_score.rs index d8d0650daf7..4c7a09bbcb2 100644 --- a/protocols/gossipsub/src/peer_score.rs +++ b/protocols/gossipsub/src/peer_score.rs @@ -860,7 +860,7 @@ impl PeerScore { //should always be true let window_time = validated_time .checked_add(topic_params.mesh_message_deliveries_window) - .unwrap_or_else(|| *now); + .unwrap_or(*now); if now > &window_time { falls_in_mesh_deliver_window = false; } diff --git a/protocols/identify/src/identify.rs b/protocols/identify/src/identify.rs index f39e9d6900e..20daddcc38d 100644 --- a/protocols/identify/src/identify.rs +++ b/protocols/identify/src/identify.rs @@ -196,16 +196,14 @@ impl Identify { I: IntoIterator, { for p in peers { - if self.pending_push.insert(p) { - if !self.connected.contains_key(&p) { - let handler = self.new_handler(); - self.events.push_back(NetworkBehaviourAction::Dial { - opts: DialOpts::peer_id(p) - .condition(dial_opts::PeerCondition::Disconnected) - .build(), - handler, - }); - } + if self.pending_push.insert(p) && !self.connected.contains_key(&p) { + let handler = self.new_handler(); + self.events.push_back(NetworkBehaviourAction::Dial { + opts: DialOpts::peer_id(p) + .condition(dial_opts::PeerCondition::Disconnected) + .build(), + handler, + }); } } } @@ -240,7 +238,7 @@ impl NetworkBehaviour for Identify { if let Some(entry) = self.discovered_peers.get_mut(peer_id) { for addr in failed_addresses .into_iter() - .flat_map(|addresses| addresses.into_iter()) + .flat_map(|addresses| addresses.iter()) { entry.remove(addr); } @@ -451,7 +449,7 @@ impl NetworkBehaviour for Identify { self.discovered_peers .get(peer) .cloned() - .map(|addr| Vec::from_iter(addr)) + .map(Vec::from_iter) .unwrap_or_default() } } @@ -510,7 +508,7 @@ fn multiaddr_matches_peer_id(addr: &Multiaddr, peer_id: &PeerId) -> bool { if let Some(Protocol::P2p(multi_addr_peer_id)) = last_component { return multi_addr_peer_id == *peer_id.as_ref(); } - return true; + true } #[cfg(test)] diff --git a/protocols/kad/src/addresses.rs b/protocols/kad/src/addresses.rs index f5bdd4d0fbc..3c2af4173fd 100644 --- a/protocols/kad/src/addresses.rs +++ b/protocols/kad/src/addresses.rs @@ -65,6 +65,7 @@ impl Addresses { /// /// An address should only be removed if is determined to be invalid or /// otherwise unreachable. + #[allow(clippy::result_unit_err)] pub fn remove(&mut self, addr: &Multiaddr) -> Result<(), ()> { if self.addrs.len() == 1 { return Err(()); diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index b6a7dc32954..d5b322e096a 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -1825,7 +1825,7 @@ where errors: Option<&Vec>, other_established: usize, ) { - for addr in errors.map(|a| a.into_iter()).into_iter().flatten() { + for addr in errors.map(|a| a.iter()).into_iter().flatten() { self.address_failed(*peer_id, addr); } diff --git a/protocols/kad/src/jobs.rs b/protocols/kad/src/jobs.rs index 7ce201a4150..17235f20741 100644 --- a/protocols/kad/src/jobs.rs +++ b/protocols/kad/src/jobs.rs @@ -108,6 +108,7 @@ impl PeriodicJob { /// Returns `true` if the job is currently not running but ready /// to be run, `false` otherwise. + #[allow(clippy::wrong_self_convention)] fn is_ready(&mut self, cx: &mut Context<'_>, now: Instant) -> bool { if let PeriodicJobState::Waiting(delay, deadline) = &mut self.state { if now >= *deadline || !Future::poll(Pin::new(delay), cx).is_pending() { diff --git a/protocols/kad/src/kbucket/bucket.rs b/protocols/kad/src/kbucket/bucket.rs index b9d34519d5d..92dc6c57a6b 100644 --- a/protocols/kad/src/kbucket/bucket.rs +++ b/protocols/kad/src/kbucket/bucket.rs @@ -365,11 +365,11 @@ where // Adjust `first_connected_pos` accordingly. match status { NodeStatus::Connected => { - if self.first_connected_pos.map_or(false, |p| p == pos.0) { - if pos.0 == self.nodes.len() { - // It was the last connected node. - self.first_connected_pos = None - } + if self.first_connected_pos.map_or(false, |p| p == pos.0) + && pos.0 == self.nodes.len() + { + // It was the last connected node. + self.first_connected_pos = None } } NodeStatus::Disconnected => { diff --git a/protocols/kad/src/kbucket/key.rs b/protocols/kad/src/kbucket/key.rs index ca3444da636..9133757a0ff 100644 --- a/protocols/kad/src/kbucket/key.rs +++ b/protocols/kad/src/kbucket/key.rs @@ -86,9 +86,9 @@ impl Key { } } -impl Into for Key { - fn into(self) -> KeyBytes { - self.bytes +impl From> for KeyBytes { + fn from(key: Key) -> KeyBytes { + key.bytes } } diff --git a/protocols/mdns/src/behaviour.rs b/protocols/mdns/src/behaviour.rs index 1c22a068b71..c844f742af9 100644 --- a/protocols/mdns/src/behaviour.rs +++ b/protocols/mdns/src/behaviour.rs @@ -122,7 +122,7 @@ impl NetworkBehaviour for Mdns { fn inject_new_listen_addr(&mut self, _id: ListenerId, _addr: &Multiaddr) { log::trace!("waking interface state because listening address changed"); - for (_, iface) in &mut self.iface_states { + for iface in self.iface_states.values_mut() { iface.fire_timer(); } } @@ -178,7 +178,7 @@ impl NetworkBehaviour for Mdns { } // Emit discovered event. let mut discovered = SmallVec::<[(PeerId, Multiaddr); 4]>::new(); - for (_, iface_state) in &mut self.iface_states { + for iface_state in self.iface_states.values_mut() { while let Some((peer, addr, expiration)) = iface_state.poll(cx, params) { if let Some((_, _, cur_expires)) = self .discovered_nodes diff --git a/protocols/ping/src/handler.rs b/protocols/ping/src/handler.rs index 87937687591..850f4ebc05f 100644 --- a/protocols/ping/src/handler.rs +++ b/protocols/ping/src/handler.rs @@ -116,6 +116,12 @@ impl Config { } } +impl Default for Config { + fn default() -> Self { + Self::new() + } +} + /// The successful result of processing an inbound or outbound ping. #[derive(Debug)] pub enum Success { diff --git a/protocols/relay/src/v2/client.rs b/protocols/relay/src/v2/client.rs index 139e4a8b7e5..e670d24e3e1 100644 --- a/protocols/relay/src/v2/client.rs +++ b/protocols/relay/src/v2/client.rs @@ -313,7 +313,7 @@ impl NetworkBehaviour for Client { ), }; - return Poll::Ready(action); + Poll::Ready(action) } } diff --git a/protocols/relay/src/v2/client/transport.rs b/protocols/relay/src/v2/client/transport.rs index 40eb6031fcc..5414353786c 100644 --- a/protocols/relay/src/v2/client/transport.rs +++ b/protocols/relay/src/v2/client/transport.rs @@ -211,7 +211,7 @@ impl Transport for ClientTransport { // traversal. One would coordinate such traversal via a previously // established relayed connection, but never using a relayed connection // itself. - return Err(TransportError::MultiaddrNotSupported(addr)); + Err(TransportError::MultiaddrNotSupported(addr)) } fn address_translation(&self, _server: &Multiaddr, _observed: &Multiaddr) -> Option { @@ -244,7 +244,7 @@ fn parse_relayed_multiaddr( if before_circuit { before_circuit = false; } else { - Err(RelayError::MultipleCircuitRelayProtocolsUnsupported)?; + return Err(RelayError::MultipleCircuitRelayProtocolsUnsupported.into()); } } Protocol::P2p(hash) => { @@ -252,12 +252,12 @@ fn parse_relayed_multiaddr( if before_circuit { if relayed_multiaddr.relay_peer_id.is_some() { - Err(RelayError::MalformedMultiaddr)?; + return Err(RelayError::MalformedMultiaddr.into()); } relayed_multiaddr.relay_peer_id = Some(peer_id) } else { if relayed_multiaddr.dst_peer_id.is_some() { - Err(RelayError::MalformedMultiaddr)?; + return Err(RelayError::MalformedMultiaddr.into()); } relayed_multiaddr.dst_peer_id = Some(peer_id) } diff --git a/protocols/relay/src/v2/protocol/inbound_hop.rs b/protocols/relay/src/v2/protocol/inbound_hop.rs index 878d85cc4e0..36b4079153d 100644 --- a/protocols/relay/src/v2/protocol/inbound_hop.rs +++ b/protocols/relay/src/v2/protocol/inbound_hop.rs @@ -86,7 +86,9 @@ impl upgrade::InboundUpgrade for Upgrade { .map_err(|_| FatalUpgradeError::ParsePeerId)?; Req::Connect(CircuitReq { dst, substream }) } - hop_message::Type::Status => Err(FatalUpgradeError::UnexpectedTypeStatus)?, + hop_message::Type::Status => { + return Err(FatalUpgradeError::UnexpectedTypeStatus.into()) + } }; Ok(req) diff --git a/protocols/relay/src/v2/protocol/inbound_stop.rs b/protocols/relay/src/v2/protocol/inbound_stop.rs index d38e72c1627..0f3919a84d9 100644 --- a/protocols/relay/src/v2/protocol/inbound_stop.rs +++ b/protocols/relay/src/v2/protocol/inbound_stop.rs @@ -78,7 +78,7 @@ impl upgrade::InboundUpgrade for Upgrade { limit: limit.map(Into::into), }) } - stop_message::Type::Status => Err(FatalUpgradeError::UnexpectedTypeStatus)?, + stop_message::Type::Status => Err(FatalUpgradeError::UnexpectedTypeStatus.into()), } } .boxed() diff --git a/protocols/relay/src/v2/protocol/outbound_hop.rs b/protocols/relay/src/v2/protocol/outbound_hop.rs index bbd2e0735ee..472efbe33c9 100644 --- a/protocols/relay/src/v2/protocol/outbound_hop.rs +++ b/protocols/relay/src/v2/protocol/outbound_hop.rs @@ -100,8 +100,12 @@ impl upgrade::OutboundUpgrade for Upgrade { let r#type = hop_message::Type::from_i32(r#type).ok_or(FatalUpgradeError::ParseTypeField)?; match r#type { - hop_message::Type::Connect => Err(FatalUpgradeError::UnexpectedTypeConnect)?, - hop_message::Type::Reserve => Err(FatalUpgradeError::UnexpectedTypeReserve)?, + hop_message::Type::Connect => { + return Err(FatalUpgradeError::UnexpectedTypeConnect.into()) + } + hop_message::Type::Reserve => { + return Err(FatalUpgradeError::UnexpectedTypeReserve.into()) + } hop_message::Type::Status => {} } @@ -114,18 +118,20 @@ impl upgrade::OutboundUpgrade for Upgrade { Upgrade::Reserve => { match status { Status::Ok => {} - Status::ReservationRefused => Err(ReservationFailedReason::Refused)?, + Status::ReservationRefused => { + return Err(ReservationFailedReason::Refused.into()) + } Status::ResourceLimitExceeded => { - Err(ReservationFailedReason::ResourceLimitExceeded)? + return Err(ReservationFailedReason::ResourceLimitExceeded.into()) } - s => Err(FatalUpgradeError::UnexpectedStatus(s))?, + s => return Err(FatalUpgradeError::UnexpectedStatus(s).into()), } let reservation = reservation.ok_or(FatalUpgradeError::MissingReservationField)?; if reservation.addrs.is_empty() { - Err(FatalUpgradeError::NoAddressesInReservation)?; + return Err(FatalUpgradeError::NoAddressesInReservation.into()); } let addrs = reservation @@ -161,12 +167,18 @@ impl upgrade::OutboundUpgrade for Upgrade { match status { Status::Ok => {} Status::ResourceLimitExceeded => { - Err(CircuitFailedReason::ResourceLimitExceeded)? + return Err(CircuitFailedReason::ResourceLimitExceeded.into()) + } + Status::ConnectionFailed => { + return Err(CircuitFailedReason::ConnectionFailed.into()) + } + Status::NoReservation => { + return Err(CircuitFailedReason::NoReservation.into()) + } + Status::PermissionDenied => { + return Err(CircuitFailedReason::PermissionDenied.into()) } - Status::ConnectionFailed => Err(CircuitFailedReason::ConnectionFailed)?, - Status::NoReservation => Err(CircuitFailedReason::NoReservation)?, - Status::PermissionDenied => Err(CircuitFailedReason::PermissionDenied)?, - s => Err(FatalUpgradeError::UnexpectedStatus(s))?, + s => return Err(FatalUpgradeError::UnexpectedStatus(s).into()), } let FramedParts { diff --git a/protocols/relay/src/v2/protocol/outbound_stop.rs b/protocols/relay/src/v2/protocol/outbound_stop.rs index ae93dbe92e5..ad74182a9c9 100644 --- a/protocols/relay/src/v2/protocol/outbound_stop.rs +++ b/protocols/relay/src/v2/protocol/outbound_stop.rs @@ -97,7 +97,9 @@ impl upgrade::OutboundUpgrade for Upgrade { let r#type = stop_message::Type::from_i32(r#type).ok_or(FatalUpgradeError::ParseTypeField)?; match r#type { - stop_message::Type::Connect => Err(FatalUpgradeError::UnexpectedTypeConnect)?, + stop_message::Type::Connect => { + return Err(FatalUpgradeError::UnexpectedTypeConnect.into()) + } stop_message::Type::Status => {} } @@ -105,9 +107,13 @@ impl upgrade::OutboundUpgrade for Upgrade { .ok_or(FatalUpgradeError::ParseStatusField)?; match status { Status::Ok => {} - Status::ResourceLimitExceeded => Err(CircuitFailedReason::ResourceLimitExceeded)?, - Status::PermissionDenied => Err(CircuitFailedReason::PermissionDenied)?, - s => Err(FatalUpgradeError::UnexpectedStatus(s))?, + Status::ResourceLimitExceeded => { + return Err(CircuitFailedReason::ResourceLimitExceeded.into()) + } + Status::PermissionDenied => { + return Err(CircuitFailedReason::PermissionDenied.into()) + } + s => return Err(FatalUpgradeError::UnexpectedStatus(s).into()), } let FramedParts { diff --git a/protocols/relay/src/v2/relay.rs b/protocols/relay/src/v2/relay.rs index e5f2cdbfe77..353218453f1 100644 --- a/protocols/relay/src/v2/relay.rs +++ b/protocols/relay/src/v2/relay.rs @@ -238,7 +238,7 @@ impl NetworkBehaviour for Relay { _remaining_established: usize, ) { if let hash_map::Entry::Occupied(mut peer) = self.reservations.entry(*peer) { - peer.get_mut().remove(&connection); + peer.get_mut().remove(connection); if peer.get().is_empty() { peer.remove(); } diff --git a/protocols/rendezvous/src/codec.rs b/protocols/rendezvous/src/codec.rs index d8d54d91177..c4e1ffdc74f 100644 --- a/protocols/rendezvous/src/codec.rs +++ b/protocols/rendezvous/src/codec.rs @@ -254,6 +254,7 @@ impl Decoder for RendezvousCodec { } } +#[allow(clippy::enum_variant_names)] #[derive(Debug, thiserror::Error)] pub enum Error { #[error("Failed to encode message as bytes")] diff --git a/protocols/rendezvous/src/handler/inbound.rs b/protocols/rendezvous/src/handler/inbound.rs index d4452b5758f..3f432bee6bd 100644 --- a/protocols/rendezvous/src/handler/inbound.rs +++ b/protocols/rendezvous/src/handler/inbound.rs @@ -32,6 +32,7 @@ use std::task::{Context, Poll}; /// The state of an inbound substream (i.e. the remote node opened it). #[allow(clippy::large_enum_variant)] +#[allow(clippy::enum_variant_names)] pub enum Stream { /// We are in the process of reading a message from the substream. PendingRead(Framed), @@ -55,6 +56,7 @@ impl fmt::Debug for Stream { } #[allow(clippy::large_enum_variant)] +#[allow(clippy::enum_variant_names)] #[derive(Debug, Clone)] pub enum OutEvent { RegistrationRequested(NewRegistration), diff --git a/protocols/rendezvous/src/handler/outbound.rs b/protocols/rendezvous/src/handler/outbound.rs index c1356ee29d0..d461e7c7294 100644 --- a/protocols/rendezvous/src/handler/outbound.rs +++ b/protocols/rendezvous/src/handler/outbound.rs @@ -121,6 +121,7 @@ pub enum OutEvent { } #[allow(clippy::large_enum_variant)] +#[allow(clippy::enum_variant_names)] #[derive(Debug)] pub enum OpenInfo { RegisterRequest(NewRegistration), diff --git a/protocols/rendezvous/src/substream_handler.rs b/protocols/rendezvous/src/substream_handler.rs index 2a4be470b18..f57dfded6c9 100644 --- a/protocols/rendezvous/src/substream_handler.rs +++ b/protocols/rendezvous/src/substream_handler.rs @@ -274,6 +274,7 @@ where } /// Event sent from the [`libp2p_swarm::NetworkBehaviour`] to the [`SubstreamConnectionHandler`]. +#[allow(clippy::enum_variant_names)] #[derive(Debug)] pub enum InEvent { /// Open a new substream using the provided `open_info`. diff --git a/protocols/request-response/src/lib.rs b/protocols/request-response/src/lib.rs index a0c53101307..f8a4e2eb3a9 100644 --- a/protocols/request-response/src/lib.rs +++ b/protocols/request-response/src/lib.rs @@ -706,7 +706,7 @@ where self.pending_events .push_back(NetworkBehaviourAction::GenerateEvent( RequestResponseEvent::OutboundFailure { - peer: peer, + peer, request_id: request.request_id, error: OutboundFailure::DialFailure, }, diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index ed90da0f63c..90dcabe9f46 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -176,6 +176,7 @@ pub struct IncomingInfo<'a> { impl<'a> IncomingInfo<'a> { /// Builds the [`ConnectedPoint`] corresponding to the incoming connection. + #[allow(clippy::wrong_self_convention)] pub fn to_connected_point(&self) -> ConnectedPoint { ConnectedPoint::Listener { local_addr: self.local_addr.clone(), diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 4c3a16fecda..03533b28377 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -633,6 +633,7 @@ where /// collaborative manner across [`ConnectionHandler`]s /// with [`ConnectionHandler::connection_keep_alive`] or directly with /// [`ConnectionHandlerEvent::Close`]. + #[allow(clippy::result_unit_err)] pub fn disconnect_peer_id(&mut self, peer_id: PeerId) -> Result<(), ()> { let was_connected = self.pool.is_connected(peer_id); self.pool.disconnect(peer_id); From 9d73fccee7fe55463844701d78db4717747af504 Mon Sep 17 00:00:00 2001 From: Hubert Bugaj Date: Wed, 27 Apr 2022 21:25:56 +0200 Subject: [PATCH 3/5] revive some clippy warnings, add changelog --- protocols/kad/CHANGELOG.md | 5 ++++- protocols/kad/src/jobs.rs | 11 +++++------ protocols/rendezvous/CHANGELOG.md | 4 ++++ protocols/rendezvous/src/codec.rs | 3 +-- swarm/CHANGELOG.md | 5 ++++- swarm/src/connection.rs | 3 +-- swarm/src/connection/pool.rs | 2 +- 7 files changed, 20 insertions(+), 13 deletions(-) diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index 2388b27312b..3d157760ca8 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -6,7 +6,10 @@ - Derive `Error` for `GetRecordError` (see [PR 2614]). -[pr 2614]: https://github.com/libp2p/rust-libp2p/pull/2614 +- Renamed `PeriodicJob::is_ready` to `PeriodicJob::check_ready`. See [PR 2620]. + +[PR 2614]: https://github.com/libp2p/rust-libp2p/pull/2614 +[PR 2620]: https://github.com/libp2p/rust-libp2p/pull/2620 # 0.36.0 diff --git a/protocols/kad/src/jobs.rs b/protocols/kad/src/jobs.rs index 17235f20741..7e8ca628ce6 100644 --- a/protocols/kad/src/jobs.rs +++ b/protocols/kad/src/jobs.rs @@ -108,8 +108,7 @@ impl PeriodicJob { /// Returns `true` if the job is currently not running but ready /// to be run, `false` otherwise. - #[allow(clippy::wrong_self_convention)] - fn is_ready(&mut self, cx: &mut Context<'_>, now: Instant) -> bool { + fn check_ready(&mut self, cx: &mut Context<'_>, now: Instant) -> bool { if let PeriodicJobState::Waiting(delay, deadline) = &mut self.state { if now >= *deadline || !Future::poll(Pin::new(delay), cx).is_pending() { return true; @@ -196,7 +195,7 @@ impl PutRecordJob { where for<'a> T: RecordStore<'a>, { - if self.inner.is_ready(cx, now) { + if self.inner.check_ready(cx, now) { let publish = self.next_publish.map_or(false, |t_pub| now >= t_pub); let records = store .records() @@ -240,7 +239,7 @@ impl PutRecordJob { let deadline = now + self.inner.interval; let delay = Delay::new(self.inner.interval); self.inner.state = PeriodicJobState::Waiting(delay, deadline); - assert!(!self.inner.is_ready(cx, now)); + assert!(!self.inner.check_ready(cx, now)); } Poll::Pending @@ -297,7 +296,7 @@ impl AddProviderJob { where for<'a> T: RecordStore<'a>, { - if self.inner.is_ready(cx, now) { + if self.inner.check_ready(cx, now) { let records = store .provided() .map(|r| r.into_owned()) @@ -318,7 +317,7 @@ impl AddProviderJob { let deadline = now + self.inner.interval; let delay = Delay::new(self.inner.interval); self.inner.state = PeriodicJobState::Waiting(delay, deadline); - assert!(!self.inner.is_ready(cx, now)); + assert!(!self.inner.check_ready(cx, now)); } Poll::Pending diff --git a/protocols/rendezvous/CHANGELOG.md b/protocols/rendezvous/CHANGELOG.md index d2c09314457..49b78252f19 100644 --- a/protocols/rendezvous/CHANGELOG.md +++ b/protocols/rendezvous/CHANGELOG.md @@ -4,6 +4,10 @@ - Update to `libp2p-swarm` `v0.36.0`. +- Renamed `Error::ConversionError` to `Error::Conversion` in the `codec` module. See [PR 2620]. + +[PR 2620]: https://github.com/libp2p/rust-libp2p/pull/2620 + # 0.5.0 - Update to `libp2p-swarm` `v0.35.0`. diff --git a/protocols/rendezvous/src/codec.rs b/protocols/rendezvous/src/codec.rs index c4e1ffdc74f..3798cea70a8 100644 --- a/protocols/rendezvous/src/codec.rs +++ b/protocols/rendezvous/src/codec.rs @@ -254,7 +254,6 @@ impl Decoder for RendezvousCodec { } } -#[allow(clippy::enum_variant_names)] #[derive(Debug, thiserror::Error)] pub enum Error { #[error("Failed to encode message as bytes")] @@ -264,7 +263,7 @@ pub enum Error { #[error("Failed to read/write")] Io(#[from] std::io::Error), #[error("Failed to convert wire message to internal data model")] - ConversionError(#[from] ConversionError), + Conversion(#[from] ConversionError), } impl From for wire::Message { diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 8573803b5e6..079c0a3f351 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -6,8 +6,11 @@ - Make `behaviour::either` module private. See [PR 2610] +- Rename `IncomingInfo::to_connected_point` to `IncomingInfo::create_connected_point`. See [PR 2620]. + [PR 2529]: https://github.com/libp2p/rust-libp2p/pull/2529 -[PR 2610]: https://github.com/libp2p/rust-libp2p/pull/2610/ +[PR 2610]: https://github.com/libp2p/rust-libp2p/pull/2610 +[PR 2620]: https://github.com/libp2p/rust-libp2p/pull/2620 # 0.35.0 diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index 90dcabe9f46..d613b4cb031 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -176,8 +176,7 @@ pub struct IncomingInfo<'a> { impl<'a> IncomingInfo<'a> { /// Builds the [`ConnectedPoint`] corresponding to the incoming connection. - #[allow(clippy::wrong_self_convention)] - pub fn to_connected_point(&self) -> ConnectedPoint { + pub fn create_connected_point(&self) -> ConnectedPoint { ConnectedPoint::Listener { local_addr: self.local_addr.clone(), send_back_addr: self.send_back_addr.clone(), diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index 5fa1da1ef3f..e62f3ea643f 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -550,7 +550,7 @@ where where TFut: Future> + Send + 'static, { - let endpoint = info.to_connected_point(); + let endpoint = info.create_connected_point(); if let Err(limit) = self.counters.check_max_pending_incoming() { return Err((limit, handler)); From da37c6e0494aea83efd1219c7f84f70024fd669d Mon Sep 17 00:00:00 2001 From: Hubert Bugaj Date: Thu, 28 Apr 2022 12:28:13 +0200 Subject: [PATCH 4/5] refactored large conditional --- protocols/gossipsub/CHANGELOG.md | 4 +++ protocols/gossipsub/src/behaviour.rs | 36 ++++++++++++++++----------- protocols/gossipsub/src/time_cache.rs | 4 +-- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index 0a325478078..3d4b2b8e215 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -4,6 +4,10 @@ - Update to `libp2p-swarm` `v0.36.0`. +- changed `TimeCache::contains_key` and `DuplicateCache::contains` to immutable methods. See [PR 2620]. + +[PR 2620]: https://github.com/libp2p/rust-libp2p/pull/2620 + # 0.37.0 - Update to `libp2p-swarm` `v0.35.0`. diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index ff7fa8c1504..51082bd4b41 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -1215,6 +1215,21 @@ where let mut iwant_ids = HashSet::new(); + let want_message = |id: &MessageId| { + if self.duplicate_cache.contains(id) { + return false; + } + + if self.pending_iwant_msgs.contains(id) { + return false; + } + + self.peer_score + .as_ref() + .map(|(_, _, _, promises)| !promises.contains(id)) + .unwrap_or(true) + }; + for (topic, ids) in ihave_msgs { // only process the message if we are subscribed if !self.mesh.contains_key(&topic) { @@ -1225,21 +1240,12 @@ where continue; } - for id in ids { - if !self.duplicate_cache.contains(&id) - && !self.pending_iwant_msgs.contains(&id) - && self - .peer_score - .as_ref() - .map(|(_, _, _, promises)| !promises.contains(&id)) - .unwrap_or(true) - { - // have not seen this message and are not currently requesting it - if iwant_ids.insert(id) { - // Register the IWANT metric - if let Some(metrics) = self.metrics.as_mut() { - metrics.register_iwant(&topic); - } + for id in ids.into_iter().filter(want_message) { + // have not seen this message and are not currently requesting it + if iwant_ids.insert(id) { + // Register the IWANT metric + if let Some(metrics) = self.metrics.as_mut() { + metrics.register_iwant(&topic); } } } diff --git a/protocols/gossipsub/src/time_cache.rs b/protocols/gossipsub/src/time_cache.rs index 63a78e951f3..864300b0bb4 100644 --- a/protocols/gossipsub/src/time_cache.rs +++ b/protocols/gossipsub/src/time_cache.rs @@ -172,7 +172,7 @@ where self.list.clear(); } - pub fn contains_key(&mut self, key: &Key) -> bool { + pub fn contains_key(&self, key: &Key) -> bool { self.map.contains_key(key) } @@ -208,7 +208,7 @@ where } } - pub fn contains(&mut self, key: &Key) -> bool { + pub fn contains(&self, key: &Key) -> bool { self.0.contains_key(key) } } From 8b844c7b4408f661d3e4eaf921231350fbd44f7d Mon Sep 17 00:00:00 2001 From: Hubert Bugaj Date: Tue, 3 May 2022 12:20:40 +0200 Subject: [PATCH 5/5] remove needless changelog mention --- protocols/kad/CHANGELOG.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index 3d157760ca8..502f788a590 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -6,10 +6,7 @@ - Derive `Error` for `GetRecordError` (see [PR 2614]). -- Renamed `PeriodicJob::is_ready` to `PeriodicJob::check_ready`. See [PR 2620]. - [PR 2614]: https://github.com/libp2p/rust-libp2p/pull/2614 -[PR 2620]: https://github.com/libp2p/rust-libp2p/pull/2620 # 0.36.0