Documentation ¶
Index ¶
- Constants
- func ListenUDP(priv *ecdsa.PrivateKey, nodeType NodeType, laddr string, natm nat.Interface, ...) (*Table, *EndPoint, error)
- type EndPoint
- type ExtData
- type Node
- type NodeID
- type NodeReq
- type NodeRes
- type NodeType
- type RpcNode
- type Table
- func (tab *Table) AddNode(node *Node)
- func (tab *Table) Bondall(nodes []*Node) int
- func (tab *Table) Close()
- func (tab *Table) FindNodes() (buf []*Node)
- func (tab *Table) HasNode(nid NodeID) bool
- func (tab *Table) RemoveNode(nid NodeID)
- func (tab *Table) Self() *Node
- func (tab *Table) SetFallbackNodes(nodes []*Node) error
Constants ¶
const NodeIDBits = 512
const Version = 0x01
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Node ¶
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 TYPE NodeType Ext ExtData // 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
hnode://<hex node id>&<int8 node role> <hex node id>&<int8 node role>
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.
hnode://<hex node id>&<int8 node role>@10.3.58.6:30303?discport=30301
func (*Node) Incomplete ¶
Incomplete returns true for nodes with no IP address.
func (*Node) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Node) String ¶
The string representation of a Node is a URL. Please see ParseNode for a description of the format.
func (*Node) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
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 MustBytesID ¶
MustBytesID converts a byte slice to a NodeID. It panics if the byte slice is not a valid NodeID.
func MustHexID ¶
MustHexID converts a hex string to a NodeID. It panics if the string is not a valid NodeID.
func (NodeID) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (NodeID) Pubkey ¶
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) TerminalString ¶
TerminalString returns a shortened hex string for terminal logging.
func (*NodeID) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type RpcNode ¶
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
func (*Table) Close ¶
func (tab *Table) Close()
Close terminates the network listener and flushes the node database.
func (*Table) RemoveNode ¶
func (*Table) Self ¶
Self returns the local node. The returned node should not be modified by the caller.