]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix pending of already completed pieces when pending ranges of pieces
authorMatt Joiner <anacrolix@gmail.com>
Mon, 8 Feb 2016 10:36:50 +0000 (21:36 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 8 Feb 2016 10:36:50 +0000 (21:36 +1100)
client.go
torrent.go

index 5429dd870d37892b783c097932f9e54ae7e27f28..2d6a3582bce2dc3d42bd8fe430fbaf46077b1095 100644 (file)
--- a/client.go
+++ b/client.go
@@ -1957,9 +1957,7 @@ func (t Torrent) AddPeers(pp []Peer) error {
 func (t Torrent) DownloadAll() {
        t.cl.mu.Lock()
        defer t.cl.mu.Unlock()
-       for i := range iter.N(t.torrent.Info.NumPieces()) {
-               t.torrent.pendPiece(i, t.cl)
-       }
+       t.torrent.pendPieceRange(0, t.torrent.numPieces())
 }
 
 // Returns nil metainfo if it isn't in the cache. Checks that the retrieved
index 7671da4fbe7a66b00a542f6a174073c11c61a218..c4c52f5a7fda80c95c54498d3500984a7dc51585 100644 (file)
@@ -951,7 +951,7 @@ func (t *torrent) piecePriorityUncached(piece int) (ret piecePriority) {
        return
 }
 
-func (t *torrent) pendPiece(piece int, cl *Client) {
+func (t *torrent) pendPiece(piece int) {
        if t.pendingPieces.Contains(piece) {
                return
        }
@@ -974,20 +974,15 @@ func (t *torrent) getCompletedPieces() (ret bitmap.Bitmap) {
        return
 }
 
-func (t *torrent) pendPieces(pend *bitmap.Bitmap) {
-       t.pendingPieces.Union(pend)
-       t.updatePiecePriorities()
-}
-
 func (t *torrent) unpendPieces(unpend *bitmap.Bitmap) {
        t.pendingPieces.Sub(unpend)
        t.updatePiecePriorities()
 }
 
 func (t *torrent) pendPieceRange(begin, end int) {
-       var bm bitmap.Bitmap
-       bm.AddRange(begin, end)
-       t.pendPieces(&bm)
+       for i := begin; i < end; i++ {
+               t.pendPiece(i)
+       }
 }
 
 func (t *torrent) unpendPieceRange(begin, end int) {