v4wire

package
v1.10.3 Latest Latest
Warning

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

Go to latest
Published: May 5, 2021 License: GPL-3.0 Imports: 13 Imported by: 64

Documentation

Overview

Package v4wire implements the Discovery v4 Wire Protocol.

Index

Constants

View Source
const (
	PingPacket = iota + 1 // zero is 'reserved'
	PongPacket
	FindnodePacket
	NeighborsPacket
	ENRRequestPacket
	ENRResponsePacket
)

RPC packet types

View Source
const MaxNeighbors = 12

This number is the maximum number of neighbor nodes in a Neigbors packet.

Variables

View Source
var (
	ErrPacketTooSmall = errors.New("too small")
	ErrBadHash        = errors.New("bad hash")
	ErrBadPoint       = errors.New("invalid curve point")
)

Functions

func Decode

func Decode(input []byte) (Packet, Pubkey, []byte, error)

Decode reads a discovery v4 packet.

func DecodePubkey

func DecodePubkey(curve elliptic.Curve, e Pubkey) (*ecdsa.PublicKey, error)

DecodePubkey reads an encoded secp256k1 public key.

func Encode

func Encode(priv *ecdsa.PrivateKey, req Packet) (packet, hash []byte, err error)

Encode encodes a discovery packet.

func Expired

func Expired(ts uint64) bool

Expired checks whether the given UNIX time stamp is in the past.

Types

type ENRRequest

type ENRRequest struct {
	Expiration uint64
	// Ignore additional fields (for forward compatibility).
	Rest []rlp.RawValue `rlp:"tail"`
}

enrRequest queries for the remote node's record.

func (*ENRRequest) Kind

func (req *ENRRequest) Kind() byte

func (*ENRRequest) Name

func (req *ENRRequest) Name() string

type ENRResponse

type ENRResponse struct {
	ReplyTok []byte // Hash of the enrRequest packet.
	Record   enr.Record
	// Ignore additional fields (for forward compatibility).
	Rest []rlp.RawValue `rlp:"tail"`
}

enrResponse is the reply to enrRequest.

func (*ENRResponse) Kind

func (req *ENRResponse) Kind() byte

func (*ENRResponse) Name

func (req *ENRResponse) Name() string

type Endpoint

type Endpoint struct {
	IP  net.IP // len 4 for IPv4 or 16 for IPv6
	UDP uint16 // for discovery protocol
	TCP uint16 // for RLPx protocol
}

Endpoint represents a network endpoint.

func NewEndpoint

func NewEndpoint(addr *net.UDPAddr, tcpPort uint16) Endpoint

NewEndpoint creates an endpoint.

type Findnode

type Findnode struct {
	Target     Pubkey
	Expiration uint64
	// Ignore additional fields (for forward compatibility).
	Rest []rlp.RawValue `rlp:"tail"`
}

Findnode is a query for nodes close to the given target.

func (*Findnode) Kind

func (req *Findnode) Kind() byte

func (*Findnode) Name

func (req *Findnode) Name() string

type Neighbors

type Neighbors struct {
	Nodes      []Node
	Expiration uint64
	// Ignore additional fields (for forward compatibility).
	Rest []rlp.RawValue `rlp:"tail"`
}

Neighbors is the reply to findnode.

func (*Neighbors) Kind

func (req *Neighbors) Kind() byte

func (*Neighbors) Name

func (req *Neighbors) Name() string

type Node

type Node struct {
	IP  net.IP // len 4 for IPv4 or 16 for IPv6
	UDP uint16 // for discovery protocol
	TCP uint16 // for RLPx protocol
	ID  Pubkey
}

Node represents information about a node.

type Packet

type Packet interface {
	// packet name and type for logging purposes.
	Name() string
	Kind() byte
}

type Ping

type Ping struct {
	Version    uint
	From, To   Endpoint
	Expiration uint64
	// Ignore additional fields (for forward compatibility).
	Rest []rlp.RawValue `rlp:"tail"`
}

RPC request structures

func (*Ping) ENRSeq

func (req *Ping) ENRSeq() uint64

func (*Ping) Kind

func (req *Ping) Kind() byte

func (*Ping) Name

func (req *Ping) Name() string

type Pong

type Pong struct {
	// This field should mirror the UDP envelope address
	// of the ping packet, which provides a way to discover the
	// the external address (after NAT).
	To         Endpoint
	ReplyTok   []byte // This contains the hash of the ping packet.
	Expiration uint64 // Absolute timestamp at which the packet becomes invalid.
	// Ignore additional fields (for forward compatibility).
	Rest []rlp.RawValue `rlp:"tail"`
}

Pong is the reply to ping.

func (*Pong) ENRSeq

func (req *Pong) ENRSeq() uint64

func (*Pong) Kind

func (req *Pong) Kind() byte

func (*Pong) Name

func (req *Pong) Name() string

type Pubkey

type Pubkey [64]byte

Pubkey represents an encoded 64-byte secp256k1 public key.

func EncodePubkey

func EncodePubkey(key *ecdsa.PublicKey) Pubkey

EncodePubkey encodes a secp256k1 public key.

func (Pubkey) ID

func (e Pubkey) ID() enode.ID

ID returns the node ID corresponding to the public key.

Jump to

Keyboard shortcuts

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