add rate limiting to outbound p2p msg sending (#3560)

treat peers as abusive based on incoming msgs, not outgoing msg rates
This commit is contained in:
Antioch Peverell
2021-02-15 13:49:31 +00:00
committed by GitHub
parent 7649d361e4
commit 4ab72902e0
5 changed files with 33 additions and 28 deletions
+8
View File
@@ -99,6 +99,14 @@ impl RateCounter {
.filter(|x| !x.is_quiet())
.count() as u64
}
/// Elapsed time in ms since the last entry.
/// We use this to rate limit when sending.
pub fn elapsed_since_last_msg(&self) -> Option<u64> {
self.last_min_entries
.last()
.map(|x| millis_since_epoch().saturating_sub(x.timestamp))
}
}
// turns out getting the millisecs since epoch in Rust isn't as easy as it