Struct ClientIpRateKey
#[non_exhaustive]pub struct ClientIpRateKey { /* private fields */ }net 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§
§impl ClientIpRateKey
impl ClientIpRateKey
pub const fn new() -> ClientIpRateKey
pub const fn new() -> ClientIpRateKey
Create a new ClientIpRateKey, aggregating IPv6 clients to /64.
pub fn with_ipv6_prefix(self, prefix: u8) -> ClientIpRateKey
pub fn with_ipv6_prefix(self, prefix: u8) -> ClientIpRateKey
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.
pub fn set_ipv6_prefix(&mut self, prefix: u8) -> &mut ClientIpRateKey
pub fn set_ipv6_prefix(&mut self, prefix: u8) -> &mut ClientIpRateKey
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§
§impl Clone for ClientIpRateKey
impl Clone for ClientIpRateKey
§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
§impl Debug for ClientIpRateKey
impl Debug for ClientIpRateKey
§impl Default for ClientIpRateKey
impl Default for ClientIpRateKey
§fn default() -> ClientIpRateKey
fn default() -> ClientIpRateKey
§impl<Input> InputToRateKey<Input> for ClientIpRateKey
impl<Input> InputToRateKey<Input> 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§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§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<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more