Include completion known in PieceState

This commit is contained in:
Matt Joiner 2018-01-28 15:58:55 +11:00
parent de928be582
commit 906d3bc5bb
3 changed files with 17 additions and 4 deletions

View File

@ -229,3 +229,9 @@ func (p *Piece) uncachedPriority() (ret piecePriority) {
ret.Raise(p.priority)
return
}
func (p *Piece) completion() (ret storage.Completion) {
ret.Complete = p.t.pieceComplete(p.index)
ret.Ok = p.storageCompletionOk
return
}

View File

@ -1,10 +1,14 @@
package torrent
import (
"github.com/anacrolix/torrent/storage"
)
// The current state of a piece.
type PieceState struct {
Priority piecePriority
// The piece is available in its entirety.
Complete bool
storage.Completion
// The piece is being hashed, or is queued for hash.
Checking bool
// Some of the piece has been obtained.

View File

@ -449,9 +449,7 @@ func (t *Torrent) name() string {
func (t *Torrent) pieceState(index int) (ret PieceState) {
p := &t.pieces[index]
ret.Priority = t.piecePriority(index)
if t.pieceComplete(index) {
ret.Complete = true
}
ret.Completion = p.completion()
if p.queuedForHash() || p.hashing {
ret.Checking = true
}
@ -511,6 +509,8 @@ func pieceStateRunStatusChars(psr PieceStateRun) (ret string) {
return "R"
case PiecePriorityNow:
return "!"
case PiecePriorityHigh:
return "H"
default:
return ""
}
@ -524,6 +524,9 @@ func pieceStateRunStatusChars(psr PieceStateRun) (ret string) {
if psr.Complete {
ret += "C"
}
if !psr.Ok {
ret += "?"
}
return
}