11 "github.com/anacrolix/torrent/peer_protocol"
15 pieceHash = crypto.SHA1
16 maxRequests = 250 // Maximum pending requests we allow peers to send us.
17 chunkSize = 0x4000 // 16KiB
18 bep20 = "-GT0000-" // Peer ID client identifier prefix
19 nominalDialTimeout = time.Second * 30
20 minDialTimeout = 5 * time.Second
28 func (ih *InfoHash) AsString() string {
32 func (ih *InfoHash) HexString() string {
33 return fmt.Sprintf("%x", ih[:])
36 type piecePriority byte
39 piecePriorityNone piecePriority = iota
41 piecePriorityReadahead
48 PendingChunkSpecs map[chunkSpec]struct{}
53 Priority piecePriority
56 func (p *piece) shuffledPendingChunkSpecs() (css []chunkSpec) {
57 if len(p.PendingChunkSpecs) == 0 {
60 css = make([]chunkSpec, 0, len(p.PendingChunkSpecs))
61 for cs := range p.PendingChunkSpecs {
69 css[i], css[j] = css[j], css[i]
74 func lastChunkSpec(pieceLength peer_protocol.Integer) (cs chunkSpec) {
75 cs.Begin = (pieceLength - 1) / chunkSize * chunkSize
76 cs.Length = pieceLength - cs.Begin
80 type chunkSpec struct {
81 Begin, Length peer_protocol.Integer
85 Index peer_protocol.Integer
89 func newRequest(index, begin, length peer_protocol.Integer) request {
90 return request{index, chunkSpec{begin, length}}
94 // Requested data not yet available.
95 errDataNotReady = errors.New("data not ready")
98 // The size in bytes of a metadata extension piece.
99 func metadataPieceSize(totalSize int, piece int) int {
100 ret := totalSize - piece*(1<<14)
107 type superer interface {
111 // Returns ok if there's a parent, and it's not nil.
112 func super(child interface{}) (parent interface{}, ok bool) {
113 s, ok := child.(superer)