store

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package store provides interfaces and default in-memory implementation of storage for DHT metadata.

Usage:

s := newMemoryStore()

data := []byte("some data")
key := NewKey(data)

replicationTime := time.Now().Add(time.Second * 1337)
expirationTime := time.Now().Add(time.Second * 42)

s.Store(key, data, replicationTime, expirationTime, true)

s.Retrieve(key)

s.Delete(key)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

type Factory interface {
	Create() Store
}

Factory allows to create new storage.

func NewMemoryStoreFactory

func NewMemoryStoreFactory() Factory

NewMemoryStoreFactory creates new factory of memory storage.

type Key

type Key []byte

Key is storage key. For now it is 20-byte slice.

func NewKey

func NewKey(data []byte) Key

NewKey creates new key for given data.

func (Key) String

func (k Key) String() string

String is a string representation of key.

type Store

type Store interface {
	// Store should store a key/value pair for the local host with the
	// given replication and expiration times.
	Store(key Key, data []byte, replication time.Time, expiration time.Time, publisher bool) error

	// Retrieve should return the local key/value if it exists.
	Retrieve(key Key) (data []byte, found bool)

	// Delete should delete a key/value pair from the Store.
	Delete(key Key)

	// GetKeysReadyToReplicate should return the keys of all data to be
	// replicated across the network. Typically all data should be
	// replicated every tReplicate seconds.
	GetKeysReadyToReplicate() []Key

	// ExpireKeys should expire all key/values due for expiration.
	ExpireKeys()
}

Store is the interface for implementing the storage mechanism for the DHT.

func NewMemoryStore

func NewMemoryStore() Store

NewMemoryStore creates new memory store.

func NewStore

func NewStore() Store

NewStore creates new memory store.

Jump to

Keyboard shortcuts

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