record

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

Functions

func MakePutRecord

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

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

func SplitKey

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

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

Types

type ErrBetterRecord

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

func (e *ErrBetterRecord) Error() string

type NamespacedValidator

type NamespacedValidator map[string]Validator

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

func (NamespacedValidator) Select

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

Select conforms to the Validator interface.

func (NamespacedValidator) Validate

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

Validate conforms to the Validator interface.

func (NamespacedValidator) ValidatorByKey

func (v NamespacedValidator) ValidatorByKey(key string) Validator

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

type PublicKeyValidator

type PublicKeyValidator struct{}

PublicKeyValidator is a Validator that validates public keys.

func (PublicKeyValidator) Select

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

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

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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