When stealing pieces, only steal from slower peers

This commit is contained in:
Igor Katson 2023-12-25 09:08:16 -05:00
parent 1e525eb91e
commit 5d4ffae6de
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
2 changed files with 13 additions and 30 deletions

View file

@ -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))
}
}