Skip to main content

RateLimitState

Struct RateLimitState 

Source
pub struct RateLimitState { /* private fields */ }
Expand description

Per-identity limits. Cheap to clone (all fields are shared / atomic).

Implementations§

Source§

impl RateLimitState

Source

pub fn from_entry( bw: Option<RatePer>, quota: Option<RatePer>, bw_partitions: usize, ) -> Self

Build a fresh state from an identity’s authorized_keys entry. bw_partitions is the number of worker threads the server is running (§9.2 per-core split); passing 1 preserves the pre-§9.2 single-bucket behaviour.

Source

pub fn from_entry_with_metrics( bw: Option<RatePer>, quota: Option<RatePer>, bw_partitions: usize, metrics: Option<Arc<ServerMetrics>>, ) -> Self

Same as Self::from_entry but plumbs the process-wide metrics bag so quota breaches show up on /admin/v1/metrics.

Source

pub fn attach_ctrl(&self, tx: UnboundedSender<ServerFrame>)

Install a fresh control-stream sender. Called at session start, replacing any leftover sender from a prior session for the same identity.

Source

pub fn detach_ctrl(&self)

Detach the current control-stream sender. Called at session end.

Source

pub async fn throttle(&self, n: u32)

Await bandwidth-bucket tokens for n bytes, blocking as needed.

If no bw= cap is set this is a no-op. On a multi-worker runtime the current thread’s current_worker_id picks which per-core partition to spend tokens against (§9.2).

Source

pub fn charge(&self, tunnel_id: TunnelId, n: u64) -> Charge

Account n bytes against the period quota. Rolls the counter over automatically at the reset deadline. On breach a RateLimit frame is queued for the control stream and Charge::QuotaExceeded is returned.

Source

pub fn quota_used_snapshot(&self) -> u64

Bytes currently counted against the period quota. Used by the §16.4 admin API’s /metrics endpoint.

Source

pub fn retry_after_ms(&self) -> u32

Millis until the current quota period resets. Clamped to u32::MAX to fit RateLimit.retry_after_ms.

Trait Implementations§

Source§

impl Debug for RateLimitState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more