Jeez...
This commit is contained in:
parent
efcffdd072
commit
51d1a0b0c7
7 changed files with 183 additions and 115 deletions
|
|
@ -11,7 +11,10 @@ use parking_lot::Mutex;
|
|||
use size_format::SizeFormatterBinary as SF;
|
||||
use tracing::{debug, info, warn};
|
||||
|
||||
use crate::{chunk_tracker::ChunkTracker, file_ops::FileOps};
|
||||
use crate::{
|
||||
chunk_tracker::{ChunkTracker, HaveNeededSelected},
|
||||
file_ops::FileOps,
|
||||
};
|
||||
|
||||
use super::{paused::TorrentStatePaused, ManagedTorrentInfo};
|
||||
|
||||
|
|
@ -88,7 +91,7 @@ impl TorrentStateInitializing {
|
|||
"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.total_selected_bytes)
|
||||
SF::new(initial_check_results.selected_bytes)
|
||||
);
|
||||
|
||||
self.meta.spawner.spawn_block_in_place(|| {
|
||||
|
|
@ -123,10 +126,9 @@ impl TorrentStateInitializing {
|
|||
});
|
||||
|
||||
let chunk_tracker = ChunkTracker::new(
|
||||
initial_check_results.needed_pieces,
|
||||
initial_check_results.have_pieces,
|
||||
initial_check_results.selected_pieces,
|
||||
self.meta.lengths,
|
||||
initial_check_results.total_selected_bytes,
|
||||
)
|
||||
.context("error creating chunk tracker")?;
|
||||
|
||||
|
|
@ -135,8 +137,11 @@ impl TorrentStateInitializing {
|
|||
files,
|
||||
filenames,
|
||||
chunk_tracker,
|
||||
have_bytes: initial_check_results.have_bytes,
|
||||
needed_bytes: initial_check_results.needed_bytes,
|
||||
hns: HaveNeededSelected {
|
||||
have_bytes: initial_check_results.have_bytes,
|
||||
needed_bytes: initial_check_results.needed_bytes,
|
||||
selected_bytes: initial_check_results.selected_bytes,
|
||||
},
|
||||
};
|
||||
Ok(paused)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ use tokio_util::sync::CancellationToken;
|
|||
use tracing::{debug, error, error_span, info, trace, warn};
|
||||
|
||||
use crate::{
|
||||
chunk_tracker::{ChunkMarkingResult, ChunkTracker},
|
||||
chunk_tracker::{ChunkMarkingResult, ChunkTracker, HaveNeededSelected},
|
||||
file_ops::FileOps,
|
||||
peer_connection::{
|
||||
PeerConnection, PeerConnectionHandler, PeerConnectionOptions, WriterRequest,
|
||||
|
|
@ -203,9 +203,9 @@ impl TorrentStateLive {
|
|||
let down_speed_estimator = SpeedEstimator::new(5);
|
||||
let up_speed_estimator = SpeedEstimator::new(5);
|
||||
|
||||
let have_bytes = paused.have_bytes;
|
||||
let needed_bytes = paused.needed_bytes;
|
||||
let total_selected_bytes = paused.chunk_tracker.get_total_selected_bytes();
|
||||
let have_bytes = paused.hns.have_bytes;
|
||||
let needed_bytes = paused.hns.needed_bytes;
|
||||
let total_selected_bytes = paused.hns.selected_bytes;
|
||||
let lengths = *paused.chunk_tracker.get_lengths();
|
||||
|
||||
let state = Arc::new(TorrentStateLive {
|
||||
|
|
@ -676,8 +676,11 @@ impl TorrentStateLive {
|
|||
files,
|
||||
filenames,
|
||||
chunk_tracker,
|
||||
have_bytes,
|
||||
needed_bytes,
|
||||
hns: HaveNeededSelected {
|
||||
have_bytes,
|
||||
needed_bytes,
|
||||
selected_bytes: self.total_selected_bytes,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -916,7 +919,7 @@ impl PeerHandler {
|
|||
let n = {
|
||||
let mut n_opt = None;
|
||||
let bf = &live.bitfield;
|
||||
for n in g.get_chunks()?.iter_needed_pieces() {
|
||||
for n in g.get_chunks()?.iter_queued_pieces() {
|
||||
if bf.get(n).map(|v| *v) == Some(true) {
|
||||
n_opt = Some(n);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -353,9 +353,9 @@ impl ManagedTorrent {
|
|||
}
|
||||
ManagedTorrentState::Paused(p) => {
|
||||
resp.state = S::Paused;
|
||||
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;
|
||||
resp.total_bytes = p.hns.total();
|
||||
resp.progress_bytes = p.hns.progress();
|
||||
resp.finished = p.hns.finished();
|
||||
}
|
||||
ManagedTorrentState::Live(l) => {
|
||||
resp.state = S::Live;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::{collections::HashSet, fs::File, path::PathBuf, sync::Arc};
|
|||
|
||||
use parking_lot::Mutex;
|
||||
|
||||
use crate::chunk_tracker::ChunkTracker;
|
||||
use crate::chunk_tracker::{ChunkTracker, HaveNeededSelected};
|
||||
|
||||
use super::ManagedTorrentInfo;
|
||||
|
||||
|
|
@ -11,17 +11,15 @@ pub struct TorrentStatePaused {
|
|||
pub(crate) files: Vec<Arc<Mutex<File>>>,
|
||||
pub(crate) filenames: Vec<PathBuf>,
|
||||
pub(crate) chunk_tracker: ChunkTracker,
|
||||
pub(crate) have_bytes: u64,
|
||||
pub(crate) needed_bytes: u64,
|
||||
pub(crate) hns: HaveNeededSelected,
|
||||
}
|
||||
|
||||
impl TorrentStatePaused {
|
||||
pub(crate) fn update_only_files(&mut self, only_files: &HashSet<usize>) -> anyhow::Result<()> {
|
||||
let hn = self
|
||||
let hns = self
|
||||
.chunk_tracker
|
||||
.update_only_files(self.info.info.iter_file_lengths()?, only_files)?;
|
||||
self.have_bytes = hn.have_bytes;
|
||||
self.needed_bytes = hn.needed_bytes;
|
||||
self.hns = hns;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue