pub struct DhtRateLimiter(/* private fields */);Expand description
Three-layer rate limiter for inbound cdn/dht/v1 requests. Newtype over the
shared ThreeLayerRateLimiter that injects the DHT metrics sink.
Implementations§
Source§impl DhtRateLimiter
impl DhtRateLimiter
Sourcepub fn new(cfg: &DhtRateLimitConfig, metrics: Arc<Metrics>) -> Self
pub fn new(cfg: &DhtRateLimitConfig, metrics: Arc<Metrics>) -> Self
Build a limiter from the resolved DHT config snapshot.
Sourcepub fn from_resolved(resolved: &ResolvedDht, metrics: Arc<Metrics>) -> Self
pub fn from_resolved(resolved: &ResolvedDht, metrics: Arc<Metrics>) -> Self
Build a limiter straight from the resolved [dht.rate_limit] section.
Prefer this over Self::new at wiring sites: DhtRateLimitConfig is
an alias of the shared RateLimitConfig, so new cannot tell a config
mapped from [dht.rate_limit] from one mapped out of
[probe.rate_limit]. Taking &ResolvedDht makes the wrong pairing a
type error (#1457); see
crate::handlers::probe_rate_limit::ProbeRateLimiter::from_resolved
for the direction that actually loosens a cap.
Sourcepub fn check(
&self,
peer_node_id: &NodeId,
peer_ip: Option<IpAddr>,
) -> Result<(), DhtRejectLayer>
pub fn check( &self, peer_node_id: &NodeId, peer_ip: Option<IpAddr>, ) -> Result<(), DhtRejectLayer>
Try to admit one inbound DHT request. See
ThreeLayerRateLimiter::check.
Sourcepub fn admit_batch_extra(
&self,
peer_node_id: &NodeId,
peer_ip: Option<IpAddr>,
extra: usize,
) -> usize
pub fn admit_batch_extra( &self, peer_node_id: &NodeId, peer_ip: Option<IpAddr>, extra: usize, ) -> usize
Stage 2 of batch admission. See
ThreeLayerRateLimiter::admit_batch_extra.
Sourcepub fn gc_per_ip(&self) -> Option<(usize, usize)>
pub fn gc_per_ip(&self) -> Option<(usize, usize)>
Periodic GC sweep for the per-IP keyed map (#645).
Sourcepub fn gc_per_peer(&self) -> Option<(usize, usize)>
pub fn gc_per_peer(&self) -> Option<(usize, usize)>
Periodic GC sweep for the per-peer keyed map (#645).
Sourcepub fn per_ip_tracked(&self) -> usize
pub fn per_ip_tracked(&self) -> usize
Current tracked-key count for the per-IP keyed map (#645).
Sourcepub fn per_peer_tracked(&self) -> usize
pub fn per_peer_tracked(&self) -> usize
Current tracked-key count for the per-peer keyed map (#645).
Auto Trait Implementations§
impl !Freeze for DhtRateLimiter
impl !RefUnwindSafe for DhtRateLimiter
impl !UnwindSafe for DhtRateLimiter
impl Send for DhtRateLimiter
impl Sync for DhtRateLimiter
impl Unpin for DhtRateLimiter
impl UnsafeUnpin for DhtRateLimiter
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request