add '--port' command line option for veilid-server that changes the base port for all protocols

This commit is contained in:
Christien Rioux 2024-08-05 12:27:39 -05:00
parent 2d6736f667
commit f7ce5f93d0
2 changed files with 20 additions and 7 deletions

View File

@ -136,11 +136,11 @@ pub struct CmdlineArgs {
#[arg(long, value_name = "BOOTSTRAP_LIST")] #[arg(long, value_name = "BOOTSTRAP_LIST")]
bootstrap: Option<String>, bootstrap: Option<String>,
/// panic on ctrl-c instead of graceful shutdown /// Panic on ctrl-c instead of graceful shutdown
#[arg(long)] #[arg(long)]
panic: bool, panic: bool,
/// password override to use for network isolation /// Password override to use for network isolation
#[arg(long, value_name = "KEY")] #[arg(long, value_name = "KEY")]
network_key: Option<String>, network_key: Option<String>,
@ -149,14 +149,18 @@ pub struct CmdlineArgs {
#[arg(long)] #[arg(long)]
wait_for_debug: bool, wait_for_debug: bool,
/// enable tokio console /// Enable tokio console
#[cfg(feature = "rt-tokio")] #[cfg(feature = "rt-tokio")]
#[arg(long)] #[arg(long)]
console: bool, console: bool,
/// change ingore_log_targets /// Change targets to ignore for logging
#[arg(long)] #[arg(long)]
ignore_log_targets: Option<Vec<String>>, ignore_log_targets: Option<Vec<String>>,
/// Override all network listen addresses with ':port'
#[arg(long)]
port: Option<u16>,
} }
#[instrument(level = "trace", skip_all, err)] #[instrument(level = "trace", skip_all, err)]
@ -317,6 +321,15 @@ fn main() -> EyreResult<()> {
settingsrw.logging.terminal.ignore_log_targets = ignore_log_targets 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); drop(settingsrw);
// Set specific config settings // Set specific config settings

View File

@ -263,7 +263,7 @@ pub fn load_config(cfg: config::Config, config_file: &Path) -> EyreResult<config
} }
} }
#[derive(Copy, Clone, Debug, PartialEq, ValueEnum)] #[derive(Copy, Clone, Debug, Eq, PartialEq, ValueEnum)]
pub enum LogLevel { pub enum LogLevel {
Off, Off,
Error, Error,
@ -320,7 +320,7 @@ pub fn convert_loglevel(log_level: LogLevel) -> veilid_core::VeilidConfigLogLeve
} }
} }
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, Eq, PartialEq)]
pub struct ParsedUrl { pub struct ParsedUrl {
pub urlstring: String, pub urlstring: String,
pub url: Url, pub url: Url,
@ -376,7 +376,7 @@ impl serde::Serialize for ParsedUrl {
} }
} }
#[derive(Debug, PartialEq)] #[derive(Debug, Clone, Eq, PartialEq)]
pub struct NamedSocketAddrs { pub struct NamedSocketAddrs {
pub name: String, pub name: String,
pub addrs: Vec<SocketAddr>, pub addrs: Vec<SocketAddr>,