enr

package
v2.2.23+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2019 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package enr implements Ethereum Node Records as defined in EIP-778. A node record holds arbitrary information about a node on the peer-to-peer network.

Records contain named keys. To store and retrieve key/values in a record, use the Entry interface.

Records must be signed before transmitting them to another node. Decoding a record verifies its signature. When creating a record, set the entries you want, then call Sign to add the signature. Modifying a record invalidates the signature.

Package enr supports the "secp256k1-keccak" identity scheme.

Index

Constants

View Source
const ID_SECP256k1_KECCAK = ID("secp256k1-keccak") // the default identity scheme
View Source
const SizeLimit = 300 // maximum encoded size of a node record in bytes

Variables

This section is empty.

Functions

func IsNotFound

func IsNotFound(err error) bool

IsNotFound reports whether the given error means that a key/value pair is missing from a record.

Types

type DiscPort

type DiscPort uint16

DiscPort is the "discv5" key, which holds the UDP port for discovery v5.

func (DiscPort) ENRKey

func (v DiscPort) ENRKey() string

type Entry

type Entry interface {
	ENRKey() string
}

Entry is implemented by known node record entry types.

To define a new entry that is to be included in a node record, create a Go type that satisfies this interface. The type should also implement rlp.Decoder if additional checks are needed on the value.

func WithEntry

func WithEntry(k string, v interface{}) Entry

WithEntry wraps any value with a key name. It can be used to set and load arbitrary values in a record. The value v must be supported by rlp. To use WithEntry with Load, the value must be a pointer.

type ID

type ID string

ID is the "id" key, which holds the name of the identity scheme.

func (ID) ENRKey

func (v ID) ENRKey() string

type IP4

type IP4 net.IP

IP4 is the "ip4" key, which holds a 4-byte IPv4 address.

func (*IP4) DecodeRLP

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

DecodeRLP implements rlp.Decoder.

func (IP4) ENRKey

func (v IP4) ENRKey() string

func (IP4) EncodeRLP

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

EncodeRLP implements rlp.Encoder.

type IP6

type IP6 net.IP

IP6 is the "ip6" key, which holds a 16-byte IPv6 address.

func (*IP6) DecodeRLP

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

DecodeRLP implements rlp.Decoder.

func (IP6) ENRKey

func (v IP6) ENRKey() string

func (IP6) EncodeRLP

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

EncodeRLP implements rlp.Encoder.

type KeyError

type KeyError struct {
	Key string
	Err error
}

KeyError is an error related to a key.

func (*KeyError) Error

func (err *KeyError) Error() string

Error implements error.

type Record

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

Record represents a node record. The zero value is an empty record.

func (*Record) DecodeRLP

func (r *Record) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder. Decoding verifies the signature.

func (Record) EncodeRLP

func (r Record) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder. Encoding fails if the record is unsigned.

func (*Record) Load

func (r *Record) Load(e Entry) error

Load retrieves the value of a key/value pair. The given Entry must be a pointer and will be set to the value of the entry in the record.

Errors returned by Load are wrapped in KeyError. You can distinguish decoding errors from missing keys using the IsNotFound function.

func (*Record) NodeAddr

func (r *Record) NodeAddr() []byte

NodeAddr returns the node address. The return value will be nil if the record is unsigned.

func (*Record) Seq

func (r *Record) Seq() uint64

Seq returns the sequence number.

func (*Record) Set

func (r *Record) Set(e Entry)

Set adds or updates the given entry in the record. It panics if the value can't be encoded.

func (*Record) SetSeq

func (r *Record) SetSeq(s uint64)

SetSeq updates the record sequence number. This invalidates any signature on the record. Calling SetSeq is usually not required because signing the redord increments the sequence number.

func (*Record) Sign

func (r *Record) Sign(privkey *ecdsa.PrivateKey) error

Sign signs the record with the given private key. It updates the record's identity scheme, public key and increments the sequence number. Sign returns an error if the encoded record is larger than the size limit.

func (*Record) Signed

func (r *Record) Signed() bool

Signed reports whether the record has a valid signature.

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.

Jump to

Keyboard shortcuts

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