From 65cc8994a6230b43e74b53b42b5c5c8655320d5e Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Wed, 16 Feb 2022 17:16:54 +0200 Subject: [PATCH] *: Derive `Debug` and `Clone`(#2495) Co-authored-by: Max Inden --- core/src/identity.rs | 2 +- core/src/identity/rsa.rs | 8 +++++++ muxers/yamux/src/lib.rs | 2 +- protocols/floodsub/src/lib.rs | 1 + protocols/gossipsub/src/behaviour.rs | 1 + protocols/gossipsub/src/metrics.rs | 1 + protocols/gossipsub/src/protocol.rs | 2 +- protocols/identify/src/identify.rs | 2 +- protocols/kad/src/record/store/memory.rs | 2 +- protocols/mdns/src/lib.rs | 2 +- protocols/ping/src/handler.rs | 2 +- protocols/relay/src/v1/behaviour.rs | 2 +- protocols/relay/src/v1/handler.rs | 1 + protocols/relay/src/v2/relay.rs | 22 ++++++++++++++++++++ protocols/relay/src/v2/relay/handler.rs | 1 + protocols/relay/src/v2/relay/rate_limiter.rs | 2 +- 16 files changed, 44 insertions(+), 9 deletions(-) diff --git a/core/src/identity.rs b/core/src/identity.rs index 054138f88a4..ee431e7ee9c 100644 --- a/core/src/identity.rs +++ b/core/src/identity.rs @@ -63,7 +63,7 @@ use std::convert::{TryFrom, TryInto}; /// let keypair = Keypair::rsa_from_pkcs8(&mut bytes); /// ``` /// -#[derive(Clone)] +#[derive(Debug, Clone)] pub enum Keypair { /// An Ed25519 keypair. Ed25519(ed25519::Keypair), diff --git a/core/src/identity/rsa.rs b/core/src/identity/rsa.rs index 97e8f23cf42..4175732ffb1 100644 --- a/core/src/identity/rsa.rs +++ b/core/src/identity/rsa.rs @@ -33,6 +33,14 @@ use zeroize::Zeroize; #[derive(Clone)] pub struct Keypair(Arc); +impl std::fmt::Debug for Keypair { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + f.debug_struct("Keypair") + .field("public", self.0.public_key()) + .finish() + } +} + impl Keypair { /// Decode an RSA keypair from a DER-encoded private key in PKCS#8 PrivateKeyInfo /// format (i.e. unencrypted) as defined in [RFC5208]. diff --git a/muxers/yamux/src/lib.rs b/muxers/yamux/src/lib.rs index 941e0fefd8e..45c77486009 100644 --- a/muxers/yamux/src/lib.rs +++ b/muxers/yamux/src/lib.rs @@ -198,7 +198,7 @@ where } /// The yamux configuration. -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct YamuxConfig { inner: yamux::Config, mode: Option, diff --git a/protocols/floodsub/src/lib.rs b/protocols/floodsub/src/lib.rs index 5481ddbf43d..16f0df610a9 100644 --- a/protocols/floodsub/src/lib.rs +++ b/protocols/floodsub/src/lib.rs @@ -37,6 +37,7 @@ pub use self::protocol::{FloodsubMessage, FloodsubRpc}; pub use self::topic::Topic; /// Configuration options for the Floodsub protocol. +#[derive(Debug, Clone)] pub struct FloodsubConfig { /// Peer id of the local node. Used for the source of the messages that we publish. pub local_peer_id: PeerId, diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index ed8e58db0cd..b8232ece9d6 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -149,6 +149,7 @@ pub enum GossipsubEvent { /// A data structure for storing configuration for publishing messages. See [`MessageAuthenticity`] /// for further details. #[allow(clippy::large_enum_variant)] +#[derive(Clone)] enum PublishConfig { Signing { keypair: Keypair, diff --git a/protocols/gossipsub/src/metrics.rs b/protocols/gossipsub/src/metrics.rs index f171a0d2c99..648c8684f4d 100644 --- a/protocols/gossipsub/src/metrics.rs +++ b/protocols/gossipsub/src/metrics.rs @@ -40,6 +40,7 @@ const DEFAULT_MAX_TOPICS: usize = 300; // store metrics. const DEFAULT_MAX_NEVER_SUBSCRIBED_TOPICS: usize = 50; +#[derive(Debug, Clone)] pub struct Config { /// This provides an upper bound to the number of mesh topics we create metrics for. It /// prevents unbounded labels being created in the metrics. diff --git a/protocols/gossipsub/src/protocol.rs b/protocols/gossipsub/src/protocol.rs index c0a3ec6a9bd..72c985f2534 100644 --- a/protocols/gossipsub/src/protocol.rs +++ b/protocols/gossipsub/src/protocol.rs @@ -44,7 +44,7 @@ use unsigned_varint::codec; pub(crate) const SIGNING_PREFIX: &[u8] = b"libp2p-pubsub:"; /// Implementation of [`InboundUpgrade`] and [`OutboundUpgrade`] for the Gossipsub protocol. -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct ProtocolConfig { /// The Gossipsub protocol id to listen on. protocol_ids: Vec, diff --git a/protocols/identify/src/identify.rs b/protocols/identify/src/identify.rs index 45530404a66..f5ab6944555 100644 --- a/protocols/identify/src/identify.rs +++ b/protocols/identify/src/identify.rs @@ -82,7 +82,7 @@ enum Reply { /// Configuration for the [`Identify`] [`NetworkBehaviour`]. #[non_exhaustive] -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct IdentifyConfig { /// Application-specific version of the protocol family used by the peer, /// e.g. `ipfs/1.0.0` or `polkadot/1.0.0`. diff --git a/protocols/kad/src/record/store/memory.rs b/protocols/kad/src/record/store/memory.rs index c6a006b6cd5..93542683a57 100644 --- a/protocols/kad/src/record/store/memory.rs +++ b/protocols/kad/src/record/store/memory.rs @@ -44,7 +44,7 @@ pub struct MemoryStore { } /// Configuration for a `MemoryStore`. -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct MemoryStoreConfig { /// The maximum number of records. pub max_records: usize, diff --git a/protocols/mdns/src/lib.rs b/protocols/mdns/src/lib.rs index 0cf257370ff..a99eab691a2 100644 --- a/protocols/mdns/src/lib.rs +++ b/protocols/mdns/src/lib.rs @@ -49,7 +49,7 @@ lazy_static! { } /// Configuration for mDNS. -#[derive(Clone, Debug)] +#[derive(Debug, Clone)] pub struct MdnsConfig { /// TTL to use for mdns records. pub ttl: Duration, diff --git a/protocols/ping/src/handler.rs b/protocols/ping/src/handler.rs index d10538562de..afdb882e7ac 100644 --- a/protocols/ping/src/handler.rs +++ b/protocols/ping/src/handler.rs @@ -38,7 +38,7 @@ use std::{ use void::Void; /// The configuration for outbound pings. -#[derive(Clone, Debug)] +#[derive(Debug, Clone)] pub struct Config { /// The timeout of an outbound ping. timeout: Duration, diff --git a/protocols/relay/src/v1/behaviour.rs b/protocols/relay/src/v1/behaviour.rs index aaddb0bbe61..88219410d61 100644 --- a/protocols/relay/src/v1/behaviour.rs +++ b/protocols/relay/src/v1/behaviour.rs @@ -102,7 +102,7 @@ enum IncomingRelayReq { }, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct RelayConfig { /// How long to keep connections alive when they're idle. /// diff --git a/protocols/relay/src/v1/handler.rs b/protocols/relay/src/v1/handler.rs index 4da3ed93f14..f6fd32165f1 100644 --- a/protocols/relay/src/v1/handler.rs +++ b/protocols/relay/src/v1/handler.rs @@ -37,6 +37,7 @@ use std::fmt; use std::task::{Context, Poll}; use std::time::Duration; +#[derive(Debug, Clone)] pub struct RelayHandlerConfig { pub connection_idle_timeout: Duration, } diff --git a/protocols/relay/src/v2/relay.rs b/protocols/relay/src/v2/relay.rs index 4cca6b3519e..e724976d6ae 100644 --- a/protocols/relay/src/v2/relay.rs +++ b/protocols/relay/src/v2/relay.rs @@ -61,6 +61,28 @@ pub struct Config { pub circuit_src_rate_limiters: Vec>, } +impl std::fmt::Debug for Config { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Config") + .field("max_reservations", &self.max_reservations) + .field("max_reservations_per_peer", &self.max_reservations_per_peer) + .field("reservation_duration", &self.reservation_duration) + .field( + "reservation_rate_limiters", + &format!("[{} rate limiters]", self.reservation_rate_limiters.len()), + ) + .field("max_circuits", &self.max_circuits) + .field("max_circuits_per_peer", &self.max_circuits_per_peer) + .field("max_circuit_duration", &self.max_circuit_duration) + .field("max_circuit_bytes", &self.max_circuit_bytes) + .field( + "circuit_src_rate_limiters", + &format!("[{} rate limiters]", self.circuit_src_rate_limiters.len()), + ) + .finish() + } +} + impl Default for Config { fn default() -> Self { let reservation_rate_limiters = vec![ diff --git a/protocols/relay/src/v2/relay/handler.rs b/protocols/relay/src/v2/relay/handler.rs index 547469797dd..e42f3735e4a 100644 --- a/protocols/relay/src/v2/relay/handler.rs +++ b/protocols/relay/src/v2/relay/handler.rs @@ -44,6 +44,7 @@ use std::fmt; use std::task::{Context, Poll}; use std::time::Duration; +#[derive(Debug, Clone)] pub struct Config { pub reservation_duration: Duration, pub max_circuit_duration: Duration, diff --git a/protocols/relay/src/v2/relay/rate_limiter.rs b/protocols/relay/src/v2/relay/rate_limiter.rs index c89a6c0761b..d0b4b4e631f 100644 --- a/protocols/relay/src/v2/relay/rate_limiter.rs +++ b/protocols/relay/src/v2/relay/rate_limiter.rs @@ -84,7 +84,7 @@ mod generic { } /// Configuration for a [`RateLimiter`]. - #[derive(Clone, Copy)] + #[derive(Debug, Clone, Copy)] pub struct RateLimiterConfig { /// The maximum number of tokens in the bucket at any point in time. pub limit: NonZeroU32,