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_consumer(
&self,
consumer: &str,
limit_override: Option<u32>,
) -> RateLimitResult
pub async fn check_connection_for_consumer( &self, consumer: &str, limit_override: Option<u32>, ) -> RateLimitResult
Check if a connection attempt is allowed for the resolved consumer.
limit_override carries the signed
limits.max_connection_attempts_per_minute when present; the
configured window applies otherwise.
Sourcepub async fn check_connection_for_account(
&self,
account: &str,
limit_override: Option<u32>,
) -> RateLimitResult
pub async fn check_connection_for_account( &self, account: &str, limit_override: Option<u32>, ) -> RateLimitResult
Check if a connection attempt is allowed for the resolved account.
limit_override carries the signed
account_limits.max_connection_attempts_per_minute when present; the
configured window applies otherwise.
Sourcepub async fn check_subscription_create_for_consumer(
&self,
consumer: &str,
limit: Option<u32>,
) -> RateLimitResult
pub async fn check_subscription_create_for_consumer( &self, consumer: &str, limit: Option<u32>, ) -> RateLimitResult
Check the signed per-consumer subscription-create rate.
Enforced only when the token carries
limits.max_subscription_creates_per_minute; a None limit is
allowed without creating bucket state.
Sourcepub async fn check_subscription_create_for_account(
&self,
account: &str,
limit: Option<u32>,
) -> RateLimitResult
pub async fn check_subscription_create_for_account( &self, account: &str, limit: Option<u32>, ) -> RateLimitResult
Check the signed per-account subscription-create rate.
Enforced only when the token carries
account_limits.max_subscription_creates_per_minute; a None limit
is allowed without creating bucket state.
Sourcepub async fn check_connection_for_subject(
&self,
subject: &str,
) -> RateLimitResult
👎Deprecated: use check_connection_for_consumer with the resolved consumer identity
pub async fn check_connection_for_subject( &self, subject: &str, ) -> RateLimitResult
use check_connection_for_consumer with the resolved consumer identity
Check if connection is allowed for the given subject
Sourcepub async fn check_connection_for_metering_key(
&self,
metering_key: &str,
) -> RateLimitResult
👎Deprecated: use check_connection_for_account with the resolved account identity
pub async fn check_connection_for_metering_key( &self, metering_key: &str, ) -> RateLimitResult
use check_connection_for_account with the resolved account identity
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