pub struct TarpitManager { /* private fields */ }Expand description
Thread-safe tarpit manager.
Uses DashMap for lock-free concurrent access to tarpit states. Uses a semaphore to limit concurrent tarpit delays and prevent resource exhaustion.
Implementations§
Source§impl TarpitManager
impl TarpitManager
Sourcepub fn new(config: TarpitConfig) -> Self
pub fn new(config: TarpitConfig) -> Self
Create a new tarpit manager with the given configuration.
Sourcepub fn config(&self) -> &TarpitConfig
pub fn config(&self) -> &TarpitConfig
Get the configuration.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if tarpitting is enabled.
Sourcepub fn peek_delay(&self, ip: &str) -> TarpitDecision
pub fn peek_delay(&self, ip: &str) -> TarpitDecision
Calculate delay for an IP without incrementing state.
Use this for read-only delay calculation (e.g., for headers).
Sourcepub fn tarpit(&self, ip: &str) -> TarpitDecision
pub fn tarpit(&self, ip: &str) -> TarpitDecision
Calculate and apply tarpit for an IP, incrementing state.
Returns the delay decision. Use apply_delay to actually sleep.
Sourcepub async fn apply_delay(&self, ip: &str) -> TarpitDecision
pub async fn apply_delay(&self, ip: &str) -> TarpitDecision
Apply tarpit delay asynchronously.
Uses tokio::time::sleep which releases the worker thread during the delay. Limited by semaphore to prevent resource exhaustion from too many concurrent delays.
If the concurrent delay limit is reached, returns a decision with delay_ms=0 to prevent DoS attacks that exploit the tarpit mechanism itself.
Sourcepub fn rejected_count(&self) -> u64
pub fn rejected_count(&self) -> u64
Returns the number of tarpits rejected due to capacity limits.
Sourcepub fn available_slots(&self) -> usize
pub fn available_slots(&self) -> usize
Returns the number of available tarpit slots.
Sourcepub fn is_tarpitted(&self, ip: &str) -> bool
pub fn is_tarpitted(&self, ip: &str) -> bool
Check if an IP is actively tarpitted (level > 1).
Sourcepub fn get_state(&self, ip: &str) -> Option<TarpitState>
pub fn get_state(&self, ip: &str) -> Option<TarpitState>
Get tarpit state for an IP.
Sourcepub fn start_background_tasks(self: Arc<Self>)
pub fn start_background_tasks(self: Arc<Self>)
Start background tasks (decay, cleanup).
Spawns a background task that periodically runs maintenance.
Sourcepub async fn decay_all(&self)
pub async fn decay_all(&self)
Run decay on all states with chunked processing to avoid blocking.
Reduces delay levels for IPs that have been idle and removes expired states.
Sourcepub fn stats(&self) -> TarpitStats
pub fn stats(&self) -> TarpitStats
Get tarpit statistics.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for TarpitManager
impl !RefUnwindSafe for TarpitManager
impl Send for TarpitManager
impl Sync for TarpitManager
impl Unpin for TarpitManager
impl UnsafeUnpin for TarpitManager
impl !UnwindSafe for TarpitManager
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
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>
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