4 "github.com/anacrolix/torrent/metainfo"
5 request_strategy "github.com/anacrolix/torrent/request-strategy"
6 "github.com/anacrolix/torrent/storage"
9 type requestStrategyInput struct {
11 capFunc storage.TorrentCapacity
14 func (r requestStrategyInput) Torrent(ih metainfo.Hash) request_strategy.Torrent {
15 return requestStrategyTorrent{r.cl.torrents[ih]}
18 func (r requestStrategyInput) Capacity() (int64, bool) {
25 func (r requestStrategyInput) MaxUnverifiedBytes() int64 {
26 return r.cl.config.MaxUnverifiedBytes
29 var _ request_strategy.Input = requestStrategyInput{}
31 // Returns what is necessary to run request_strategy.GetRequestablePieces for primaryTorrent.
32 func (cl *Client) getRequestStrategyInput(primaryTorrent *Torrent) (input request_strategy.Input) {
33 return requestStrategyInput{
35 capFunc: primaryTorrent.storage.Capacity,
39 func (t *Torrent) getRequestStrategyInput() request_strategy.Input {
40 return t.cl.getRequestStrategyInput(t)
43 type requestStrategyTorrent struct {
47 func (r requestStrategyTorrent) IgnorePiece(i int) bool {
48 if r.t.ignorePieceForRequests(i) {
51 if r.t.pieceNumPendingChunks(i) == 0 {
58 func (r requestStrategyTorrent) PieceLength() int64 {
59 return r.t.info.PieceLength
62 var _ request_strategy.Torrent = requestStrategyTorrent{}
64 type requestStrategyPiece struct {
69 func (r requestStrategyPiece) Request() bool {
70 return !r.t.ignorePieceForRequests(r.i)
73 func (r requestStrategyPiece) NumPendingChunks() int {
74 return int(r.t.pieceNumPendingChunks(r.i))
77 var _ request_strategy.Piece = requestStrategyPiece{}