add default value for Config

This commit is contained in:
al8n 2022-12-21 00:33:08 +13:00
parent b05d24e0d4
commit b8172167f4
3 changed files with 24 additions and 1 deletions

12
Cargo.lock generated
View File

@ -965,6 +965,17 @@ version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
[[package]]
name = "smart-default"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "133659a15339456eeeb07572eb02a91c91e9815e9cbc89566944d2c8d3efdbf6"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "sscanf"
version = "0.3.1"
@ -1204,6 +1215,7 @@ dependencies = [
"secp256k1",
"serde",
"serde_json",
"smart-default",
"sscanf",
"url",
"waku-sys",

View File

@ -23,5 +23,6 @@ secp256k1 = { version = "0.24", features = ["rand", "recovery", "serde"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sscanf = "0.3"
smart-default = "0.6"
url = "2.3"
waku-sys = { version = "0.1.0-beta1", path = "../waku-sys" }

View File

@ -7,15 +7,18 @@ use std::str::FromStr;
use multiaddr::Multiaddr;
use secp256k1::SecretKey;
use serde::{Deserialize, Serialize};
use smart_default::SmartDefault;
// internal
/// Waku node configuration
#[derive(Clone, Default, Serialize, Deserialize, Debug)]
#[derive(Clone, SmartDefault, Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct WakuNodeConfig {
/// Listening IP address. Default `0.0.0.0`
#[default(Some(std::net::IpAddr::V4(std::net::Ipv4Addr::new(0, 0, 0, 0))))]
pub host: Option<std::net::IpAddr>,
/// Libp2p TCP listening port. Default `60000`. Use `0` for **random**
#[default(Some(60000))]
pub port: Option<usize>,
/// External address to advertise to other nodes. Can be ip4, ip6 or dns4, dns6.
/// If null, the multiaddress(es) generated from the ip and port specified in the config (or default ones) will be used.
@ -25,22 +28,29 @@ pub struct WakuNodeConfig {
#[serde(with = "secret_key_serde")]
pub node_key: Option<SecretKey>,
/// Interval in seconds for pinging peers to keep the connection alive. Default `20`
#[default(Some(20))]
pub keep_alive_interval: Option<usize>,
/// Enable relay protocol. Default `true`
#[default(Some(true))]
pub relay: Option<bool>,
/// The minimum number of peers required on a topic to allow broadcasting a message. Default `0`
#[default(Some(0))]
pub min_peers_to_publish: Option<usize>,
/// Enable filter protocol. Default `false`
#[default(Some(false))]
pub filter: Option<bool>,
/// Set the log level. Default `INFO`. Allowed values "DEBUG", "INFO", "WARN", "ERROR", "DPANIC", "PANIC", "FATAL"
#[default(Some(WakuLogLevel::Info))]
pub log_level: Option<WakuLogLevel>,
/// Enable DiscoveryV5. Default `false`
#[default(Some(false))]
#[serde(rename = "discV5")]
pub disc_v5: Option<bool>,
/// Array of bootstrap nodes ENR.
#[serde(rename = "discV5BootstrapNodes")]
pub disc_v5_bootstrap_nodes: Vec<String>,
/// UDP port for DiscoveryV5. Default `9000`.
#[default(Some(9000))]
#[serde(rename = "discV5UDPPort")]
pub disc_v5_udp_port: Option<u16>,
}