Skip to content

Commit

Permalink
Add dashboard server port command line argument
Browse files Browse the repository at this point in the history
  • Loading branch information
absolutely-vivid committed Aug 10, 2024
1 parent 97ea527 commit ec1c67e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/bin/omnip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SocketAddr>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -430,6 +431,7 @@ pub fn create_config(
threads: usize,
watch_proxy_rules_change: bool,
tcp_nodelay: bool,
dashboard_addr: Option<String>,
) -> Result<Config> {
let (server_type, orig_server_addr, is_layered_proto) = parse_server_addr(addr.as_str());

Expand Down Expand Up @@ -467,6 +469,11 @@ pub fn create_config(
num_cpus::get()
};

let dashboard_server_addr = dashboard_addr.as_deref().and_then(parse_socket_addr);
if dashboard_server_addr.is_none() {
log_and_bail!("server addr must be an IP address: {:?}", addr);
}

Ok(Config {
server_type,
addr: server_addr,
Expand All @@ -480,6 +487,7 @@ pub fn create_config(
name_servers,
watch_proxy_rules_change,
tcp_nodelay,
dashboard_addr: dashboard_server_addr,
})
}

Expand Down Expand Up @@ -561,6 +569,7 @@ pub mod android {
jthreads as usize,
false,
jtcpNoDelay != 0,
None,
) {
Ok(config) => config,
Err(e) => {
Expand Down
5 changes: 4 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit ec1c67e

Please sign in to comment.