]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Track piece marking state separately
authorMatt Joiner <anacrolix@gmail.com>
Sat, 21 Nov 2020 02:40:09 +0000 (13:40 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Sat, 21 Nov 2020 02:44:23 +0000 (13:44 +1100)
piece.go
piecestate.go
torrent.go

index 08fc9bab0dfc93706e48a1389ee819fa8bd094de..c1410d0afcda1b6b96382387ba47f6b43c87041b 100644 (file)
--- a/piece.go
+++ b/piece.go
@@ -50,6 +50,7 @@ type Piece struct {
 
        numVerifies         int64
        hashing             bool
+       marking             bool
        storageCompletionOk bool
 
        publicPieceState PieceState
index 7a2e71642ed82421b31eda01c3a66491bd71371b..089adca44051d1602a2be57eb4d949cc6ea6880b 100644 (file)
@@ -8,8 +8,14 @@ import (
 type PieceState struct {
        Priority piecePriority
        storage.Completion
-       // The piece is being hashed, or is queued for hash.
+       // The piece is being hashed, or is queued for hash. Deprecated: Use those fields instead.
        Checking bool
+
+       Hashing       bool
+       QueuedForHash bool
+       // The piece state is being marked in the storage.
+       Marking bool
+
        // Some of the piece has been obtained.
        Partial bool
 }
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.