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
impl VoiceBudget
pub fn new(now: Instant) -> Self
Sourcepub fn allow(&mut self, now: Instant, bytes: usize) -> bool
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.
Sourcepub fn touch(&mut self, now: Instant)
pub fn touch(&mut self, now: Instant)
Note that the connection did something that is not a keepalive.
Sourcepub fn bandwidth(&mut self, now: Instant) -> u32
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.