Added loglevel to waku config

This commit is contained in:
Daniel Sanchez Quiros 2022-10-26 12:14:43 +02:00
parent 0333d3256c
commit 742cf914b5
6 changed files with 100 additions and 17 deletions

53
Cargo.lock generated
View File

@ -84,6 +84,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "base-x"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270"
[[package]]
name = "base64"
version = "0.13.0"
@ -119,12 +125,6 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bs58"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3"
[[package]]
name = "bumpalo"
version = "3.11.1"
@ -379,6 +379,26 @@ version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57"
[[package]]
name = "data-encoding-macro"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86927b7cd2fe88fa698b87404b287ab98d1a0063a34071d92e575b72d3029aca"
dependencies = [
"data-encoding",
"data-encoding-macro-internal",
]
[[package]]
name = "data-encoding-macro-internal"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a5bbed42daaa95e780b60a50546aa345b8413a1e46f9a40a12907d3598f038db"
dependencies = [
"data-encoding",
"syn",
]
[[package]]
name = "either"
version = "1.8.0"
@ -630,14 +650,14 @@ dependencies = [
[[package]]
name = "multiaddr"
version = "0.14.0"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c580bfdd8803cce319b047d239559a22f809094aaea4ac13902a1fdcfcd4261"
checksum = "8b8d2f5ee4645ab2c09b846006f3bb0916e728a0384982544dba553be727d772"
dependencies = [
"arrayref",
"bs58",
"byteorder",
"data-encoding",
"multibase",
"multihash",
"percent-encoding",
"serde",
@ -646,6 +666,17 @@ dependencies = [
"url",
]
[[package]]
name = "multibase"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b3539ec3c1f04ac9748a260728e855f261b4977f5c3406612c884564f329404"
dependencies = [
"base-x",
"data-encoding",
"data-encoding-macro",
]
[[package]]
name = "multihash"
version = "0.16.3"
@ -929,9 +960,9 @@ checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898"
[[package]]
name = "secp256k1"
version = "0.24.0"
version = "0.24.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7649a0b3ffb32636e60c7ce0d70511eda9c52c658cd0634e194d5a19943aeff"
checksum = "ff55dc09d460954e9ef2fa8a7ced735a964be9981fd50e870b2b3b0705e14964"
dependencies = [
"rand",
"secp256k1-sys",

View File

@ -11,10 +11,10 @@ authors = [
aes-gcm = { version = "0.10", features = ["aes"] }
base64 = "0.13"
hex = "0.4"
secp256k1 = { version = "0.24", features = ["rand", "recovery", "serde"] }
multiaddr = "0.14"
multiaddr = "0.15"
once_cell = "1.15"
rand = "0.8"
secp256k1 = { version = "0.24", features = ["rand", "recovery", "serde"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sscanf = "0.3"

View File

@ -9,7 +9,7 @@ mod node;
pub use node::{
waku_create_content_topic, waku_create_pubsub_topic, waku_dafault_pubsub_topic, waku_new,
waku_store_query, Aes256Gcm, Initialized, Key, Multiaddr, Protocol, PublicKey, Running,
SecretKey, WakuNodeConfig, WakuNodeHandle, WakuPeerData, WakuPeers,
SecretKey, WakuLogLevel, WakuNodeConfig, WakuNodeHandle, WakuPeerData, WakuPeers,
};
pub use general::{

View File

@ -1,5 +1,7 @@
//! Waku node [configuration](https://rfc.vac.dev/spec/36/#jsonconfig-type) related items
use std::fmt::{Display, Formatter};
use std::str::FromStr;
// std
// crates
use multiaddr::Multiaddr;
@ -30,6 +32,55 @@ pub struct WakuNodeConfig {
pub min_peers_to_publish: Option<usize>,
/// Enable filter protocol. Default `false`
pub filter: Option<bool>,
/// Set the log level. Default `INFO`. Allowed values "DEBUG", "INFO", "WARN", "ERROR", "DPANIC", "PANIC", "FATAL"
pub log_level: Option<WakuLogLevel>,
}
#[derive(Clone, Default, Serialize, Deserialize)]
pub enum WakuLogLevel {
#[default]
Info,
Debug,
Warn,
Error,
DPanic,
Panic,
Fatal,
}
impl FromStr for WakuLogLevel {
type Err = std::io::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"info" => Ok(Self::Info),
"debug" => Ok(Self::Debug),
"warn" => Ok(Self::Warn),
"error" => Ok(Self::Error),
"dpanic" => Ok(Self::DPanic),
"panic" => Ok(Self::Panic),
"fatal" => Ok(Self::Fatal),
_ => Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
format!("Unrecognized waku log level: {}. Allowed values \"DEBUG\", \"INFO\", \"WARN\", \"ERROR\", \"DPANIC\", \"PANIC\", \"FATAL\"", s),
)),
}
}
}
impl Display for WakuLogLevel {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let tag = match self {
WakuLogLevel::Info => "INFO",
WakuLogLevel::Debug => "DEBUG",
WakuLogLevel::Warn => "WARN",
WakuLogLevel::Error => "ERROR",
WakuLogLevel::DPanic => "DPANIC",
WakuLogLevel::Panic => "PANIC",
WakuLogLevel::Fatal => "FATAL",
};
write!(f, "{tag}")
}
}
mod secret_key_serde {

View File

@ -25,7 +25,7 @@ use crate::general::{
WakuMessage, WakuPubSubTopic,
};
pub use config::WakuNodeConfig;
pub use config::{WakuLogLevel, WakuNodeConfig};
pub use peers::{Protocol, WakuPeerData, WakuPeers};
pub use relay::{waku_create_content_topic, waku_create_pubsub_topic, waku_dafault_pubsub_topic};
pub use store::waku_store_query;

View File

@ -6,8 +6,8 @@ use std::net::IpAddr;
use std::str::FromStr;
use std::time::{Duration, SystemTime};
use waku::{
waku_new, waku_set_event_callback, Encoding, Event, ProtocolId, WakuContentTopic, WakuMessage,
WakuNodeConfig,
waku_new, waku_set_event_callback, Encoding, Event, ProtocolId, WakuContentTopic, WakuLogLevel,
WakuMessage, WakuNodeConfig,
};
const NODES: &[&str] = &[
@ -28,6 +28,7 @@ pub fn main() -> Result<(), String> {
relay: None,
min_peers_to_publish: None,
filter: None,
log_level: Some(WakuLogLevel::Error),
};
let node = waku_new(Some(config))?;
let node = node.start()?;