]> Sergey Matveev's repositories - btrtrc.git/blob - request-strategy/peer.go
4a3d0689a4371bce9045b3ecdffd78aa97872f28
[btrtrc.git] / request-strategy / peer.go
1 package request_strategy
2
3 import (
4         "time"
5         "unsafe"
6 )
7
8 type PeerNextRequestState struct {
9         Interested bool
10         Requests   map[Request]struct{}
11 }
12
13 type PeerPointer = unsafe.Pointer
14
15 type Peer struct {
16         HasPiece           func(pieceIndex) bool
17         MaxRequests        func() int
18         HasExistingRequest func(Request) bool
19         Choking            bool
20         PieceAllowedFast   func(pieceIndex) bool
21         DownloadRate       float64
22         Age                time.Duration
23         Id                 PeerPointer
24 }
25
26 // TODO: This might be used in more places I think.
27 func (p *Peer) canRequestPiece(i pieceIndex) bool {
28         return p.HasPiece(i) && (!p.Choking || p.PieceAllowedFast(i))
29 }