-func (cl *Client) getRequestStrategyInput() request_strategy.Input {
- ts := make([]request_strategy.Torrent, 0, len(cl.torrents))
- for _, t := range cl.torrents {
- if !t.haveInfo() {
- // This would be removed if metadata is handled here. We have to guard against not
- // knowing the piece size. If we have no info, we have no pieces too, so the end result
- // is the same.
- continue
- }
- rst := request_strategy.Torrent{
- InfoHash: t.infoHash,
- ChunksPerPiece: t.chunksPerRegularPiece(),
- }
- if t.storage != nil {
- rst.Capacity = t.storage.Capacity
- }
- rst.Pieces = make([]request_strategy.Piece, 0, len(t.pieces))
- for i := range t.pieces {
- p := &t.pieces[i]
- rst.Pieces = append(rst.Pieces, request_strategy.Piece{
- Request: !t.ignorePieceForRequests(i),
- Priority: p.purePriority(),
- Partial: t.piecePartiallyDownloaded(i),
- Availability: p.availability,
- Length: int64(p.length()),
- NumPendingChunks: int(t.pieceNumPendingChunks(i)),
- IterPendingChunks: p.undirtiedChunksIter(),
- })
- }
- t.iterPeers(func(p *Peer) {
- if p.closed.IsSet() {
- return
- }
- if p.piecesReceivedSinceLastRequestUpdate > p.maxPiecesReceivedBetweenRequestUpdates {
- p.maxPiecesReceivedBetweenRequestUpdates = p.piecesReceivedSinceLastRequestUpdate
- }
- p.piecesReceivedSinceLastRequestUpdate = 0
- rst.Peers = append(rst.Peers, request_strategy.Peer{
- Pieces: *p.newPeerPieces(),
- MaxRequests: p.nominalMaxRequests(),
- ExistingRequests: p.actualRequestState.Requests,
- Choking: p.peerChoking,
- PieceAllowedFast: p.peerAllowedFast,
- DownloadRate: p.downloadRate(),
- Age: time.Since(p.completedHandshake),
- Id: peerId{
- Peer: p,
- ptr: uintptr(unsafe.Pointer(p)),
- },
- })
- })
- ts = append(ts, rst)
- }
- return request_strategy.Input{
- Torrents: ts,
- MaxUnverifiedBytes: cl.config.MaxUnverifiedBytes,