Skip to content

Commit

Permalink
do not request duplicate blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkalti committed Mar 4, 2019
1 parent 054d038 commit 8b0f810
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions internal/piecedownloader/piecedownloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func New(pi *piece.Piece, pe Peer, allowedFast bool, buf bufferpool.Buffer) *Pie

func (d *PieceDownloader) Choked() {
for i := range d.pending {
d.remaining = append(d.remaining, i)
delete(d.pending, i)
d.remaining = append(d.remaining, i)
}
}

Expand All @@ -66,8 +66,8 @@ func (d *PieceDownloader) GotBlock(block piece.Block, data []byte) error {
}

func (d *PieceDownloader) Rejected(block piece.Block) {
d.remaining = append(d.remaining, block.Index)
delete(d.pending, block.Index)
d.remaining = append(d.remaining, block.Index)
}

func (d *PieceDownloader) CancelPending() {
Expand All @@ -90,9 +90,11 @@ func (d *PieceDownloader) RequestBlocks(queueLength int) {
if !ok {
panic("cannot get block")
}
d.Peer.RequestPiece(d.Piece.Index, b.Begin, b.Length)
if _, ok := d.done[i]; !ok {
d.Peer.RequestPiece(d.Piece.Index, b.Begin, b.Length)
}
d.remaining = d.remaining[1:]
d.pending[b.Index] = struct{}{}
d.pending[i] = struct{}{}
}
}

Expand Down

0 comments on commit 8b0f810

Please sign in to comment.