Comments
This commit is contained in:
parent
5c90e0cdd9
commit
f7b22aa0aa
1 changed files with 8 additions and 12 deletions
|
|
@ -13,7 +13,7 @@ pub struct ChunkTracker {
|
||||||
// it's set to 0.
|
// it's set to 0.
|
||||||
//
|
//
|
||||||
// Initially this is the opposite of "have", until we start making requests.
|
// Initially this is the opposite of "have", until we start making requests.
|
||||||
// An in-flight request is not in "needed", and not in "have".
|
// An in-flight request is not in in the queue, and not in "have".
|
||||||
//
|
//
|
||||||
// needed initial value = selected & !have
|
// needed initial value = selected & !have
|
||||||
queue_pieces: BF,
|
queue_pieces: BF,
|
||||||
|
|
@ -37,8 +37,12 @@ pub struct ChunkTracker {
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||||
pub struct HaveNeededSelected {
|
pub struct HaveNeededSelected {
|
||||||
|
// How many bytes we have downloaded and verified.
|
||||||
pub have_bytes: u64,
|
pub have_bytes: u64,
|
||||||
|
// How many bytes do we need to download for selected to be
|
||||||
|
// a subset of have.
|
||||||
pub needed_bytes: u64,
|
pub needed_bytes: u64,
|
||||||
|
// How many bytes the user selected (by picking files).
|
||||||
pub selected_bytes: u64,
|
pub selected_bytes: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -307,20 +311,12 @@ impl ChunkTracker {
|
||||||
while remaining_file_len > 0 {
|
while remaining_file_len > 0 {
|
||||||
current_piece_selected |= len > 0 && file_required;
|
current_piece_selected |= len > 0 && file_required;
|
||||||
let shift = std::cmp::min(current_piece_remaining as u64, remaining_file_len);
|
let shift = std::cmp::min(current_piece_remaining as u64, remaining_file_len);
|
||||||
assert!(shift > 0);
|
if shift == 0 {
|
||||||
|
anyhow::bail!("bug: shift = 0, this shouldn't have happened")
|
||||||
|
}
|
||||||
remaining_file_len -= shift;
|
remaining_file_len -= shift;
|
||||||
current_piece_remaining -= shift as u32;
|
current_piece_remaining -= shift as u32;
|
||||||
|
|
||||||
// dbg!(
|
|
||||||
// idx,
|
|
||||||
// shift,
|
|
||||||
// remaining_file_len,
|
|
||||||
// current_piece_remaining,
|
|
||||||
// current_piece_needed,
|
|
||||||
// file_required,
|
|
||||||
// current_piece
|
|
||||||
// );
|
|
||||||
|
|
||||||
if current_piece_remaining == 0 {
|
if current_piece_remaining == 0 {
|
||||||
let current_piece_have = self.have[current_piece.piece_index.get() as usize];
|
let current_piece_have = self.have[current_piece.piece_index.get() as usize];
|
||||||
if current_piece_have {
|
if current_piece_have {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue