Skip to content

Commit f5c1506

Browse files
Add dashboard server port command line argument
1 parent 97ea527 commit f5c1506

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/bin/omnip.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ fn main() -> Result<()> {
3131
args.threads,
3232
args.watch_proxy_rules_change,
3333
args.tcp_nodelay,
34+
Some(args.dashboard_addr),
3435
)?;
3536

3637
let common_quic_config = CommonQuicConfig {
@@ -114,6 +115,11 @@ struct OmnipArgs {
114115
#[arg(short = 'u', long, default_value = "")]
115116
upstream: String,
116117

118+
/// Dashboard server address [ip:port]
119+
/// for example: 127.0.0.1:8000, [::1]:8000
120+
#[arg(short = 'd', long, default_value = "")]
121+
dashboard_addr: String,
122+
117123
/// Path to the proxy rules file
118124
#[arg(short = 'r', long, default_value = "")]
119125
proxy_rules_file: String,

src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ pub struct Config {
277277
pub name_servers: String,
278278
pub watch_proxy_rules_change: bool,
279279
pub tcp_nodelay: bool,
280+
pub dashboard_addr: Option<SocketAddr>,
280281
}
281282

282283
#[derive(Debug)]
@@ -430,6 +431,7 @@ pub fn create_config(
430431
threads: usize,
431432
watch_proxy_rules_change: bool,
432433
tcp_nodelay: bool,
434+
dashboard_addr: Option<String>,
433435
) -> Result<Config> {
434436
let (server_type, orig_server_addr, is_layered_proto) = parse_server_addr(addr.as_str());
435437

@@ -467,6 +469,13 @@ pub fn create_config(
467469
num_cpus::get()
468470
};
469471

472+
let dashboard_server_addr = match dashboard_addr.as_deref().and_then(parse_socket_addr) {
473+
Some(socket_addr) => Some(socket_addr),
474+
None => {
475+
log_and_bail!("server addr must be an IP address: {:?}", addr);
476+
}
477+
};
478+
470479
Ok(Config {
471480
server_type,
472481
addr: server_addr,
@@ -480,6 +489,7 @@ pub fn create_config(
480489
name_servers,
481490
watch_proxy_rules_change,
482491
tcp_nodelay,
492+
dashboard_addr: dashboard_server_addr,
483493
})
484494
}
485495

@@ -561,6 +571,7 @@ pub mod android {
561571
jthreads as usize,
562572
false,
563573
jtcpNoDelay != 0,
574+
None,
564575
) {
565576
Ok(config) => config,
566577
Err(e) => {

src/server.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ impl Server {
163163
self.set_and_post_server_state(ServerState::Preparing);
164164

165165
// start the dashboard server
166-
let addr = local_socket_addr_with_unspecified_port(self.config.addr.is_ipv6());
166+
let addr = match self.config.dashboard_addr {
167+
Some(dashboard_addr) => dashboard_addr,
168+
None => local_socket_addr_with_unspecified_port(self.config.addr.is_ipv6()),
169+
};
167170
let dashboard_server = DashboardServer::new();
168171
let dashboard_listener = dashboard_server.bind(addr).await?;
169172
let dashboard_addr = dashboard_listener.local_addr().ok();

0 commit comments

Comments
 (0)