9 pp "github.com/anacrolix/torrent/peer_protocol"
13 pieceHash = crypto.SHA1
14 maxRequests = 250 // Maximum pending requests we allow peers to send us.
15 chunkSize = 0x4000 // 16KiB
16 bep20 = "-GT0000-" // Peer ID client identifier prefix
17 nominalDialTimeout = time.Second * 30
18 minDialTimeout = 5 * time.Second
26 func (ih *InfoHash) AsString() string {
30 func (ih *InfoHash) HexString() string {
31 return fmt.Sprintf("%x", ih[:])
34 func lastChunkSpec(pieceLength pp.Integer) (cs chunkSpec) {
35 cs.Begin = (pieceLength - 1) / chunkSize * chunkSize
36 cs.Length = pieceLength - cs.Begin
40 type chunkSpec struct {
41 Begin, Length pp.Integer
49 func newRequest(index, begin, length pp.Integer) request {
50 return request{index, chunkSpec{begin, length}}
54 // Requested data not yet available.
55 errDataNotReady = errors.New("data not ready")
58 // The size in bytes of a metadata extension piece.
59 func metadataPieceSize(totalSize int, piece int) int {
60 ret := totalSize - piece*(1<<14)
67 type superer interface {
71 // Returns ok if there's a parent, and it's not nil.
72 func super(child interface{}) (parent interface{}, ok bool) {
73 s, ok := child.(superer)