From: Matt Joiner Date: Mon, 10 May 2021 07:03:56 +0000 (+1000) Subject: Ignore pieces for request after accounting for storage X-Git-Tag: v1.29.0~31^2~47 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=6d25c99ac65ed32dc1f550df5dc5adf774944690;p=btrtrc.git Ignore pieces for request after accounting for storage --- 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