Added loglevel to waku config (#16)
This commit is contained in:
parent
0333d3256c
commit
c3ced48966
|
@ -84,6 +84,12 @@ version = "1.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base-x"
|
||||||
|
version = "0.2.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "base64"
|
name = "base64"
|
||||||
version = "0.13.0"
|
version = "0.13.0"
|
||||||
|
@ -119,12 +125,6 @@ version = "1.3.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bs58"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bumpalo"
|
name = "bumpalo"
|
||||||
version = "3.11.1"
|
version = "3.11.1"
|
||||||
|
@ -379,6 +379,26 @@ version = "2.3.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57"
|
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]]
|
[[package]]
|
||||||
name = "either"
|
name = "either"
|
||||||
version = "1.8.0"
|
version = "1.8.0"
|
||||||
|
@ -630,14 +650,14 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "multiaddr"
|
name = "multiaddr"
|
||||||
version = "0.14.0"
|
version = "0.15.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3c580bfdd8803cce319b047d239559a22f809094aaea4ac13902a1fdcfcd4261"
|
checksum = "8b8d2f5ee4645ab2c09b846006f3bb0916e728a0384982544dba553be727d772"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayref",
|
"arrayref",
|
||||||
"bs58",
|
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"data-encoding",
|
"data-encoding",
|
||||||
|
"multibase",
|
||||||
"multihash",
|
"multihash",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -646,6 +666,17 @@ dependencies = [
|
||||||
"url",
|
"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]]
|
[[package]]
|
||||||
name = "multihash"
|
name = "multihash"
|
||||||
version = "0.16.3"
|
version = "0.16.3"
|
||||||
|
@ -929,9 +960,9 @@ checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "secp256k1"
|
name = "secp256k1"
|
||||||
version = "0.24.0"
|
version = "0.24.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b7649a0b3ffb32636e60c7ce0d70511eda9c52c658cd0634e194d5a19943aeff"
|
checksum = "ff55dc09d460954e9ef2fa8a7ced735a964be9981fd50e870b2b3b0705e14964"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rand",
|
"rand",
|
||||||
"secp256k1-sys",
|
"secp256k1-sys",
|
||||||
|
|
|
@ -11,10 +11,10 @@ authors = [
|
||||||
aes-gcm = { version = "0.10", features = ["aes"] }
|
aes-gcm = { version = "0.10", features = ["aes"] }
|
||||||
base64 = "0.13"
|
base64 = "0.13"
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
secp256k1 = { version = "0.24", features = ["rand", "recovery", "serde"] }
|
multiaddr = "0.15"
|
||||||
multiaddr = "0.14"
|
|
||||||
once_cell = "1.15"
|
once_cell = "1.15"
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
|
secp256k1 = { version = "0.24", features = ["rand", "recovery", "serde"] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
sscanf = "0.3"
|
sscanf = "0.3"
|
||||||
|
|
|
@ -9,7 +9,7 @@ mod node;
|
||||||
pub use node::{
|
pub use node::{
|
||||||
waku_create_content_topic, waku_create_pubsub_topic, waku_dafault_pubsub_topic, waku_new,
|
waku_create_content_topic, waku_create_pubsub_topic, waku_dafault_pubsub_topic, waku_new,
|
||||||
waku_store_query, Aes256Gcm, Initialized, Key, Multiaddr, Protocol, PublicKey, Running,
|
waku_store_query, Aes256Gcm, Initialized, Key, Multiaddr, Protocol, PublicKey, Running,
|
||||||
SecretKey, WakuNodeConfig, WakuNodeHandle, WakuPeerData, WakuPeers,
|
SecretKey, WakuLogLevel, WakuNodeConfig, WakuNodeHandle, WakuPeerData, WakuPeers,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use general::{
|
pub use general::{
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
//! Waku node [configuration](https://rfc.vac.dev/spec/36/#jsonconfig-type) related items
|
//! Waku node [configuration](https://rfc.vac.dev/spec/36/#jsonconfig-type) related items
|
||||||
|
|
||||||
|
use std::fmt::{Display, Formatter};
|
||||||
|
use std::str::FromStr;
|
||||||
// std
|
// std
|
||||||
// crates
|
// crates
|
||||||
use multiaddr::Multiaddr;
|
use multiaddr::Multiaddr;
|
||||||
|
@ -30,6 +32,55 @@ pub struct WakuNodeConfig {
|
||||||
pub min_peers_to_publish: Option<usize>,
|
pub min_peers_to_publish: Option<usize>,
|
||||||
/// Enable filter protocol. Default `false`
|
/// Enable filter protocol. Default `false`
|
||||||
pub filter: Option<bool>,
|
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 {
|
mod secret_key_serde {
|
||||||
|
|
|
@ -25,7 +25,7 @@ use crate::general::{
|
||||||
WakuMessage, WakuPubSubTopic,
|
WakuMessage, WakuPubSubTopic,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use config::WakuNodeConfig;
|
pub use config::{WakuLogLevel, WakuNodeConfig};
|
||||||
pub use peers::{Protocol, WakuPeerData, WakuPeers};
|
pub use peers::{Protocol, WakuPeerData, WakuPeers};
|
||||||
pub use relay::{waku_create_content_topic, waku_create_pubsub_topic, waku_dafault_pubsub_topic};
|
pub use relay::{waku_create_content_topic, waku_create_pubsub_topic, waku_dafault_pubsub_topic};
|
||||||
pub use store::waku_store_query;
|
pub use store::waku_store_query;
|
||||||
|
|
|
@ -6,8 +6,8 @@ use std::net::IpAddr;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
use waku::{
|
use waku::{
|
||||||
waku_new, waku_set_event_callback, Encoding, Event, ProtocolId, WakuContentTopic, WakuMessage,
|
waku_new, waku_set_event_callback, Encoding, Event, ProtocolId, WakuContentTopic, WakuLogLevel,
|
||||||
WakuNodeConfig,
|
WakuMessage, WakuNodeConfig,
|
||||||
};
|
};
|
||||||
|
|
||||||
const NODES: &[&str] = &[
|
const NODES: &[&str] = &[
|
||||||
|
@ -28,6 +28,7 @@ pub fn main() -> Result<(), String> {
|
||||||
relay: None,
|
relay: None,
|
||||||
min_peers_to_publish: None,
|
min_peers_to_publish: None,
|
||||||
filter: None,
|
filter: None,
|
||||||
|
log_level: Some(WakuLogLevel::Error),
|
||||||
};
|
};
|
||||||
let node = waku_new(Some(config))?;
|
let node = waku_new(Some(config))?;
|
||||||
let node = node.start()?;
|
let node = node.start()?;
|
||||||
|
|
Loading…
Reference in New Issue