pub struct ColdStartLimiter { /* private fields */ }Expand description
Tracks recent cold start attempts per URI to prevent DOS.
Uses rate limiting with a configurable minimum interval between cold start attempts for the same URI. This prevents malicious or buggy clients from overwhelming the server with rapid file loading requests.
§Examples
use deps_lsp::document::ColdStartLimiter;
use tower_lsp_server::ls_types::Uri;
use std::time::Duration;
let limiter = ColdStartLimiter::new(Duration::from_millis(100));
let uri = Uri::from_file_path("/test.toml").unwrap();
assert!(limiter.allow_cold_start(&uri));
assert!(!limiter.allow_cold_start(&uri)); // Rate limitedImplementations§
Source§impl ColdStartLimiter
impl ColdStartLimiter
Sourcepub fn new(min_interval: Duration) -> Self
pub fn new(min_interval: Duration) -> Self
Creates a new cold start limiter with the specified minimum interval.
Sourcepub fn allow_cold_start(&self, uri: &Uri) -> bool
pub fn allow_cold_start(&self, uri: &Uri) -> bool
Returns true if cold start is allowed, false if rate limited.
Updates the last attempt time if the cold start is allowed.
Sourcepub fn cleanup_old_entries(&self, max_age: Duration)
pub fn cleanup_old_entries(&self, max_age: Duration)
Cleans up old entries periodically.
Removes entries older than max_age to prevent unbounded memory growth.
Should be called from a background task.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ColdStartLimiter
impl !RefUnwindSafe for ColdStartLimiter
impl Send for ColdStartLimiter
impl Sync for ColdStartLimiter
impl Unpin for ColdStartLimiter
impl UnwindSafe for ColdStartLimiter
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more