]> Sergey Matveev's repositories - btrtrc.git/blobdiff - torrent.go
Track piece marking state separately
[btrtrc.git] / torrent.go
index 9e980abe265bb8c7c13b63d614bdd4a613fe4b03..af8a2b00857030042d7df99000362f192fb34d30 100644 (file)
@@ -500,9 +500,10 @@ func (t *Torrent) pieceState(index pieceIndex) (ret PieceState) {
        p := &t.pieces[index]
        ret.Priority = t.piecePriority(index)
        ret.Completion = p.completion()
-       if p.queuedForHash() || p.hashing {
-               ret.Checking = true
-       }
+       ret.QueuedForHash = p.queuedForHash()
+       ret.Hashing = p.hashing
+       ret.Checking = ret.QueuedForHash || ret.Hashing
+       ret.Marking = p.marking
        if !ret.Complete && t.piecePartiallyDownloaded(index) {
                ret.Partial = true
        }
@@ -562,9 +563,15 @@ func (psr PieceStateRun) String() (ret string) {
                        return ""
                }
        }()
-       if psr.Checking {
+       if psr.Hashing {
                ret += "H"
        }
+       if psr.QueuedForHash {
+               ret += "Q"
+       }
+       if psr.Marking {
+               ret += "M"
+       }
        if psr.Partial {
                ret += "P"
        }
@@ -1739,6 +1746,13 @@ func (t *Torrent) pieceHashed(piece pieceIndex, passed bool, hashIoErr error) {
                }
        }
 
+       p.marking = true
+       t.publishPieceChange(piece)
+       defer func() {
+               p.marking = false
+               t.publishPieceChange(piece)
+       }()
+
        if passed {
                if len(p.dirtiers) != 0 {
                        // Don't increment stats above connection-level for every involved connection.