go-libp2p-record: github.com/libp2p/go-libp2p-record Index | Files | Directories

package record

import "github.com/libp2p/go-libp2p-record"


Package Files

pubkey.go record.go util.go validator.go


var ErrInvalidRecordType = errors.New("invalid record keytype")

ErrInvalidRecordType is returned if a DHTRecord keys prefix is not found in the Validator map of the DHT.

func MakePutRecord Uses

func MakePutRecord(key string, value []byte) *pb.Record

MakePutRecord creates a dht record for the given key/value pair

func SplitKey Uses

func SplitKey(key string) (string, string, error)

SplitKey takes a key in the form `/$namespace/$path` and splits it into `$namespace` and `$path`.

type ErrBetterRecord Uses

type ErrBetterRecord struct {
    // Key is the key associated with the record.
    Key string
    // Value is the best value that was found, according to the record's
    // validator.
    Value []byte

ErrBetterRecord is returned by a subsystem when it fails because it found a better record.

func (*ErrBetterRecord) Error Uses

func (e *ErrBetterRecord) Error() string

type NamespacedValidator Uses

type NamespacedValidator map[string]Validator

NamespacedValidator is a validator that delegates to sub-validators by namespace.

func (NamespacedValidator) Select Uses

func (v NamespacedValidator) Select(key string, values [][]byte) (int, error)

Select conforms to the Validator interface.

func (NamespacedValidator) Validate Uses

func (v NamespacedValidator) Validate(key string, value []byte) error

Validate conforms to the Validator interface.

func (NamespacedValidator) ValidatorByKey Uses

func (v NamespacedValidator) ValidatorByKey(key string) Validator

ValidatorByKey looks up the validator responsible for validating the given key.

type PublicKeyValidator Uses

type PublicKeyValidator struct{}

PublicKeyValidator is a Validator that validates public keys.

func (PublicKeyValidator) Select Uses

func (pkv PublicKeyValidator) Select(k string, vals [][]byte) (int, error)

Select conforms to the Validator interface.

It always returns 0 as all public keys are equivalently valid.

func (PublicKeyValidator) Validate Uses

func (pkv PublicKeyValidator) Validate(key string, value []byte) error

Validate conforms to the Validator interface.

It verifies that the passed in record value is the PublicKey that matches the passed in key.

type Validator Uses

type Validator interface {
    // Validate validates the given record, returning an error if it's
    // invalid (e.g., expired, signed by the wrong key, etc.).
    Validate(key string, value []byte) error

    // Select selects the best record from the set of records (e.g., the
    // newest).
    // Decisions made by select should be stable.
    Select(key string, values [][]byte) (int, error)

Validator is an interface that should be implemented by record validators.



Package record imports 9 packages (graph) and is imported by 88 packages. Updated 2020-05-07. Refresh now. Tools for package owners.