From f7ce5f93d0e8524877e6796bc9fd24aa13761cfd Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Mon, 5 Aug 2024 12:27:39 -0500 Subject: [PATCH] add '--port' command line option for veilid-server that changes the base port for all protocols --- veilid-server/src/main.rs | 21 +++++++++++++++++---- veilid-server/src/settings.rs | 6 +++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/veilid-server/src/main.rs b/veilid-server/src/main.rs index f2755c0c..5f9a5100 100644 --- a/veilid-server/src/main.rs +++ b/veilid-server/src/main.rs @@ -136,11 +136,11 @@ pub struct CmdlineArgs { #[arg(long, value_name = "BOOTSTRAP_LIST")] bootstrap: Option, - /// panic on ctrl-c instead of graceful shutdown + /// Panic on ctrl-c instead of graceful shutdown #[arg(long)] panic: bool, - /// password override to use for network isolation + /// Password override to use for network isolation #[arg(long, value_name = "KEY")] network_key: Option, @@ -149,14 +149,18 @@ pub struct CmdlineArgs { #[arg(long)] wait_for_debug: bool, - /// enable tokio console + /// Enable tokio console #[cfg(feature = "rt-tokio")] #[arg(long)] console: bool, - /// change ingore_log_targets + /// Change targets to ignore for logging #[arg(long)] ignore_log_targets: Option>, + + /// Override all network listen addresses with ':port' + #[arg(long)] + port: Option, } #[instrument(level = "trace", skip_all, err)] @@ -317,6 +321,15 @@ fn main() -> EyreResult<()> { settingsrw.logging.terminal.ignore_log_targets = ignore_log_targets } + if let Some(port) = args.port { + let listen_address = + NamedSocketAddrs::from_str(&format!(":{}", port)).wrap_err("invalid port")?; + settingsrw.core.network.protocol.udp.listen_address = listen_address.clone(); + settingsrw.core.network.protocol.tcp.listen_address = listen_address.clone(); + settingsrw.core.network.protocol.ws.listen_address = listen_address.clone(); + settingsrw.core.network.protocol.wss.listen_address = listen_address; + } + drop(settingsrw); // Set specific config settings diff --git a/veilid-server/src/settings.rs b/veilid-server/src/settings.rs index d65f271a..f6a8aca2 100644 --- a/veilid-server/src/settings.rs +++ b/veilid-server/src/settings.rs @@ -263,7 +263,7 @@ pub fn load_config(cfg: config::Config, config_file: &Path) -> EyreResult veilid_core::VeilidConfigLogLeve } } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, Eq, PartialEq)] pub struct ParsedUrl { pub urlstring: String, pub url: Url, @@ -376,7 +376,7 @@ impl serde::Serialize for ParsedUrl { } } -#[derive(Debug, PartialEq)] +#[derive(Debug, Clone, Eq, PartialEq)] pub struct NamedSocketAddrs { pub name: String, pub addrs: Vec,