// 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.
}
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 {
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) {
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
}
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())
}
return p.t.chunkSize
}
-func (p *Piece) lastChunkIndex() int {
+func (p *Piece) lastChunkIndex() pp.Integer {
return p.numChunks() - 1
}
}
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 {
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)