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    pub fn default() -> Arc<Self> {
17        Arc::new(Self)
18    }
19}
20
21impl DdosProtection for NoopDdosProtection {
22    fn allow_request(&self, _ip: &str) -> bool {
23        true
24    }
25
26    fn report_bad_request(&self, _ip: &str) {}
27
28    fn try_acquire_connection(&self, _ip: &str) -> bool {
29        true
30    }
31
32    fn release_connection(&self, _ip: &str) {}
33}