diff --git a/request-strategy.go b/request-strategy.go index 9369905b..8f3811d4 100644 --- a/request-strategy.go +++ b/request-strategy.go @@ -31,6 +31,10 @@ func (me *clientPieceRequestOrder) addPieces(t *Torrent, numPieces pieceIndex) { } } +func (me *clientPieceRequestOrder) Len() int { + return len(me.pieces) +} + func (me *clientPieceRequestOrder) removePieces(t *Torrent) { newPieces := make([]pieceRequestOrderPiece, 0, len(me.pieces)-t.numPieces()) for _, p := range me.pieces { @@ -118,9 +122,6 @@ func (cl *Client) doRequests() { // For a given piece, the set of allPeers indices that absorbed requests for the piece. contributed := make(map[int]struct{}) for _, p := range requestOrder.pieces { - if p.t.ignorePieceForRequests(p.index) { - continue - } peers := allPeers[p.t] torrentPiece := p.t.piece(p.index) if left := storageLeft[p.t.storage.Capacity]; left != nil { @@ -129,6 +130,9 @@ func (cl *Client) doRequests() { } *left -= int64(torrentPiece.length()) } + if p.t.ignorePieceForRequests(p.index) { + continue + } p.t.piece(p.index).iterUndirtiedChunks(func(chunk ChunkSpec) bool { req := Request{pp.Integer(p.index), chunk} const skipAlreadyRequested = false