Documentation ¶
Index ¶
- Constants
- Variables
- func DistCmp(target, a, b ID) int
- func IsBootNode(nodeType NodeTypeOption) bool
- func IsConnectableNode(nodeType NodeTypeOption) bool
- func IsFullNode(nodeType NodeTypeOption) bool
- func IsLightNode(nodeType NodeTypeOption) bool
- func IsLightServer(nodeType NodeTypeOption) bool
- func IsStorageNode(nodeType NodeTypeOption) bool
- func LogDist(a, b ID) int
- func SignV4(r *enr.Record, privkey *ecdsa.PrivateKey) error
- type DB
- func (db *DB) Close()
- func (db *DB) DeleteNode(id ID)
- func (db *DB) FindFails(id ID, ip net.IP) int
- func (db *DB) GetNodeLatency(id ID, ip net.IP) int64
- func (db *DB) LastPingReceived(id ID, ip net.IP) time.Time
- func (db *DB) LastPongReceived(id ID, ip net.IP) time.Time
- func (db *DB) Node(id ID) *Node
- func (db *DB) NodeSeq(id ID) uint64
- func (db *DB) QuerySeeds(n int, maxAge time.Duration) []*Node
- func (db *DB) Resolve(n *Node) *Node
- func (db *DB) UpdateFindFails(id ID, ip net.IP, fails int) error
- func (db *DB) UpdateLastPingReceived(id ID, ip net.IP, instance time.Time) error
- func (db *DB) UpdateLastPongReceived(id ID, ip net.IP, instance time.Time) error
- func (db *DB) UpdateNode(node *Node) error
- func (db *DB) UpdateNodeLatency(id ID, ip net.IP, instance int64) error
- type ID
- type LocalNode
- func (ln *LocalNode) Database() *DB
- func (ln *LocalNode) Delete(e enr.Entry)
- func (ln *LocalNode) ID() ID
- func (ln *LocalNode) Node() *Node
- func (ln *LocalNode) NodeType() uint8
- func (ln *LocalNode) Set(e enr.Entry)
- func (ln *LocalNode) SetFallbackIP(ip net.IP)
- func (ln *LocalNode) SetFallbackUDP(port int)
- func (ln *LocalNode) SetStaticIP(ip net.IP)
- func (ln *LocalNode) UDPContact(toaddr *net.UDPAddr)
- func (ln *LocalNode) UDPEndpointStatement(fromaddr, endpoint *net.UDPAddr)
- type Node
- func (n *Node) ID() ID
- func (n *Node) IP() net.IP
- func (n *Node) Incomplete() bool
- func (n *Node) LIP() net.IP
- func (n *Node) LUDP() uint16
- func (n *Node) Load(k enr.Entry) error
- func (n *Node) MarshalText() ([]byte, error)
- func (n *Node) NodeType() enr.NodeType
- func (n *Node) Pubkey() *ecdsa.PublicKey
- func (n *Node) Record() *enr.Record
- func (n *Node) Seq() uint64
- func (n *Node) Set(val enr.Entry)
- func (n *Node) SetNodeType(nodeType enr.NodeType)
- func (n *Node) String() string
- func (n *Node) TCP() int
- func (n *Node) UDP() int
- func (n *Node) UnmarshalText(text []byte) error
- func (n *Node) ValidateComplete() error
- type NodeTypeOption
- type NullID
- type RetrievalOption
- type Secp256k1
- type SyncingOption
- type V4ID
Constants ¶
const ( NodeTypeFull NodeTypeOption = 0x24 //NodeTypeLight = 0x11 NodeTypeLightServer = 0x21 NodeTypeStorage = 0x22 NodeTypeBoot = 0x09 )
Variables ¶
var ValidSchemes = enr.SchemeMap{ "v4": V4ID{}, }
List of known secure identity schemes.
var ValidSchemesForTesting = enr.SchemeMap{ "v4": V4ID{}, "null": NullID{}, }
Functions ¶
func DistCmp ¶
DistCmp compares the distances a->target and b->target. Returns -1 if a is closer to target, 1 if b is closer to target and 0 if they are equal.
func IsBootNode ¶
func IsBootNode(nodeType NodeTypeOption) bool
func IsConnectableNode ¶
func IsConnectableNode(nodeType NodeTypeOption) bool
func IsFullNode ¶
func IsFullNode(nodeType NodeTypeOption) bool
func IsLightNode ¶
func IsLightNode(nodeType NodeTypeOption) bool
func IsLightServer ¶
func IsLightServer(nodeType NodeTypeOption) bool
func IsStorageNode ¶
func IsStorageNode(nodeType NodeTypeOption) bool
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is the node database, storing previously seen nodes and any collected metadata about them for QoS purposes.
func OpenDB ¶
OpenDB opens a node database for storing and retrieving infos about known peers in the network. If no path is given an in-memory, temporary database is constructed.
func (*DB) DeleteNode ¶
DeleteNode deletes all information associated with a node.
func (*DB) GetNodeLatency ¶
UpdateLastPongReceived updates the last pong time of a node.
func (*DB) LastPingReceived ¶
LastPingReceived retrieves the time of the last ping packet received from a remote node.
func (*DB) LastPongReceived ¶
LastPongReceived retrieves the time of the last successful pong from remote node.
func (*DB) QuerySeeds ¶
QuerySeeds retrieves random nodes to be used as potential seed nodes for bootstrapping.
func (*DB) Resolve ¶
Resolve returns the stored record of the node if it has a larger sequence number than n.
func (*DB) UpdateFindFails ¶
UpdateFindFails updates the number of findnode failures since bonding.
func (*DB) UpdateLastPingReceived ¶
UpdateLastPingReceived updates the last time we tried contacting a remote node.
func (*DB) UpdateLastPongReceived ¶
UpdateLastPongReceived updates the last pong time of a node.
func (*DB) UpdateNode ¶
UpdateNode inserts - potentially overwriting - a node into the peer database.
type ID ¶
type ID [32]byte
ID is a unique identifier for each node.
func HexID ¶
HexID converts a hex string to an ID. The string may be prefixed with 0x. It panics if the string is not a valid ID.
func PubkeyToIDV4 ¶
PubkeyToIDV4 derives the v4 node address from the given public key.
func (ID) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (ID) TerminalString ¶
TerminalString returns a shortened hex string for terminal logging.
func (*ID) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type LocalNode ¶
type LocalNode struct {
// contains filtered or unexported fields
}
LocalNode produces the signed node record of a local node, i.e. a node run in the current process. Setting ENR entries via the Set method updates the record. A new version of the record is signed on demand when the Node method is called.
func NewLocalNode ¶
func NewLocalNode(db *DB, key *ecdsa.PrivateKey, nodeType uint8) *LocalNode
NewLocalNode creates a local node.
func (*LocalNode) Set ¶
Set puts the given entry into the local record, overwriting any existing value.
func (*LocalNode) SetFallbackIP ¶
SetFallbackIP sets the last-resort IP address. This address is used if no endpoint prediction can be made and no static IP is set.
func (*LocalNode) SetFallbackUDP ¶
SetFallbackUDP sets the last-resort UDP port. This port is used if no endpoint prediction can be made.
func (*LocalNode) SetStaticIP ¶
SetStaticIP sets the local IP to the given one unconditionally. This disables endpoint prediction.
func (*LocalNode) UDPContact ¶
UDPContact should be called whenever the local node has announced itself to another node via UDP. It feeds the local endpoint predictor.
func (*LocalNode) UDPEndpointStatement ¶
UDPEndpointStatement should be called whenever a statement about the local node's UDP endpoint is received. It feeds the local endpoint predictor.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node represents a host on the network.
func MustParseV4 ¶
MustParseV4 parses a node URL. It panics if the URL is not valid.
func New ¶
New wraps a node record. The record must be valid according to the given identity scheme.
func NewV4 ¶
NewV4 creates a node from discovery v4 node information. The record contained in the node has a zero-length signature.
func ParseV4 ¶
ParseV4 parses a node URL.
There are two basic forms of node URLs:
- 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.
func (*Node) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Node) Record ¶
Record returns the node's record. The return value is a copy and may be modified by the caller.
func (*Node) SetNodeType ¶
IP returns the IP address of the node.
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.
func (*Node) ValidateComplete ¶
checks whether n is a valid complete node.
type NodeTypeOption ¶
type NodeTypeOption uint8
type NullID ¶
type NullID struct{}
NullID is the "null" ENR identity scheme. This scheme stores the node ID in the record without any signature.
type RetrievalOption ¶
type RetrievalOption uint8
const ( // Retrieval disabled. Used mostly for tests to isolate syncing features (i.e. syncing only) RetrievalDisabled RetrievalOption = 1 // Only the client side of the retrieve request is registered. // (light nodes do not serve retrieve requests) // once the client is registered, subscription to retrieve request stream is always sent RetrievalClientOnly RetrievalOption = 2 // Both client and server funcs are registered, subscribe sent automatically RetrievalEnabled RetrievalOption = 4 )
func GetRetrievalOptions ¶
func GetRetrievalOptions(nodeType NodeTypeOption) RetrievalOption
type Secp256k1 ¶
Secp256k1 is the "secp256k1" key, which holds a public key.
type SyncingOption ¶
type SyncingOption uint8
Enumerate options for syncing and retrieval
const ( // Syncing disabled SyncingDisabled SyncingOption = 1 // Register the client and the server but not subscribe SyncingRegisterOnly SyncingOption = 2 // Both client and server funcs are registered, subscribe sent automatically SyncingAutoSubscribe SyncingOption = 4 )
Syncing options
func GetSyncingOptions ¶
func GetSyncingOptions(nodeType NodeTypeOption) SyncingOption