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
impl RateCounter
Sourcepub fn new() -> RateCounter
pub fn new() -> RateCounter
Instantiate a new rate counter
Sourcepub fn inc(&mut self, bytes: u64)
pub fn inc(&mut self, bytes: u64)
Increments number of bytes transferred, updating counts and rates.
Sourcepub fn inc_quiet(&mut self, bytes: u64)
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).
Sourcepub fn bytes_per_min(&self) -> u64
pub fn bytes_per_min(&self) -> u64
Number of bytes counted in the last minute. Includes “quiet” byte increments.
Sourcepub fn count_per_min(&self) -> u64
pub fn count_per_min(&self) -> u64
Count of increases in the last minute. Excludes “quiet” byte increments.
Sourcepub fn elapsed_since_last_msg(&self) -> Option<u64>
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.