mirror of
https://github.com/telemt/telemt.git
synced 2026-11-03 22:31:59 +03:00
Rustfmt
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
use std::collections::BTreeSet;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -69,8 +68,7 @@ pub(super) async fn run_telemt_core(
|
||||
let quota_state_path = config.general.quota_state_path.clone();
|
||||
let quota_state =
|
||||
crate::quota_state::QuotaStateOwner::new(quota_state_path, quota_store.clone());
|
||||
let configured_quota_users = config.access.users.keys().cloned().collect::<BTreeSet<_>>();
|
||||
quota_state.load(&configured_quota_users).await;
|
||||
quota_state.load_for_config(&config).await?;
|
||||
|
||||
let upstream_manager = Arc::new(
|
||||
UpstreamManager::new(
|
||||
@@ -131,12 +129,28 @@ pub(super) async fn run_telemt_core(
|
||||
traffic_limiter,
|
||||
user_admission,
|
||||
);
|
||||
let quota_guard = quota_state.lock().await;
|
||||
let _ = shared_state.activate_user_config_source(
|
||||
1,
|
||||
None,
|
||||
&config.access.users,
|
||||
&config.access.user_enabled,
|
||||
);
|
||||
shared_state.publish_quota_config(1, &Arc::new(config.clone()), true);
|
||||
drop(quota_guard);
|
||||
if let Err(error) = quota_state
|
||||
.process_schedules(
|
||||
crate::quota_state::now_epoch_secs(),
|
||||
!config.access.user_quota_periods.is_empty(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
if !config.access.user_quota_periods.is_empty() {
|
||||
return Err(error.into());
|
||||
}
|
||||
warn!(error = %error, "Deferred quota calendar cleanup until persistence recovers");
|
||||
}
|
||||
quota_state.spawn_scheduler(&process_control_plane);
|
||||
let max_connections_limit = if config.server.max_connections == 0 {
|
||||
Semaphore::MAX_PERMITS
|
||||
} else {
|
||||
|
||||
@@ -156,6 +156,7 @@ pub(crate) async fn spawn_runtime_tasks(
|
||||
Some("spawn config hot-reload watcher".to_string()),
|
||||
)
|
||||
.await;
|
||||
let quota_source_authority = shared_state.user_admission();
|
||||
let (config_rx, log_level_rx, config_watcher_task) = spawn_config_watcher(
|
||||
config_path.to_path_buf(),
|
||||
config.clone(),
|
||||
@@ -164,6 +165,10 @@ pub(crate) async fn spawn_runtime_tasks(
|
||||
task_scope.cancellation_token(),
|
||||
Some(upstream_manager.dns_resolver()),
|
||||
config_watcher_activation,
|
||||
Some(shared_state.quota_mutation_gate()),
|
||||
Some(Arc::new(move || {
|
||||
quota_source_authority.has_fresh_quota_schedules()
|
||||
})),
|
||||
);
|
||||
task_scope.spawn(config_watcher_task);
|
||||
startup_tracker
|
||||
@@ -267,6 +272,7 @@ pub(crate) async fn spawn_runtime_tasks(
|
||||
if config_rx_user_enabled.changed().await.is_err() {
|
||||
break;
|
||||
}
|
||||
let quota_guard = shared_user_enabled.quota_mutation_gate().lock_owned().await;
|
||||
let cfg = config_rx_user_enabled.borrow_and_update().clone();
|
||||
let Some(cancelled_users) = shared_user_enabled.apply_user_config_from_source(
|
||||
generation_id,
|
||||
@@ -275,6 +281,8 @@ pub(crate) async fn spawn_runtime_tasks(
|
||||
) else {
|
||||
continue;
|
||||
};
|
||||
shared_user_enabled.publish_quota_config(generation_id, &cfg, true);
|
||||
drop(quota_guard);
|
||||
for (user, cancelled) in cancelled_users {
|
||||
if cancelled > 0 {
|
||||
info!(
|
||||
|
||||
Reference in New Issue
Block a user