DHT stats in HTTP API

This commit is contained in:
Igor Katson 2021-07-14 13:40:56 +01:00
parent f00f522767
commit 98dff76c40
10 changed files with 111 additions and 62 deletions

View file

@ -62,11 +62,13 @@ pub struct AggregatePeerStats {
pub queued: usize,
pub connecting: usize,
pub live: usize,
pub seen: usize,
}
impl PeerStates {
pub fn stats(&self) -> AggregatePeerStats {
self.states
let mut stats = self
.states
.values()
.fold(AggregatePeerStats::default(), |mut s, p| {
match p {
@ -75,7 +77,9 @@ impl PeerStates {
PeerState::Queued => s.queued += 1,
};
s
})
});
stats.seen = self.seen.len();
stats
}
pub fn add_if_not_seen(
&mut self,
@ -547,6 +551,10 @@ impl TorrentState {
true
}
pub fn peer_stats_snapshot(&self) -> AggregatePeerStats {
self.locked.read().peers.stats()
}
pub fn stats_snapshot(&self) -> StatsSnapshot {
let g = self.locked.read();
use Ordering::*;