discv4

package
v0.0.0-...-5d8902e Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

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

RPC packet types

View Source
const MaxNeighbors = 12

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

func (*ENRRequest) String

func (req *ENRRequest) String() 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

func (*ENRResponse) String

func (req *ENRResponse) String() 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

func (Endpoint) String

func (e Endpoint) String() string

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

func (*Findnode) String

func (req *Findnode) String() 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

func (*Neighbors) String

func (req *Neighbors) String() 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
}

type Packet

type Packet interface {
	// Name is the name of the package, for logging purposes.
	Name() string
	// Kind is the packet type, for logging purposes.
	Kind() byte
}

type Ping

type Ping struct {
	Version    uint
	From, To   Endpoint
	Expiration uint64
	ENRSeq     uint64 `rlp:"optional"` // Sequence number of local record, added by EIP-868.

	// Ignore additional fields (for forward compatibility).
	Rest []rlp.RawValue `rlp:"tail"`
}

func (*Ping) Kind

func (req *Ping) Kind() byte

func (*Ping) Name

func (req *Ping) Name() string

func (*Ping) String

func (req *Ping) String() 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
	// 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.
	ENRSeq     uint64 `rlp:"optional"` // Sequence number of local record, added by EIP-868.

	// Ignore additional fields (for forward compatibility).
	Rest []rlp.RawValue `rlp:"tail"`
}

Pong is the reply to ping.

func (*Pong) Kind

func (req *Pong) Kind() byte

func (*Pong) Name

func (req *Pong) Name() string

func (*Pong) String

func (req *Pong) String() string

type Pubkey

type Pubkey [64]byte

func EncodePubkey

func EncodePubkey(key *ecdsa.PublicKey) Pubkey

EncodePubkey encodes a secp256k1 public key.

func (Pubkey) ID

func (e Pubkey) ID() enode.ID

type Secp256k1

type Secp256k1 ecdsa.PublicKey

Secp256k1 is the "secp256k1" key, which holds a public key.

func (*Secp256k1) DecodeRLP

func (v *Secp256k1) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder.

func (Secp256k1) ENRKey

func (v Secp256k1) ENRKey() string

func (Secp256k1) EncodeRLP

func (v Secp256k1) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder.

type StateSeries

type StateSeries struct {
	Type  string
	Hash  []byte
	State int
}

type UDPv4

type UDPv4 struct {
	// contains filtered or unexported fields
}

UDPv4 implements the v4 wire protocol.

func ListenV4

func ListenV4(c d2p.UDPConn, ln *enode.LocalNode, cfg d2p.Config) (*UDPv4, error)

func (*UDPv4) Close

func (t *UDPv4) Close()

Close shuts down the socket and aborts any running queries.

func (*UDPv4) GenPacket

func (t *UDPv4) GenPacket(f *filler.Filler, packetType string, n *enode.Node) Packet

func (*UDPv4) GetPri

func (t *UDPv4) GetPri() *ecdsa.PrivateKey

func (*UDPv4) Pending

func (t *UDPv4) Pending(id enode.ID, ip net.IP, ptype byte, callback replyMatchFunc) *replyMatcher

func (*UDPv4) SelectSeed

func (t *UDPv4) SelectSeed(seedQueue []*V4Seed) *V4Seed

func (*UDPv4) Self

func (t *UDPv4) Self() *enode.Node

func (*UDPv4) Send

func (t *UDPv4) Send(n *enode.Node, req Packet) []byte

type V4Seed

type V4Seed struct {
	ID        string         `json:"id"`        // 种子的唯一标识符
	Packets   []Packet       `json:"packets"`   // 用于变异的Packet切片
	Priority  int            `json:"priority"`  // 种子的优先级
	Mutations int            `json:"mutations"` // 该种子已经经过的变异次数
	Series    []*StateSeries `json:"series"`
}

Jump to

Keyboard shortcuts

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