Documentation ¶
Overview ¶
Package enr implements Cypherium 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
- func IsNotFound(err error) bool
- func RegisterIdentityScheme(name string, scheme IdentityScheme)
- func SignV4(r *Record, privkey *ecdsa.PrivateKey) error
- type Entry
- type ID
- type IP
- type IdentityScheme
- type KeyError
- type Record
- func (r *Record) AppendElements(list []interface{}) []interface{}
- func (r *Record) DecodeRLP(s *rlp.Stream) error
- func (r Record) EncodeRLP(w io.Writer) error
- func (r *Record) Load(e Entry) error
- func (r *Record) NodeAddr() []byte
- func (r *Record) Seq() uint64
- func (r *Record) Set(e Entry)
- func (r *Record) SetSeq(s uint64)
- func (r *Record) SetSig(idscheme string, sig []byte) error
- func (r *Record) Signed() bool
- type Secp256k1
- type TCP
- type UDP
Constants ¶
const IDv4 = ID("v4") // the default identity scheme
const SizeLimit = 300 // maximum encoded size of a node record in bytes
Variables ¶
This section is empty.
Functions ¶
func IsNotFound ¶
IsNotFound reports whether the given error means that a key/value pair is missing from a record.
func RegisterIdentityScheme ¶
func RegisterIdentityScheme(name string, scheme IdentityScheme)
RegisterIdentityScheme adds an identity scheme to the global registry.
Types ¶
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.
type IP ¶
IP is the "ip" key, which holds the IP address of the node.
type IdentityScheme ¶
An IdentityScheme is capable of verifying record signatures and deriving node addresses.
func FindIdentityScheme ¶
func FindIdentityScheme(name string) IdentityScheme
FindIdentityScheme resolves name to an identity scheme in the global registry.
type Record ¶
type Record struct {
// contains filtered or unexported fields
}
Record represents a node record. The zero value is an empty record.
func (*Record) AppendElements ¶
func (r *Record) AppendElements(list []interface{}) []interface{}
AppendElements appends the sequence number and entries to the given slice.
func (Record) EncodeRLP ¶
EncodeRLP implements rlp.Encoder. Encoding fails if the record is unsigned.
func (*Record) Load ¶
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 ¶
NodeAddr returns the node address. The return value will be nil if the record is unsigned or uses an unknown identity scheme.
func (*Record) Set ¶
Set adds or updates the given entry in the record. It panics if the value can't be encoded. If the record is signed, Set increments the sequence number and invalidates the sequence number.
func (*Record) SetSeq ¶
SetSeq updates the record sequence number. This invalidates any signature on the record. Calling SetSeq is usually not required because setting any key in a signed record increments the sequence number.
type Secp256k1 ¶
Secp256k1 is the "secp256k1" key, which holds a public key.