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
25
crates/librqbit/src/torrent_state/live/stats/atomic.rs
Normal file
25
crates/librqbit/src/torrent_state/live/stats/atomic.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
use std::{
|
||||
sync::atomic::{AtomicU64, Ordering},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub struct AtomicStats {
|
||||
pub have_bytes: AtomicU64,
|
||||
pub downloaded_and_checked_bytes: AtomicU64,
|
||||
pub downloaded_and_checked_pieces: AtomicU64,
|
||||
pub uploaded_bytes: AtomicU64,
|
||||
pub fetched_bytes: AtomicU64,
|
||||
pub total_piece_download_ms: AtomicU64,
|
||||
}
|
||||
|
||||
impl AtomicStats {
|
||||
pub fn average_piece_download_time(&self) -> Option<Duration> {
|
||||
let d = self.downloaded_and_checked_pieces.load(Ordering::Acquire);
|
||||
let t = self.total_piece_download_ms.load(Ordering::Acquire);
|
||||
if d == 0 {
|
||||
return None;
|
||||
}
|
||||
Some(Duration::from_secs_f64(t as f64 / d as f64 / 1000f64))
|
||||
}
|
||||
}
|
||||
2
crates/librqbit/src/torrent_state/live/stats/mod.rs
Normal file
2
crates/librqbit/src/torrent_state/live/stats/mod.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
pub mod atomic;
|
||||
pub mod snapshot;
|
||||
32
crates/librqbit/src/torrent_state/live/stats/snapshot.rs
Normal file
32
crates/librqbit/src/torrent_state/live/stats/snapshot.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
use std::time::{Duration, Instant};
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::torrent_state::live::peers::stats::snapshot::AggregatePeerStats;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct StatsSnapshot {
|
||||
pub have_bytes: u64,
|
||||
pub downloaded_and_checked_bytes: u64,
|
||||
pub downloaded_and_checked_pieces: u64,
|
||||
pub fetched_bytes: u64,
|
||||
pub uploaded_bytes: u64,
|
||||
pub initially_needed_bytes: u64,
|
||||
pub remaining_bytes: u64,
|
||||
pub total_bytes: u64,
|
||||
#[serde(skip)]
|
||||
pub time: Instant,
|
||||
pub total_piece_download_ms: u64,
|
||||
pub peer_stats: AggregatePeerStats,
|
||||
}
|
||||
|
||||
impl StatsSnapshot {
|
||||
pub fn average_piece_download_time(&self) -> Option<Duration> {
|
||||
let d = self.downloaded_and_checked_pieces;
|
||||
let t = self.total_piece_download_ms;
|
||||
if d == 0 {
|
||||
return None;
|
||||
}
|
||||
Some(Duration::from_secs_f64(t as f64 / d as f64 / 1000f64))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue