mirror of
https://github.com/telemt/telemt.git
synced 2026-04-15 17:44:11 +03:00
ME Keepalives
Co-Authored-By: brekotis <93345790+brekotis@users.noreply.github.com>
This commit is contained in:
@@ -99,6 +99,7 @@ async fn check_family(
|
||||
match res {
|
||||
Ok(Ok(())) => {
|
||||
info!(%addr, dc = %dc, ?family, "ME reconnected for DC coverage");
|
||||
pool.stats.increment_me_reconnect_success();
|
||||
backoff.insert(key, pool.me_reconnect_backoff_base.as_millis() as u64);
|
||||
let jitter = pool.me_reconnect_backoff_base.as_millis() as u64 / JITTER_FRAC_NUM;
|
||||
let wait = pool.me_reconnect_backoff_base
|
||||
@@ -107,11 +108,15 @@ async fn check_family(
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
Ok(Err(e)) => debug!(%addr, dc = %dc, error = %e, ?family, "ME reconnect failed"),
|
||||
Ok(Err(e)) => {
|
||||
pool.stats.increment_me_reconnect_attempt();
|
||||
debug!(%addr, dc = %dc, error = %e, ?family, "ME reconnect failed")
|
||||
}
|
||||
Err(_) => debug!(%addr, dc = %dc, ?family, "ME reconnect timed out"),
|
||||
}
|
||||
}
|
||||
if !success {
|
||||
pool.stats.increment_me_reconnect_attempt();
|
||||
let curr = *backoff.get(&key).unwrap_or(&(pool.me_reconnect_backoff_base.as_millis() as u64));
|
||||
let next_ms = (curr.saturating_mul(2)).min(pool.me_reconnect_backoff_cap.as_millis() as u64);
|
||||
backoff.insert(key, next_ms);
|
||||
|
||||
@@ -74,6 +74,7 @@ pub struct MePool {
|
||||
pub(super) nat_reflection_cache: Arc<Mutex<NatReflectionCache>>,
|
||||
pub(super) writer_available: Arc<Notify>,
|
||||
pub(super) conn_count: AtomicUsize,
|
||||
pub(super) stats: Arc<crate::stats::Stats>,
|
||||
pool_size: usize,
|
||||
}
|
||||
|
||||
@@ -99,6 +100,7 @@ impl MePool {
|
||||
default_dc: Option<i32>,
|
||||
decision: NetworkDecision,
|
||||
rng: Arc<SecureRandom>,
|
||||
stats: Arc<crate::stats::Stats>,
|
||||
me_keepalive_enabled: bool,
|
||||
me_keepalive_interval_secs: u64,
|
||||
me_keepalive_jitter_secs: u64,
|
||||
@@ -130,6 +132,7 @@ impl MePool {
|
||||
stun_backoff_until: Arc::new(RwLock::new(None)),
|
||||
me_one_retry,
|
||||
me_one_timeout: Duration::from_millis(me_one_timeout_ms),
|
||||
stats,
|
||||
me_keepalive_enabled,
|
||||
me_keepalive_interval: Duration::from_secs(me_keepalive_interval_secs),
|
||||
me_keepalive_jitter: Duration::from_secs(me_keepalive_jitter_secs),
|
||||
@@ -440,7 +443,15 @@ impl MePool {
|
||||
if keepalive_random {
|
||||
rand::rng().fill(&mut payload);
|
||||
}
|
||||
if rpc_writer.send_keepalive(payload).await.is_err() { break; }
|
||||
match rpc_writer.send_keepalive(payload).await {
|
||||
Ok(()) => {
|
||||
stats.increment_me_keepalive_sent();
|
||||
}
|
||||
Err(_) => {
|
||||
stats.increment_me_keepalive_failed();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(WriterCommand::Close) | None => break,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user