krpc

package
v0.0.0-...-57e5bf5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2016 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const CompactIPv4NodeInfoLen = 26

The size in bytes of a NodeInfo in its compact binary representation.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompactIPv4NodeInfo

type CompactIPv4NodeInfo []NodeInfo

func (CompactIPv4NodeInfo) MarshalBencode

func (i CompactIPv4NodeInfo) MarshalBencode() (ret []byte, err error)

func (*CompactIPv4NodeInfo) UnmarshalBencode

func (i *CompactIPv4NodeInfo) UnmarshalBencode(_b []byte) (err error)

type KRPCError

type KRPCError struct {
	Code int
	Msg  string
}

Represented as a string or list in bencode.

func (KRPCError) Error

func (e KRPCError) Error() string

func (KRPCError) MarshalBencode

func (e KRPCError) MarshalBencode() (ret []byte, err error)

func (*KRPCError) UnmarshalBencode

func (e *KRPCError) UnmarshalBencode(_b []byte) (err error)

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  *KRPCError       `bencode:"e,omitempty"` // ERROR type only
	IP util.CompactPeer `bencode:"ip,omitempty"`
}

Msg represents messages that nodes in the network send to each other as specified by the protocol. They are also refered 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

func (Msg) Error

func (m Msg) Error() *KRPCError

func (Msg) SenderID

func (m Msg) SenderID() string

The node ID of the source of this Msg.

func (Msg) String

func (m Msg) String() string

type MsgArgs

type MsgArgs struct {
	ID       string `bencode:"id"`        // ID of the quirying Node
	InfoHash string `bencode:"info_hash"` // InfoHash of the torrent
	Target   string `bencode:"target"`    // ID of the node sought
}

type NodeInfo

type NodeInfo struct {
	ID   [20]byte
	Addr *net.UDPAddr
}

func (*NodeInfo) PutCompact

func (ni *NodeInfo) PutCompact(b []byte) error

Writes the node info to its compact binary representation in b. See CompactNodeInfoLen.

func (*NodeInfo) UnmarshalCompactIPv4

func (ni *NodeInfo) UnmarshalCompactIPv4(b []byte) error

type Return

type Return struct {
	ID     string              `bencode:"id"` // ID of the querying node
	Nodes  CompactIPv4NodeInfo `bencode:"nodes,omitempty"`
	Token  string              `bencode:"token,omitempty"`
	Values []util.CompactPeer  `bencode:"values,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL