Documentation ¶
Index ¶
- Constants
- Variables
- type CompactIPv4NodeAddrs
- func (CompactIPv4NodeAddrs) ElemSize() int
- func (me CompactIPv4NodeAddrs) MarshalBencode() ([]byte, error)
- func (me CompactIPv4NodeAddrs) MarshalBinary() ([]byte, error)
- func (me CompactIPv4NodeAddrs) NodeAddrs() []NodeAddr
- func (me *CompactIPv4NodeAddrs) UnmarshalBencode(b []byte) error
- func (me *CompactIPv4NodeAddrs) UnmarshalBinary(b []byte) error
- type CompactIPv4NodeInfo
- type CompactIPv6NodeAddrs
- func (CompactIPv6NodeAddrs) ElemSize() int
- func (me CompactIPv6NodeAddrs) MarshalBencode() ([]byte, error)
- func (me CompactIPv6NodeAddrs) MarshalBinary() ([]byte, error)
- func (me CompactIPv6NodeAddrs) NodeAddrs() []NodeAddr
- func (me *CompactIPv6NodeAddrs) UnmarshalBencode(b []byte) error
- func (me *CompactIPv6NodeAddrs) UnmarshalBinary(b []byte) error
- type CompactIPv6NodeInfo
- type Error
- type ID
- type Msg
- type MsgArgs
- type NodeAddr
- func (me *NodeAddr) FromUDPAddr(ua *net.UDPAddr)
- func (me NodeAddr) MarshalBencode() ([]byte, error)
- func (me NodeAddr) MarshalBinary() ([]byte, error)
- func (me NodeAddr) String() string
- func (me NodeAddr) UDP() *net.UDPAddr
- func (me *NodeAddr) UnmarshalBencode(b []byte) (err error)
- func (me *NodeAddr) UnmarshalBinary(b []byte) error
- type NodeInfo
- type Return
- type Want
Constants ¶
const ( ErrorCodeGenericError = 201 ErrorCodeServerError = 202 ErrorCodeProtocolError = 203 ErrorCodeMethodUnknown = 204 )
These are documented in BEP 5.
Variables ¶
var ErrorMethodUnknown = Error{ Code: ErrorCodeMethodUnknown, Msg: "Method Unknown", }
Functions ¶
This section is empty.
Types ¶
type CompactIPv4NodeAddrs ¶
type CompactIPv4NodeAddrs []NodeAddr
func (CompactIPv4NodeAddrs) ElemSize ¶
func (CompactIPv4NodeAddrs) ElemSize() int
func (CompactIPv4NodeAddrs) MarshalBencode ¶
func (me CompactIPv4NodeAddrs) MarshalBencode() ([]byte, error)
func (CompactIPv4NodeAddrs) MarshalBinary ¶
func (me CompactIPv4NodeAddrs) MarshalBinary() ([]byte, error)
func (CompactIPv4NodeAddrs) NodeAddrs ¶
func (me CompactIPv4NodeAddrs) NodeAddrs() []NodeAddr
func (*CompactIPv4NodeAddrs) UnmarshalBencode ¶
func (me *CompactIPv4NodeAddrs) UnmarshalBencode(b []byte) error
func (*CompactIPv4NodeAddrs) UnmarshalBinary ¶
func (me *CompactIPv4NodeAddrs) UnmarshalBinary(b []byte) error
type CompactIPv4NodeInfo ¶
type CompactIPv4NodeInfo []NodeInfo
func (CompactIPv4NodeInfo) ElemSize ¶
func (CompactIPv4NodeInfo) ElemSize() int
func (CompactIPv4NodeInfo) MarshalBencode ¶
func (me CompactIPv4NodeInfo) MarshalBencode() ([]byte, error)
func (CompactIPv4NodeInfo) MarshalBinary ¶
func (me CompactIPv4NodeInfo) MarshalBinary() ([]byte, error)
func (*CompactIPv4NodeInfo) UnmarshalBencode ¶
func (me *CompactIPv4NodeInfo) UnmarshalBencode(b []byte) error
func (*CompactIPv4NodeInfo) UnmarshalBinary ¶
func (me *CompactIPv4NodeInfo) UnmarshalBinary(b []byte) error
type CompactIPv6NodeAddrs ¶
type CompactIPv6NodeAddrs []NodeAddr
func (CompactIPv6NodeAddrs) ElemSize ¶
func (CompactIPv6NodeAddrs) ElemSize() int
func (CompactIPv6NodeAddrs) MarshalBencode ¶
func (me CompactIPv6NodeAddrs) MarshalBencode() ([]byte, error)
func (CompactIPv6NodeAddrs) MarshalBinary ¶
func (me CompactIPv6NodeAddrs) MarshalBinary() ([]byte, error)
func (CompactIPv6NodeAddrs) NodeAddrs ¶
func (me CompactIPv6NodeAddrs) NodeAddrs() []NodeAddr
func (*CompactIPv6NodeAddrs) UnmarshalBencode ¶
func (me *CompactIPv6NodeAddrs) UnmarshalBencode(b []byte) error
func (*CompactIPv6NodeAddrs) UnmarshalBinary ¶
func (me *CompactIPv6NodeAddrs) UnmarshalBinary(b []byte) error
type CompactIPv6NodeInfo ¶
type CompactIPv6NodeInfo []NodeInfo
func (CompactIPv6NodeInfo) ElemSize ¶
func (CompactIPv6NodeInfo) ElemSize() int
func (CompactIPv6NodeInfo) MarshalBencode ¶
func (me CompactIPv6NodeInfo) MarshalBencode() ([]byte, error)
func (CompactIPv6NodeInfo) MarshalBinary ¶
func (me CompactIPv6NodeInfo) MarshalBinary() ([]byte, error)
func (*CompactIPv6NodeInfo) UnmarshalBencode ¶
func (me *CompactIPv6NodeInfo) UnmarshalBencode(b []byte) error
func (*CompactIPv6NodeInfo) UnmarshalBinary ¶
func (me *CompactIPv6NodeInfo) UnmarshalBinary(b []byte) error
type Error ¶
Represented as a string or list in bencode.
func (Error) MarshalBencode ¶
func (*Error) UnmarshalBencode ¶
type ID ¶
type ID [20]byte
func IdFromString ¶
func (*ID) MarshalBencode ¶
func (*ID) UnmarshalBencode ¶
type Msg ¶
type Msg struct { Q string `bencode:"q,omitempty"` // Query method (one of 4: "ping", "find_node", "get_peers", "announce_peer") A *MsgArgs `bencode:"a,omitempty"` // named arguments sent with a query T string `bencode:"t"` // required: transaction ID Y string `bencode:"y"` // required: type of the message: q for QUERY, r for RESPONSE, e for ERROR R *Return `bencode:"r,omitempty"` // RESPONSE type only E *Error `bencode:"e,omitempty"` // ERROR type only IP NodeAddr `bencode:"ip,omitempty"` ReadOnly bool `bencode:"ro,omitempty"` }
Msg represents messages that nodes in the network send to each other as specified by the protocol. They are also referred to as the KRPC messages. There are three types of messages: QUERY, RESPONSE, ERROR The message is a dictonary that is then "bencoded" (serialization & compression format adopted by the BitTorrent) and sent via the UDP connection to peers.
A KRPC message is a single dictionary with two keys common to every message and additional keys depending on the type of message. Every message has a key "t" with a string value representing a transaction ID. This transaction ID is generated by the querying node and is echoed in the response, so responses may be correlated with multiple queries to the same node. The transaction ID should be encoded as a short string of binary numbers, typically 2 characters are enough as they cover 2^16 outstanding queries. The other key contained in every KRPC message is "y" with a single character value describing the type of message. The value of the "y" key is one of "q" for query, "r" for response, or "e" for error. 3 message types: QUERY, RESPONSE, ERROR
type MsgArgs ¶
type MsgArgs struct { ID ID `bencode:"id"` // ID of the querying Node InfoHash ID `bencode:"info_hash,omitempty"` // InfoHash of the torrent Target ID `bencode:"target,omitempty"` // ID of the node sought Token string `bencode:"token,omitempty"` // Token received from an earlier get_peers query Port *int `bencode:"port,omitempty"` // Sender's torrent port ImpliedPort bool `bencode:"implied_port,omitempty"` // Use senders apparent DHT port Want []Want `bencode:"want,omitempty"` // Contains strings like "n4" and "n6" from BEP 32. NoSeed int `bencode:"noseed,omitempty"` // BEP 33 Scrape int `bencode:"scrape,omitempty"` // BEP 33 }
type NodeAddr ¶
func (*NodeAddr) FromUDPAddr ¶
func (NodeAddr) MarshalBencode ¶
func (NodeAddr) MarshalBinary ¶
func (*NodeAddr) UnmarshalBencode ¶
func (*NodeAddr) UnmarshalBinary ¶
type NodeInfo ¶
func RandomNodeInfo ¶
func (NodeInfo) MarshalBinary ¶
func (*NodeInfo) UnmarshalBinary ¶
type Return ¶
type Return struct { ID ID `bencode:"id"` // ID of the queried node Nodes CompactIPv4NodeInfo `bencode:"nodes,omitempty"` // K closest nodes to the requested target Nodes6 CompactIPv6NodeInfo `bencode:"nodes6,omitempty"` // K closest nodes to the requested target Token *string `bencode:"token,omitempty"` // Token for future announce_peer Values []NodeAddr `bencode:"values,omitempty"` // Torrent peers }