discover

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2015 License: GPL-3.0 Imports: 32 Imported by: 0

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

View Source
const Version = 4

Variables

This section is empty.

Functions

This section is empty.

Types

type Node added in v0.9.39

type Node struct {
	IP       net.IP // len 4 for IPv4 or 16 for IPv6
	UDP, TCP uint16 // port numbers
	ID       NodeID // the node's public key
	// contains filtered or unexported fields
}

Node represents a host on the network.

func MustParseNode added in v0.9.39

func MustParseNode(rawurl string) *Node

MustParseNode parses a node URL. It panics if the URL is not valid.

func ParseNode added in v0.9.39

func ParseNode(rawurl string) (*Node, error)

ParseNode parses a node URL.

A node URL has scheme "enode".

The hexadecimal 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) String added in v0.9.39

func (n *Node) String() string

The string representation of a Node is a URL. Please see ParseNode for a description of the format.

type NodeID added in v0.9.39

type NodeID [nodeIDBits / 8]byte

NodeID is a unique identifier for each node. The node identifier is a marshaled elliptic curve public key.

func HexID added in v0.9.39

func HexID(in string) (NodeID, error)

HexID converts a hex string to a NodeID. The string may be prefixed with 0x.

func MustHexID added in v0.9.39

func MustHexID(in string) NodeID

MustHexID converts a hex string to a NodeID. It panics if the string is not a valid NodeID.

func PubkeyID added in v0.9.39

func PubkeyID(pub *ecdsa.PublicKey) NodeID

PubkeyID returns a marshaled representation of the given public key.

func (NodeID) GoString added in v0.9.39

func (n NodeID) GoString() string

The Go syntax representation of a NodeID is a call to HexID.

func (NodeID) Pubkey added in v0.9.39

func (id NodeID) Pubkey() (*ecdsa.PublicKey, error)

Pubkey returns the public key represented by the node ID. It returns an error if the ID is not a point on the curve.

func (NodeID) String added in v0.9.39

func (n NodeID) String() string

NodeID prints as a long hexadecimal number.

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) Bootstrap added in v0.9.39

func (tab *Table) Bootstrap(nodes []*Node)

Bootstrap sets the bootstrap nodes. These nodes are used to connect to the network if the table is empty. Bootstrap will also attempt to fill the table by performing random lookup operations on the network.

func (*Table) Close added in v0.9.39

func (tab *Table) Close()

Close terminates the network listener and flushes the node database.

func (*Table) Lookup added in v0.9.39

func (tab *Table) Lookup(targetID NodeID) []*Node

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

func (tab *Table) ReadRandomNodes(buf []*Node) (n int)

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) Self added in v0.9.39

func (tab *Table) Self() *Node

Self returns the local node. The returned node should not be modified by the caller.

Jump to

Keyboard shortcuts

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