Documentation ¶
Overview ¶
Package discover implements the Node Discovery Protocol.
The Node Discovery protocol provides a way to find RLPx nodes that can be connected to. It uses a Kademlia-like protocol to maintain a distributed database of the IDs and endpoints of all listening nodes.
Index ¶
Constants ¶
const Version = 45
Variables ¶
var ( // Note: golang/net.IP provides some similar functionality via #IsLinkLocalUnicast, ...Multicast, etc. // I would rather duplicate the information in a unified and comprehensive system than // patch-in with a couple available library methods. // I expect many of these occasions will be very unlikely. // // IPv4 Ipv4ReservedRangeThis = [2]net.IP{net.ParseIP("0.0.0.0"), net.ParseIP("0.255.255.255")} Ipv4ReservedRangePrivateNetwork = [2]net.IP{net.ParseIP("10.0.0.0"), net.ParseIP("10.255.255.255")} Ipv4ReservedRangeLoopback = [2]net.IP{net.ParseIP("127.0.0.0"), net.ParseIP("127.255.255.255")} Ipv4ReservedRangeLocalPrivate2 = [2]net.IP{net.ParseIP("192.168.0.0"), net.ParseIP("192.168.255.255")} Ipv6ReservedRangeLoopback = [2]net.IP{net.ParseIP("::1"), net.ParseIP("::1")} )
Errors
Functions ¶
Types ¶
type Node ¶
type Node struct { IP net.IP `json:"ip"` // len 4 for IPv4 or 16 for IPv6 // port numbers UDP uint16 `json:"udp"` TCP uint16 `json:"tcp"` ID NodeID `json:"node_id"` // the node's public key // contains filtered or unexported fields }
Node represents a host on the network. The fields of Node may not be modified.
func MustParseNode ¶
MustParseNode parses a node URL. It panics if the URL is not valid.
func ParseNode ¶
ParseNode parses a node designator.
There are two basic forms of node designators
- incomplete nodes, which only have the public key (node ID)
- complete nodes, which contain the public key and IP/Port information
For incomplete nodes, the designator must look like one of these
enode://<hex node id> <hex node id>
For complete nodes, the node ID is encoded in the username portion of the URL, separated from the host by an @ sign. The hostname can only be given as an IP address, DNS domain names are not allowed. The port in the host name section is the TCP listening port. If the TCP and UDP (discovery) ports differ, the UDP port is specified as query parameter "discport".
In the following example, the node URL describes a node with IP address 10.3.58.6, TCP listening port 30303 and UDP discovery port 30301.
enode://<hex node id>@10.3.58.6:30303?discport=30301
func (*Node) Incomplete ¶
Incomplete returns true for nodes with no IP address.
type NodeID ¶
type NodeID [nodeIDBits / 8]byte
NodeID is a unique identifier for each node. The node identifier is a marshaled elliptic curve public key.
func MustHexID ¶
MustHexID converts a hex string to a NodeID. It panics if the string is not a valid NodeID.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
func ListenUDP ¶
func ListenUDP(priv *ecdsa.PrivateKey, laddr string, natm nat.Interface, nodeDBPath string) (*Table, error)
ListenUDP returns a new table that listens for UDP packets on laddr.
func (*Table) Close ¶
func (tab *Table) Close()
Close terminates the network listener and flushes the node database.
func (*Table) Lookup ¶
Lookup performs a network search for nodes close to the given target. It approaches the target by querying nodes that are closer to it on each iteration. The given target does not need to be an actual node identifier.
func (*Table) ReadRandomNodes ¶
ReadRandomNodes fills the given slice with random nodes from the table. It will not write the same node more than once. The nodes in the slice are copies and can be modified by the caller.
func (*Table) Resolve ¶
Resolve searches for a specific node with the given ID. It returns nil if the node could not be found.
func (*Table) Self ¶
Self returns the local node. The returned node should not be modified by the caller.
func (*Table) SetFallbackNodes ¶
SetFallbackNodes sets the initial points of contact. These nodes are used to connect to the network if the table is empty and there are no known nodes in the database.