When stealing pieces, only steal from slower peers
This commit is contained in:
parent
1e525eb91e
commit
5d4ffae6de
2 changed files with 13 additions and 30 deletions
|
|
@ -1,7 +1,4 @@
|
|||
use std::{
|
||||
sync::atomic::{AtomicU64, Ordering},
|
||||
time::Duration,
|
||||
};
|
||||
use std::sync::atomic::AtomicU64;
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub struct AtomicStats {
|
||||
|
|
@ -12,14 +9,3 @@ pub struct AtomicStats {
|
|||
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))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue