diff --git a/.gx/lastpubver b/.gx/lastpubver index 0067830..72ed71a 100644 --- a/.gx/lastpubver +++ b/.gx/lastpubver @@ -1 +1 @@ -0.0.20: Qmeg56ecxRnVv7VWViMrDeEMoBHaNFMs4vQnyQrJ79Zz7i +0.1.0: QmeMussyD8s3fQ3pM19ZsfbxvomEqPV9FvczLMWyBDYSnS diff --git a/arc_cache.go b/arc_cache.go index 4339bb5..78e3135 100644 --- a/arc_cache.go +++ b/arc_cache.go @@ -35,7 +35,7 @@ func newARCCachedBS(ctx context.Context, bs Blockstore, lruSize int) (*arccache, return c, nil } -func (b *arccache) DeleteBlock(k *cid.Cid) error { +func (b *arccache) DeleteBlock(k cid.Cid) error { if has, _, ok := b.hasCached(k); ok && !has { return ErrNotFound } @@ -53,10 +53,10 @@ func (b *arccache) DeleteBlock(k *cid.Cid) error { // if ok == false has is inconclusive // if ok == true then has respons to question: is it contained -func (b *arccache) hasCached(k *cid.Cid) (has bool, size int, ok bool) { +func (b *arccache) hasCached(k cid.Cid) (has bool, size int, ok bool) { b.total.Inc() - if k == nil { - log.Error("nil cid in arccache") + if !k.Defined() { + log.Error("undefined cid in arccache") // Return cache invalid so the call to blockstore happens // in case of invalid key and correct error is created. return false, -1, false @@ -75,7 +75,7 @@ func (b *arccache) hasCached(k *cid.Cid) (has bool, size int, ok bool) { return false, -1, false } -func (b *arccache) Has(k *cid.Cid) (bool, error) { +func (b *arccache) Has(k cid.Cid) (bool, error) { if has, _, ok := b.hasCached(k); ok { return has, nil } @@ -87,7 +87,7 @@ func (b *arccache) Has(k *cid.Cid) (bool, error) { return has, nil } -func (b *arccache) GetSize(k *cid.Cid) (int, error) { +func (b *arccache) GetSize(k cid.Cid) (int, error) { if _, blockSize, ok := b.hasCached(k); ok { return blockSize, nil } @@ -100,9 +100,9 @@ func (b *arccache) GetSize(k *cid.Cid) (int, error) { return blockSize, err } -func (b *arccache) Get(k *cid.Cid) (blocks.Block, error) { - if k == nil { - log.Error("nil cid in arc cache") +func (b *arccache) Get(k cid.Cid) (blocks.Block, error) { + if !k.Defined() { + log.Error("undefined cid in arc cache") return nil, ErrNotFound } @@ -154,15 +154,15 @@ func (b *arccache) HashOnRead(enabled bool) { b.blockstore.HashOnRead(enabled) } -func (b *arccache) cacheHave(c *cid.Cid, have bool) { +func (b *arccache) cacheHave(c cid.Cid, have bool) { b.arc.Add(c.KeyString(), cacheHave(have)) } -func (b *arccache) cacheSize(c *cid.Cid, blockSize int) { +func (b *arccache) cacheSize(c cid.Cid, blockSize int) { b.arc.Add(c.KeyString(), cacheSize(blockSize)) } -func (b *arccache) AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error) { +func (b *arccache) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) { return b.blockstore.AllKeysChan(ctx) } diff --git a/arc_cache_test.go b/arc_cache_test.go index 2f80819..facbf34 100644 --- a/arc_cache_test.go +++ b/arc_cache_test.go @@ -153,7 +153,7 @@ func TestArcCreationFailure(t *testing.T) { func TestInvalidKey(t *testing.T) { arc, _, _ := createStores(t) - bl, err := arc.Get(nil) + bl, err := arc.Get(cid.Cid{}) if bl != nil { t.Fatal("blocks should be nil") diff --git a/blockstore.go b/blockstore.go index 4dd670c..6bb8e39 100644 --- a/blockstore.go +++ b/blockstore.go @@ -32,12 +32,12 @@ var ErrNotFound = errors.New("blockstore: block not found") // Blockstore wraps a Datastore block-centered methods and provides a layer // of abstraction which allows to add different caching strategies. type Blockstore interface { - DeleteBlock(*cid.Cid) error - Has(*cid.Cid) (bool, error) - Get(*cid.Cid) (blocks.Block, error) + DeleteBlock(cid.Cid) error + Has(cid.Cid) (bool, error) + Get(cid.Cid) (blocks.Block, error) // GetSize returns the CIDs mapped BlockSize - GetSize(*cid.Cid) (int, error) + GetSize(cid.Cid) (int, error) // Put puts a given block to the underlying datastore Put(blocks.Block) error @@ -49,7 +49,7 @@ type Blockstore interface { // 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) + AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) // HashOnRead specifies if every read block should be // rehashed to make sure it matches its CID. @@ -114,9 +114,9 @@ func (bs *blockstore) HashOnRead(enabled bool) { bs.rehash = enabled } -func (bs *blockstore) Get(k *cid.Cid) (blocks.Block, error) { - if k == nil { - log.Error("nil cid in blockstore") +func (bs *blockstore) Get(k cid.Cid) (blocks.Block, error) { + if !k.Defined() { + log.Error("undefined cid in blockstore") return nil, ErrNotFound } @@ -173,11 +173,11 @@ func (bs *blockstore) PutMany(blocks []blocks.Block) error { return t.Commit() } -func (bs *blockstore) Has(k *cid.Cid) (bool, error) { +func (bs *blockstore) Has(k cid.Cid) (bool, error) { return bs.datastore.Has(dshelp.CidToDsKey(k)) } -func (bs *blockstore) GetSize(k *cid.Cid) (int, error) { +func (bs *blockstore) GetSize(k cid.Cid) (int, error) { bdata, err := bs.datastore.Get(dshelp.CidToDsKey(k)) if err == ds.ErrNotFound { return -1, ErrNotFound @@ -188,7 +188,7 @@ func (bs *blockstore) GetSize(k *cid.Cid) (int, error) { return len(bdata), nil } -func (bs *blockstore) DeleteBlock(k *cid.Cid) error { +func (bs *blockstore) DeleteBlock(k cid.Cid) error { err := bs.datastore.Delete(dshelp.CidToDsKey(k)) if err == ds.ErrNotFound { return ErrNotFound @@ -200,7 +200,7 @@ func (bs *blockstore) DeleteBlock(k *cid.Cid) error { // this is very simplistic, in the future, take dsq.Query as a param? // // AllKeysChan respects context. -func (bs *blockstore) AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error) { +func (bs *blockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) { // KeysOnly, because that would be _a lot_ of data. q := dsq.Query{KeysOnly: true} @@ -209,7 +209,7 @@ func (bs *blockstore) AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error) return nil, err } - output := make(chan *cid.Cid, dsq.KeysOnlyBufSize) + output := make(chan cid.Cid, dsq.KeysOnlyBufSize) go func() { defer func() { res.Close() // ensure exit (signals early exit, too) diff --git a/blockstore_test.go b/blockstore_test.go index ae71b54..d0fa739 100644 --- a/blockstore_test.go +++ b/blockstore_test.go @@ -29,7 +29,7 @@ func TestGetWhenKeyNotPresent(t *testing.T) { func TestGetWhenKeyIsNil(t *testing.T) { bs := NewBlockstore(ds_sync.MutexWrap(ds.NewMapDatastore())) - _, err := bs.Get(nil) + _, err := bs.Get(cid.Cid{}) if err != ErrNotFound { t.Fail() } @@ -113,13 +113,13 @@ func TestHashOnRead(t *testing.T) { } } -func newBlockStoreWithKeys(t *testing.T, d ds.Datastore, N int) (Blockstore, []*cid.Cid) { +func newBlockStoreWithKeys(t *testing.T, d ds.Datastore, N int) (Blockstore, []cid.Cid) { if d == nil { d = ds.NewMapDatastore() } bs := NewBlockstore(ds_sync.MutexWrap(d)) - keys := make([]*cid.Cid, N) + keys := make([]cid.Cid, N) for i := 0; i < N; i++ { block := blocks.NewBlock([]byte(fmt.Sprintf("some data %d", i))) err := bs.Put(block) @@ -131,8 +131,8 @@ func newBlockStoreWithKeys(t *testing.T, d ds.Datastore, N int) (Blockstore, []* return bs, keys } -func collect(ch <-chan *cid.Cid) []*cid.Cid { - var keys []*cid.Cid +func collect(ch <-chan cid.Cid) []cid.Cid { + var keys []cid.Cid for k := range ch { keys = append(keys, k) } @@ -217,7 +217,7 @@ func TestAllKeysRespectsContext(t *testing.T) { } -func expectMatches(t *testing.T, expect, actual []*cid.Cid) { +func expectMatches(t *testing.T, expect, actual []cid.Cid) { if len(expect) != len(actual) { t.Errorf("expect and actual differ: %d != %d", len(expect), len(actual)) diff --git a/bloom_cache.go b/bloom_cache.go index 7e11689..c58120c 100644 --- a/bloom_cache.go +++ b/bloom_cache.go @@ -97,7 +97,7 @@ func (b *bloomcache) Rebuild(ctx context.Context) { atomic.StoreInt32(&b.active, 1) } -func (b *bloomcache) DeleteBlock(k *cid.Cid) error { +func (b *bloomcache) DeleteBlock(k cid.Cid) error { if has, ok := b.hasCached(k); ok && !has { return ErrNotFound } @@ -107,10 +107,10 @@ func (b *bloomcache) DeleteBlock(k *cid.Cid) error { // if ok == false has is inconclusive // if ok == true then has respons to question: is it contained -func (b *bloomcache) hasCached(k *cid.Cid) (has bool, ok bool) { +func (b *bloomcache) hasCached(k cid.Cid) (has bool, ok bool) { b.total.Inc() - if k == nil { - log.Error("nil cid in bloom cache") + if !k.Defined() { + log.Error("undefined in bloom cache") // Return cache invalid so call to blockstore // in case of invalid key is forwarded deeper return false, false @@ -125,7 +125,7 @@ func (b *bloomcache) hasCached(k *cid.Cid) (has bool, ok bool) { return false, false } -func (b *bloomcache) Has(k *cid.Cid) (bool, error) { +func (b *bloomcache) Has(k cid.Cid) (bool, error) { if has, ok := b.hasCached(k); ok { return has, nil } @@ -133,11 +133,11 @@ func (b *bloomcache) Has(k *cid.Cid) (bool, error) { return b.blockstore.Has(k) } -func (b *bloomcache) GetSize(k *cid.Cid) (int, error) { +func (b *bloomcache) GetSize(k cid.Cid) (int, error) { return b.blockstore.GetSize(k) } -func (b *bloomcache) Get(k *cid.Cid) (blocks.Block, error) { +func (b *bloomcache) Get(k cid.Cid) (blocks.Block, error) { if has, ok := b.hasCached(k); ok && !has { return nil, ErrNotFound } @@ -173,7 +173,7 @@ func (b *bloomcache) HashOnRead(enabled bool) { b.blockstore.HashOnRead(enabled) } -func (b *bloomcache) AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error) { +func (b *bloomcache) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) { return b.blockstore.AllKeysChan(ctx) } diff --git a/idstore.go b/idstore.go index a1ef4d6..2a5bf84 100644 --- a/idstore.go +++ b/idstore.go @@ -17,7 +17,7 @@ func NewIdStore(bs Blockstore) Blockstore { return &idstore{bs} } -func extractContents(k *cid.Cid) (bool, []byte) { +func extractContents(k cid.Cid) (bool, []byte) { dmh, err := mh.Decode(k.Hash()) if err != nil || dmh.Code != mh.ID { return false, nil @@ -25,7 +25,7 @@ func extractContents(k *cid.Cid) (bool, []byte) { return true, dmh.Digest } -func (b *idstore) DeleteBlock(k *cid.Cid) error { +func (b *idstore) DeleteBlock(k cid.Cid) error { isId, _ := extractContents(k) if isId { return nil @@ -33,7 +33,7 @@ func (b *idstore) DeleteBlock(k *cid.Cid) error { return b.bs.DeleteBlock(k) } -func (b *idstore) Has(k *cid.Cid) (bool, error) { +func (b *idstore) Has(k cid.Cid) (bool, error) { isId, _ := extractContents(k) if isId { return true, nil @@ -41,7 +41,7 @@ func (b *idstore) Has(k *cid.Cid) (bool, error) { return b.bs.Has(k) } -func (b *idstore) GetSize(k *cid.Cid) (int, error) { +func (b *idstore) GetSize(k cid.Cid) (int, error) { isId, bdata := extractContents(k) if isId { return len(bdata), nil @@ -49,7 +49,7 @@ func (b *idstore) GetSize(k *cid.Cid) (int, error) { return b.bs.GetSize(k) } -func (b *idstore) Get(k *cid.Cid) (blocks.Block, error) { +func (b *idstore) Get(k cid.Cid) (blocks.Block, error) { isId, bdata := extractContents(k) if isId { return blocks.NewBlockWithCid(bdata, k) @@ -81,6 +81,6 @@ func (b *idstore) HashOnRead(enabled bool) { b.bs.HashOnRead(enabled) } -func (b *idstore) AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error) { +func (b *idstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) { return b.bs.AllKeysChan(ctx) } diff --git a/package.json b/package.json index 03c640e..bfe3e6a 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,9 @@ "gxDependencies": [ { "author": "stebalien", - "hash": "QmWAzSEoqZ6xU6pu8yL8e5WaMb7wtbfbhhN4p1DknUPtr3", + "hash": "QmRcHuYzAyswytBuMF78rj3LTChYszomRFXNg4685ZN1WM", "name": "go-block-format", - "version": "0.1.11" + "version": "0.2.0" }, { "author": "jbenet", @@ -33,15 +33,15 @@ }, { "author": "whyrusleeping", - "hash": "QmZFbDTY9jfSBms2MchvYM9oYRbAF19K7Pby47yDBfpPrb", + "hash": "QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7", "name": "go-cid", - "version": "0.8.0" + "version": "0.9.0" }, { "author": "hector", - "hash": "Qmf1xGr3SyBpiPp3ZDuKkYMh4gnRk9K4QnbL17kstnf35h", + "hash": "QmXejiSr776HgKLEGSs7unW7GT82AgfMbQX5crfSybGU8b", "name": "go-ipfs-ds-help", - "version": "0.0.10" + "version": "0.1.0" }, { "author": "kubuxu", @@ -60,6 +60,6 @@ "license": "MIT", "name": "go-ipfs-blockstore", "releaseCmd": "git commit -a -m \"gx publish $VERSION\"", - "version": "0.0.20" + "version": "0.1.0" }