]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Ignore pieces for request after accounting for storage
authorMatt Joiner <anacrolix@gmail.com>
Mon, 10 May 2021 07:03:56 +0000 (17:03 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 7 Jun 2021 03:01:39 +0000 (13:01 +1000)
request-strategy.go

index 9369905be9ec558ad43d2d0793e44ec82f8f86ae..8f3811d4ae92d825b7a1ffca0200de102fc9f7dd 100644 (file)
@@ -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