Skip to content

Commit

Permalink
*: Derive Debug and Clone(#2495)
Browse files Browse the repository at this point in the history
Co-authored-by: Max Inden <[email protected]>
  • Loading branch information
nazar-pc and mxinden authored Feb 16, 2022
1 parent 9f1114d commit 65cc899
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 9 deletions.
2 changes: 1 addition & 1 deletion core/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
8 changes: 8 additions & 0 deletions core/src/identity/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ use zeroize::Zeroize;
#[derive(Clone)]
pub struct Keypair(Arc<RsaKeyPair>);

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].
Expand Down
2 changes: 1 addition & 1 deletion muxers/yamux/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ where
}

/// The yamux configuration.
#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct YamuxConfig {
inner: yamux::Config,
mode: Option<yamux::Mode>,
Expand Down
1 change: 1 addition & 0 deletions protocols/floodsub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions protocols/gossipsub/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion protocols/gossipsub/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProtocolId>,
Expand Down
2 changes: 1 addition & 1 deletion protocols/identify/src/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion protocols/kad/src/record/store/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion protocols/mdns/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion protocols/ping/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion protocols/relay/src/v1/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ enum IncomingRelayReq {
},
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct RelayConfig {
/// How long to keep connections alive when they're idle.
///
Expand Down
1 change: 1 addition & 0 deletions protocols/relay/src/v1/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
22 changes: 22 additions & 0 deletions protocols/relay/src/v2/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ pub struct Config {
pub circuit_src_rate_limiters: Vec<Box<dyn rate_limiter::RateLimiter>>,
}

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![
Expand Down
1 change: 1 addition & 0 deletions protocols/relay/src/v2/relay/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion protocols/relay/src/v2/relay/rate_limiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 65cc899

Please sign in to comment.