Struct grin_util::RateCounter

source ·
pub struct RateCounter { /* private fields */ }
Expand description

A rate counter tracks the number of transfers, the amount of data exchanged and the rate of transfer (via a few timers) over the last minute. The counter does not try to be accurate and update times proactively, instead it only does so lazily. As a result, produced rates are worst-case estimates.

Implementations§

source§

impl RateCounter

source

pub fn new() -> RateCounter

Instantiate a new rate counter

source

pub fn inc(&mut self, bytes: u64)

Increments number of bytes transferred, updating counts and rates.

source

pub fn inc_quiet(&mut self, bytes: u64)

Increments number of bytes without updating the count or rate. We filter out 0 last_min_times when calculating rate. Used during txhashset.zip download to track bytes downloaded without treating a peer as abusive (too high a rate of download).

source

pub fn bytes_per_min(&self) -> u64

Number of bytes counted in the last minute. Includes “quiet” byte increments.

source

pub fn count_per_min(&self) -> u64

Count of increases in the last minute. Excludes “quiet” byte increments.

source

pub fn elapsed_since_last_msg(&self) -> Option<u64>

Elapsed time in ms since the last entry. We use this to rate limit when sending.

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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<T> UnsafeAny for T
where T: Any,