]> Sergey Matveev's repositories - btrtrc.git/blobdiff - piece.go
Change pieceIndex to peer_protocol.Integer
[btrtrc.git] / piece.go
index 5e0c82a80f5c96a0a855ea4960d490d47e6760aa..9729c44c2d71a9a21c2bb5f42c8b14c11295bd3d 100644 (file)
--- a/piece.go
+++ b/piece.go
@@ -42,7 +42,7 @@ type Piece struct {
        // The completed piece SHA1 hash, from the metainfo "pieces" field.
        hash  metainfo.Hash
        t     *Torrent
-       index int
+       index pieceIndex
        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.
@@ -69,7 +69,7 @@ func (p *Piece) String() string {
 }
 
 func (p *Piece) Info() metainfo.Piece {
-       return p.t.info.Piece(p.index)
+       return p.t.info.Piece(int(p.index))
 }
 
 func (p *Piece) Storage() storage.Piece {
@@ -88,8 +88,8 @@ func (p *Piece) hasDirtyChunks() bool {
        return p.dirtyChunks.Len() != 0
 }
 
-func (p *Piece) numDirtyChunks() (ret int) {
-       return p.dirtyChunks.Len()
+func (p *Piece) numDirtyChunks() pp.Integer {
+       return pp.Integer(p.dirtyChunks.Len())
 }
 
 func (p *Piece) unpendChunkIndex(i int) {
@@ -101,13 +101,13 @@ func (p *Piece) pendChunkIndex(i int) {
        p.dirtyChunks.Remove(i)
 }
 
-func (p *Piece) numChunks() int {
+func (p *Piece) numChunks() pp.Integer {
        return p.t.pieceNumChunks(p.index)
 }
 
 func (p *Piece) undirtiedChunkIndices() (ret bitmap.Bitmap) {
        ret = p.dirtyChunks.Copy()
-       ret.FlipRange(0, p.numChunks())
+       ret.FlipRange(0, bitmap.BitIndex(p.numChunks()))
        return
 }
 
@@ -137,11 +137,11 @@ func (p *Piece) waitNoPendingWrites() {
        p.pendingWritesMutex.Unlock()
 }
 
-func (p *Piece) chunkIndexDirty(chunk int) bool {
-       return p.dirtyChunks.Contains(chunk)
+func (p *Piece) chunkIndexDirty(chunk pp.Integer) bool {
+       return p.dirtyChunks.Contains(bitmap.BitIndex(chunk))
 }
 
-func (p *Piece) chunkIndexSpec(chunk int) chunkSpec {
+func (p *Piece) chunkIndexSpec(chunk pp.Integer) chunkSpec {
        return chunkIndexSpec(chunk, p.length(), p.chunkSize())
 }
 
@@ -168,7 +168,7 @@ func (p *Piece) chunkSize() pp.Integer {
        return p.t.chunkSize
 }
 
-func (p *Piece) lastChunkIndex() int {
+func (p *Piece) lastChunkIndex() pp.Integer {
        return p.numChunks() - 1
 }
 
@@ -196,7 +196,7 @@ func (p *Piece) VerifyData() {
 }
 
 func (p *Piece) queuedForHash() bool {
-       return p.t.piecesQueuedForHash.Get(p.index)
+       return p.t.piecesQueuedForHash.Get(bitmap.BitIndex(p.index))
 }
 
 func (p *Piece) torrentBeginOffset() int64 {
@@ -221,13 +221,13 @@ func (p *Piece) uncachedPriority() (ret piecePriority) {
        for _, f := range p.files {
                ret.Raise(f.prio)
        }
-       if p.t.readerNowPieces.Contains(p.index) {
+       if p.t.readerNowPieces.Contains(int(p.index)) {
                ret.Raise(PiecePriorityNow)
        }
        // if t.readerNowPieces.Contains(piece - 1) {
        //      return PiecePriorityNext
        // }
-       if p.t.readerReadaheadPieces.Contains(p.index) {
+       if p.t.readerReadaheadPieces.Contains(bitmap.BitIndex(p.index)) {
                ret.Raise(PiecePriorityReadahead)
        }
        ret.Raise(p.priority)