pub struct RateLimitBucketBudget {
pub max_distinct_per_peer: u32,
pub max_distinct_global: u32,
pub window: Duration,
}Expand description
Caps on how many distinct rate-limit buckets one scope may create,
applied by super::RateLimitLayer’s default key derivation.
§Where the defaults come from
max_distinct_per_peer = 128 is sized so that no realistic legitimate
peer reaches it: a single NAT egress (or IPv6 /64) serving 128
simultaneously-active distinct credentials within one scope lifetime is
already an unusual deployment, and one that should be configuring this rather than
inheriting it. An attacker, by contrast, needs one bucket per request
to amplify — so 128 is three orders of magnitude below what the attack
needs while still above what real traffic uses.
max_distinct_global = 8192 applies only when there is no verified
peer address at all (no ConnectInfo), where every caller shares one
scope. It is deliberately far larger, because collateral there hits
unrelated callers: the global scope degrades to a single loud
overflow bucket only when the deployment is both misconfigured and
under attack.
window (default 60s) is a floor on how long one admitted
credential holds its slot, not a fixed period that resets the scope.
The store raises it to at least the buckets’ own TTL
(cratestack_core::scope_ttl_secs), because a record that expired
first bounded nothing — the next generation re-admitted max_distinct
more while the previous one was still alive, for a real steady state of
max_distinct × ceil(bucket_ttl / window) (cratestack#871 review,
blocker 2). Slots expire individually and are refreshed on use, so an
active credential keeps its slot while a rotated-away one releases it.
Fields§
§max_distinct_per_peer: u32§max_distinct_global: u32§window: DurationImplementations§
Source§impl RateLimitBucketBudget
impl RateLimitBucketBudget
pub const DEFAULT_MAX_DISTINCT_PER_PEER: u32 = 128
pub const DEFAULT_MAX_DISTINCT_GLOBAL: u32 = 8192
pub const DEFAULT_WINDOW: Duration
pub fn new( max_distinct_per_peer: u32, max_distinct_global: u32, window: Duration, ) -> RateLimitBucketBudget
pub fn max_distinct_per_peer(self, max: u32) -> RateLimitBucketBudget
pub fn max_distinct_global(self, max: u32) -> RateLimitBucketBudget
pub fn window(self, window: Duration) -> RateLimitBucketBudget
Trait Implementations§
Source§impl Clone for RateLimitBucketBudget
impl Clone for RateLimitBucketBudget
Source§fn clone(&self) -> RateLimitBucketBudget
fn clone(&self) -> RateLimitBucketBudget
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for RateLimitBucketBudget
Source§impl Debug for RateLimitBucketBudget
impl Debug for RateLimitBucketBudget
Source§impl Default for RateLimitBucketBudget
impl Default for RateLimitBucketBudget
Source§fn default() -> RateLimitBucketBudget
fn default() -> RateLimitBucketBudget
impl Eq for RateLimitBucketBudget
Source§impl PartialEq for RateLimitBucketBudget
impl PartialEq for RateLimitBucketBudget
Source§fn eq(&self, other: &RateLimitBucketBudget) -> bool
fn eq(&self, other: &RateLimitBucketBudget) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for RateLimitBucketBudget
Auto Trait Implementations§
impl Freeze for RateLimitBucketBudget
impl RefUnwindSafe for RateLimitBucketBudget
impl Send for RateLimitBucketBudget
impl Sync for RateLimitBucketBudget
impl Unpin for RateLimitBucketBudget
impl UnsafeUnpin for RateLimitBucketBudget
impl UnwindSafe for RateLimitBucketBudget
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
§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> ⓘ
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§impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
impl<T> OrderedSeq<'_, T> for Twhere
T: Clone,
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
§type Iter<'a> = Once<&'a T>
where
T: 'a
type Iter<'a> = Once<&'a T> where T: 'a
§fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
§fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
MaybeRef].