storage

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxKeyLength is the max key length (in Bytes) for an SL.
	MaxKeyLength = 32

	// MaxValueLength is the max value length for an SL.
	MaxValueLength = 2 * 1024 * 1024 // 2 MB

	// EntriesKeyLength is the fixed length (in Bytes) of all entry keys.
	EntriesKeyLength = 32

	// MaxEntriesValueLength is the maximum length of all entry values. We add a little buffer
	// on top of the value to account for Entry values other than the actual ciphertext (which
	// we want to be <= 2MB).
	MaxEntriesValueLength = 2*1024*1024 + 1024
)

Variables

View Source
var (
	// Server namespace contains values relevant to a server.
	Server = []byte("server")

	// Client namespace contains values relevant to a client.
	Client = []byte("client")

	// Documents namespace contains all libri p2p Stored values.
	Documents = []byte("documents")
)

Functions

This section is empty.

Types

type Checker

type Checker interface {
	// Check that a key or value is valid.
	Check(x []byte) error
}

Checker checks that a key or value is value.

func NewEmptyChecker

func NewEmptyChecker() Checker

NewEmptyChecker creates a new Checker instance that ensures values have non-zero length.

func NewExactLengthChecker

func NewExactLengthChecker(length int) Checker

NewExactLengthChecker creates a Checker instance that ensures that values are not empty and have a specified length.

func NewMaxLengthChecker

func NewMaxLengthChecker(max int) Checker

NewMaxLengthChecker creates a new Checker that ensures that values are not empty and have length less <= max length.

type Deleter

type Deleter interface {
	// Delete a value with the given key and namespace.
	Delete(key []byte) error
}

Deleter deletes a value from durable storage.

type DocumentDeleter

type DocumentDeleter interface {
	// Delete the api.Document value with the given key.
	Delete(key id.ID) error
}

DocumentDeleter deletes api.Document values.

type DocumentLD

type DocumentLD interface {
	DocumentLoader
	DocumentDeleter
}

DocumentLD stores & loads api.Document values.

type DocumentLoader

type DocumentLoader interface {
	// Load an api.Document value with the given key.
	Load(key id.ID) (*api.Document, error)

	// Mac an api.Document value with the given key and mac key.
	Mac(key id.ID, macKey []byte) ([]byte, error)
}

DocumentLoader loads api.Document values.

type DocumentSL

type DocumentSL interface {
	DocumentStorer
	DocumentLoader
}

DocumentSL stores & loads api.Document values.

type DocumentSLD

type DocumentSLD interface {
	DocumentSL
	DocumentDeleter
}

DocumentSLD stores, loads, & deletes api.Document values.

func NewDocumentSLD

func NewDocumentSLD(kvdb db.KVDB) DocumentSLD

NewDocumentSLD creates a new NamespaceSL for the "entries" namespace backed by a db.KVDB instance.

type DocumentStorer

type DocumentStorer interface {
	// Store an api.Document value under the given key.
	Store(key id.ID, value *api.Document) error

	Iterate(done chan struct{}, callback func(key id.ID, value []byte)) error
}

DocumentStorer stores api.Document values.

type KeyValueChecker

type KeyValueChecker interface {
	// Check checks that a key-value combination is valid.
	Check(key []byte, value []byte) error
}

KeyValueChecker checks that a key-value combination is valid.

func NewHashKeyValueChecker

func NewHashKeyValueChecker() KeyValueChecker

NewHashKeyValueChecker returns a new KeyValueChecker that checks that the key is the SHA256 hash of the value.

type Loader

type Loader interface {
	// Load a value for a given key and namespace.
	Load(key []byte) ([]byte, error)
}

Loader loads a value from durable storage.

type Storer

type Storer interface {
	// Store a key-value pair in a given namespace.
	Store(key []byte, value []byte) error

	// Iterate iterates through the key-value pairs of a given namespace within a given key range.
	// It calls the callback function for each key-value pair.
	Iterate(keyLB, keyUB []byte, done chan struct{}, callback func(key, value []byte)) error
}

Storer stores a value to durable storage.

type StorerLoader

type StorerLoader interface {
	Storer
	Loader
}

StorerLoader can both store and load values.

func NewClientSL

func NewClientSL(kvdb db.KVDB) StorerLoader

NewClientSL creates a new NamespaceSL for the "client" namespace backed by a db.KVDB instance.

func NewKVDBStorerLoader

func NewKVDBStorerLoader(
	ns []byte, db db.KVDB, keyChecker Checker, valueChecker Checker,
) StorerLoader

NewKVDBStorerLoader returns a new StorerLoader backed by a db.KVDB instance and with the given key and value checkers.

func NewServerSL

func NewServerSL(kvdb db.KVDB) StorerLoader

NewServerSL creates a new NamespaceSL for the "server" namespace backed by a db.KVDB instance.

type StorerLoaderDeleter

type StorerLoaderDeleter interface {
	StorerLoader
	Deleter
}

StorerLoaderDeleter can store, load, and delete values.

func NewKVDBStorerLoaderDeleter

func NewKVDBStorerLoaderDeleter(
	ns []byte, db db.KVDB, keyChecker Checker, valueChecker Checker,
) StorerLoaderDeleter

NewKVDBStorerLoaderDeleter returns a new StorerLoaderDeleter backed by a db.KVDB instance and with the given key and value checkers.

type TestDocSLD

type TestDocSLD struct {
	StoreErr   error
	Stored     map[string]*api.Document
	IterateErr error
	LoadErr    error
	MacErr     error
	DeleteErr  error
	// contains filtered or unexported fields
}

TestDocSLD mocks DocumentSLD.

func NewTestDocSLD

func NewTestDocSLD() *TestDocSLD

NewTestDocSLD creates a new TestDocSLD.

func (*TestDocSLD) Delete

func (f *TestDocSLD) Delete(key id.ID) error

Delete mocks DocumentSLD.Delete().

func (*TestDocSLD) Iterate

func (f *TestDocSLD) Iterate(done chan struct{}, callback func(key id.ID, value []byte)) error

Iterate mocks DocumentSLD.Iterate().

func (*TestDocSLD) Load

func (f *TestDocSLD) Load(key id.ID) (*api.Document, error)

Load mocks DocumentSLD.Load().

func (*TestDocSLD) Mac

func (f *TestDocSLD) Mac(key id.ID, macKey []byte) ([]byte, error)

Mac mocks DocumentSLD.Mac().

func (*TestDocSLD) Store

func (f *TestDocSLD) Store(key id.ID, value *api.Document) error

Store mocks DocumentSLD.Store().

type TestSLD

type TestSLD struct {
	Bytes      []byte
	LoadErr    error
	IterateErr error
	StoreErr   error
	DeleteErr  error
	// contains filtered or unexported fields
}

TestSLD mocks StorerLoaderDeleter interface.

func (*TestSLD) Delete

func (l *TestSLD) Delete(key []byte) error

Delete mocks StorerLoaderDeleter.Delete().

func (*TestSLD) Iterate

func (l *TestSLD) Iterate(
	keyLB, keyUB []byte, done chan struct{}, callback func(key, value []byte),
) error

Iterate mocks StorerLoaderDeleter.Iterate().

func (*TestSLD) Load

func (l *TestSLD) Load(key []byte) ([]byte, error)

Load mocks StorerLoaderDeleter.Load().

func (*TestSLD) Store

func (l *TestSLD) Store(key []byte, value []byte) error

Store mocks StorerLoaderDeleter.Store().

Jump to

Keyboard shortcuts

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