12 ActionConnect Action = iota
18 const ConnectRequestConnectionId = 0x41727101980
22 optionTypeEndOfOptions = 0
27 type TransactionId = int32
29 type ConnectionId = uint64
31 type ConnectionRequest struct {
32 ConnectionId ConnectionId
34 TransactionId TransactionId
37 type ConnectionResponse struct {
38 ConnectionId ConnectionId
41 type ResponseHeader struct {
43 TransactionId TransactionId
46 type RequestHeader struct {
47 ConnectionId ConnectionId
49 TransactionId TransactionId
52 type AnnounceResponseHeader struct {
58 type InfoHash = [20]byte
60 func marshal(data interface{}) (b []byte, err error) {
62 err = Write(&buf, data)
67 func mustMarshal(data interface{}) []byte {
68 b, err := marshal(data)
75 // This is for fixed-size, builtin types only I think.
76 func Write(w io.Writer, data interface{}) error {
77 return binary.Write(w, binary.BigEndian, data)
80 func Read(r io.Reader, data interface{}) error {
81 return binary.Read(r, binary.BigEndian, data)