Fix pending of already completed pieces when pending ranges of pieces
This commit is contained in:
parent
3df7d61836
commit
24b8b13d2d
|
@ -1957,9 +1957,7 @@ func (t Torrent) AddPeers(pp []Peer) error {
|
||||||
func (t Torrent) DownloadAll() {
|
func (t Torrent) DownloadAll() {
|
||||||
t.cl.mu.Lock()
|
t.cl.mu.Lock()
|
||||||
defer t.cl.mu.Unlock()
|
defer t.cl.mu.Unlock()
|
||||||
for i := range iter.N(t.torrent.Info.NumPieces()) {
|
t.torrent.pendPieceRange(0, t.torrent.numPieces())
|
||||||
t.torrent.pendPiece(i, t.cl)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns nil metainfo if it isn't in the cache. Checks that the retrieved
|
// Returns nil metainfo if it isn't in the cache. Checks that the retrieved
|
||||||
|
|
13
torrent.go
13
torrent.go
|
@ -951,7 +951,7 @@ func (t *torrent) piecePriorityUncached(piece int) (ret piecePriority) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *torrent) pendPiece(piece int, cl *Client) {
|
func (t *torrent) pendPiece(piece int) {
|
||||||
if t.pendingPieces.Contains(piece) {
|
if t.pendingPieces.Contains(piece) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -974,20 +974,15 @@ func (t *torrent) getCompletedPieces() (ret bitmap.Bitmap) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *torrent) pendPieces(pend *bitmap.Bitmap) {
|
|
||||||
t.pendingPieces.Union(pend)
|
|
||||||
t.updatePiecePriorities()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *torrent) unpendPieces(unpend *bitmap.Bitmap) {
|
func (t *torrent) unpendPieces(unpend *bitmap.Bitmap) {
|
||||||
t.pendingPieces.Sub(unpend)
|
t.pendingPieces.Sub(unpend)
|
||||||
t.updatePiecePriorities()
|
t.updatePiecePriorities()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *torrent) pendPieceRange(begin, end int) {
|
func (t *torrent) pendPieceRange(begin, end int) {
|
||||||
var bm bitmap.Bitmap
|
for i := begin; i < end; i++ {
|
||||||
bm.AddRange(begin, end)
|
t.pendPiece(i)
|
||||||
t.pendPieces(&bm)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *torrent) unpendPieceRange(begin, end int) {
|
func (t *torrent) unpendPieceRange(begin, end int) {
|
||||||
|
|
Loading…
Reference in New Issue