From d6644e29fe5b3e47051330a2236b54b1bc624dfd Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Mon, 14 Feb 2022 14:34:31 +0100 Subject: [PATCH] move src/shared_rate_limiter.rs to src/tools/shared_rate_limiter.rs Signed-off-by: Dietmar Maurer --- src/lib.rs | 3 --- src/tools/mod.rs | 3 +++ src/{ => tools}/shared_rate_limiter.rs | 9 +++++++++ src/traffic_control_cache.rs | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) rename src/{ => tools}/shared_rate_limiter.rs (89%) diff --git a/src/lib.rs b/src/lib.rs index 50548132..e18b9614 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,9 +33,6 @@ pub mod client_helpers; pub mod rrd_cache; -mod shared_rate_limiter; -pub use shared_rate_limiter::SharedRateLimiter; - pub mod traffic_control_cache; /// Get the server's certificate info (from `proxy.pem`). diff --git a/src/tools/mod.rs b/src/tools/mod.rs index 685eb4a2..32013a3f 100644 --- a/src/tools/mod.rs +++ b/src/tools/mod.rs @@ -16,6 +16,9 @@ pub mod apt; pub mod config; pub mod disks; +mod shared_rate_limiter; +pub use shared_rate_limiter::SharedRateLimiter; + pub mod statistics; pub mod subscription; pub mod systemd; diff --git a/src/shared_rate_limiter.rs b/src/tools/shared_rate_limiter.rs similarity index 89% rename from src/shared_rate_limiter.rs rename to src/tools/shared_rate_limiter.rs index a0febc26..1a0656d4 100644 --- a/src/shared_rate_limiter.rs +++ b/src/tools/shared_rate_limiter.rs @@ -55,12 +55,21 @@ impl Init for SharedRateLimiterData { } } +/// Rate limiter designed for shared memory ([SharedMemory]) +/// +/// The actual [RateLimiter] is protected by a [SharedMutex] and +/// implements [Init]. This way we can share the limiter between +/// different processes. pub struct SharedRateLimiter { shmem: SharedMemory } impl SharedRateLimiter { + /// Creates a new mmap'ed instance. + /// + /// Data is mapped in `/var/run/proxmox-backup/shmem/tbf/` using + /// `TMPFS`. pub fn mmap_shmem(name: &str, rate: u64, burst: u64) -> Result { let mut path = PathBuf::from(BASE_PATH); diff --git a/src/traffic_control_cache.rs b/src/traffic_control_cache.rs index 24786ead..9dfaa32e 100644 --- a/src/traffic_control_cache.rs +++ b/src/traffic_control_cache.rs @@ -18,7 +18,7 @@ use pbs_api_types::TrafficControlRule; use pbs_config::ConfigVersionCache; -use super::SharedRateLimiter; +use crate::tools::SharedRateLimiter; lazy_static::lazy_static!{ /// Shared traffic control cache singleton.