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:
parent
50fc7f2f01
commit
325855ba56
8 changed files with 91 additions and 46 deletions
|
|
@ -24,6 +24,8 @@ pub struct ChunkTracker {
|
|||
|
||||
// What pieces to download first.
|
||||
priority_piece_ids: Vec<usize>,
|
||||
|
||||
total_selected_bytes: u64,
|
||||
}
|
||||
|
||||
// TODO: this should be redone from "have" pieces, not from "needed" pieces.
|
||||
|
|
@ -58,7 +60,12 @@ pub enum ChunkMarkingResult {
|
|||
}
|
||||
|
||||
impl ChunkTracker {
|
||||
pub fn new(needed_pieces: BF, have_pieces: BF, lengths: Lengths) -> Self {
|
||||
pub fn new(
|
||||
needed_pieces: BF,
|
||||
have_pieces: BF,
|
||||
lengths: Lengths,
|
||||
total_selected_bytes: u64,
|
||||
) -> Self {
|
||||
// TODO: ideally this needs to be a list based on needed files, e.g.
|
||||
// last needed piece for each file. But let's keep simple for now.
|
||||
|
||||
|
|
@ -80,9 +87,14 @@ impl ChunkTracker {
|
|||
lengths,
|
||||
have: have_pieces,
|
||||
priority_piece_ids,
|
||||
total_selected_bytes,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_total_selected_bytes(&self) -> u64 {
|
||||
self.total_selected_bytes
|
||||
}
|
||||
|
||||
pub fn get_lengths(&self) -> &Lengths {
|
||||
&self.lengths
|
||||
}
|
||||
|
|
@ -104,6 +116,16 @@ impl ChunkTracker {
|
|||
.sum()
|
||||
}
|
||||
|
||||
pub fn calc_needed_bytes(&self) -> u64 {
|
||||
self.needed_pieces
|
||||
.iter_ones()
|
||||
.filter_map(|piece_id| {
|
||||
let piece_id = self.lengths.validate_piece_index(piece_id as u32)?;
|
||||
Some(self.lengths.piece_length(piece_id) as u64)
|
||||
})
|
||||
.sum()
|
||||
}
|
||||
|
||||
pub fn iter_needed_pieces(&self) -> impl Iterator<Item = usize> + '_ {
|
||||
self.priority_piece_ids
|
||||
.iter()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue