#[non_exhaustive]pub struct ClientIpRateKey { /* private fields */ }std only.Expand description
An InputToRateKey extractor keying on the client IP address,
resolved via client_ip:
Forwarded information (populated by
e.g. forwarded-header or PROXY-protocol layers) wins over the
transport peer address (SocketInfo).
Only populate Forwarded from a trusted proxy boundary: accepting a
client-supplied forwarding header lets that client choose and rotate its
own rate key.
The resolved address is canonicalised before keying: IPv4-mapped IPv6
peers (::ffff:a.b.c.d) collapse to their IPv4 form, and IPv6 clients
are aggregated to with_ipv6_prefix (default
/64). Without this a single client keys to 2^64 distinct buckets and
per-client limiting is a no-op against exactly the clients most able to
abuse it.
The aggregation prefix and the policy’s max_keys must be sized together:
one routed /48 contains 65 536 /64 keys, equal to the default
KeyedRatePolicy capacity. Aggregate more broadly
when one client or tenant may legitimately control many /64 networks.
Implementations§
Source§impl ClientIpRateKey
impl ClientIpRateKey
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Create a new ClientIpRateKey, aggregating IPv6 clients to /64.
Sourcepub fn with_ipv6_prefix(self, prefix: u8) -> Self
pub fn with_ipv6_prefix(self, prefix: u8) -> Self
Aggregate IPv6 client addresses to this prefix length (clamped
to 1..=128) before keying; 128 keys on the exact address.
IPv4 clients are always keyed on the exact address. Choose this
together with KeyedRatePolicy::set_max_keys:
a broader prefix consumes fewer cache entries but groups more
clients into one budget.
Sourcepub fn set_ipv6_prefix(&mut self, prefix: u8) -> &mut Self
pub fn set_ipv6_prefix(&mut self, prefix: u8) -> &mut Self
Aggregate IPv6 client addresses to this prefix length (clamped
to 1..=128) before keying; 128 keys on the exact address.
IPv4 clients are always keyed on the exact address. Choose this
together with KeyedRatePolicy::set_max_keys:
a broader prefix consumes fewer cache entries but groups more
clients into one budget.
Trait Implementations§
Source§impl Clone for ClientIpRateKey
impl Clone for ClientIpRateKey
Source§fn clone(&self) -> ClientIpRateKey
fn clone(&self) -> ClientIpRateKey
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 ClientIpRateKey
Source§impl Debug for ClientIpRateKey
impl Debug for ClientIpRateKey
Source§impl Default for ClientIpRateKey
impl Default for ClientIpRateKey
Auto Trait Implementations§
impl Freeze for ClientIpRateKey
impl RefUnwindSafe for ClientIpRateKey
impl Send for ClientIpRateKey
impl Sync for ClientIpRateKey
impl Unpin for ClientIpRateKey
impl UnsafeUnpin for ClientIpRateKey
impl UnwindSafe for ClientIpRateKey
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> Pointable for T
impl<T> Pointable for T
Source§impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
Source§impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
type Error = <U as RamaTryFrom<T, CrateMarker>>::Error
fn rama_try_into(self) -> Result<U, <U as RamaTryFrom<T, CrateMarker>>::Error>
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<V, F> ValueFormatter<&V> for F
impl<V, F> ValueFormatter<&V> for F
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &&V)
fn format_value(writer: impl ValueWriter, value: &&V)
value to writerSource§impl<V, F> ValueFormatter<Arc<V>> for F
impl<V, F> ValueFormatter<Arc<V>> for F
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &Arc<V>)
fn format_value(writer: impl ValueWriter, value: &Arc<V>)
value to writerSource§impl<V, F> ValueFormatter<Box<V>> for F
impl<V, F> ValueFormatter<Box<V>> for F
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &Box<V>)
fn format_value(writer: impl ValueWriter, value: &Box<V>)
value to writerSource§impl<V, F> ValueFormatter<Cow<'_, V>> for F
impl<V, F> ValueFormatter<Cow<'_, V>> for F
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
value to writerSource§impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &Option<V>)
fn format_value(writer: impl ValueWriter, value: &Option<V>)
value to writer