torrent.go | 9 +++++++++ diff --git a/torrent.go b/torrent.go index 1e47f5e4073b4b92329c5a4dac509d85f479aa37..bfa84366aa4a8cd7aa7392e77e66af8dfcf0a8ba 100644 --- a/torrent.go +++ b/torrent.go @@ -149,6 +149,9 @@ // Chunks we've written to since the corresponding piece was last checked. dirtyChunks roaring.Bitmap pex pexState + + // Is On when all pieces are complete. + Complete chansync.Flag } func (t *Torrent) pieceAvailabilityFromPeers(i pieceIndex) (count int) { @@ -413,6 +416,7 @@ } t.nameMu.Lock() t.info = info t.nameMu.Unlock() + t.updateComplete() t.fileIndex = segments.NewIndex(common.LengthIterFromUpvertedFiles(info.UpvertedFiles())) t.displayName = "" // Save a few bytes lol. t.initFiles() @@ -1264,6 +1268,7 @@ t._completedPieces.Add(x) } else { t._completedPieces.Remove(x) } + t.updateComplete() if complete && len(p.dirtiers) != 0 { t.logger.Printf("marked piece %v complete but still has dirtiers", piece) } @@ -2289,3 +2294,7 @@ func (t *Torrent) pieceRequestIndexOffset(piece pieceIndex) RequestIndex { return RequestIndex(piece) * t.chunksPerRegularPiece() } + +func (t *Torrent) updateComplete() { + t.Complete.SetBool(t.haveAllPieces()) +}