Commit e0e856aa authored by Jeromy's avatar Jeromy

data storage interfaces

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>
parent ce57a766
......@@ -40,12 +40,19 @@ type Blockstore interface {
DeleteBlock(*cid.Cid) error
Has(*cid.Cid) (bool, error)
Get(*cid.Cid) (blocks.Block, error)
// Put puts a given block to the underlying datastore
Put(blocks.Block) error
// PutMany puts a slice of blocks at the same time using batching
// capabilities of the underlying datastore whenever possible.
PutMany([]blocks.Block) error
// AllKeysChan returns a channel from which
// the CIDs in the Blockstore can be read. It should respect
// the given context, closing the channel if it becomes Done.
AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error)
// HashOnRead specifies if every read block should be
// rehashed to make sure it matches its CID.
HashOnRead(enabled bool)
......
......@@ -25,13 +25,26 @@ var ErrNotFound = errors.New("blockservice: key not found")
// datastore and may retrieve data from a remote Exchange.
// It uses an internal `datastore.Datastore` instance to store values.
type BlockService interface {
// Blockstore returns a reference to the underlying blockstore
Blockstore() blockstore.Blockstore
// Exchange returns a reference to the underlying exchange (usually bitswap)
Exchange() exchange.Interface
// AddBlock puts a given block to the underlying datastore
AddBlock(o blocks.Block) (*cid.Cid, error)
// AddBlocks adds a slice of blocks at the same time using batching
// capabilities of the underlying datastore whenever possible.
AddBlocks(bs []blocks.Block) ([]*cid.Cid, error)
GetBlock(ctx context.Context, c *cid.Cid) (blocks.Block, error)
GetBlocks(ctx context.Context, ks []*cid.Cid) <-chan blocks.Block
DeleteBlock(o blocks.Block) error
// GetBlocks does a batch request for the given cids, returning blocks as
// they are found, in no particular order.
GetBlocks(ctx context.Context, ks []*cid.Cid) <-chan blocks.Block
Close() error
}
......
......@@ -16,24 +16,41 @@ var (
ErrApiNotRunning = errors.New("api not running")
)
// Repo represents all persistent data of a given ipfs node.
type Repo interface {
// Config returns the ipfs configuration file from the repo. Changes made
// to the returned config are not automatically persisted.
Config() (*config.Config, error)
// BackupConfig creates a backup of the current configuration file using
// the given prefix for naming.
BackupConfig(prefix string) (string, error)
// SetConfig persists the given configuration struct to storage.
SetConfig(*config.Config) error
// SetConfigKey sets the given key-value pair within the config and persists it to storage.
SetConfigKey(key string, value interface{}) error
// GetConfigKey reads the value for the given key from the configuration in storage.
GetConfigKey(key string) (interface{}, error)
// Datastore returns a reference to the configured data storage backend.
Datastore() Datastore
// GetStorageUsage returns the number of bytes stored.
GetStorageUsage() (uint64, error)
// Keystore returns a reference to the key management interface.
Keystore() keystore.Keystore
// FileManager returns a reference to the filestore file manager.
FileManager() *filestore.FileManager
// SetAPIAddr sets the API address in the repo.
SetAPIAddr(addr ma.Multiaddr) error
// SwarmKey returns the configured shared symmetric key for the private networks feature.
SwarmKey() ([]byte, error)
io.Closer
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment