split up librqbit torrent state into smaller files
This commit is contained in:
parent
7cd6102c6a
commit
edaf3e0997
17 changed files with 502 additions and 440 deletions
43
crates/librqbit/src/torrent_state/live/peers/stats/atomic.rs
Normal file
43
crates/librqbit/src/torrent_state/live/peers/stats/atomic.rs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
use std::sync::atomic::AtomicU32;
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::torrent_state::{
|
||||
live::peer::PeerState,
|
||||
utils::{atomic_dec, atomic_inc},
|
||||
};
|
||||
|
||||
#[derive(Debug, Default, Serialize)]
|
||||
pub struct AggregatePeerStatsAtomic {
|
||||
pub queued: AtomicU32,
|
||||
pub connecting: AtomicU32,
|
||||
pub live: AtomicU32,
|
||||
pub seen: AtomicU32,
|
||||
pub dead: AtomicU32,
|
||||
pub not_needed: AtomicU32,
|
||||
}
|
||||
|
||||
impl AggregatePeerStatsAtomic {
|
||||
pub fn counter(&self, state: &PeerState) -> &AtomicU32 {
|
||||
match state {
|
||||
PeerState::Connecting(_) => &self.connecting,
|
||||
PeerState::Live(_) => &self.live,
|
||||
PeerState::Queued => &self.queued,
|
||||
PeerState::Dead => &self.dead,
|
||||
PeerState::NotNeeded => &self.not_needed,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inc(&self, state: &PeerState) {
|
||||
atomic_inc(self.counter(state));
|
||||
}
|
||||
|
||||
pub fn dec(&self, state: &PeerState) {
|
||||
atomic_dec(self.counter(state));
|
||||
}
|
||||
|
||||
pub fn incdec(&self, old: &PeerState, new: &PeerState) {
|
||||
self.dec(old);
|
||||
self.inc(new);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
pub mod atomic;
|
||||
pub mod snapshot;
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
use std::sync::atomic::Ordering;
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
use super::atomic::AggregatePeerStatsAtomic;
|
||||
|
||||
#[derive(Debug, Default, Serialize, PartialEq, Eq)]
|
||||
pub struct AggregatePeerStats {
|
||||
pub queued: usize,
|
||||
pub connecting: usize,
|
||||
pub live: usize,
|
||||
pub seen: usize,
|
||||
pub dead: usize,
|
||||
pub not_needed: usize,
|
||||
}
|
||||
|
||||
impl<'a> From<&'a AggregatePeerStatsAtomic> for AggregatePeerStats {
|
||||
fn from(s: &'a AggregatePeerStatsAtomic) -> Self {
|
||||
let ordering = Ordering::Relaxed;
|
||||
Self {
|
||||
queued: s.queued.load(ordering) as usize,
|
||||
connecting: s.connecting.load(ordering) as usize,
|
||||
live: s.live.load(ordering) as usize,
|
||||
seen: s.seen.load(ordering) as usize,
|
||||
dead: s.dead.load(ordering) as usize,
|
||||
not_needed: s.not_needed.load(ordering) as usize,
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue