Documentation
¶
Overview ¶
Package node implements the Node representation for discv4.
Unlike discv5 nodes which track sessions and ENR sequences, discv4 nodes track bond status and last seen timestamps for the bond mechanism.
Index ¶
- func Distance(a, b ID) []byte
- func DistanceCmp(target, a, b ID) int
- type BondStatus
- type ID
- type Node
- func (n *Node) Addr() *net.UDPAddr
- func (n *Node) BondExpiration() time.Time
- func (n *Node) BondStatus() BondStatus
- func (n *Node) ConsecutiveTimeouts() uint32
- func (n *Node) ENR() *enr.Record
- func (n *Node) Enode() *enode.Enode
- func (n *Node) FailedPings() uint32
- func (n *Node) ID() ID
- func (n *Node) IDBytes() []byte
- func (n *Node) IncrementPacketsReceived()
- func (n *Node) IncrementPacketsSent()
- func (n *Node) IsBonded() bool
- func (n *Node) LastPingSent() time.Time
- func (n *Node) LastPongReceived() time.Time
- func (n *Node) LastSeen() time.Time
- func (n *Node) MarkPingReceived()
- func (n *Node) MarkPingSent()
- func (n *Node) MarkPongReceived(bondDuration time.Duration)
- func (n *Node) MarkPongSent()
- func (n *Node) MarkTimeout()
- func (n *Node) PublicKey() *ecdsa.PublicKey
- func (n *Node) SetAddr(addr *net.UDPAddr)
- func (n *Node) SetENR(record *enr.Record)
- func (n *Node) SetStats(sharedStats *stats.SharedStats)
- func (n *Node) String() string
- func (n *Node) TotalPacketsReceived() uint64
- func (n *Node) TotalPacketsSent() uint64
- func (n *Node) UpdateLastSeen()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Distance ¶
Distance calculates the XOR distance between two node IDs.
This is used for Kademlia-style routing (if needed by higher layers).
func DistanceCmp ¶
DistanceCmp compares the distance from target to a vs b.
Returns:
- negative if distance(target, a) < distance(target, b)
- zero if distance(target, a) == distance(target, b)
- positive if distance(target, a) > distance(target, b)
Types ¶
type BondStatus ¶
type BondStatus int
BondStatus represents the bonding state of a node.
const ( // BondStatusUnknown means we have never interacted with this node BondStatusUnknown BondStatus = iota // BondStatusPingSent means we sent a PING and are waiting for PONG BondStatusPingSent // BondStatusBonded means we have completed a successful PING/PONG exchange BondStatusBonded // BondStatusExpired means the bond has expired (24 hours since last PONG) BondStatusExpired )
func (BondStatus) String ¶
func (s BondStatus) String() string
String returns the string representation of bond status.
type ID ¶
type ID [32]byte
ID represents a node identifier (32-byte Keccak256 hash of public key).
func PubkeyToID ¶
PubkeyToID converts a public key to a node ID.
The node ID is the Keccak256 hash of the uncompressed public key (without the 0x04 prefix).
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node represents a discv4 node with bond tracking.
The bond mechanism in discv4 requires nodes to complete a PING/PONG exchange before they can send FINDNODE requests. This prevents amplification attacks.
func ParseEnode ¶
ParseEnode creates a node from an enode:// URL string.
func (*Node) BondExpiration ¶
BondExpiration returns when the current bond expires.
func (*Node) BondStatus ¶
func (n *Node) BondStatus() BondStatus
BondStatus returns the current bond status.
func (*Node) ConsecutiveTimeouts ¶
ConsecutiveTimeouts returns the number of consecutive timeouts.
func (*Node) FailedPings ¶
FailedPings returns the number of failed ping attempts.
func (*Node) IncrementPacketsReceived ¶
func (n *Node) IncrementPacketsReceived()
IncrementPacketsReceived increments the received packet counter.
func (*Node) IncrementPacketsSent ¶
func (n *Node) IncrementPacketsSent()
IncrementPacketsSent increments the sent packet counter.
func (*Node) LastPingSent ¶
LastPingSent returns when we last sent a PING.
func (*Node) LastPongReceived ¶
LastPongReceived returns when we last received a PONG.
func (*Node) MarkPingReceived ¶
func (n *Node) MarkPingReceived()
MarkPingReceived records that we received a PING from this node.
func (*Node) MarkPingSent ¶
func (n *Node) MarkPingSent()
MarkPingSent records that we sent a PING to this node.
func (*Node) MarkPongReceived ¶
MarkPongReceived records that we received a PONG from this node.
This establishes or renews the bond.
func (*Node) MarkPongSent ¶
func (n *Node) MarkPongSent()
MarkPongSent records that we sent a PONG to this node.
func (*Node) MarkTimeout ¶
func (n *Node) MarkTimeout()
MarkTimeout records a timeout (failed to receive expected response).
func (*Node) SetAddr ¶
SetAddr updates the node's address.
This is used when we receive packets from a different address than expected.
func (*Node) SetStats ¶
func (n *Node) SetStats(sharedStats *stats.SharedStats)
SetStats replaces the node's stats with a shared stats pointer. This allows the node to update stats owned by a parent node.
func (*Node) TotalPacketsReceived ¶
TotalPacketsReceived returns the total packets received from this node.
func (*Node) TotalPacketsSent ¶
TotalPacketsSent returns the total packets sent to this node.
func (*Node) UpdateLastSeen ¶
func (n *Node) UpdateLastSeen()
UpdateLastSeen updates the last seen timestamp.