WEB Carriers Safe-matrix Refactored

Co-Authored-By: brekotis <93345790+brekotis@users.noreply.github.com>
This commit is contained in:
Alexey
2026-08-26 20:33:33 +03:00
parent 8b2b88f30c
commit 34eeb2d856
49 changed files with 3406 additions and 936 deletions
+45 -7
View File
@@ -67,6 +67,7 @@ impl WebProcessRuntime {
state.bootstraps_per_ip.clear();
state.sessions.values().cloned().collect::<Vec<_>>()
};
self.stream_admission.lock().closed = true;
for session in &sessions {
session.close();
}
@@ -85,10 +86,8 @@ impl WebProcessRuntime {
let _ = tokio::time::timeout(Duration::from_secs(timeout_secs), waits).await;
self.tasks.close();
let _ = tokio::time::timeout(Duration::from_secs(timeout_secs), self.tasks.wait()).await;
let (sessions_live, streams_live) = {
let state = self.state.lock();
(state.sessions.len(), state.streams_live)
};
let sessions_live = self.state.lock().sessions.len();
let streams_live = self.stream_admission.lock().streams_live;
let budget = self.data_budget.snapshot();
info!(
target: "telemt::web",
@@ -113,12 +112,51 @@ impl WebProcessRuntime {
pub(super) fn cleanup(&self) {
self.cleanup_websockets();
let now = Instant::now();
self.learning.lock().prune(now);
let sessions = {
let generation = self.active_generation();
let config = &generation.config().web;
let learning_enabled = config.carrier_negotiation_enabled() && config.carrier_learning;
let mut learning = self.learning.lock();
let _ = learning.apply_policy(
now,
learning_enabled,
config.carrier_negotiation_aggressiveness,
Duration::from_secs(config.timeouts.carrier_learning_secs),
);
learning.prune(now);
drop(learning);
let (sessions, expired_chains) = {
let mut state = self.state.lock();
let expired = state
.bootstraps
.iter()
.filter_map(|(hash, bootstrap)| {
(bootstrap.carrier_phase == super::state::CarrierChainPhase::Provisional
&& bootstrap
.carrier_deadline_at
.is_some_and(|deadline| now >= deadline)
&& bootstrap
.session
.as_ref()
.is_some_and(|session| !session.is_carrier_committed()))
.then_some((*hash, bootstrap.session.clone()))
})
.collect::<Vec<_>>();
let expired_chains = expired
.iter()
.filter_map(|(_, session)| session.clone())
.collect::<Vec<_>>();
for (hash, _) in expired {
remove_bootstrap_locked(&mut state, hash);
}
remove_expired_locked(&mut state, now);
state.sessions.values().cloned().collect::<Vec<_>>()
(
state.sessions.values().cloned().collect::<Vec<_>>(),
expired_chains,
)
};
for session in expired_chains {
session.close();
}
for session in sessions {
session.close_if_due(now);
}