Seems alright now

This commit is contained in:
Igor Katson 2023-11-25 00:54:21 +00:00
parent 17b243921d
commit fa97dedb98
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
5 changed files with 50 additions and 31 deletions

View file

@ -87,6 +87,16 @@ impl ChunkTracker {
self.needed_pieces.set(index.get() as usize, false)
}
pub fn calc_have_bytes(&self) -> u64 {
self.have
.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()