Fix only files not working properly (#59)

* 1/n fixing only files - tracking stats better

* 2/n proper tracking of stats when only certain files selected
This commit is contained in:
Igor Katson 2023-12-14 11:58:09 +00:00 committed by GitHub
parent 50fc7f2f01
commit 325855ba56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 91 additions and 46 deletions

View file

@ -174,6 +174,7 @@ pub struct TorrentStateLive {
filenames: Vec<PathBuf>,
initially_needed_bytes: u64,
total_selected_bytes: u64,
stats: AtomicStats,
lengths: Lengths,
@ -203,7 +204,8 @@ impl TorrentStateLive {
let up_speed_estimator = SpeedEstimator::new(5);
let have_bytes = paused.have_bytes;
let needed_bytes = paused.info.lengths.total_length() - have_bytes;
let needed_bytes = paused.needed_bytes;
let total_selected_bytes = paused.chunk_tracker.get_total_selected_bytes();
let lengths = *paused.chunk_tracker.get_lengths();
let state = Arc::new(TorrentStateLive {
@ -222,6 +224,7 @@ impl TorrentStateLive {
},
initially_needed_bytes: needed_bytes,
lengths,
total_selected_bytes,
peer_semaphore: Arc::new(Semaphore::new(128)),
peer_queue_tx,
finished_notify: Notify::new(),
@ -599,6 +602,10 @@ impl TorrentStateLive {
});
}
pub fn get_total_selected_bytes(&self) -> u64 {
self.total_selected_bytes
}
pub fn get_uploaded_bytes(&self) -> u64 {
self.stats.uploaded_bytes.load(Ordering::Relaxed)
}
@ -690,16 +697,11 @@ impl TorrentStateLive {
pub fn stats_snapshot(&self) -> StatsSnapshot {
use Ordering::*;
let downloaded_bytes = self.stats.downloaded_and_checked_bytes.load(Relaxed);
let remaining = self.initially_needed_bytes - downloaded_bytes;
StatsSnapshot {
have_bytes: self.stats.have_bytes.load(Relaxed),
downloaded_and_checked_bytes: downloaded_bytes,
downloaded_and_checked_pieces: self.stats.downloaded_and_checked_pieces.load(Relaxed),
fetched_bytes: self.stats.fetched_bytes.load(Relaxed),
uploaded_bytes: self.stats.uploaded_bytes.load(Relaxed),
total_bytes: self.lengths.total_length(),
initially_needed_bytes: self.initially_needed_bytes,
remaining_bytes: remaining,
total_piece_download_ms: self.stats.total_piece_download_ms.load(Relaxed),
peer_stats: self.peers.stats(),
}
@ -750,6 +752,7 @@ impl TorrentStateLive {
chunk_tracker.mark_piece_broken(piece_id);
}
let have_bytes = chunk_tracker.calc_have_bytes();
let needed_bytes = chunk_tracker.calc_needed_bytes();
// g.chunks;
Ok(TorrentStatePaused {
@ -758,6 +761,7 @@ impl TorrentStateLive {
filenames,
chunk_tracker,
have_bytes,
needed_bytes,
})
}

View file

@ -6,14 +6,12 @@ use crate::torrent_state::live::peers::stats::snapshot::AggregatePeerStats;
#[derive(Debug, Serialize, Default)]
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,
pub downloaded_and_checked_pieces: u64,
pub total_piece_download_ms: u64,
pub peer_stats: AggregatePeerStats,
}