From b353144537b689c166557c341da32f65b5bfa59a Mon Sep 17 00:00:00 2001 From: Caio Date: Mon, 28 Oct 2019 10:28:32 -0300 Subject: [PATCH 1/3] Implement Debug for some structures `NetworkConfiguration`, `TransportConfig`, `NodeKeyConfig` and `Secret`. Needs a new release of the `rust-libp2p` crate. This PR is just a reminder. --- core/network/src/config.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/network/src/config.rs b/core/network/src/config.rs index 445d4427bd91c..b399459fd7df3 100644 --- a/core/network/src/config.rs +++ b/core/network/src/config.rs @@ -234,7 +234,7 @@ impl From for ParseErr { } /// Network service configuration. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct NetworkConfiguration { /// Directory path to store general network configuration. None means nothing will be saved. pub config_path: Option, @@ -317,7 +317,7 @@ impl NetworkConfiguration { } /// Configuration for the transport layer. -#[derive(Clone)] +#[derive(Clone, Debug)] pub enum TransportConfig { /// Normal transport mode. Normal { @@ -362,7 +362,7 @@ impl NonReservedPeerMode { /// The configuration of a node's secret key, describing the type of key /// and how it is obtained. A node's identity keypair is the result of /// the evaluation of the node key configuration. -#[derive(Clone)] +#[derive(Clone, Debug)] pub enum NodeKeyConfig { /// A Ed25519 secret key configuration. Ed25519(Secret) @@ -372,7 +372,7 @@ pub enum NodeKeyConfig { pub type Ed25519Secret = Secret; /// The configuration options for obtaining a secret key `K`. -#[derive(Clone)] +#[derive(Clone, Debug)] pub enum Secret { /// Use the given secret key `K`. Input(K), From 332911e7959659517e305eb65ea927c7fea6a583 Mon Sep 17 00:00:00 2001 From: Caio Date: Thu, 31 Oct 2019 10:43:41 -0300 Subject: [PATCH 2/3] Explicitly separate `std` and `core` --- core/network/src/config.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/network/src/config.rs b/core/network/src/config.rs index b399459fd7df3..bcc4c1416c535 100644 --- a/core/network/src/config.rs +++ b/core/network/src/config.rs @@ -28,12 +28,11 @@ use crate::service::{ExHashT, TransactionPool}; use bitflags::bitflags; use consensus::{block_validation::BlockAnnounceValidator, import_queue::ImportQueue}; use sr_primitives::traits::{Block as BlockT}; -use std::sync::Arc; use libp2p::identity::{Keypair, ed25519}; use libp2p::wasm_ext; use libp2p::{PeerId, Multiaddr, multiaddr}; -use std::error::Error; -use std::{io::{self, Write}, iter, fmt, fs, net::Ipv4Addr, path::{Path, PathBuf}}; +use core::{fmt, iter}; +use std::{error::Error, fs, io::{self, Write}, net::Ipv4Addr, path::{Path, PathBuf}, sync::Arc}; use zeroize::Zeroize; /// Network initialization parameters. From 3729884893c5be22f2b25b0ebd592c70b8a60247 Mon Sep 17 00:00:00 2001 From: Caio Date: Thu, 31 Oct 2019 10:45:07 -0300 Subject: [PATCH 3/3] Add manual implementation for Secret --- core/network/src/config.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/network/src/config.rs b/core/network/src/config.rs index bcc4c1416c535..be01b90c36363 100644 --- a/core/network/src/config.rs +++ b/core/network/src/config.rs @@ -371,7 +371,7 @@ pub enum NodeKeyConfig { pub type Ed25519Secret = Secret; /// The configuration options for obtaining a secret key `K`. -#[derive(Clone, Debug)] +#[derive(Clone)] pub enum Secret { /// Use the given secret key `K`. Input(K), @@ -385,6 +385,16 @@ pub enum Secret { New } +impl fmt::Debug for Secret { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + Secret::Input(_) => f.debug_tuple("Secret::Input").finish(), + Secret::File(path) => f.debug_tuple("Secret::File").field(path).finish(), + Secret::New => f.debug_tuple("Secret::New").finish(), + } + } +} + impl NodeKeyConfig { /// Evaluate a `NodeKeyConfig` to obtain an identity `Keypair`: ///