Documentation ¶
Overview ¶
Package mock defines types that are used by different implementations of mock storages.
Implementations of mock storages are located in directories under this package:
- db - LevelDB backend
- mem - in memory map backend
- rpc - RPC client that can connect to other backends
Mock storages can implement Importer and Exporter interfaces for importing and exporting all chunk data that they contain. The exported file is a tar archive with all files named by hexadecimal representations of chunk keys and with content with JSON-encoded ExportedChunk structure. Exported format should be preserved across all mock store implementations.
Index ¶
Constants ¶
const ( // DefaultLimit should be used as default limit for // Keys, Nodes, NodeKeys and KeyNodes GlobarStorer // methids implementations. DefaultLimit = 100 // MaxLimit should be used as the maximal returned number // of items for Keys, Nodes, NodeKeys and KeyNodes GlobarStorer // methids implementations, regardless of provided limit. MaxLimit = 1000 )
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound indicates that the chunk is not found.
Functions ¶
This section is empty.
Types ¶
type ExportedChunk ¶
ExportedChunk is the structure that is saved in tar archive for each chunk as JSON-encoded bytes.
type GlobalStorer ¶
type GlobalStorer interface { Get(addr common.Address, key []byte) (data []byte, err error) Put(addr common.Address, key []byte, data []byte) error Delete(addr common.Address, key []byte) error HasKey(addr common.Address, key []byte) bool Keys(startKey []byte, limit int) (keys Keys, err error) Nodes(startAddr *common.Address, limit int) (nodes Nodes, err error) NodeKeys(addr common.Address, startKey []byte, limit int) (keys Keys, err error) KeyNodes(key []byte, startAddr *common.Address, limit int) (nodes Nodes, err error) // NewNodeStore creates an instance of NodeStore // to be used by a single swarm node with // address addr. NewNodeStore(addr common.Address) *NodeStore }
GlobalStorer defines methods for mock db store that stores chunk data for all swarm nodes. It is used in tests to construct mock NodeStores for swarm nodes and to track and validate chunks.
type NodeStore ¶
type NodeStore struct {
// contains filtered or unexported fields
}
NodeStore holds the node address and a reference to the GlobalStore in order to access and store chunk data only for one node.
func NewNodeStore ¶
func NewNodeStore(addr common.Address, store GlobalStorer) *NodeStore
NewNodeStore creates a new instance of NodeStore that keeps chunk data using GlobalStorer with a provided address.
func (*NodeStore) Delete ¶
Delete removes chunk data for a key for a node that has the address provided on NodeStore initialization.
func (*NodeStore) Get ¶
Get returns chunk data for a key for a node that has the address provided on NodeStore initialization.
Directories ¶
Path | Synopsis |
---|---|
Package db implements a mock store that keeps all chunk data in LevelDB database.
|
Package db implements a mock store that keeps all chunk data in LevelDB database. |
Package mem implements a mock store that keeps all chunk data in memory.
|
Package mem implements a mock store that keeps all chunk data in memory. |
Package rpc implements an RPC client that connect to a centralized mock store.
|
Package rpc implements an RPC client that connect to a centralized mock store. |
Package test provides functions that are used for testing GlobalStorer implementations.
|
Package test provides functions that are used for testing GlobalStorer implementations. |