mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-02 20:51:21 +00:00
*: Derive Debug
and Clone
(#2495)
Co-authored-by: Max Inden <mail@max-inden.de>
This commit is contained in:
parent
9f1114d8b9
commit
65cc8994a6
@ -63,7 +63,7 @@ use std::convert::{TryFrom, TryInto};
|
|||||||
/// let keypair = Keypair::rsa_from_pkcs8(&mut bytes);
|
/// let keypair = Keypair::rsa_from_pkcs8(&mut bytes);
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
#[derive(Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Keypair {
|
pub enum Keypair {
|
||||||
/// An Ed25519 keypair.
|
/// An Ed25519 keypair.
|
||||||
Ed25519(ed25519::Keypair),
|
Ed25519(ed25519::Keypair),
|
||||||
|
@ -33,6 +33,14 @@ use zeroize::Zeroize;
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Keypair(Arc<RsaKeyPair>);
|
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 {
|
impl Keypair {
|
||||||
/// Decode an RSA keypair from a DER-encoded private key in PKCS#8 PrivateKeyInfo
|
/// Decode an RSA keypair from a DER-encoded private key in PKCS#8 PrivateKeyInfo
|
||||||
/// format (i.e. unencrypted) as defined in [RFC5208].
|
/// format (i.e. unencrypted) as defined in [RFC5208].
|
||||||
|
@ -198,7 +198,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The yamux configuration.
|
/// The yamux configuration.
|
||||||
#[derive(Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct YamuxConfig {
|
pub struct YamuxConfig {
|
||||||
inner: yamux::Config,
|
inner: yamux::Config,
|
||||||
mode: Option<yamux::Mode>,
|
mode: Option<yamux::Mode>,
|
||||||
|
@ -37,6 +37,7 @@ pub use self::protocol::{FloodsubMessage, FloodsubRpc};
|
|||||||
pub use self::topic::Topic;
|
pub use self::topic::Topic;
|
||||||
|
|
||||||
/// Configuration options for the Floodsub protocol.
|
/// Configuration options for the Floodsub protocol.
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
pub struct FloodsubConfig {
|
pub struct FloodsubConfig {
|
||||||
/// Peer id of the local node. Used for the source of the messages that we publish.
|
/// Peer id of the local node. Used for the source of the messages that we publish.
|
||||||
pub local_peer_id: PeerId,
|
pub local_peer_id: PeerId,
|
||||||
|
@ -149,6 +149,7 @@ pub enum GossipsubEvent {
|
|||||||
/// A data structure for storing configuration for publishing messages. See [`MessageAuthenticity`]
|
/// A data structure for storing configuration for publishing messages. See [`MessageAuthenticity`]
|
||||||
/// for further details.
|
/// for further details.
|
||||||
#[allow(clippy::large_enum_variant)]
|
#[allow(clippy::large_enum_variant)]
|
||||||
|
#[derive(Clone)]
|
||||||
enum PublishConfig {
|
enum PublishConfig {
|
||||||
Signing {
|
Signing {
|
||||||
keypair: Keypair,
|
keypair: Keypair,
|
||||||
|
@ -40,6 +40,7 @@ const DEFAULT_MAX_TOPICS: usize = 300;
|
|||||||
// store metrics.
|
// store metrics.
|
||||||
const DEFAULT_MAX_NEVER_SUBSCRIBED_TOPICS: usize = 50;
|
const DEFAULT_MAX_NEVER_SUBSCRIBED_TOPICS: usize = 50;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
/// This provides an upper bound to the number of mesh topics we create metrics for. It
|
/// This provides an upper bound to the number of mesh topics we create metrics for. It
|
||||||
/// prevents unbounded labels being created in the metrics.
|
/// prevents unbounded labels being created in the metrics.
|
||||||
|
@ -44,7 +44,7 @@ use unsigned_varint::codec;
|
|||||||
pub(crate) const SIGNING_PREFIX: &[u8] = b"libp2p-pubsub:";
|
pub(crate) const SIGNING_PREFIX: &[u8] = b"libp2p-pubsub:";
|
||||||
|
|
||||||
/// Implementation of [`InboundUpgrade`] and [`OutboundUpgrade`] for the Gossipsub protocol.
|
/// Implementation of [`InboundUpgrade`] and [`OutboundUpgrade`] for the Gossipsub protocol.
|
||||||
#[derive(Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ProtocolConfig {
|
pub struct ProtocolConfig {
|
||||||
/// The Gossipsub protocol id to listen on.
|
/// The Gossipsub protocol id to listen on.
|
||||||
protocol_ids: Vec<ProtocolId>,
|
protocol_ids: Vec<ProtocolId>,
|
||||||
|
@ -82,7 +82,7 @@ enum Reply {
|
|||||||
|
|
||||||
/// Configuration for the [`Identify`] [`NetworkBehaviour`].
|
/// Configuration for the [`Identify`] [`NetworkBehaviour`].
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct IdentifyConfig {
|
pub struct IdentifyConfig {
|
||||||
/// Application-specific version of the protocol family used by the peer,
|
/// Application-specific version of the protocol family used by the peer,
|
||||||
/// e.g. `ipfs/1.0.0` or `polkadot/1.0.0`.
|
/// e.g. `ipfs/1.0.0` or `polkadot/1.0.0`.
|
||||||
|
@ -44,7 +44,7 @@ pub struct MemoryStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Configuration for a `MemoryStore`.
|
/// Configuration for a `MemoryStore`.
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct MemoryStoreConfig {
|
pub struct MemoryStoreConfig {
|
||||||
/// The maximum number of records.
|
/// The maximum number of records.
|
||||||
pub max_records: usize,
|
pub max_records: usize,
|
||||||
|
@ -49,7 +49,7 @@ lazy_static! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Configuration for mDNS.
|
/// Configuration for mDNS.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct MdnsConfig {
|
pub struct MdnsConfig {
|
||||||
/// TTL to use for mdns records.
|
/// TTL to use for mdns records.
|
||||||
pub ttl: Duration,
|
pub ttl: Duration,
|
||||||
|
@ -38,7 +38,7 @@ use std::{
|
|||||||
use void::Void;
|
use void::Void;
|
||||||
|
|
||||||
/// The configuration for outbound pings.
|
/// The configuration for outbound pings.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
/// The timeout of an outbound ping.
|
/// The timeout of an outbound ping.
|
||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
|
@ -102,7 +102,7 @@ enum IncomingRelayReq {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct RelayConfig {
|
pub struct RelayConfig {
|
||||||
/// How long to keep connections alive when they're idle.
|
/// How long to keep connections alive when they're idle.
|
||||||
///
|
///
|
||||||
|
@ -37,6 +37,7 @@ use std::fmt;
|
|||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
pub struct RelayHandlerConfig {
|
pub struct RelayHandlerConfig {
|
||||||
pub connection_idle_timeout: Duration,
|
pub connection_idle_timeout: Duration,
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,28 @@ pub struct Config {
|
|||||||
pub circuit_src_rate_limiters: Vec<Box<dyn rate_limiter::RateLimiter>>,
|
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 {
|
impl Default for Config {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let reservation_rate_limiters = vec![
|
let reservation_rate_limiters = vec![
|
||||||
|
@ -44,6 +44,7 @@ use std::fmt;
|
|||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub reservation_duration: Duration,
|
pub reservation_duration: Duration,
|
||||||
pub max_circuit_duration: Duration,
|
pub max_circuit_duration: Duration,
|
||||||
|
@ -84,7 +84,7 @@ mod generic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Configuration for a [`RateLimiter`].
|
/// Configuration for a [`RateLimiter`].
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct RateLimiterConfig {
|
pub struct RateLimiterConfig {
|
||||||
/// The maximum number of tokens in the bucket at any point in time.
|
/// The maximum number of tokens in the bucket at any point in time.
|
||||||
pub limit: NonZeroU32,
|
pub limit: NonZeroU32,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user