🎈 perf: arguments

Synchronize configuration items and command-line parameter names
Incompatibility warning
This commit is contained in:
m1m1sha 2024-09-12 10:21:53 +08:00
parent 096ed39d23
commit f46ba4f7c6
2 changed files with 78 additions and 70 deletions

View File

@ -63,15 +63,15 @@ core_clap:
default_protocol:
en: "default protocol to use when connecting to peers"
zh-CN: "连接到对等节点时使用的默认协议"
disable_encryption:
en: "disable encryption for peers communication, default is false, must be same with peers"
zh-CN: "禁用对等节点通信的加密默认为false必须与对等节点相同"
enable_encryption:
en: "enable encryption for peers communication, default is true, must be same with peers"
zh-CN: "启用对等节点通信的加密默认为true必须与对等节点相同"
multi_thread:
en: "use multi-thread runtime, default is single-thread"
zh-CN: "使用多线程运行时,默认为单线程"
disable_ipv6:
en: "do not use ipv6"
zh-CN: "使用IPv6"
enable_ipv6:
en: "use ipv6, default is true"
zh-CN: "使用IPv6默认为true"
dev_name:
en: "optional tun interface name"
zh-CN: "可选的TUN接口名称"
@ -93,10 +93,10 @@ core_clap:
use_smoltcp:
en: "enable smoltcp stack for subnet proxy"
zh-CN: "为子网代理启用smoltcp堆栈"
manual_routes:
routes:
en: "assign routes cidr manually, will disable subnet proxy and wireguard routes propagated from peers. e.g.: 192.168.0.0/16"
zh-CN: "手动分配路由CIDR将禁用子网代理和从对等节点传播的wireguard路由。例如192.168.0.0/16"
relay_network_whitelist:
foreign_network_whitelist:
en: |+
only forward traffic from the whitelist networks, supporting wildcard strings, multiple network names can be separated by spaces.
if this parameter is empty, forwarding is disabled. by default, all networks are allowed.

View File

@ -170,20 +170,6 @@ struct Cli {
)]
vpn_portal: Option<String>,
#[arg(
long,
help = t!("core_clap.default_protocol").to_string()
)]
default_protocol: Option<String>,
#[arg(
short = 'u',
long,
help = t!("core_clap.disable_encryption").to_string(),
default_value = "false"
)]
disable_encryption: bool,
#[arg(
long,
help = t!("core_clap.multi_thread").to_string(),
@ -191,22 +177,54 @@ struct Cli {
)]
multi_thread: bool,
#[arg(
long,
help = t!("core_clap.disable_ipv6").to_string(),
default_value = "false"
)]
disable_ipv6: bool,
#[arg(
long,
help = t!("core_clap.dev_name").to_string()
help = t!("core_clap.routes").to_string(),
num_args = 0..
)]
dev_name: Option<String>,
routes: Option<Vec<String>>,
#[cfg(feature = "socks5")]
#[arg(
long,
help = t!("core_clap.socks5").to_string()
)]
socks5: Option<u16>,
// flag
#[arg(
long,
help = t!("core_clap.default_protocol").to_string(),
default_value = "tcp"
)]
default_protocol: String,
#[arg(
long,
help = t!("core_clap.mtu").to_string()
help = t!("core_clap.dev_name").to_string(),
default_value = ""
)]
dev_name: String,
#[arg(
short = 'u',
long,
help = t!("core_clap.enable_encryption").to_string(),
default_value = "true"
)]
enable_encryption: bool,
#[arg(
long,
help = t!("core_clap.enable_ipv6").to_string(),
default_value = "true"
)]
enable_ipv6: bool,
#[arg(
long,
help = t!("core_clap.mtu").to_string(),
)]
mtu: Option<u16>,
@ -217,13 +235,6 @@ struct Cli {
)]
latency_first: bool,
#[arg(
long,
help = t!("core_clap.exit_nodes").to_string(),
num_args = 0..
)]
exit_nodes: Vec<Ipv4Addr>,
#[arg(
long,
help = t!("core_clap.enable_exit_node").to_string(),
@ -231,6 +242,13 @@ struct Cli {
)]
enable_exit_node: bool,
#[arg(
long,
help = t!("core_clap.exit_nodes").to_string(),
num_args = 0..
)]
exit_nodes: Vec<Ipv4Addr>,
#[arg(
long,
help = t!("core_clap.no_tun").to_string(),
@ -247,17 +265,10 @@ struct Cli {
#[arg(
long,
help = t!("core_clap.manual_routes").to_string(),
help = t!("core_clap.foreign_network_whitelist").to_string(),
num_args = 0..
)]
manual_routes: Option<Vec<String>>,
#[arg(
long,
help = t!("core_clap.relay_network_whitelist").to_string(),
num_args = 0..
)]
relay_network_whitelist: Option<Vec<String>>,
foreign_network_whitelist: Option<Vec<String>>,
#[arg(
long,
@ -266,26 +277,19 @@ struct Cli {
)]
disable_p2p: bool,
#[arg(
long,
help = t!("core_clap.disable_udp_hole_punching").to_string(),
default_value = "false"
)]
disable_udp_hole_punching: bool,
#[arg(
long,
help = t!("core_clap.relay_all_peer_rpc").to_string(),
default_value = "false"
)]
relay_all_peer_rpc: bool,
#[cfg(feature = "socks5")]
#[arg(
long,
help = t!("core_clap.socks5").to_string()
help = t!("core_clap.disable_udp_hole_punching").to_string(),
default_value = "false"
)]
socks5: Option<u16>,
disable_udp_hole_punching: bool,
}
rust_i18n::i18n!("locales", fallback = "en");
@ -489,9 +493,9 @@ impl From<Cli> for TomlConfigLoader {
});
}
if cli.manual_routes.is_some() {
if cli.routes.is_some() {
cfg.set_routes(Some(
cli.manual_routes
cli.routes
.clone()
.unwrap()
.iter()
@ -514,20 +518,24 @@ impl From<Cli> for TomlConfigLoader {
}
let mut f = cfg.get_flags();
if cli.default_protocol.is_some() {
f.default_protocol = cli.default_protocol.as_ref().unwrap().clone();
}
f.enable_encryption = !cli.disable_encryption;
f.enable_ipv6 = !cli.disable_ipv6;
f.default_protocol = cli.default_protocol.clone();
f.enable_encryption = cli.enable_encryption;
f.enable_ipv6 = cli.enable_ipv6;
f.latency_first = cli.latency_first;
f.dev_name = cli.dev_name.unwrap_or(Default::default());
if let Some(mtu) = cli.mtu {
f.mtu = mtu;
}
f.dev_name = cli.dev_name.clone();
f.mtu = if let Some(mtu) = cli.mtu {
mtu
} else {
if cli.enable_encryption {
1400
} else {
1420
}
};
f.enable_exit_node = cli.enable_exit_node;
f.no_tun = cli.no_tun || cfg!(not(feature = "tun"));
f.use_smoltcp = cli.use_smoltcp;
if let Some(wl) = cli.relay_network_whitelist {
if let Some(wl) = cli.foreign_network_whitelist {
f.foreign_network_whitelist = wl.join(" ");
}
f.disable_p2p = cli.disable_p2p;