From b8172167f4cb9642813d0d1c8c0acaa860b0af7f Mon Sep 17 00:00:00 2001 From: al8n Date: Wed, 21 Dec 2022 00:33:08 +1300 Subject: [PATCH] add default value for Config --- Cargo.lock | 12 ++++++++++++ waku-bindings/Cargo.toml | 1 + waku-bindings/src/node/config.rs | 12 +++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 924059c..d42df85 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/waku-bindings/Cargo.toml b/waku-bindings/Cargo.toml index d6a9046..ac57668 100644 --- a/waku-bindings/Cargo.toml +++ b/waku-bindings/Cargo.toml @@ -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" } diff --git a/waku-bindings/src/node/config.rs b/waku-bindings/src/node/config.rs index 46eba11..0cff8ee 100644 --- a/waku-bindings/src/node/config.rs +++ b/waku-bindings/src/node/config.rs @@ -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, /// Libp2p TCP listening port. Default `60000`. Use `0` for **random** + #[default(Some(60000))] pub port: Option, /// 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, /// Interval in seconds for pinging peers to keep the connection alive. Default `20` + #[default(Some(20))] pub keep_alive_interval: Option, /// Enable relay protocol. Default `true` + #[default(Some(true))] pub relay: Option, /// 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, /// Enable filter protocol. Default `false` + #[default(Some(false))] pub filter: Option, /// Set the log level. Default `INFO`. Allowed values "DEBUG", "INFO", "WARN", "ERROR", "DPANIC", "PANIC", "FATAL" + #[default(Some(WakuLogLevel::Info))] pub log_level: Option, /// Enable DiscoveryV5. Default `false` + #[default(Some(false))] #[serde(rename = "discV5")] pub disc_v5: Option, /// Array of bootstrap nodes ENR. #[serde(rename = "discV5BootstrapNodes")] pub disc_v5_bootstrap_nodes: Vec, /// UDP port for DiscoveryV5. Default `9000`. + #[default(Some(9000))] #[serde(rename = "discV5UDPPort")] pub disc_v5_udp_port: Option, }