Add a flag for Complete
This commit is contained in:
parent
81c47d5705
commit
c9c137d8f2
@ -149,6 +149,9 @@ type Torrent struct {
|
|||||||
dirtyChunks roaring.Bitmap
|
dirtyChunks roaring.Bitmap
|
||||||
|
|
||||||
pex pexState
|
pex pexState
|
||||||
|
|
||||||
|
// Is On when all pieces are complete.
|
||||||
|
Complete chansync.Flag
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Torrent) pieceAvailabilityFromPeers(i pieceIndex) (count int) {
|
func (t *Torrent) pieceAvailabilityFromPeers(i pieceIndex) (count int) {
|
||||||
@ -413,6 +416,7 @@ func (t *Torrent) setInfo(info *metainfo.Info) error {
|
|||||||
t.nameMu.Lock()
|
t.nameMu.Lock()
|
||||||
t.info = info
|
t.info = info
|
||||||
t.nameMu.Unlock()
|
t.nameMu.Unlock()
|
||||||
|
t.updateComplete()
|
||||||
t.fileIndex = segments.NewIndex(common.LengthIterFromUpvertedFiles(info.UpvertedFiles()))
|
t.fileIndex = segments.NewIndex(common.LengthIterFromUpvertedFiles(info.UpvertedFiles()))
|
||||||
t.displayName = "" // Save a few bytes lol.
|
t.displayName = "" // Save a few bytes lol.
|
||||||
t.initFiles()
|
t.initFiles()
|
||||||
@ -1264,6 +1268,7 @@ func (t *Torrent) updatePieceCompletion(piece pieceIndex) bool {
|
|||||||
} else {
|
} else {
|
||||||
t._completedPieces.Remove(x)
|
t._completedPieces.Remove(x)
|
||||||
}
|
}
|
||||||
|
t.updateComplete()
|
||||||
if complete && len(p.dirtiers) != 0 {
|
if complete && len(p.dirtiers) != 0 {
|
||||||
t.logger.Printf("marked piece %v complete but still has dirtiers", piece)
|
t.logger.Printf("marked piece %v complete but still has dirtiers", piece)
|
||||||
}
|
}
|
||||||
@ -2289,3 +2294,7 @@ func (t *Torrent) numChunks() RequestIndex {
|
|||||||
func (t *Torrent) pieceRequestIndexOffset(piece pieceIndex) RequestIndex {
|
func (t *Torrent) pieceRequestIndexOffset(piece pieceIndex) RequestIndex {
|
||||||
return RequestIndex(piece) * t.chunksPerRegularPiece()
|
return RequestIndex(piece) * t.chunksPerRegularPiece()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Torrent) updateComplete() {
|
||||||
|
t.Complete.SetBool(t.haveAllPieces())
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user