]> Sergey Matveev's repositories - btrtrc.git/blob - types/types.go
Drop support for go 1.20
[btrtrc.git] / types / types.go
1 package types
2
3 import (
4         pp "github.com/anacrolix/torrent/peer_protocol"
5 )
6
7 type PieceIndex = int
8
9 type ChunkSpec struct {
10         Begin, Length pp.Integer
11 }
12
13 type Request struct {
14         Index pp.Integer
15         ChunkSpec
16 }
17
18 func (r Request) ToMsg(mt pp.MessageType) pp.Message {
19         return pp.Message{
20                 Type:   mt,
21                 Index:  r.Index,
22                 Begin:  r.Begin,
23                 Length: r.Length,
24         }
25 }
26
27 // Describes the importance of obtaining a particular piece.
28 type PiecePriority byte
29
30 func (pp *PiecePriority) Raise(maybe PiecePriority) bool {
31         if maybe > *pp {
32                 *pp = maybe
33                 return true
34         }
35         return false
36 }
37
38 // Priority for use in PriorityBitmap
39 func (me PiecePriority) BitmapPriority() int {
40         return -int(me)
41 }
42
43 const (
44         PiecePriorityNone      PiecePriority = iota // Not wanted. Must be the zero value.
45         PiecePriorityNormal                         // Wanted.
46         PiecePriorityHigh                           // Wanted a lot.
47         PiecePriorityReadahead                      // May be required soon.
48         // Succeeds a piece where a read occurred. Currently the same as Now,
49         // apparently due to issues with caching.
50         PiecePriorityNext
51         PiecePriorityNow // A Reader is reading in this piece. Highest urgency.
52 )