pex pexState
- // Is On when all pieces are complete.
+ // Is On when all pieces are complete, no hashing is pending or occurring.
complete chansync.Flag
// Torrent sources in use keyed by the source string. string -> error. If the slot is occupied
return
}
if t.storage == nil {
- return storage.Completion{Complete: false, Ok: true}
+ return storage.Completion{Complete: false, Ok: false}
}
return p.Storage().Completion()
}
t.openNewConns()
}
p.t.updatePieceRequestOrderPiece(piece)
- t.updateComplete()
+ t.deferUpdateComplete()
if complete && len(p.dirtiers) != 0 {
t.logger.Printf("marked piece %v complete but still has dirtiers", piece)
}
func (t *Torrent) startHash(pi pieceIndex) {
p := t.piece(pi)
t.piecesQueuedForHash.Remove(pi)
- t.deferUpdateComplete()
p.hashing = true
t.deferPublishPieceStateChange(pi)
t.updatePiecePriority(pi, "Torrent.startHash")
t.pieceHashed(index, correct, copyErr)
t.updatePiecePriority(index, "Torrent.finishHash")
t.activePieceHashes--
+ if t.activePieceHashes == 0 {
+ t.deferUpdateComplete()
+ }
t.cl.activePieceHashers--
}
func (t *Torrent) updateComplete() {
// TODO: Announce complete to trackers?
- t.complete.SetBool(t.haveAllPieces())
+ t.complete.SetBool(t.isComplete())
+}
+
+func (t *Torrent) isComplete() bool {
+ if t.activePieceHashes != 0 {
+ return false
+ }
+ if !t.piecesQueuedForHash.IsEmpty() {
+ return false
+ }
+ if !t.haveAllPieces() {
+ return false
+ }
+ return true
}
func (t *Torrent) cancelRequest(r RequestIndex) *PeerConn {