VoiceBudget

Struct VoiceBudget 

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

One connection’s voice traffic account.

Three things that share a clock and a lock: the token bucket that decides admission, the one-second window that measures throughput, and the last sign of life that is not a keepalive. Keeping them together is what makes the hot path take one lock rather than three.

The clock is passed in rather than read here: the packet path already knows what time it is, and a test that has to sleep to observe a rate limit is a test that will be flaky by Friday.

Implementations§

Source§

impl VoiceBudget

Source

pub fn new(now: Instant) -> Self

Source

pub fn allow(&mut self, now: Instant, bytes: usize) -> bool

Take one packet’s worth of budget, refilling for elapsed time first, and bill what it carried.

A refused packet is billed nothing, like the reference server’s own record: addFrame is both the limiter and the meter, and a frame it rejects never enters the window.

bytes is the decoded packet, to which the network overhead is added. false means the caller must drop the packet.

Source

pub fn touch(&mut self, now: Instant)

Note that the connection did something that is not a keepalive.

Source

pub fn bandwidth(&mut self, now: Instant) -> u32

Voice throughput over the last second, in bytes per second.

The unit is the client’s: it divides by 125 to print kbit/s.

REF: references/mumble/src/murmur/ServerUser.cpp : bandwidth() sums the frames of the last second and divides by the elapsed time. REF: references/mumble/src/mumble/UserInformation.cpp : the dialog prints msg.bandwidth() / 125.0 as kbit/s.

Source

pub fn idle(&self, now: Instant) -> Duration

How long this connection has been doing nothing.

REF: references/mumble/src/murmur/ServerUser.cpp : idleSeconds() takes the shorter of “since the last voice frame” and “since the last control message that unidles”.

Trait Implementations§

Source§

impl Debug for VoiceBudget

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<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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.