Documentation
¶
Overview ¶
Package enode implements parsing and encoding of the legacy enode:// URL format.
The enode URL scheme is used in Ethereum's discv4 protocol to identify nodes. It has the form:
enode://<hex node id>@<ip>:<tcp_port>?discport=<udp_port>
Where:
- hex node id: 128 hex characters (64 bytes) representing the uncompressed public key
- ip: IPv4 or IPv6 address
- tcp_port: TCP port for RLPx connections
- discport: Optional UDP port for discovery (defaults to tcp_port if omitted)
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidScheme is returned when the URL scheme is not "enode" ErrInvalidScheme = errors.New("enode: invalid URL scheme, want \"enode\"") // ErrMissingNodeID is returned when the URL does not contain a node ID ErrMissingNodeID = errors.New("enode: does not contain node ID") // ErrInvalidNodeID is returned when the node ID is not 128 hex characters ErrInvalidNodeID = errors.New("enode: invalid node ID, want 128 hex characters") // ErrInvalidIP is returned when the IP address is invalid ErrInvalidIP = errors.New("enode: invalid IP address") // ErrInvalidPort is returned when the port is invalid ErrInvalidPort = errors.New("enode: invalid port") )
Functions ¶
This section is empty.
Types ¶
type Enode ¶
type Enode struct {
// PublicKey is the node's secp256k1 public key
PublicKey *ecdsa.PublicKey
// IP is the node's IP address (can be nil for incomplete nodes)
IP net.IP
// TCP is the TCP port for RLPx connections
TCP uint16
// UDP is the UDP port for discovery protocol
UDP uint16
// Hostname is the DNS hostname (if any)
Hostname string
}
Enode represents a parsed enode:// URL.
It contains the node's public key and network endpoint information.
func MustParse ¶
MustParse parses an enode:// URL and panics if parsing fails.
This is useful for static URLs that are known to be valid.
func Parse ¶
Parse parses an enode:// URL string.
Supported formats:
- Complete: enode://<hex-nodeid>@<ip>:<port>
- With discport: enode://<hex-nodeid>@<ip>:<port>?discport=<udp-port>
- Incomplete: enode://<hex-nodeid> or just <hex-nodeid>
Example:
node, err := enode.Parse("enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@127.0.0.1:30303?discport=30301")
func (*Enode) IsComplete ¶
IsComplete returns true if the enode has IP and port information.
func (*Enode) IsIncomplete ¶
IsIncomplete returns true if the enode only has a public key.
func (*Enode) NodeID ¶
NodeID returns the Keccak256 hash of the public key.
This is used as the node identifier in the discovery protocol.
func (*Enode) String ¶
String returns the enode URL representation.
Format: enode://<hex-nodeid>@<ip>:<tcp-port>?discport=<udp-port>
If UDP port equals TCP port, the discport parameter is omitted. If IP is not set (incomplete node), returns: enode://<hex-nodeid>