record

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2020 License: MIT, MIT Imports: 9 Imported by: 0

README

go-libp2p-record

Discourse posts

signed records for use with routing systems

Documentation

See https://godoc.org/github.com/libp2p/go-libp2p-record.

Testing

This package has some tests that rely on generating weak RSA keys (for speed). In order to successfully run the tests, one must set the environment variable, LIBP2P_ALLOW_WEAK_RSA_KEYS to any non-empty value, such as 1.

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the libp2p Code of Conduct.

Want to hack on libp2p?

License

MIT


The last gx published version of this module was: 4.1.15: QmbeHtaBy9nZsW4cHRcvgVY4CnDhXudE2Dr6qDxS7yg9rX

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