*: Derive Debug and Clone(#2495)

Co-authored-by: Max Inden <mail@max-inden.de>
This commit is contained in:
Nazar Mokrynskyi 2022-02-16 17:16:54 +02:00 committed by GitHub
parent 9f1114d8b9
commit 65cc8994a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 44 additions and 9 deletions

View File

@ -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),

View File

@ -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].

View File

@ -198,7 +198,7 @@ where
}
/// The yamux configuration.
#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct YamuxConfig {
inner: yamux::Config,
mode: Option<yamux::Mode>,

View File

@ -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,

View File

@ -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,

View File

@ -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.

View File

@ -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>,

View File

@ -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`.

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -102,7 +102,7 @@ enum IncomingRelayReq {
},
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct RelayConfig {
/// How long to keep connections alive when they're idle.
///

View File

@ -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,
}

View File

@ -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![

View File

@ -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,

View File

@ -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,