@cryptotaxi247 / kubo / commits / e0e856aa9

data storage interfaces

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Jan 21, 2018 at 11:46 UTC e0e856aa9371cd2104e8c05429be21f187b33f00
3 files changed +38 -1
blocks/blockstore/blockstore.go
+7
@@ -40,12 +40,19 @@ type Blockstore interface {
40 DeleteBlock(*cid.Cid) error
41 Has(*cid.Cid) (bool, error)
42 Get(*cid.Cid) (blocks.Block, error)
43 +
44 + // Put puts a given block to the underlying datastore
45 Put(blocks.Block) error
46 +
47 + // PutMany puts a slice of blocks at the same time using batching
48 + // capabilities of the underlying datastore whenever possible.
49 PutMany([]blocks.Block) error
50 +
51 // AllKeysChan returns a channel from which
52 // the CIDs in the Blockstore can be read. It should respect
53 // the given context, closing the channel if it becomes Done.
54 AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error)
55 +
56 // HashOnRead specifies if every read block should be
57 // rehashed to make sure it matches its CID.
58 HashOnRead(enabled bool)
blockservice/blockservice.go
+14 -1
@@ -25,13 +25,26 @@ var ErrNotFound = errors.New("blockservice: key not found")
25 // datastore and may retrieve data from a remote Exchange.
26 // It uses an internal `datastore.Datastore` instance to store values.
27 type BlockService interface {
28 + // Blockstore returns a reference to the underlying blockstore
29 Blockstore() blockstore.Blockstore
30 +
31 + // Exchange returns a reference to the underlying exchange (usually bitswap)
32 Exchange() exchange.Interface
33 +
34 + // AddBlock puts a given block to the underlying datastore
35 AddBlock(o blocks.Block) (*cid.Cid, error)
36 +
37 + // AddBlocks adds a slice of blocks at the same time using batching
38 + // capabilities of the underlying datastore whenever possible.
39 AddBlocks(bs []blocks.Block) ([]*cid.Cid, error)
40 +
41 GetBlock(ctx context.Context, c *cid.Cid) (blocks.Block, error)
33 - GetBlocks(ctx context.Context, ks []*cid.Cid) <-chan blocks.Block
42 DeleteBlock(o blocks.Block) error
43 +
44 + // GetBlocks does a batch request for the given cids, returning blocks as
45 + // they are found, in no particular order.
46 + GetBlocks(ctx context.Context, ks []*cid.Cid) <-chan blocks.Block
47 +
48 Close() error
49 }
50
repo/repo.go
+17
@@ -16,24 +16,41 @@ var (
16 ErrApiNotRunning = errors.New("api not running")
17 )
18
19 +// Repo represents all persistent data of a given ipfs node.
20 type Repo interface {
21 + // Config returns the ipfs configuration file from the repo. Changes made
22 + // to the returned config are not automatically persisted.
23 Config() (*config.Config, error)
24 +
25 + // BackupConfig creates a backup of the current configuration file using
26 + // the given prefix for naming.
27 BackupConfig(prefix string) (string, error)
28 +
29 + // SetConfig persists the given configuration struct to storage.
30 SetConfig(*config.Config) error
31
32 + // SetConfigKey sets the given key-value pair within the config and persists it to storage.
33 SetConfigKey(key string, value interface{}) error
34 +
35 + // GetConfigKey reads the value for the given key from the configuration in storage.
36 GetConfigKey(key string) (interface{}, error)
37
38 + // Datastore returns a reference to the configured data storage backend.
39 Datastore() Datastore
40 +
41 + // GetStorageUsage returns the number of bytes stored.
42 GetStorageUsage() (uint64, error)
43
44 + // Keystore returns a reference to the key management interface.
45 Keystore() keystore.Keystore
46
47 + // FileManager returns a reference to the filestore file manager.
48 FileManager() *filestore.FileManager
49
50 // SetAPIAddr sets the API address in the repo.
51 SetAPIAddr(addr ma.Multiaddr) error
52
53 + // SwarmKey returns the configured shared symmetric key for the private networks feature.
54 SwarmKey() ([]byte, error)
55
56 io.Closer