pub struct WebSocketRateLimiter { /* private fields */ }Expand description
Multi-tenant rate limiter with per-key tracking
Implementations§
Source§impl WebSocketRateLimiter
impl WebSocketRateLimiter
Sourcepub fn new(config: RateLimiterConfig) -> Self
pub fn new(config: RateLimiterConfig) -> Self
Create a new rate limiter with the given configuration
Sourcepub async fn check_handshake(&self, addr: SocketAddr) -> RateLimitResult
pub async fn check_handshake(&self, addr: SocketAddr) -> RateLimitResult
Check if handshake is allowed from the given IP
Sourcepub async fn check_connection_for_subject(
&self,
subject: &str,
) -> RateLimitResult
pub async fn check_connection_for_subject( &self, subject: &str, ) -> RateLimitResult
Check if connection is allowed for the given subject
Sourcepub async fn check_connection_for_metering_key(
&self,
metering_key: &str,
) -> RateLimitResult
pub async fn check_connection_for_metering_key( &self, metering_key: &str, ) -> RateLimitResult
Check if connection is allowed for the given metering key
Sourcepub async fn check_subscription(&self, client_id: Uuid) -> RateLimitResult
pub async fn check_subscription(&self, client_id: Uuid) -> RateLimitResult
Check if subscription is allowed for the given connection
Sourcepub async fn check_message(&self, client_id: Uuid) -> RateLimitResult
pub async fn check_message(&self, client_id: Uuid) -> RateLimitResult
Check if message is allowed for the given connection
Sourcepub async fn check_snapshot(&self, client_id: Uuid) -> RateLimitResult
pub async fn check_snapshot(&self, client_id: Uuid) -> RateLimitResult
Check if snapshot is allowed for the given connection
Sourcepub async fn cleanup_stale_buckets(&self)
pub async fn cleanup_stale_buckets(&self)
Clean up stale buckets to prevent memory growth
Sourcepub async fn remove_client_buckets(&self, client_id: Uuid)
pub async fn remove_client_buckets(&self, client_id: Uuid)
Remove all rate limit buckets for a disconnected client
Sourcepub fn start_cleanup_task(&self)
pub fn start_cleanup_task(&self)
Start a background task to periodically clean up stale buckets
Trait Implementations§
Source§impl Clone for WebSocketRateLimiter
impl Clone for WebSocketRateLimiter
Auto Trait Implementations§
impl Freeze for WebSocketRateLimiter
impl !RefUnwindSafe for WebSocketRateLimiter
impl Send for WebSocketRateLimiter
impl Sync for WebSocketRateLimiter
impl Unpin for WebSocketRateLimiter
impl UnsafeUnpin for WebSocketRateLimiter
impl !UnwindSafe for WebSocketRateLimiter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more