Skip to content

Commit

Permalink
Reduce repeated block download
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanjermakov committed Oct 27, 2023
1 parent fc2c2c6 commit ac1343d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,10 @@ pub async fn write_loop(
debug!("next request piece: {:?}", piece);
let total_blocks = piece.total_blocks();

// TODO: only request blocks you don't have
for i in 0..total_blocks {
let block_idxs = (0..total_blocks)
.filter(|i| !piece.blocks.contains_key(i))
.collect::<Vec<_>>();
for i in block_idxs {
let request_msg = Message::Request {
piece_index: piece.index,
begin: i * BLOCK_SIZE,
Expand Down

0 comments on commit ac1343d

Please sign in to comment.