mirror of
https://github.com/telemt/telemt.git
synced 2026-04-17 18:44:10 +03:00
ME Probe parallelized
This commit is contained in:
@@ -132,6 +132,10 @@ pub(crate) fn default_middle_proxy_nat_stun_servers() -> Vec<String> {
|
||||
]
|
||||
}
|
||||
|
||||
pub(crate) fn default_stun_nat_probe_concurrency() -> usize {
|
||||
8
|
||||
}
|
||||
|
||||
pub(crate) fn default_middle_proxy_warm_standby() -> usize {
|
||||
DEFAULT_MIDDLE_PROXY_WARM_STANDBY
|
||||
}
|
||||
|
||||
@@ -96,6 +96,9 @@ fn warn_non_hot_changes(old: &ProxyConfig, new: &ProxyConfig) {
|
||||
if old.general.use_middle_proxy != new.general.use_middle_proxy {
|
||||
warn!("config reload: use_middle_proxy changed; restart required");
|
||||
}
|
||||
if old.general.stun_nat_probe_concurrency != new.general.stun_nat_probe_concurrency {
|
||||
warn!("config reload: general.stun_nat_probe_concurrency changed; restart required");
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolve the public host for link generation — mirrors the logic in main.rs.
|
||||
|
||||
@@ -166,6 +166,12 @@ impl ProxyConfig {
|
||||
}
|
||||
}
|
||||
|
||||
if config.general.stun_nat_probe_concurrency == 0 {
|
||||
return Err(ProxyError::Config(
|
||||
"general.stun_nat_probe_concurrency must be > 0".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
if config.general.me_reinit_every_secs == 0 {
|
||||
return Err(ProxyError::Config(
|
||||
"general.me_reinit_every_secs must be > 0".to_string(),
|
||||
@@ -607,6 +613,26 @@ mod tests {
|
||||
let _ = std::fs::remove_file(path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stun_nat_probe_concurrency_zero_is_rejected() {
|
||||
let toml = r#"
|
||||
[general]
|
||||
stun_nat_probe_concurrency = 0
|
||||
|
||||
[censorship]
|
||||
tls_domain = "example.com"
|
||||
|
||||
[access.users]
|
||||
user = "00000000000000000000000000000000"
|
||||
"#;
|
||||
let dir = std::env::temp_dir();
|
||||
let path = dir.join("telemt_stun_nat_probe_concurrency_zero_test.toml");
|
||||
std::fs::write(&path, toml).unwrap();
|
||||
let err = ProxyConfig::load(&path).unwrap_err().to_string();
|
||||
assert!(err.contains("general.stun_nat_probe_concurrency must be > 0"));
|
||||
let _ = std::fs::remove_file(path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn me_reinit_every_default_is_set() {
|
||||
let toml = r#"
|
||||
|
||||
@@ -168,6 +168,10 @@ pub struct GeneralConfig {
|
||||
#[serde(default = "default_middle_proxy_nat_stun_servers")]
|
||||
pub middle_proxy_nat_stun_servers: Vec<String>,
|
||||
|
||||
/// Maximum number of concurrent STUN probes during NAT detection.
|
||||
#[serde(default = "default_stun_nat_probe_concurrency")]
|
||||
pub stun_nat_probe_concurrency: usize,
|
||||
|
||||
/// Desired size of active Middle-Proxy writer pool.
|
||||
#[serde(default = "default_pool_size")]
|
||||
pub middle_proxy_pool_size: usize,
|
||||
@@ -378,6 +382,7 @@ impl Default for GeneralConfig {
|
||||
middle_proxy_nat_probe: default_true(),
|
||||
middle_proxy_nat_stun: default_middle_proxy_nat_stun(),
|
||||
middle_proxy_nat_stun_servers: default_middle_proxy_nat_stun_servers(),
|
||||
stun_nat_probe_concurrency: default_stun_nat_probe_concurrency(),
|
||||
middle_proxy_pool_size: default_pool_size(),
|
||||
middle_proxy_warm_standby: default_middle_proxy_warm_standby(),
|
||||
me_keepalive_enabled: default_true(),
|
||||
|
||||
Reference in New Issue
Block a user