]> Sergey Matveev's repositories - btrtrc.git/blobdiff - piece.go
Add File priorities
[btrtrc.git] / piece.go
index 71c6041787289e217d4db4a39057dc3a7a85adfb..c5d7f134677932533a82a9d16369137d72e65f11 100644 (file)
--- a/piece.go
+++ b/piece.go
@@ -27,7 +27,7 @@ func (me piecePriority) BitmapPriority() int {
 }
 
 const (
-       PiecePriorityNone      piecePriority = iota // Not wanted.
+       PiecePriorityNone      piecePriority = iota // Not wanted. Must be the zero value.
        PiecePriorityNormal                         // Wanted.
        PiecePriorityHigh                           // Wanted a lot.
        PiecePriorityReadahead                      // May be required soon.
@@ -42,6 +42,7 @@ type Piece struct {
        hash  metainfo.Hash
        t     *Torrent
        index int
+       files []*File
        // Chunks we've written to since the last check. The chunk offset and
        // length can be determined by the request chunkSize in use.
        dirtyChunks bitmap.Bitmap
@@ -192,3 +193,11 @@ func (p *Piece) VerifyData() {
 func (p *Piece) queuedForHash() bool {
        return p.t.piecesQueuedForHash.Get(p.index)
 }
+
+func (p *Piece) torrentBeginOffset() int64 {
+       return int64(p.index) * p.t.info.PieceLength
+}
+
+func (p *Piece) torrentEndOffset() int64 {
+       return p.torrentBeginOffset() + int64(p.length())
+}