From 3d744fb87e39605c1a8d8c6fc92022bdc3e5d512 Mon Sep 17 00:00:00 2001 From: John Smith Date: Wed, 5 Jan 2022 20:32:43 -0500 Subject: [PATCH] dump config --- Cargo.lock | 23 +++++++++ veilid-server/Cargo.toml | 1 + veilid-server/src/settings.rs | 87 ++++++++++++++++++++++++++--------- veilid-server/src/unix.rs | 14 ++++++ 4 files changed, 103 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 84dc16d4..05cc4e02 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1708,6 +1708,16 @@ dependencies = [ "syn", ] +[[package]] +name = "indexmap" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" +dependencies = [ + "autocfg", + "hashbrown", +] + [[package]] name = "input_buffer" version = "0.3.1" @@ -3212,6 +3222,18 @@ dependencies = [ "serde 0.8.23", ] +[[package]] +name = "serde_yaml" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a521f2940385c165a24ee286aa8599633d162077a54bdcae2a6fd5a7bfa7a0" +dependencies = [ + "indexmap", + "ryu", + "serde 1.0.130", + "yaml-rust", +] + [[package]] name = "serial_test" version = "0.4.0" @@ -3838,6 +3860,7 @@ dependencies = [ "parking_lot 0.11.2", "serde 1.0.130", "serde_derive", + "serde_yaml", "serial_test 0.5.1", "simplelog", "url", diff --git a/veilid-server/Cargo.toml b/veilid-server/Cargo.toml index d61ed783..5924994f 100644 --- a/veilid-server/Cargo.toml +++ b/veilid-server/Cargo.toml @@ -26,6 +26,7 @@ failure = "^0" cfg-if = "^0" serde = "^1" serde_derive = "^1" +serde_yaml = "^0" futures = "^0" url = "^2" ctrlc = "^3" diff --git a/veilid-server/src/settings.rs b/veilid-server/src/settings.rs index e9976fdf..d1e24b55 100644 --- a/veilid-server/src/settings.rs +++ b/veilid-server/src/settings.rs @@ -168,6 +168,22 @@ impl<'de> serde::Deserialize<'de> for LogLevel { } } } +impl serde::Serialize for LogLevel { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let s = match self { + LogLevel::Error => "error", + LogLevel::Warn => "warn", + LogLevel::Info => "info", + LogLevel::Debug => "debug", + LogLevel::Trace => "trace", + }; + s.serialize(serializer) + } +} + pub fn convert_loglevel(log_level: LogLevel) -> LevelFilter { match log_level { LogLevel::Error => LevelFilter::Error, @@ -223,6 +239,15 @@ impl<'de> serde::Deserialize<'de> for ParsedUrl { } } +impl serde::Serialize for ParsedUrl { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + self.urlstring.serialize(serializer) + } +} + #[derive(Debug, Clone, PartialEq)] pub struct ParsedNodeDialInfo { pub node_dial_info_string: String, @@ -263,6 +288,15 @@ impl<'de> serde::Deserialize<'de> for ParsedNodeDialInfo { } } +impl serde::Serialize for ParsedNodeDialInfo { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + self.node_dial_info_string.serialize(serializer) + } +} + #[derive(Debug, PartialEq)] pub struct NamedSocketAddrs { pub name: String, @@ -290,6 +324,15 @@ impl<'de> serde::Deserialize<'de> for NamedSocketAddrs { } } +impl serde::Serialize for NamedSocketAddrs { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + self.name.serialize(serializer) + } +} + impl NamedSocketAddrs { pub fn offset_port(&mut self, offset: u16) -> Result<(), ()> { // Bump port on name @@ -312,13 +355,13 @@ impl NamedSocketAddrs { } } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Terminal { pub enabled: bool, pub level: LogLevel, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct File { pub enabled: bool, pub path: String, @@ -326,26 +369,26 @@ pub struct File { pub level: LogLevel, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Client { pub enabled: bool, pub level: LogLevel, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct ClientApi { pub enabled: bool, pub listen_address: NamedSocketAddrs, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Logging { pub terminal: Terminal, pub file: File, pub client: Client, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Https { pub enabled: bool, pub listen_address: NamedSocketAddrs, @@ -353,7 +396,7 @@ pub struct Https { pub url: Option, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Http { pub enabled: bool, pub listen_address: NamedSocketAddrs, @@ -361,13 +404,13 @@ pub struct Http { pub url: Option, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Application { pub https: Https, pub http: Http, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Udp { pub enabled: bool, pub socket_pool_size: u32, @@ -375,7 +418,7 @@ pub struct Udp { pub public_address: Option, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Tcp { pub connect: bool, pub listen: bool, @@ -384,7 +427,7 @@ pub struct Tcp { pub public_address: Option, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Ws { pub connect: bool, pub listen: bool, @@ -394,7 +437,7 @@ pub struct Ws { pub url: Option, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Wss { pub connect: bool, pub listen: bool, @@ -404,7 +447,7 @@ pub struct Wss { pub url: Option, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Protocol { pub udp: Udp, pub tcp: Tcp, @@ -412,14 +455,14 @@ pub struct Protocol { pub wss: Wss, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Tls { pub certificate_path: PathBuf, pub private_key_path: PathBuf, pub connection_initial_timeout: u64, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Rpc { pub concurrency: u32, pub queue_size: u32, @@ -429,7 +472,7 @@ pub struct Rpc { pub max_route_hop_count: u8, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Dht { pub resolve_node_timeout: Option, pub resolve_node_count: u32, @@ -446,7 +489,7 @@ pub struct Dht { pub validate_dial_info_receipt_time: u64, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Leases { pub max_server_signal_leases: u32, pub max_server_relay_leases: u32, @@ -454,7 +497,7 @@ pub struct Leases { pub max_client_relay_leases: u32, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Network { pub max_connections: u32, pub connection_initial_timeout: u64, @@ -473,23 +516,23 @@ pub struct Network { pub leases: Leases, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Testing { pub subnode_index: u16, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct TableStore { pub directory: PathBuf, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Core { pub tablestore: TableStore, pub network: Network, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct SettingsInner { pub daemon: bool, pub client_api: ClientApi, diff --git a/veilid-server/src/unix.rs b/veilid-server/src/unix.rs index ab8a7b36..fb4718d5 100644 --- a/veilid-server/src/unix.rs +++ b/veilid-server/src/unix.rs @@ -57,6 +57,11 @@ fn parse_command_line(default_config_path: &OsStr) -> Result Result<(), String> { clogwriter, )) } + + // --- Dump Config --- + if matches.occurrences_of("dump-config") != 0 { + //let cfg = config::Config::try_from(&*settingsr); + return serde_yaml::to_writer(std::io::stdout(), &*settingsr).map_err(|e| e.to_string()); + } + + // --- Normal Startup --- + CombinedLogger::init(logs).map_err(|e| format!("failed to init logs: {}", e))?; // Create Veilid Core