Skip to main content

hashiverse_lib/transport/ddos/
noop_ddos.rs

1//! # No-op DDoS protection
2//!
3//! Implements [`crate::transport::ddos::ddos::DdosProtection`] as unconditional accept:
4//! every connection is allowed, no score is tracked, no IP is ever banned. Used by
5//! tests that exercise code paths downstream of the DDoS layer without also wanting
6//! to reason about scoring dynamics.
7
8use std::sync::Arc;
9use crate::transport::ddos::ddos::DdosProtection;
10
11/// No-op DDoS protection — allows all requests unconditionally.
12/// Use this in general integration tests where DDoS behaviour is not under test.
13pub struct NoopDdosProtection;
14
15impl NoopDdosProtection {
16    #[allow(clippy::should_implement_trait)] // wraps Arc<Self>, can't satisfy the Default trait
17    pub fn default() -> Arc<Self> {
18        Arc::new(Self)
19    }
20}
21
22impl DdosProtection for NoopDdosProtection {
23    fn allow_request(&self, _ip: &str) -> bool {
24        true
25    }
26
27    fn report_bad_request(&self, _ip: &str) {}
28
29    fn try_acquire_connection(&self, _ip: &str) -> bool {
30        true
31    }
32
33    fn release_connection(&self, _ip: &str) {}
34}