github.com/anacrolix/torrent@v1.61.0/client-piece-request-order.go (about)

     1  package torrent
     2  
     3  import (
     4  	requestStrategy "github.com/anacrolix/torrent/internal/request-strategy"
     5  	"github.com/anacrolix/torrent/storage"
     6  )
     7  
     8  // clientPieceRequestOrderKey is a key for the piece request order map in the Client.
     9  type clientPieceRequestOrderKeyTypes interface {
    10  	storage.TorrentCapacity | *Torrent
    11  }
    12  
    13  // clientPieceRequestOrderKey is a generic key type for the piece request order map.
    14  type clientPieceRequestOrderKey[T clientPieceRequestOrderKeyTypes] struct {
    15  	inner T
    16  }
    17  
    18  // clientPieceRequestOrderRegularTorrentKey is a concrete key type for regular torrents.
    19  type clientPieceRequestOrderRegularTorrentKey clientPieceRequestOrderKey[*Torrent]
    20  
    21  func (c clientPieceRequestOrderRegularTorrentKey) getRequestStrategyInput(cl *Client) requestStrategy.Input {
    22  	return requestStrategyInputSingleTorrent{
    23  		requestStrategyInputCommon: cl.getRequestStrategyInputCommon(),
    24  		t:                          c.inner,
    25  	}
    26  }
    27  
    28  // clientPieceRequestOrderSharedStorageTorrentKey is a concrete key type for shared storage torrents.
    29  type clientPieceRequestOrderSharedStorageTorrentKey clientPieceRequestOrderKey[storage.TorrentCapacity]
    30  
    31  func (c clientPieceRequestOrderSharedStorageTorrentKey) getRequestStrategyInput(cl *Client) requestStrategy.Input {
    32  	return requestStrategyInputMultiTorrent{
    33  		requestStrategyInputCommon: cl.getRequestStrategyInputCommon(),
    34  		torrents:                   cl.torrentsByShortHash,
    35  		capFunc:                    c.inner,
    36  	}
    37  }
    38  
    39  type clientPieceRequestOrderKeySumType interface {
    40  	// getRequestStrategyInput returns the request strategy input for the torrent. It depends on the
    41  	// storage capacity arrangements which is the defining differentiator for the client piece
    42  	// request order keys. This code reads like that stupid second-year software design course I
    43  	// failed 3 times.
    44  	getRequestStrategyInput(cl *Client) requestStrategy.Input
    45  }
    46  
    47  type clientPieceRequestOrderValue struct {
    48  	// TODO: Check if we actually ended up needing this?
    49  	torrents map[*Torrent]struct{}
    50  	pieces   *requestStrategy.PieceRequestOrder
    51  }