mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-01 16:59:21 +00:00
Support configurable TCP STUN servers (#2314)
tcp_stun_servers explicitly controls TCP STUN servers. If tcp_stun_servers is not configured, TCP STUN falls back to configured stun_servers. If neither is configured, TCP STUN uses the built-in default TCP STUN list. Empty lists explicitly disable the corresponding STUN server list. Empty CLI/env overrides now clear existing configured STUN servers instead of appending nothing.
This commit is contained in:
@@ -255,11 +255,14 @@ core_clap:
|
||||
en: "if true, allow relay quic packets from foreign network. default is false (not forward foreign network quic packets)"
|
||||
zh-CN: "如果为true,则作为共享节点时也可以转发其他网络的 QUIC 数据包。默认值为false(不转发)"
|
||||
stun_servers:
|
||||
en: "Override default STUN servers; If configured but empty, STUN servers are not used"
|
||||
zh-CN: "覆盖内置的默认 STUN server 列表;如果设置了但是为空,则不使用 STUN servers;如果没设置,则使用默认 STUN server 列表"
|
||||
en: "Override default UDP STUN servers. TCP STUN also uses this list when tcp-stun-servers is unset. If configured but empty, UDP STUN and fallback TCP/IPv6 STUN are disabled"
|
||||
zh-CN: "覆盖内置的默认 UDP STUN server 列表;未设置 tcp-stun-servers 时,TCP STUN 也使用此列表;如果设置了但是为空,则禁用 UDP STUN 以及回退的 TCP/IPv6 STUN"
|
||||
stun_servers_v6:
|
||||
en: "Override default STUN servers, IPv6; If configured but empty, IPv6 STUN servers are not used"
|
||||
zh-CN: "覆盖内置的默认 IPv6 STUN server 列表;如果设置了但是为空,则不使用 IPv6 STUN servers;如果没设置,则使用默认 IPv6 STUN server 列表"
|
||||
en: "Override default IPv6 STUN servers. If unset while stun-servers is configured, IPv6 STUN is disabled. If configured but empty, IPv6 STUN servers are not used"
|
||||
zh-CN: "覆盖内置的默认 IPv6 STUN server 列表;如果未设置但已设置 stun-servers,则禁用 IPv6 STUN;如果设置了但是为空,则不使用 IPv6 STUN servers"
|
||||
tcp_stun_servers:
|
||||
en: "Override default TCP STUN servers. If unset, TCP STUN uses stun-servers when configured, otherwise default TCP STUN servers. If configured but empty, TCP STUN is disabled"
|
||||
zh-CN: "覆盖内置的默认 TCP STUN server 列表;如果未设置,TCP STUN 会优先使用 stun-servers,否则使用默认 TCP STUN server 列表;如果设置了但是为空,则禁用 TCP STUN"
|
||||
secure_mode:
|
||||
en: "if true, enable secure mode. default is false"
|
||||
zh-CN: "如果为true,则启用安全模式。默认值为false"
|
||||
|
||||
+61
-6
@@ -692,6 +692,15 @@ struct NetworkOptions {
|
||||
)]
|
||||
stun_servers_v6: Option<Vec<String>>,
|
||||
|
||||
#[arg(
|
||||
long,
|
||||
env = "ET_TCP_STUN_SERVERS",
|
||||
value_delimiter = ',',
|
||||
help = t!("core_clap.tcp_stun_servers").to_string(),
|
||||
num_args = 0..
|
||||
)]
|
||||
tcp_stun_servers: Option<Vec<String>>,
|
||||
|
||||
#[arg(
|
||||
long,
|
||||
env = "ET_SECURE_MODE",
|
||||
@@ -1190,15 +1199,33 @@ impl NetworkOptions {
|
||||
cfg.set_udp_whitelist(old_udp_whitelist);
|
||||
|
||||
if let Some(stun_servers) = &self.stun_servers {
|
||||
let mut old_stun_servers = cfg.get_stun_servers().unwrap_or_default();
|
||||
old_stun_servers.extend(stun_servers.iter().cloned());
|
||||
cfg.set_stun_servers(Some(old_stun_servers));
|
||||
if stun_servers.is_empty() {
|
||||
cfg.set_stun_servers(Some(Vec::new()));
|
||||
} else {
|
||||
let mut old_stun_servers = cfg.get_stun_servers().unwrap_or_default();
|
||||
old_stun_servers.extend(stun_servers.iter().cloned());
|
||||
cfg.set_stun_servers(Some(old_stun_servers));
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(stun_servers_v6) = &self.stun_servers_v6 {
|
||||
let mut old_stun_servers_v6 = cfg.get_stun_servers_v6().unwrap_or_default();
|
||||
old_stun_servers_v6.extend(stun_servers_v6.iter().cloned());
|
||||
cfg.set_stun_servers_v6(Some(old_stun_servers_v6));
|
||||
if stun_servers_v6.is_empty() {
|
||||
cfg.set_stun_servers_v6(Some(Vec::new()));
|
||||
} else {
|
||||
let mut old_stun_servers_v6 = cfg.get_stun_servers_v6().unwrap_or_default();
|
||||
old_stun_servers_v6.extend(stun_servers_v6.iter().cloned());
|
||||
cfg.set_stun_servers_v6(Some(old_stun_servers_v6));
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(tcp_stun_servers) = &self.tcp_stun_servers {
|
||||
if tcp_stun_servers.is_empty() {
|
||||
cfg.set_tcp_stun_servers(Some(Vec::new()));
|
||||
} else {
|
||||
let mut old_tcp_stun_servers = cfg.get_tcp_stun_servers().unwrap_or_default();
|
||||
old_tcp_stun_servers.extend(tcp_stun_servers.iter().cloned());
|
||||
cfg.set_tcp_stun_servers(Some(old_tcp_stun_servers));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -1306,6 +1333,9 @@ fn parse_cli() -> Cli {
|
||||
if let Some(stun_servers_v6) = &mut cli.network_options.stun_servers_v6 {
|
||||
stun_servers_v6.retain(|s| !s.trim().is_empty());
|
||||
}
|
||||
if let Some(tcp_stun_servers) = &mut cli.network_options.tcp_stun_servers {
|
||||
tcp_stun_servers.retain(|s| !s.trim().is_empty());
|
||||
}
|
||||
cli
|
||||
}
|
||||
|
||||
@@ -1771,4 +1801,29 @@ enabled = true
|
||||
assert_eq!(identity.network_secret_digest, None);
|
||||
assert_eq!(cfg.get_hostname(), "override-host");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_stun_server_options_clear_existing_config() {
|
||||
let cfg = TomlConfigLoader::new_from_str(
|
||||
r#"
|
||||
stun_servers = ["udp.example.com:3478"]
|
||||
stun_servers_v6 = ["v6.example.com:3478"]
|
||||
tcp_stun_servers = ["tcp.example.com:3478"]
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
NetworkOptions {
|
||||
stun_servers: Some(Vec::new()),
|
||||
stun_servers_v6: Some(Vec::new()),
|
||||
tcp_stun_servers: Some(Vec::new()),
|
||||
..Default::default()
|
||||
}
|
||||
.merge_into(&cfg)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(cfg.get_stun_servers(), Some(Vec::new()));
|
||||
assert_eq!(cfg.get_stun_servers_v6(), Some(Vec::new()));
|
||||
assert_eq!(cfg.get_tcp_stun_servers(), Some(Vec::new()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user