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

@ -86,9 +86,10 @@ impl TorrentStateInitializing {
})?;
info!(
"Initial check results: have {}, needed {}",
"Initial check results: have {}, needed {}, total selected {}",
SF::new(initial_check_results.have_bytes),
SF::new(initial_check_results.needed_bytes)
SF::new(initial_check_results.needed_bytes),
SF::new(initial_check_results.total_selected_bytes)
);
self.meta.spawner.spawn_block_in_place(|| {
@ -126,6 +127,7 @@ impl TorrentStateInitializing {
initial_check_results.needed_pieces,
initial_check_results.have_pieces,
self.meta.lengths,
initial_check_results.total_selected_bytes,
);
let paused = TorrentStatePaused {
@ -134,6 +136,7 @@ impl TorrentStateInitializing {
filenames,
chunk_tracker,
have_bytes: initial_check_results.have_bytes,
needed_bytes: initial_check_results.needed_bytes,
};
Ok(paused)
}

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,
}

View file

@ -364,14 +364,20 @@ impl ManagedTorrent {
}
ManagedTorrentState::Paused(p) => {
resp.state = "paused";
resp.progress_bytes = p.have_bytes;
resp.finished = p.have_bytes == resp.total_bytes;
resp.total_bytes = p.chunk_tracker.get_total_selected_bytes();
resp.progress_bytes = resp.total_bytes - p.needed_bytes;
resp.finished = resp.progress_bytes == resp.total_bytes;
}
ManagedTorrentState::Live(l) => {
resp.state = "live";
let live_stats = LiveStats::from(l.as_ref());
resp.progress_bytes = live_stats.snapshot.have_bytes;
resp.finished = resp.progress_bytes == resp.total_bytes;
let total = l.get_total_selected_bytes();
let remaining = l.get_left_to_download_bytes();
let progress = total - remaining;
resp.progress_bytes = progress;
resp.total_bytes = total;
resp.finished = remaining == 0;
resp.live = Some(live_stats);
}
ManagedTorrentState::Error(e) => {

View file

@ -12,6 +12,7 @@ pub struct TorrentStatePaused {
pub(crate) filenames: Vec<PathBuf>,
pub(crate) chunk_tracker: ChunkTracker,
pub(crate) have_bytes: u64,
pub(crate) needed_bytes: u64,
}
// impl TorrentStatePaused {