7 pp "github.com/anacrolix/torrent/peer_protocol"
10 type piecePriority byte
13 piecePriorityNone piecePriority = iota
15 piecePriorityReadahead
22 // Chunks we don't have. The offset and length can be determined by our
23 // request chunkSize in use.
24 PendingChunkSpecs []bool
29 Priority piecePriority
32 func (p *piece) pendingChunk(cs chunkSpec) bool {
33 if p.PendingChunkSpecs == nil {
36 return p.PendingChunkSpecs[chunkIndex(cs)]
39 func (p *piece) numPendingChunks() (ret int) {
40 for _, pending := range p.PendingChunkSpecs {
48 func (p *piece) unpendChunkIndex(i int) {
49 if p.PendingChunkSpecs == nil {
52 p.PendingChunkSpecs[i] = false
55 func chunkIndexSpec(index int, pieceLength pp.Integer) chunkSpec {
56 ret := chunkSpec{pp.Integer(index) * chunkSize, chunkSize}
57 if ret.Begin+ret.Length > pieceLength {
58 ret.Length = pieceLength - ret.Begin
63 func (p *piece) shuffledPendingChunkSpecs(pieceLength pp.Integer) (css []chunkSpec) {
64 if p.numPendingChunks() == 0 {
67 css = make([]chunkSpec, 0, p.numPendingChunks())
68 for i, pending := range p.PendingChunkSpecs {
70 css = append(css, chunkIndexSpec(i, pieceLength))
78 css[i], css[j] = css[j], css[i]