mirror of
https://github.com/telemt/telemt.git
synced 2026-04-16 01:54:11 +03:00
Unified STUN + ME Primary parallelized
- Unified STUN server source-of-truth - parallelize per-DC primary ME init for multi-endpoint DCs
This commit is contained in:
@@ -1199,6 +1199,35 @@ impl MePool {
|
||||
return false;
|
||||
}
|
||||
addrs.shuffle(&mut rand::rng());
|
||||
if addrs.len() > 1 {
|
||||
let mut join = tokio::task::JoinSet::new();
|
||||
for (ip, port) in addrs {
|
||||
let addr = SocketAddr::new(ip, port);
|
||||
let pool = Arc::clone(&self);
|
||||
let rng_clone = Arc::clone(&rng);
|
||||
join.spawn(async move { (addr, pool.connect_one(addr, rng_clone.as_ref()).await) });
|
||||
}
|
||||
|
||||
while let Some(res) = join.join_next().await {
|
||||
match res {
|
||||
Ok((addr, Ok(()))) => {
|
||||
info!(%addr, dc = %dc, "ME connected");
|
||||
join.abort_all();
|
||||
while join.join_next().await.is_some() {}
|
||||
return true;
|
||||
}
|
||||
Ok((addr, Err(e))) => {
|
||||
warn!(%addr, dc = %dc, error = %e, "ME connect failed, trying next");
|
||||
}
|
||||
Err(e) => {
|
||||
warn!(dc = %dc, error = %e, "ME connect task failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
warn!(dc = %dc, "All ME servers for DC failed at init");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (ip, port) in addrs {
|
||||
let addr = SocketAddr::new(ip, port);
|
||||
match self.connect_one(addr, rng.as_ref()).await {
|
||||
|
||||
@@ -17,7 +17,15 @@ const STUN_BATCH_TIMEOUT: Duration = Duration::from_secs(5);
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn stun_probe(stun_addr: Option<String>) -> Result<crate::network::stun::DualStunResult> {
|
||||
let stun_addr = stun_addr.unwrap_or_else(|| "stun.l.google.com:19302".to_string());
|
||||
let stun_addr = stun_addr.unwrap_or_else(|| {
|
||||
crate::config::defaults::default_stun_servers()
|
||||
.into_iter()
|
||||
.next()
|
||||
.unwrap_or_default()
|
||||
});
|
||||
if stun_addr.is_empty() {
|
||||
return Err(ProxyError::Proxy("STUN server is not configured".to_string()));
|
||||
}
|
||||
stun_probe_dual(&stun_addr).await
|
||||
}
|
||||
|
||||
@@ -31,10 +39,12 @@ impl MePool {
|
||||
if !self.nat_stun_servers.is_empty() {
|
||||
return self.nat_stun_servers.clone();
|
||||
}
|
||||
if let Some(s) = &self.nat_stun {
|
||||
if let Some(s) = &self.nat_stun
|
||||
&& !s.trim().is_empty()
|
||||
{
|
||||
return vec![s.clone()];
|
||||
}
|
||||
vec!["stun.l.google.com:19302".to_string()]
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
async fn probe_stun_batch_for_family(
|
||||
|
||||
Reference in New Issue
Block a user