From f5c1506bbe9ff916944c233d31c14d96f024e182 Mon Sep 17 00:00:00 2001 From: Vivid Date: Tue, 6 Aug 2024 19:43:37 +0000 Subject: [PATCH] Add dashboard server port command line argument --- src/bin/omnip.rs | 6 ++++++ src/lib.rs | 11 +++++++++++ src/server.rs | 5 ++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/bin/omnip.rs b/src/bin/omnip.rs index 4da90f8..446a79f 100644 --- a/src/bin/omnip.rs +++ b/src/bin/omnip.rs @@ -31,6 +31,7 @@ fn main() -> Result<()> { args.threads, args.watch_proxy_rules_change, args.tcp_nodelay, + Some(args.dashboard_addr), )?; let common_quic_config = CommonQuicConfig { @@ -114,6 +115,11 @@ struct OmnipArgs { #[arg(short = 'u', long, default_value = "")] upstream: String, + /// Dashboard server address [ip:port] + /// for example: 127.0.0.1:8000, [::1]:8000 + #[arg(short = 'd', long, default_value = "")] + dashboard_addr: String, + /// Path to the proxy rules file #[arg(short = 'r', long, default_value = "")] proxy_rules_file: String, diff --git a/src/lib.rs b/src/lib.rs index fd83164..83d1c53 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -277,6 +277,7 @@ pub struct Config { pub name_servers: String, pub watch_proxy_rules_change: bool, pub tcp_nodelay: bool, + pub dashboard_addr: Option, } #[derive(Debug)] @@ -430,6 +431,7 @@ pub fn create_config( threads: usize, watch_proxy_rules_change: bool, tcp_nodelay: bool, + dashboard_addr: Option, ) -> Result { let (server_type, orig_server_addr, is_layered_proto) = parse_server_addr(addr.as_str()); @@ -467,6 +469,13 @@ pub fn create_config( num_cpus::get() }; + let dashboard_server_addr = match dashboard_addr.as_deref().and_then(parse_socket_addr) { + Some(socket_addr) => Some(socket_addr), + None => { + log_and_bail!("server addr must be an IP address: {:?}", addr); + } + }; + Ok(Config { server_type, addr: server_addr, @@ -480,6 +489,7 @@ pub fn create_config( name_servers, watch_proxy_rules_change, tcp_nodelay, + dashboard_addr: dashboard_server_addr, }) } @@ -561,6 +571,7 @@ pub mod android { jthreads as usize, false, jtcpNoDelay != 0, + None, ) { Ok(config) => config, Err(e) => { diff --git a/src/server.rs b/src/server.rs index 9cc4a1c..2009fc1 100644 --- a/src/server.rs +++ b/src/server.rs @@ -163,7 +163,10 @@ impl Server { self.set_and_post_server_state(ServerState::Preparing); // start the dashboard server - let addr = local_socket_addr_with_unspecified_port(self.config.addr.is_ipv6()); + let addr = match self.config.dashboard_addr { + Some(dashboard_addr) => dashboard_addr, + None => local_socket_addr_with_unspecified_port(self.config.addr.is_ipv6()), + }; let dashboard_server = DashboardServer::new(); let dashboard_listener = dashboard_server.bind(addr).await?; let dashboard_addr = dashboard_listener.local_addr().ok();