Speed computation now better fits torrent with large pieces

This commit is contained in:
Igor Katson 2021-10-16 00:13:58 +01:00
parent d0757d41c5
commit 3b8c4e053f

View file

@ -247,10 +247,14 @@ impl TorrentManager {
let state = mgr.state.clone();
async move {
loop {
let downloaded = state.stats_snapshot().downloaded_and_checked_bytes;
let stats = state.stats_snapshot();
let fetched = state.stats_snapshot().fetched_bytes;
let needed = state.initially_needed();
let remaining = needed - downloaded;
estimator.add_snapshot(downloaded, remaining, Instant::now());
// fetched can be too high in theory, so for safety make sure that it doesn't wrap around u64.
let remaining = needed
.wrapping_sub(fetched)
.min(needed - stats.downloaded_and_checked_bytes);
estimator.add_snapshot(fetched, remaining, Instant::now());
tokio::time::sleep(Duration::from_secs(1)).await;
}
}