Make Golint happy in the blocks submodule.
This has required changing the order of some parameters and adding HashOnRead to the Blockstore interface (which I have in turn added to all the wrapper implementations). License: MIT Signed-off-by: Hector Sanjuan <hector@protocol.ai>
Hector Sanjuan committed
Mar 24, 2017 at 16:36 UTC
3b6216b239d1295c7561bbb8eb641f039e56af06
15 files changed
+149
-55
blocks/blocks.go
+16
-6
@@ -1,5 +1,6 @@
1
-// package blocks contains the lowest level of IPFS data structures,
2
-// the raw block with a checksum.
1
+// Package blocks contains the lowest level of IPFS data structures.
2
+// A block is raw data accompanied by a CID. The CID contains the multihash
3
+// corresponding to the block.
4
package blocks
5
6
import (
@@ -11,8 +12,11 @@ import (
12
mh "gx/ipfs/QmbZ6Cee2uHjG7hf19qLHppgKDRtaG4CVtMzdmK9VCVqLu/go-multihash"
13
)
14
14
-var ErrWrongHash = errors.New("data did not match given hash!")
15
+// ErrWrongHash is returned when the Cid of a block is not the expected
16
+// according to the contents. It is currently used only when debugging.
17
+var ErrWrongHash = errors.New("data did not match given hash")
18
19
+// Block provides abstraction for blocks implementations.
20
type Block interface {
21
RawData() []byte
22
Cid() *cid.Cid
@@ -20,7 +24,8 @@ type Block interface {
24
Loggable() map[string]interface{}
25
}
26
23
-// Block is a singular block of data in ipfs
27
+// A BasicBlock is a singular block of data in ipfs. It implements the Block
28
+// interface.
29
type BasicBlock struct {
30
cid *cid.Cid
31
data []byte
@@ -32,9 +37,9 @@ func NewBlock(data []byte) *BasicBlock {
37
return &BasicBlock{data: data, cid: cid.NewCidV0(u.Hash(data))}
38
}
39
35
-// NewBlockWithHash creates a new block when the hash of the data
40
+// NewBlockWithCid creates a new block when the hash of the data
41
// is already known, this is used to save time in situations where
37
-// we are able to be confident that the data is correct
42
+// we are able to be confident that the data is correct.
43
func NewBlockWithCid(data []byte, c *cid.Cid) (*BasicBlock, error) {
44
if u.Debug {
45
chkc, err := c.Prefix().Sum(data)
@@ -49,22 +54,27 @@ func NewBlockWithCid(data []byte, c *cid.Cid) (*BasicBlock, error) {
54
return &BasicBlock{data: data, cid: c}, nil
55
}
56
57
+// Multihash returns the hash contained in the block CID.
58
func (b *BasicBlock) Multihash() mh.Multihash {
59
return b.cid.Hash()
60
}
61
62
+// RawData returns the block raw contents as a byte slice.
63
func (b *BasicBlock) RawData() []byte {
64
return b.data
65
}
66
67
+// Cid returns the content identifier of the block.
68
func (b *BasicBlock) Cid() *cid.Cid {
69
return b.cid
70
}
71
72
+// String provides a human-readable representation of the block CID.
73
func (b *BasicBlock) String() string {
74
return fmt.Sprintf("[Block %s]", b.Cid())
75
}
76
77
+// Loggable returns a go-log loggable item.
78
func (b *BasicBlock) Loggable() map[string]interface{} {
79
return map[string]interface{}{
80
"block": b.Cid().String(),
blocks/blockstore/arc_cache.go
+7
@@ -11,6 +11,9 @@ import (
11
lru "gx/ipfs/QmVYxfoJQiZijTgPNHCHgHELvQpbsJNTg6Crmc3dQkj3yy/golang-lru"
12
)
13
14
+// arccache wraps a BlockStore with an Adaptive Replacement Cache (ARC) for
15
+// block Cids. This provides block access-time improvements, allowing
16
+// to short-cut many searches without query-ing the underlying datastore.
17
type arccache struct {
18
arc *lru.ARCCache
19
blockstore Blockstore
@@ -128,6 +131,10 @@ func (b *arccache) PutMany(bs []blocks.Block) error {
131
return nil
132
}
133
134
+func (b *arccache) HashOnRead(enabled bool) {
135
+ b.blockstore.HashOnRead(enabled)
136
+}
137
+
138
func (b *arccache) addCache(c *cid.Cid, has bool) {
139
b.arc.Add(c.KeyString(), has)
140
}
blocks/blockstore/arc_cache_test.go
+5
-6
@@ -13,25 +13,24 @@ import (
13
14
var exampleBlock = blocks.NewBlock([]byte("foo"))
15
16
-func testArcCached(bs Blockstore, ctx context.Context) (*arccache, error) {
16
+func testArcCached(ctx context.Context, bs Blockstore) (*arccache, error) {
17
if ctx == nil {
18
ctx = context.TODO()
19
}
20
opts := DefaultCacheOpts()
21
opts.HasBloomFilterSize = 0
22
opts.HasBloomFilterHashes = 0
23
- bbs, err := CachedBlockstore(bs, ctx, opts)
23
+ bbs, err := CachedBlockstore(ctx, bs, opts)
24
if err == nil {
25
return bbs.(*arccache), nil
26
- } else {
27
- return nil, err
26
}
27
+ return nil, err
28
}
29
31
-func createStores(t *testing.T) (*arccache, *blockstore, *callbackDatastore) {
30
+func createStores(t *testing.T) (*arccache, Blockstore, *callbackDatastore) {
31
cd := &callbackDatastore{f: func() {}, ds: ds.NewMapDatastore()}
32
bs := NewBlockstore(syncds.MutexWrap(cd))
34
- arc, err := testArcCached(bs, nil)
33
+ arc, err := testArcCached(nil, bs)
34
if err != nil {
35
t.Fatal(err)
36
}
blocks/blockstore/blockstore.go
+35
-12
@@ -1,4 +1,4 @@
1
-// package blockstore implements a thin wrapper over a datastore, giving a
1
+// Package blockstore implements a thin wrapper over a datastore, giving a
2
// clean interface for Getting and Putting block objects.
3
package blockstore
4
@@ -23,22 +23,36 @@ var log = logging.Logger("blockstore")
23
// BlockPrefix namespaces blockstore datastores
24
var BlockPrefix = ds.NewKey("blocks")
25
26
-var ValueTypeMismatch = errors.New("the retrieved value is not a Block")
26
+// ErrValueTypeMismatch is an error returned when the item retrieved from
27
+// the datatstore is not a block.
28
+var ErrValueTypeMismatch = errors.New("the retrieved value is not a Block")
29
+
30
+// ErrHashMismatch is an error returned when the hash of a block
31
+// is different than expected.
32
var ErrHashMismatch = errors.New("block in storage has different hash than requested")
33
34
+// ErrNotFound is an error returned when a block is not found.
35
var ErrNotFound = errors.New("blockstore: block not found")
36
31
-// Blockstore wraps a Datastore
37
+// Blockstore wraps a Datastore block-centered methods and provides a layer
38
+// of abstraction which allows to add different caching strategies.
39
type Blockstore interface {
40
DeleteBlock(*cid.Cid) error
41
Has(*cid.Cid) (bool, error)
42
Get(*cid.Cid) (blocks.Block, error)
43
Put(blocks.Block) error
44
PutMany([]blocks.Block) error
38
-
45
+ // AllKeysChan returns a channel from which
46
+ // the CIDs in the Blockstore can be read. It should respect
47
+ // the given context, closing the channel if it becomes Done.
48
AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error)
49
+ // HashOnRead specifies if every read block should be
50
+ // rehashed to make sure it matches its CID.
51
+ HashOnRead(enabled bool)
52
}
53
54
+// GCLocker abstract functionality to lock a blockstore when performing
55
+// garbage-collection operations.
56
type GCLocker interface {
57
// GCLock locks the blockstore for garbage collection. No operations
58
// that expect to finish with a pin should ocurr simultaneously.
@@ -56,11 +70,15 @@ type GCLocker interface {
70
GCRequested() bool
71
}
72
73
+// GCBlockstore is a blockstore that can safely run garbage-collection
74
+// operations.
75
type GCBlockstore interface {
76
Blockstore
77
GCLocker
78
}
79
80
+// NewGCBlockstore returns a default implementation of GCBlockstore
81
+// using the given Blockstore and GCLocker.
82
func NewGCBlockstore(bs Blockstore, gcl GCLocker) GCBlockstore {
83
return gcBlockstore{bs, gcl}
84
}
@@ -70,7 +88,9 @@ type gcBlockstore struct {
88
GCLocker
89
}
90
73
-func NewBlockstore(d ds.Batching) *blockstore {
91
+// NewBlockstore returns a default Blockstore implementation
92
+// using the provided datastore.Batching backend.
93
+func NewBlockstore(d ds.Batching) Blockstore {
94
var dsb ds.Batching
95
dd := dsns.Wrap(d, BlockPrefix)
96
dsb = dd
@@ -108,7 +128,7 @@ func (bs *blockstore) Get(k *cid.Cid) (blocks.Block, error) {
128
}
129
bdata, ok := maybeData.([]byte)
130
if !ok {
111
- return nil, ValueTypeMismatch
131
+ return nil, ErrValueTypeMismatch
132
}
133
134
if bs.rehash {
@@ -122,9 +142,8 @@ func (bs *blockstore) Get(k *cid.Cid) (blocks.Block, error) {
142
}
143
144
return blocks.NewBlockWithCid(bdata, rbcid)
125
- } else {
126
- return blocks.NewBlockWithCid(bdata, k)
145
}
146
+ return blocks.NewBlockWithCid(bdata, k)
147
}
148
149
func (bs *blockstore) Put(block blocks.Block) error {
@@ -162,8 +181,8 @@ func (bs *blockstore) Has(k *cid.Cid) (bool, error) {
181
return bs.datastore.Has(dshelp.CidToDsKey(k))
182
}
183
165
-func (s *blockstore) DeleteBlock(k *cid.Cid) error {
166
- err := s.datastore.Delete(dshelp.CidToDsKey(k))
184
+func (bs *blockstore) DeleteBlock(k *cid.Cid) error {
185
+ err := bs.datastore.Delete(dshelp.CidToDsKey(k))
186
if err == ds.ErrNotFound {
187
return ErrNotFound
188
}
@@ -173,7 +192,7 @@ func (s *blockstore) DeleteBlock(k *cid.Cid) error {
192
// AllKeysChan runs a query for keys from the blockstore.
193
// this is very simplistic, in the future, take dsq.Query as a param?
194
//
176
-// AllKeysChan respects context
195
+// AllKeysChan respects context.
196
func (bs *blockstore) AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error) {
197
198
// KeysOnly, because that would be _a lot_ of data.
@@ -220,7 +239,9 @@ func (bs *blockstore) AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error)
239
return output, nil
240
}
241
223
-func NewGCLocker() *gclocker {
242
+// NewGCLocker returns a default implementation of
243
+// GCLocker using standard [RW] mutexes.
244
+func NewGCLocker() GCLocker {
245
return &gclocker{}
246
}
247
@@ -230,6 +251,8 @@ type gclocker struct {
251
gcreqlk sync.Mutex
252
}
253
254
+// Unlocker represents an object which can Unlock
255
+// something.
256
type Unlocker interface {
257
Unlock()
258
}
blocks/blockstore/blockstore_test.go
+2
-2
@@ -186,7 +186,7 @@ func TestAllKeysRespectsContext(t *testing.T) {
186
187
}
188
189
-func TestValueTypeMismatch(t *testing.T) {
189
+func TestErrValueTypeMismatch(t *testing.T) {
190
block := blocks.NewBlock([]byte("some data"))
191
192
datastore := ds.NewMapDatastore()
@@ -196,7 +196,7 @@ func TestValueTypeMismatch(t *testing.T) {
196
blockstore := NewBlockstore(ds_sync.MutexWrap(datastore))
197
198
_, err := blockstore.Get(block.Cid())
199
- if err != ValueTypeMismatch {
199
+ if err != ErrValueTypeMismatch {
200
t.Fatal(err)
201
}
202
}
blocks/blockstore/bloom_cache.go
+8
-3
@@ -12,9 +12,10 @@ import (
12
bloom "gx/ipfs/QmeiMCBkYHxkDkDfnDadzz4YxY5ruL5Pj499essE4vRsGM/bbloom"
13
)
14
15
-// bloomCached returns Blockstore that caches Has requests using Bloom filter
16
-// Size is size of bloom filter in bytes
17
-func bloomCached(bs Blockstore, ctx context.Context, bloomSize, hashCount int) (*bloomcache, error) {
15
+// bloomCached returns a Blockstore that caches Has requests using a Bloom
16
+// filter. bloomSize is size of bloom filter in bytes. hashCount specifies the
17
+// number of hashing functions in the bloom filter (usually known as k).
18
+func bloomCached(ctx context.Context, bs Blockstore, bloomSize, hashCount int) (*bloomcache, error) {
19
bl, err := bloom.New(float64(bloomSize), float64(hashCount))
20
if err != nil {
21
return nil, err
@@ -165,6 +166,10 @@ func (b *bloomcache) PutMany(bs []blocks.Block) error {
166
return nil
167
}
168
169
+func (b *bloomcache) HashOnRead(enabled bool) {
170
+ b.blockstore.HashOnRead(enabled)
171
+}
172
+
173
func (b *bloomcache) AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error) {
174
return b.blockstore.AllKeysChan(ctx)
175
}
blocks/blockstore/bloom_cache_test.go
+7
-8
@@ -14,18 +14,17 @@ import (
14
syncds "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore/sync"
15
)
16
17
-func testBloomCached(bs Blockstore, ctx context.Context) (*bloomcache, error) {
17
+func testBloomCached(ctx context.Context, bs Blockstore) (*bloomcache, error) {
18
if ctx == nil {
19
- ctx = context.TODO()
19
+ ctx = context.Background()
20
}
21
opts := DefaultCacheOpts()
22
opts.HasARCCacheSize = 0
23
- bbs, err := CachedBlockstore(bs, ctx, opts)
23
+ bbs, err := CachedBlockstore(ctx, bs, opts)
24
if err == nil {
25
return bbs.(*bloomcache), nil
26
- } else {
27
- return nil, err
26
}
27
+ return nil, err
28
}
29
30
func TestPutManyAddsToBloom(t *testing.T) {
@@ -34,7 +33,7 @@ func TestPutManyAddsToBloom(t *testing.T) {
33
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
34
defer cancel()
35
37
- cachedbs, err := testBloomCached(bs, ctx)
36
+ cachedbs, err := testBloomCached(ctx, bs)
37
38
select {
39
case <-cachedbs.rebuildChan:
@@ -65,7 +64,7 @@ func TestPutManyAddsToBloom(t *testing.T) {
64
65
func TestReturnsErrorWhenSizeNegative(t *testing.T) {
66
bs := NewBlockstore(syncds.MutexWrap(ds.NewMapDatastore()))
68
- _, err := bloomCached(bs, context.TODO(), -1, 1)
67
+ _, err := bloomCached(context.Background(), bs, -1, 1)
68
if err == nil {
69
t.Fail()
70
}
@@ -80,7 +79,7 @@ func TestHasIsBloomCached(t *testing.T) {
79
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
80
defer cancel()
81
83
- cachedbs, err := testBloomCached(bs, ctx)
82
+ cachedbs, err := testBloomCached(ctx, bs)
83
if err != nil {
84
t.Fatal(err)
85
}
blocks/blockstore/caching.go
+9
-3
@@ -7,6 +7,7 @@ import (
7
"gx/ipfs/QmRg1gKTHzc3CZXSKzem8aR4E3TubFhbgXwfVuWnSK5CC5/go-metrics-interface"
8
)
9
10
+// CacheOpts wraps options for CachedBlockStore().
11
// Next to each option is it aproximate memory usage per unit
12
type CacheOpts struct {
13
HasBloomFilterSize int // 1 byte
@@ -14,6 +15,7 @@ type CacheOpts struct {
15
HasARCCacheSize int // 32 bytes
16
}
17
18
+// DefaultCacheOpts returns a CacheOpts initialized with default values.
19
func DefaultCacheOpts() CacheOpts {
20
return CacheOpts{
21
HasBloomFilterSize: 512 << 10,
@@ -22,8 +24,12 @@ func DefaultCacheOpts() CacheOpts {
24
}
25
}
26
25
-func CachedBlockstore(bs Blockstore,
26
- ctx context.Context, opts CacheOpts) (cbs Blockstore, err error) {
27
+// CachedBlockstore returns a blockstore wrapped in an ARCCache and
28
+// then in a bloom filter cache, if the options indicate it.
29
+func CachedBlockstore(
30
+ ctx context.Context,
31
+ bs Blockstore,
32
+ opts CacheOpts) (cbs Blockstore, err error) {
33
cbs = bs
34
35
if opts.HasBloomFilterSize < 0 || opts.HasBloomFilterHashes < 0 ||
@@ -42,7 +48,7 @@ func CachedBlockstore(bs Blockstore,
48
}
49
if opts.HasBloomFilterSize != 0 {
50
// *8 because of bytes to bits conversion
45
- cbs, err = bloomCached(cbs, ctx, opts.HasBloomFilterSize*8, opts.HasBloomFilterHashes)
51
+ cbs, err = bloomCached(ctx, cbs, opts.HasBloomFilterSize*8, opts.HasBloomFilterHashes)
52
}
53
54
return cbs, err
blocks/blockstore/util/remove.go
+18
-3
@@ -1,13 +1,15 @@
1
-package blockstore_util
1
+// Package blockstoreutil provides utility functions for Blockstores.
2
+package blockstoreutil
3
4
import (
5
"fmt"
6
"io"
7
7
- bs "github.com/ipfs/go-ipfs/blocks/blockstore"
8
- "github.com/ipfs/go-ipfs/pin"
8
ds "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
9
cid "gx/ipfs/QmV5gPoRsjN1Gid3LMdNZTyfCtP2DsvqEbMAmz82RmmiGk/go-cid"
10
+
11
+ bs "github.com/ipfs/go-ipfs/blocks/blockstore"
12
+ "github.com/ipfs/go-ipfs/pin"
13
)
14
15
// RemovedBlock is used to respresent the result of removing a block.
@@ -21,12 +23,17 @@ type RemovedBlock struct {
23
Error string `json:",omitempty"`
24
}
25
26
+// RmBlocksOpts is used to wrap options for RmBlocks().
27
type RmBlocksOpts struct {
28
Prefix string
29
Quiet bool
30
Force bool
31
}
32
33
+// RmBlocks removes the blocks provided in the cids slice.
34
+// It returns a channel where objects of type RemovedBlock are placed, when
35
+// not using the Quiet option. Block removal is asynchronous and will
36
+// skip any pinned blocks.
37
func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, cids []*cid.Cid, opts RmBlocksOpts) (<-chan interface{}, error) {
38
// make the channel large enough to hold any result to avoid
39
// blocking while holding the GCLock
@@ -53,6 +60,11 @@ func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, cids []*cid.Cid, opts RmB
60
return out, nil
61
}
62
63
+// FilterPinned takes a slice of Cids and returns it with the pinned Cids
64
+// removed. If a Cid is pinned, it will place RemovedBlock objects in the given
65
+// out channel, with an error which indicates that the Cid is pinned.
66
+// This function is used in RmBlocks to filter out any blocks which are not
67
+// to be removed (because they are pinned).
68
func FilterPinned(pins pin.Pinner, out chan<- interface{}, cids []*cid.Cid) []*cid.Cid {
69
stillOkay := make([]*cid.Cid, 0, len(cids))
70
res, err := pins.CheckIfPinned(cids...)
@@ -73,6 +85,9 @@ func FilterPinned(pins pin.Pinner, out chan<- interface{}, cids []*cid.Cid) []*c
85
return stillOkay
86
}
87
88
+// ProcRmOutput takes the channel returned by RmBlocks and writes
89
+// to stdout/stderr according to the RemovedBlock objects received in
90
+// that channel.
91
func ProcRmOutput(in <-chan interface{}, sout io.Writer, serr io.Writer) error {
92
someFailed := false
93
for res := range in {
blocks/blocksutil/block_generator.go
+10
@@ -1,20 +1,30 @@
1
+// Package blocksutil provides utility functions for working
2
+// with Blocks.
3
package blocksutil
4
5
import "github.com/ipfs/go-ipfs/blocks"
6
7
+// NewBlockGenerator returns an object capable of
8
+// producing blocks.
9
func NewBlockGenerator() BlockGenerator {
10
return BlockGenerator{}
11
}
12
13
+// BlockGenerator generates BasicBlocks on demand.
14
+// For each instace of BlockGenerator,
15
+// each new block is different from the previous,
16
+// although two different instances will produce the same.
17
type BlockGenerator struct {
18
seq int
19
}
20
21
+// Next generates a new BasicBlock.
22
func (bg *BlockGenerator) Next() *blocks.BasicBlock {
23
bg.seq++
24
return blocks.NewBlock([]byte(string(bg.seq)))
25
}
26
27
+// Blocks generates as many BasicBlocks as specified by n.
28
func (bg *BlockGenerator) Blocks(n int) []*blocks.BasicBlock {
29
blocks := make([]*blocks.BasicBlock, 0)
30
for i := 0; i < n; i++ {
blocks/bloom/filter.go
+11
-5
@@ -1,15 +1,17 @@
1
-// package bloom implements a simple bloom filter.
1
+// Package bloom implements a simple bloom filter.
2
package bloom
3
4
import (
5
"encoding/binary"
6
"errors"
7
// Non crypto hash, because speed
8
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/mtchavez/jenkins"
8
"gx/ipfs/QmeWQMDa5dSdP4n8WDeoY5z8L2EKVqF4ZvK4VEHsLqXsGu/hamming"
9
"hash"
10
+
11
+ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/mtchavez/jenkins"
12
)
13
14
+// A Filter represents a bloom filter.
15
type Filter interface {
16
Add([]byte)
17
Find([]byte) bool
@@ -17,6 +19,8 @@ type Filter interface {
19
HammingDistance(Filter) (int, error)
20
}
21
22
+// NewFilter creates a new bloom Filter with the given
23
+// size. k (the number of hash functions), is hardcoded to 3.
24
func NewFilter(size int) Filter {
25
return &filter{
26
hash: jenkins.New(),
@@ -31,6 +35,8 @@ type filter struct {
35
k int
36
}
37
38
+// BasicFilter calls NewFilter with a bloom filter size of
39
+// 2048 bytes.
40
func BasicFilter() Filter {
41
return NewFilter(2048)
42
}
@@ -84,11 +90,11 @@ func (f *filter) Merge(o Filter) (Filter, error) {
90
}
91
92
if len(casfil.filter) != len(f.filter) {
87
- return nil, errors.New("filter lengths must match!")
93
+ return nil, errors.New("filter lengths must match")
94
}
95
96
if casfil.k != f.k {
91
- return nil, errors.New("filter k-values must match!")
97
+ return nil, errors.New("filter k-values must match")
98
}
99
100
nfilt := new(filter)
@@ -110,7 +116,7 @@ func (f *filter) HammingDistance(o Filter) (int, error) {
116
}
117
118
if len(f.filter) != len(casfil.filter) {
113
- return 0, errors.New("filter lengths must match!")
119
+ return 0, errors.New("filter lengths must match")
120
}
121
122
acc := 0
blocks/set/set.go
+12
-4
@@ -1,24 +1,30 @@
1
-// package set contains various different types of 'BlockSet's
1
+// Package set defines the BlockSet interface which provides
2
+// abstraction for sets of Cids.
3
+// It provides a default implementation using cid.Set.
4
package set
5
6
import (
5
- "github.com/ipfs/go-ipfs/blocks/bloom"
7
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
8
cid "gx/ipfs/QmV5gPoRsjN1Gid3LMdNZTyfCtP2DsvqEbMAmz82RmmiGk/go-cid"
9
+
10
+ "github.com/ipfs/go-ipfs/blocks/bloom"
11
)
12
13
var log = logging.Logger("blockset")
14
12
-// BlockSet represents a mutable set of keyed blocks
15
+// BlockSet represents a mutable set of blocks CIDs.
16
type BlockSet interface {
17
AddBlock(*cid.Cid)
18
RemoveBlock(*cid.Cid)
19
HasKey(*cid.Cid) bool
20
+ // GetBloomFilter creates and returns a bloom filter to which
21
+ // all the CIDs in the set have been added.
22
GetBloomFilter() bloom.Filter
18
-
23
GetKeys() []*cid.Cid
24
}
25
26
+// SimpleSetFromKeys returns a default implementation of BlockSet
27
+// using cid.Set. The given keys are added to the set.
28
func SimpleSetFromKeys(keys []*cid.Cid) BlockSet {
29
sbs := &simpleBlockSet{blocks: cid.NewSet()}
30
for _, k := range keys {
@@ -27,6 +33,8 @@ func SimpleSetFromKeys(keys []*cid.Cid) BlockSet {
33
return sbs
34
}
35
36
+// NewSimpleBlockSet returns a new empty default implementation
37
+// of BlockSet using cid.Set.
38
func NewSimpleBlockSet() BlockSet {
39
return &simpleBlockSet{blocks: cid.NewSet()}
40
}
core/builder.go
+1
-1
@@ -184,7 +184,7 @@ func setupNode(ctx context.Context, n *IpfsNode, cfg *BuildCfg) error {
184
opts.HasBloomFilterSize = 0
185
}
186
187
- cbs, err := bstore.CachedBlockstore(bs, ctx, opts)
187
+ cbs, err := bstore.CachedBlockstore(ctx, bs, opts)
188
if err != nil {
189
return err
190
}
exchange/bitswap/testutils.go
+3
-2
@@ -94,8 +94,9 @@ func Session(ctx context.Context, net tn.Network, p testutil.Identity) Instance
94
adapter := net.Adapter(p)
95
dstore := ds_sync.MutexWrap(datastore2.WithDelay(ds.NewMapDatastore(), bsdelay))
96
97
- bstore, err := blockstore.CachedBlockstore(blockstore.NewBlockstore(
98
- ds_sync.MutexWrap(dstore)), ctx, blockstore.DefaultCacheOpts())
97
+ bstore, err := blockstore.CachedBlockstore(ctx,
98
+ blockstore.NewBlockstore(ds_sync.MutexWrap(dstore)),
99
+ blockstore.DefaultCacheOpts())
100
if err != nil {
101
panic(err.Error()) // FIXME perhaps change signature and return error.
102
}
filestore/filestore.go
+5
@@ -199,4 +199,9 @@ func (f *Filestore) PutMany(bs []blocks.Block) error {
199
return nil
200
}
201
202
+// HashOnRead calls blockstore.HashOnRead.
203
+func (f *Filestore) HashOnRead(enabled bool) {
204
+ f.bs.HashOnRead(enabled)
205
+}
206
+
207
var _ blockstore.Blockstore = (*Filestore)(nil)