From a44081aa75c7effce06dd3dd2951d4f1b4638316 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Thu, 18 Nov 2021 17:50:25 -0800 Subject: [PATCH] WIP: updating to new datastore/blockstore code with contexts --- blockstore/api.go | 20 +++--- blockstore/badger/blockstore.go | 18 ++--- blockstore/badger/blockstore_test.go | 14 ++-- blockstore/badger/blockstore_test_suite.go | 58 ++++++++++------- blockstore/blockstore.go | 12 ++-- blockstore/buffered.go | 52 +++++++-------- blockstore/discard.go | 28 ++++---- blockstore/fallback.go | 10 +-- blockstore/idstore.go | 36 +++++----- blockstore/ipfs.go | 24 +++---- blockstore/mem.go | 20 +++--- blockstore/sync.go | 34 +++++----- blockstore/timed.go | 42 ++++++------ blockstore/timed_test.go | 24 +++---- blockstore/union.go | 36 +++++----- blockstore/union_test.go | 40 ++++++------ go.mod | 37 +++++------ go.sum | 76 +++++++++++++--------- lib/backupds/backupds_test.go | 7 +- lib/backupds/datastore.go | 49 +++++++------- lib/backupds/log.go | 10 ++- lib/backupds/read.go | 7 +- 22 files changed, 345 insertions(+), 309 deletions(-) diff --git a/blockstore/api.go b/blockstore/api.go index 6715b4766..348c0f84e 100644 --- a/blockstore/api.go +++ b/blockstore/api.go @@ -25,35 +25,35 @@ func NewAPIBlockstore(cio ChainIO) Blockstore { return Adapt(bs) // return an adapted blockstore. } -func (a *apiBlockstore) DeleteBlock(cid.Cid) error { +func (a *apiBlockstore) DeleteBlock(context.Context, cid.Cid) error { return xerrors.New("not supported") } -func (a *apiBlockstore) Has(c cid.Cid) (bool, error) { - return a.api.ChainHasObj(context.TODO(), c) +func (a *apiBlockstore) Has(ctx context.Context, c cid.Cid) (bool, error) { + return a.api.ChainHasObj(ctx, c) } -func (a *apiBlockstore) Get(c cid.Cid) (blocks.Block, error) { - bb, err := a.api.ChainReadObj(context.TODO(), c) +func (a *apiBlockstore) Get(ctx context.Context, c cid.Cid) (blocks.Block, error) { + bb, err := a.api.ChainReadObj(ctx, c) if err != nil { return nil, err } return blocks.NewBlockWithCid(bb, c) } -func (a *apiBlockstore) GetSize(c cid.Cid) (int, error) { - bb, err := a.api.ChainReadObj(context.TODO(), c) +func (a *apiBlockstore) GetSize(ctx context.Context, c cid.Cid) (int, error) { + bb, err := a.api.ChainReadObj(ctx, c) if err != nil { return 0, err } return len(bb), nil } -func (a *apiBlockstore) Put(blocks.Block) error { +func (a *apiBlockstore) Put(context.Context, blocks.Block) error { return xerrors.New("not supported") } -func (a *apiBlockstore) PutMany([]blocks.Block) error { +func (a *apiBlockstore) PutMany(context.Context, []blocks.Block) error { return xerrors.New("not supported") } @@ -61,6 +61,6 @@ func (a *apiBlockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) return nil, xerrors.New("not supported") } -func (a *apiBlockstore) HashOnRead(enabled bool) { +func (a *apiBlockstore) HashOnRead(ctx context.Context, enabled bool) { return } diff --git a/blockstore/badger/blockstore.go b/blockstore/badger/blockstore.go index a0b51d8df..e81e5838c 100644 --- a/blockstore/badger/blockstore.go +++ b/blockstore/badger/blockstore.go @@ -525,7 +525,7 @@ func (b *Blockstore) Size() (int64, error) { // View implements blockstore.Viewer, which leverages zero-copy read-only // access to values. -func (b *Blockstore) View(cid cid.Cid, fn func([]byte) error) error { +func (b *Blockstore) View(ctx context.Context, cid cid.Cid, fn func([]byte) error) error { if err := b.access(); err != nil { return err } @@ -552,7 +552,7 @@ func (b *Blockstore) View(cid cid.Cid, fn func([]byte) error) error { } // Has implements Blockstore.Has. -func (b *Blockstore) Has(cid cid.Cid) (bool, error) { +func (b *Blockstore) Has(ctx context.Context, cid cid.Cid) (bool, error) { if err := b.access(); err != nil { return false, err } @@ -582,7 +582,7 @@ func (b *Blockstore) Has(cid cid.Cid) (bool, error) { } // Get implements Blockstore.Get. -func (b *Blockstore) Get(cid cid.Cid) (blocks.Block, error) { +func (b *Blockstore) Get(ctx context.Context, cid cid.Cid) (blocks.Block, error) { if !cid.Defined() { return nil, blockstore.ErrNotFound } @@ -619,7 +619,7 @@ func (b *Blockstore) Get(cid cid.Cid) (blocks.Block, error) { } // GetSize implements Blockstore.GetSize. -func (b *Blockstore) GetSize(cid cid.Cid) (int, error) { +func (b *Blockstore) GetSize(ctx context.Context, cid cid.Cid) (int, error) { if err := b.access(); err != nil { return 0, err } @@ -652,7 +652,7 @@ func (b *Blockstore) GetSize(cid cid.Cid) (int, error) { } // Put implements Blockstore.Put. -func (b *Blockstore) Put(block blocks.Block) error { +func (b *Blockstore) Put(ctx context.Context, block blocks.Block) error { if err := b.access(); err != nil { return err } @@ -691,7 +691,7 @@ func (b *Blockstore) Put(block blocks.Block) error { } // PutMany implements Blockstore.PutMany. -func (b *Blockstore) PutMany(blocks []blocks.Block) error { +func (b *Blockstore) PutMany(ctx context.Context, blocks []blocks.Block) error { if err := b.access(); err != nil { return err } @@ -755,7 +755,7 @@ func (b *Blockstore) PutMany(blocks []blocks.Block) error { } // DeleteBlock implements Blockstore.DeleteBlock. -func (b *Blockstore) DeleteBlock(cid cid.Cid) error { +func (b *Blockstore) DeleteBlock(ctx context.Context, cid cid.Cid) error { if err := b.access(); err != nil { return err } @@ -774,7 +774,7 @@ func (b *Blockstore) DeleteBlock(cid cid.Cid) error { }) } -func (b *Blockstore) DeleteMany(cids []cid.Cid) error { +func (b *Blockstore) DeleteMany(ctx context.Context, cids []cid.Cid) error { if err := b.access(); err != nil { return err } @@ -927,7 +927,7 @@ func (b *Blockstore) ForEachKey(f func(cid.Cid) error) error { // HashOnRead implements Blockstore.HashOnRead. It is not supported by this // blockstore. -func (b *Blockstore) HashOnRead(_ bool) { +func (b *Blockstore) HashOnRead(ctx context.Context, _ bool) { log.Warnf("called HashOnRead on badger blockstore; function not supported; ignoring") } diff --git a/blockstore/badger/blockstore_test.go b/blockstore/badger/blockstore_test.go index d8ef5241b..db87262d4 100644 --- a/blockstore/badger/blockstore_test.go +++ b/blockstore/badger/blockstore_test.go @@ -2,6 +2,7 @@ package badgerbs import ( "bytes" + "context" "fmt" "io/ioutil" "os" @@ -98,6 +99,7 @@ func openBlockstore(optsSupplier func(path string) Options) func(tb testing.TB, } func testMove(t *testing.T, optsF func(string) Options) { + ctx := context.TODO() basePath, err := ioutil.TempDir("", "") if err != nil { t.Fatal(err) @@ -122,7 +124,7 @@ func testMove(t *testing.T, optsF func(string) Options) { // add some blocks for i := 0; i < 10; i++ { blk := blocks.NewBlock([]byte(fmt.Sprintf("some data %d", i))) - err := db.Put(blk) + err := db.Put(ctx, blk) if err != nil { t.Fatal(err) } @@ -132,7 +134,7 @@ func testMove(t *testing.T, optsF func(string) Options) { // delete some of them for i := 5; i < 10; i++ { c := have[i].Cid() - err := db.DeleteBlock(c) + err := db.DeleteBlock(ctx, c) if err != nil { t.Fatal(err) } @@ -145,7 +147,7 @@ func testMove(t *testing.T, optsF func(string) Options) { g.Go(func() error { for i := 10; i < 1000; i++ { blk := blocks.NewBlock([]byte(fmt.Sprintf("some data %d", i))) - err := db.Put(blk) + err := db.Put(ctx, blk) if err != nil { return err } @@ -165,7 +167,7 @@ func testMove(t *testing.T, optsF func(string) Options) { // now check that we have all the blocks in have and none in the deleted lists checkBlocks := func() { for _, blk := range have { - has, err := db.Has(blk.Cid()) + has, err := db.Has(ctx, blk.Cid()) if err != nil { t.Fatal(err) } @@ -174,7 +176,7 @@ func testMove(t *testing.T, optsF func(string) Options) { t.Fatal("missing block") } - blk2, err := db.Get(blk.Cid()) + blk2, err := db.Get(ctx, blk.Cid()) if err != nil { t.Fatal(err) } @@ -185,7 +187,7 @@ func testMove(t *testing.T, optsF func(string) Options) { } for _, c := range deleted { - has, err := db.Has(c) + has, err := db.Has(ctx, c) if err != nil { t.Fatal(err) } diff --git a/blockstore/badger/blockstore_test_suite.go b/blockstore/badger/blockstore_test_suite.go index 93be82ac8..b155f479a 100644 --- a/blockstore/badger/blockstore_test_suite.go +++ b/blockstore/badger/blockstore_test_suite.go @@ -44,28 +44,31 @@ func (s *Suite) RunTests(t *testing.T, prefix string) { } func (s *Suite) TestGetWhenKeyNotPresent(t *testing.T) { + ctx := context.TODO() bs, _ := s.NewBlockstore(t) if c, ok := bs.(io.Closer); ok { defer func() { require.NoError(t, c.Close()) }() } c := cid.NewCidV0(u.Hash([]byte("stuff"))) - bl, err := bs.Get(c) + bl, err := bs.Get(ctx, c) require.Nil(t, bl) require.Equal(t, blockstore.ErrNotFound, err) } func (s *Suite) TestGetWhenKeyIsNil(t *testing.T) { + ctx := context.TODO() bs, _ := s.NewBlockstore(t) if c, ok := bs.(io.Closer); ok { defer func() { require.NoError(t, c.Close()) }() } - _, err := bs.Get(cid.Undef) + _, err := bs.Get(ctx, cid.Undef) require.Equal(t, blockstore.ErrNotFound, err) } func (s *Suite) TestPutThenGetBlock(t *testing.T) { + ctx := context.TODO() bs, _ := s.NewBlockstore(t) if c, ok := bs.(io.Closer); ok { defer func() { require.NoError(t, c.Close()) }() @@ -73,15 +76,16 @@ func (s *Suite) TestPutThenGetBlock(t *testing.T) { orig := blocks.NewBlock([]byte("some data")) - err := bs.Put(orig) + err := bs.Put(ctx, orig) require.NoError(t, err) - fetched, err := bs.Get(orig.Cid()) + fetched, err := bs.Get(ctx, orig.Cid()) require.NoError(t, err) require.Equal(t, orig.RawData(), fetched.RawData()) } func (s *Suite) TestHas(t *testing.T) { + ctx := context.TODO() bs, _ := s.NewBlockstore(t) if c, ok := bs.(io.Closer); ok { defer func() { require.NoError(t, c.Close()) }() @@ -89,19 +93,20 @@ func (s *Suite) TestHas(t *testing.T) { orig := blocks.NewBlock([]byte("some data")) - err := bs.Put(orig) + err := bs.Put(ctx, orig) require.NoError(t, err) - ok, err := bs.Has(orig.Cid()) + ok, err := bs.Has(ctx, orig.Cid()) require.NoError(t, err) require.True(t, ok) - ok, err = bs.Has(blocks.NewBlock([]byte("another thing")).Cid()) + ok, err = bs.Has(ctx, blocks.NewBlock([]byte("another thing")).Cid()) require.NoError(t, err) require.False(t, ok) } func (s *Suite) TestCidv0v1(t *testing.T) { + ctx := context.TODO() bs, _ := s.NewBlockstore(t) if c, ok := bs.(io.Closer); ok { defer func() { require.NoError(t, c.Close()) }() @@ -109,15 +114,17 @@ func (s *Suite) TestCidv0v1(t *testing.T) { orig := blocks.NewBlock([]byte("some data")) - err := bs.Put(orig) + err := bs.Put(ctx, orig) require.NoError(t, err) - fetched, err := bs.Get(cid.NewCidV1(cid.DagProtobuf, orig.Cid().Hash())) + fetched, err := bs.Get(ctx, cid.NewCidV1(cid.DagProtobuf, orig.Cid().Hash())) require.NoError(t, err) require.Equal(t, orig.RawData(), fetched.RawData()) } func (s *Suite) TestPutThenGetSizeBlock(t *testing.T) { + ctx := context.TODO() + bs, _ := s.NewBlockstore(t) if c, ok := bs.(io.Closer); ok { defer func() { require.NoError(t, c.Close()) }() @@ -127,21 +134,21 @@ func (s *Suite) TestPutThenGetSizeBlock(t *testing.T) { missingBlock := blocks.NewBlock([]byte("missingBlock")) emptyBlock := blocks.NewBlock([]byte{}) - err := bs.Put(block) + err := bs.Put(ctx, block) require.NoError(t, err) - blockSize, err := bs.GetSize(block.Cid()) + blockSize, err := bs.GetSize(ctx, block.Cid()) require.NoError(t, err) require.Len(t, block.RawData(), blockSize) - err = bs.Put(emptyBlock) + err = bs.Put(ctx, emptyBlock) require.NoError(t, err) - emptySize, err := bs.GetSize(emptyBlock.Cid()) + emptySize, err := bs.GetSize(ctx, emptyBlock.Cid()) require.NoError(t, err) require.Zero(t, emptySize) - missingSize, err := bs.GetSize(missingBlock.Cid()) + missingSize, err := bs.GetSize(ctx, missingBlock.Cid()) require.Equal(t, blockstore.ErrNotFound, err) require.Equal(t, -1, missingSize) } @@ -203,6 +210,7 @@ func (s *Suite) TestDoubleClose(t *testing.T) { } func (s *Suite) TestReopenPutGet(t *testing.T) { + ctx := context.TODO() bs, path := s.NewBlockstore(t) c, ok := bs.(io.Closer) if !ok { @@ -210,7 +218,7 @@ func (s *Suite) TestReopenPutGet(t *testing.T) { } orig := blocks.NewBlock([]byte("some data")) - err := bs.Put(orig) + err := bs.Put(ctx, orig) require.NoError(t, err) err = c.Close() @@ -219,7 +227,7 @@ func (s *Suite) TestReopenPutGet(t *testing.T) { bs, err = s.OpenBlockstore(t, path) require.NoError(t, err) - fetched, err := bs.Get(orig.Cid()) + fetched, err := bs.Get(ctx, orig.Cid()) require.NoError(t, err) require.Equal(t, orig.RawData(), fetched.RawData()) @@ -228,6 +236,7 @@ func (s *Suite) TestReopenPutGet(t *testing.T) { } func (s *Suite) TestPutMany(t *testing.T) { + ctx := context.TODO() bs, _ := s.NewBlockstore(t) if c, ok := bs.(io.Closer); ok { defer func() { require.NoError(t, c.Close()) }() @@ -238,15 +247,15 @@ func (s *Suite) TestPutMany(t *testing.T) { blocks.NewBlock([]byte("foo2")), blocks.NewBlock([]byte("foo3")), } - err := bs.PutMany(blks) + err := bs.PutMany(ctx, blks) require.NoError(t, err) for _, blk := range blks { - fetched, err := bs.Get(blk.Cid()) + fetched, err := bs.Get(ctx, blk.Cid()) require.NoError(t, err) require.Equal(t, blk.RawData(), fetched.RawData()) - ok, err := bs.Has(blk.Cid()) + ok, err := bs.Has(ctx, blk.Cid()) require.NoError(t, err) require.True(t, ok) } @@ -259,6 +268,7 @@ func (s *Suite) TestPutMany(t *testing.T) { } func (s *Suite) TestDelete(t *testing.T) { + ctx := context.TODO() bs, _ := s.NewBlockstore(t) if c, ok := bs.(io.Closer); ok { defer func() { require.NoError(t, c.Close()) }() @@ -269,10 +279,10 @@ func (s *Suite) TestDelete(t *testing.T) { blocks.NewBlock([]byte("foo2")), blocks.NewBlock([]byte("foo3")), } - err := bs.PutMany(blks) + err := bs.PutMany(ctx, blks) require.NoError(t, err) - err = bs.DeleteBlock(blks[1].Cid()) + err = bs.DeleteBlock(ctx, blks[1].Cid()) require.NoError(t, err) ch, err := bs.AllKeysChan(context.Background()) @@ -285,17 +295,17 @@ func (s *Suite) TestDelete(t *testing.T) { cid.NewCidV1(cid.Raw, blks[2].Cid().Hash()), }) - has, err := bs.Has(blks[1].Cid()) + has, err := bs.Has(ctx, blks[1].Cid()) require.NoError(t, err) require.False(t, has) - } func insertBlocks(t *testing.T, bs blockstore.BasicBlockstore, count int) []cid.Cid { + ctx := context.TODO() keys := make([]cid.Cid, count) for i := 0; i < count; i++ { block := blocks.NewBlock([]byte(fmt.Sprintf("some data %d", i))) - err := bs.Put(block) + err := bs.Put(ctx, block) require.NoError(t, err) // NewBlock assigns a CIDv0; we convert it to CIDv1 because that's what // the store returns. diff --git a/blockstore/blockstore.go b/blockstore/blockstore.go index 8ede31eb9..409c100cf 100644 --- a/blockstore/blockstore.go +++ b/blockstore/blockstore.go @@ -1,6 +1,8 @@ package blockstore import ( + "context" + cid "github.com/ipfs/go-cid" ds "github.com/ipfs/go-datastore" logging "github.com/ipfs/go-log/v2" @@ -27,7 +29,7 @@ type BasicBlockstore = blockstore.Blockstore type Viewer = blockstore.Viewer type BatchDeleter interface { - DeleteMany(cids []cid.Cid) error + DeleteMany(ctx context.Context, cids []cid.Cid) error } // BlockstoreIterator is a trait for efficient iteration @@ -93,17 +95,17 @@ type adaptedBlockstore struct { var _ Blockstore = (*adaptedBlockstore)(nil) -func (a *adaptedBlockstore) View(cid cid.Cid, callback func([]byte) error) error { - blk, err := a.Get(cid) +func (a *adaptedBlockstore) View(ctx context.Context, cid cid.Cid, callback func([]byte) error) error { + blk, err := a.Get(ctx, cid) if err != nil { return err } return callback(blk.RawData()) } -func (a *adaptedBlockstore) DeleteMany(cids []cid.Cid) error { +func (a *adaptedBlockstore) DeleteMany(ctx context.Context, cids []cid.Cid) error { for _, cid := range cids { - err := a.DeleteBlock(cid) + err := a.DeleteBlock(ctx, cid) if err != nil { return err } diff --git a/blockstore/buffered.go b/blockstore/buffered.go index 5d3d38f78..846156fc8 100644 --- a/blockstore/buffered.go +++ b/blockstore/buffered.go @@ -88,34 +88,34 @@ func (bs *BufferedBlockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, return out, nil } -func (bs *BufferedBlockstore) DeleteBlock(c cid.Cid) error { - if err := bs.read.DeleteBlock(c); err != nil { +func (bs *BufferedBlockstore) DeleteBlock(ctx context.Context, c cid.Cid) error { + if err := bs.read.DeleteBlock(ctx, c); err != nil { return err } - return bs.write.DeleteBlock(c) + return bs.write.DeleteBlock(ctx, c) } -func (bs *BufferedBlockstore) DeleteMany(cids []cid.Cid) error { - if err := bs.read.DeleteMany(cids); err != nil { +func (bs *BufferedBlockstore) DeleteMany(ctx context.Context, cids []cid.Cid) error { + if err := bs.read.DeleteMany(ctx, cids); err != nil { return err } - return bs.write.DeleteMany(cids) + return bs.write.DeleteMany(ctx, cids) } -func (bs *BufferedBlockstore) View(c cid.Cid, callback func([]byte) error) error { +func (bs *BufferedBlockstore) View(ctx context.Context, c cid.Cid, callback func([]byte) error) error { // both stores are viewable. - if err := bs.write.View(c, callback); err == ErrNotFound { + if err := bs.write.View(ctx, c, callback); err == ErrNotFound { // not found in write blockstore; fall through. } else { return err // propagate errors, or nil, i.e. found. } - return bs.read.View(c, callback) + return bs.read.View(ctx, c, callback) } -func (bs *BufferedBlockstore) Get(c cid.Cid) (block.Block, error) { - if out, err := bs.write.Get(c); err != nil { +func (bs *BufferedBlockstore) Get(ctx context.Context, c cid.Cid) (block.Block, error) { + if out, err := bs.write.Get(ctx, c); err != nil { if err != ErrNotFound { return nil, err } @@ -123,20 +123,20 @@ func (bs *BufferedBlockstore) Get(c cid.Cid) (block.Block, error) { return out, nil } - return bs.read.Get(c) + return bs.read.Get(ctx, c) } -func (bs *BufferedBlockstore) GetSize(c cid.Cid) (int, error) { - s, err := bs.read.GetSize(c) +func (bs *BufferedBlockstore) GetSize(ctx context.Context, c cid.Cid) (int, error) { + s, err := bs.read.GetSize(ctx, c) if err == ErrNotFound || s == 0 { - return bs.write.GetSize(c) + return bs.write.GetSize(ctx, c) } return s, err } -func (bs *BufferedBlockstore) Put(blk block.Block) error { - has, err := bs.read.Has(blk.Cid()) // TODO: consider dropping this check +func (bs *BufferedBlockstore) Put(ctx context.Context, blk block.Block) error { + has, err := bs.read.Has(ctx, blk.Cid()) // TODO: consider dropping this check if err != nil { return err } @@ -145,11 +145,11 @@ func (bs *BufferedBlockstore) Put(blk block.Block) error { return nil } - return bs.write.Put(blk) + return bs.write.Put(ctx, blk) } -func (bs *BufferedBlockstore) Has(c cid.Cid) (bool, error) { - has, err := bs.write.Has(c) +func (bs *BufferedBlockstore) Has(ctx context.Context, c cid.Cid) (bool, error) { + has, err := bs.write.Has(ctx, c) if err != nil { return false, err } @@ -157,16 +157,16 @@ func (bs *BufferedBlockstore) Has(c cid.Cid) (bool, error) { return true, nil } - return bs.read.Has(c) + return bs.read.Has(ctx, c) } -func (bs *BufferedBlockstore) HashOnRead(hor bool) { - bs.read.HashOnRead(hor) - bs.write.HashOnRead(hor) +func (bs *BufferedBlockstore) HashOnRead(ctx context.Context, hor bool) { + bs.read.HashOnRead(ctx, hor) + bs.write.HashOnRead(ctx, hor) } -func (bs *BufferedBlockstore) PutMany(blks []block.Block) error { - return bs.write.PutMany(blks) +func (bs *BufferedBlockstore) PutMany(ctx context.Context, blks []block.Block) error { + return bs.write.PutMany(ctx, blks) } func (bs *BufferedBlockstore) Read() Blockstore { diff --git a/blockstore/discard.go b/blockstore/discard.go index afd0651bc..e377d427b 100644 --- a/blockstore/discard.go +++ b/blockstore/discard.go @@ -18,39 +18,39 @@ func NewDiscardStore(bs Blockstore) Blockstore { return &discardstore{bs: bs} } -func (b *discardstore) Has(cid cid.Cid) (bool, error) { - return b.bs.Has(cid) +func (b *discardstore) Has(ctx context.Context, cid cid.Cid) (bool, error) { + return b.bs.Has(ctx, cid) } -func (b *discardstore) HashOnRead(hor bool) { - b.bs.HashOnRead(hor) +func (b *discardstore) HashOnRead(ctx context.Context, hor bool) { + b.bs.HashOnRead(ctx, hor) } -func (b *discardstore) Get(cid cid.Cid) (blocks.Block, error) { - return b.bs.Get(cid) +func (b *discardstore) Get(ctx context.Context, cid cid.Cid) (blocks.Block, error) { + return b.bs.Get(ctx, cid) } -func (b *discardstore) GetSize(cid cid.Cid) (int, error) { - return b.bs.GetSize(cid) +func (b *discardstore) GetSize(ctx context.Context, cid cid.Cid) (int, error) { + return b.bs.GetSize(ctx, cid) } -func (b *discardstore) View(cid cid.Cid, f func([]byte) error) error { - return b.bs.View(cid, f) +func (b *discardstore) View(ctx context.Context, cid cid.Cid, f func([]byte) error) error { + return b.bs.View(ctx, cid, f) } -func (b *discardstore) Put(blk blocks.Block) error { +func (b *discardstore) Put(ctx context.Context, blk blocks.Block) error { return nil } -func (b *discardstore) PutMany(blks []blocks.Block) error { +func (b *discardstore) PutMany(ctx context.Context, blks []blocks.Block) error { return nil } -func (b *discardstore) DeleteBlock(cid cid.Cid) error { +func (b *discardstore) DeleteBlock(ctx context.Context, cid cid.Cid) error { return nil } -func (b *discardstore) DeleteMany(cids []cid.Cid) error { +func (b *discardstore) DeleteMany(ctx context.Context, cids []cid.Cid) error { return nil } diff --git a/blockstore/fallback.go b/blockstore/fallback.go index 5f220f941..3d0acd36d 100644 --- a/blockstore/fallback.go +++ b/blockstore/fallback.go @@ -71,14 +71,14 @@ func (fbs *FallbackStore) getFallback(c cid.Cid) (blocks.Block, error) { // chain bitswap puts blocks in temp blockstore which is cleaned up // every few min (to drop any messages we fetched but don't want) // in this case we want to keep this block around - if err := fbs.Put(b); err != nil { + if err := fbs.Put(ctx, b); err != nil { return nil, xerrors.Errorf("persisting fallback-fetched block: %w", err) } return b, nil } -func (fbs *FallbackStore) Get(c cid.Cid) (blocks.Block, error) { - b, err := fbs.Blockstore.Get(c) +func (fbs *FallbackStore) Get(ctx context.Context, c cid.Cid) (blocks.Block, error) { + b, err := fbs.Blockstore.Get(ctx, c) switch err { case nil: return b, nil @@ -89,8 +89,8 @@ func (fbs *FallbackStore) Get(c cid.Cid) (blocks.Block, error) { } } -func (fbs *FallbackStore) GetSize(c cid.Cid) (int, error) { - sz, err := fbs.Blockstore.GetSize(c) +func (fbs *FallbackStore) GetSize(ctx context.Context, c cid.Cid) (int, error) { + sz, err := fbs.Blockstore.GetSize(ctx, c) switch err { case nil: return sz, nil diff --git a/blockstore/idstore.go b/blockstore/idstore.go index e6148ff04..d0553158b 100644 --- a/blockstore/idstore.go +++ b/blockstore/idstore.go @@ -38,7 +38,7 @@ func decodeCid(cid cid.Cid) (inline bool, data []byte, err error) { return false, nil, err } -func (b *idstore) Has(cid cid.Cid) (bool, error) { +func (b *idstore) Has(ctx context.Context, cid cid.Cid) (bool, error) { inline, _, err := decodeCid(cid) if err != nil { return false, xerrors.Errorf("error decoding Cid: %w", err) @@ -48,10 +48,10 @@ func (b *idstore) Has(cid cid.Cid) (bool, error) { return true, nil } - return b.bs.Has(cid) + return b.bs.Has(ctx, cid) } -func (b *idstore) Get(cid cid.Cid) (blocks.Block, error) { +func (b *idstore) Get(ctx context.Context, cid cid.Cid) (blocks.Block, error) { inline, data, err := decodeCid(cid) if err != nil { return nil, xerrors.Errorf("error decoding Cid: %w", err) @@ -61,10 +61,10 @@ func (b *idstore) Get(cid cid.Cid) (blocks.Block, error) { return blocks.NewBlockWithCid(data, cid) } - return b.bs.Get(cid) + return b.bs.Get(ctx, cid) } -func (b *idstore) GetSize(cid cid.Cid) (int, error) { +func (b *idstore) GetSize(ctx context.Context, cid cid.Cid) (int, error) { inline, data, err := decodeCid(cid) if err != nil { return 0, xerrors.Errorf("error decoding Cid: %w", err) @@ -74,10 +74,10 @@ func (b *idstore) GetSize(cid cid.Cid) (int, error) { return len(data), err } - return b.bs.GetSize(cid) + return b.bs.GetSize(ctx, cid) } -func (b *idstore) View(cid cid.Cid, cb func([]byte) error) error { +func (b *idstore) View(ctx context.Context, cid cid.Cid, cb func([]byte) error) error { inline, data, err := decodeCid(cid) if err != nil { return xerrors.Errorf("error decoding Cid: %w", err) @@ -87,10 +87,10 @@ func (b *idstore) View(cid cid.Cid, cb func([]byte) error) error { return cb(data) } - return b.bs.View(cid, cb) + return b.bs.View(ctx, cid, cb) } -func (b *idstore) Put(blk blocks.Block) error { +func (b *idstore) Put(ctx context.Context, blk blocks.Block) error { inline, _, err := decodeCid(blk.Cid()) if err != nil { return xerrors.Errorf("error decoding Cid: %w", err) @@ -100,10 +100,10 @@ func (b *idstore) Put(blk blocks.Block) error { return nil } - return b.bs.Put(blk) + return b.bs.Put(ctx, blk) } -func (b *idstore) PutMany(blks []blocks.Block) error { +func (b *idstore) PutMany(ctx context.Context, blks []blocks.Block) error { toPut := make([]blocks.Block, 0, len(blks)) for _, blk := range blks { inline, _, err := decodeCid(blk.Cid()) @@ -118,13 +118,13 @@ func (b *idstore) PutMany(blks []blocks.Block) error { } if len(toPut) > 0 { - return b.bs.PutMany(toPut) + return b.bs.PutMany(ctx, toPut) } return nil } -func (b *idstore) DeleteBlock(cid cid.Cid) error { +func (b *idstore) DeleteBlock(ctx context.Context, cid cid.Cid) error { inline, _, err := decodeCid(cid) if err != nil { return xerrors.Errorf("error decoding Cid: %w", err) @@ -134,10 +134,10 @@ func (b *idstore) DeleteBlock(cid cid.Cid) error { return nil } - return b.bs.DeleteBlock(cid) + return b.bs.DeleteBlock(ctx, cid) } -func (b *idstore) DeleteMany(cids []cid.Cid) error { +func (b *idstore) DeleteMany(ctx context.Context, cids []cid.Cid) error { toDelete := make([]cid.Cid, 0, len(cids)) for _, cid := range cids { inline, _, err := decodeCid(cid) @@ -152,7 +152,7 @@ func (b *idstore) DeleteMany(cids []cid.Cid) error { } if len(toDelete) > 0 { - return b.bs.DeleteMany(toDelete) + return b.bs.DeleteMany(ctx, toDelete) } return nil @@ -162,8 +162,8 @@ func (b *idstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) { return b.bs.AllKeysChan(ctx) } -func (b *idstore) HashOnRead(enabled bool) { - b.bs.HashOnRead(enabled) +func (b *idstore) HashOnRead(ctx context.Context, enabled bool) { + b.bs.HashOnRead(ctx, enabled) } func (b *idstore) Close() error { diff --git a/blockstore/ipfs.go b/blockstore/ipfs.go index 51b4bd951..47662c651 100644 --- a/blockstore/ipfs.go +++ b/blockstore/ipfs.go @@ -79,12 +79,12 @@ func NewRemoteIPFSBlockstore(ctx context.Context, maddr multiaddr.Multiaddr, onl return Adapt(bs), nil } -func (i *IPFSBlockstore) DeleteBlock(cid cid.Cid) error { +func (i *IPFSBlockstore) DeleteBlock(ctx context.Context, cid cid.Cid) error { return xerrors.Errorf("not supported") } -func (i *IPFSBlockstore) Has(cid cid.Cid) (bool, error) { - _, err := i.offlineAPI.Block().Stat(i.ctx, path.IpldPath(cid)) +func (i *IPFSBlockstore) Has(ctx context.Context, cid cid.Cid) (bool, error) { + _, err := i.offlineAPI.Block().Stat(ctx, path.IpldPath(cid)) if err != nil { // The underlying client is running in Offline mode. // Stat() will fail with an err if the block isn't in the @@ -99,8 +99,8 @@ func (i *IPFSBlockstore) Has(cid cid.Cid) (bool, error) { return true, nil } -func (i *IPFSBlockstore) Get(cid cid.Cid) (blocks.Block, error) { - rd, err := i.api.Block().Get(i.ctx, path.IpldPath(cid)) +func (i *IPFSBlockstore) Get(ctx context.Context, cid cid.Cid) (blocks.Block, error) { + rd, err := i.api.Block().Get(ctx, path.IpldPath(cid)) if err != nil { return nil, xerrors.Errorf("getting ipfs block: %w", err) } @@ -113,8 +113,8 @@ func (i *IPFSBlockstore) Get(cid cid.Cid) (blocks.Block, error) { return blocks.NewBlockWithCid(data, cid) } -func (i *IPFSBlockstore) GetSize(cid cid.Cid) (int, error) { - st, err := i.api.Block().Stat(i.ctx, path.IpldPath(cid)) +func (i *IPFSBlockstore) GetSize(ctx context.Context, cid cid.Cid) (int, error) { + st, err := i.api.Block().Stat(ctx, path.IpldPath(cid)) if err != nil { return 0, xerrors.Errorf("getting ipfs block: %w", err) } @@ -122,23 +122,23 @@ func (i *IPFSBlockstore) GetSize(cid cid.Cid) (int, error) { return st.Size(), nil } -func (i *IPFSBlockstore) Put(block blocks.Block) error { +func (i *IPFSBlockstore) Put(ctx context.Context, block blocks.Block) error { mhd, err := multihash.Decode(block.Cid().Hash()) if err != nil { return err } - _, err = i.api.Block().Put(i.ctx, bytes.NewReader(block.RawData()), + _, err = i.api.Block().Put(ctx, bytes.NewReader(block.RawData()), options.Block.Hash(mhd.Code, mhd.Length), options.Block.Format(cid.CodecToStr[block.Cid().Type()])) return err } -func (i *IPFSBlockstore) PutMany(blocks []blocks.Block) error { +func (i *IPFSBlockstore) PutMany(ctx context.Context, blocks []blocks.Block) error { // TODO: could be done in parallel for _, block := range blocks { - if err := i.Put(block); err != nil { + if err := i.Put(ctx, block); err != nil { return err } } @@ -150,6 +150,6 @@ func (i *IPFSBlockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error return nil, xerrors.Errorf("not supported") } -func (i *IPFSBlockstore) HashOnRead(enabled bool) { +func (i *IPFSBlockstore) HashOnRead(ctx context.Context, enabled bool) { return // TODO: We could technically support this, but.. } diff --git a/blockstore/mem.go b/blockstore/mem.go index 8ea69d46a..a2655148f 100644 --- a/blockstore/mem.go +++ b/blockstore/mem.go @@ -15,24 +15,24 @@ func NewMemory() MemBlockstore { // MemBlockstore is a terminal blockstore that keeps blocks in memory. type MemBlockstore map[cid.Cid]blocks.Block -func (m MemBlockstore) DeleteBlock(k cid.Cid) error { +func (m MemBlockstore) DeleteBlock(ctx context.Context, k cid.Cid) error { delete(m, k) return nil } -func (m MemBlockstore) DeleteMany(ks []cid.Cid) error { +func (m MemBlockstore) DeleteMany(ctx context.Context, ks []cid.Cid) error { for _, k := range ks { delete(m, k) } return nil } -func (m MemBlockstore) Has(k cid.Cid) (bool, error) { +func (m MemBlockstore) Has(ctx context.Context, k cid.Cid) (bool, error) { _, ok := m[k] return ok, nil } -func (m MemBlockstore) View(k cid.Cid, callback func([]byte) error) error { +func (m MemBlockstore) View(ctx context.Context, k cid.Cid, callback func([]byte) error) error { b, ok := m[k] if !ok { return ErrNotFound @@ -40,7 +40,7 @@ func (m MemBlockstore) View(k cid.Cid, callback func([]byte) error) error { return callback(b.RawData()) } -func (m MemBlockstore) Get(k cid.Cid) (blocks.Block, error) { +func (m MemBlockstore) Get(ctx context.Context, k cid.Cid) (blocks.Block, error) { b, ok := m[k] if !ok { return nil, ErrNotFound @@ -49,7 +49,7 @@ func (m MemBlockstore) Get(k cid.Cid) (blocks.Block, error) { } // GetSize returns the CIDs mapped BlockSize -func (m MemBlockstore) GetSize(k cid.Cid) (int, error) { +func (m MemBlockstore) GetSize(ctx context.Context, k cid.Cid) (int, error) { b, ok := m[k] if !ok { return 0, ErrNotFound @@ -58,7 +58,7 @@ func (m MemBlockstore) GetSize(k cid.Cid) (int, error) { } // Put puts a given block to the underlying datastore -func (m MemBlockstore) Put(b blocks.Block) error { +func (m MemBlockstore) Put(ctx context.Context, b blocks.Block) error { // Convert to a basic block for safety, but try to reuse the existing // block if it's already a basic block. k := b.Cid() @@ -76,9 +76,9 @@ func (m MemBlockstore) Put(b blocks.Block) error { // PutMany puts a slice of blocks at the same time using batching // capabilities of the underlying datastore whenever possible. -func (m MemBlockstore) PutMany(bs []blocks.Block) error { +func (m MemBlockstore) PutMany(ctx context.Context, bs []blocks.Block) error { for _, b := range bs { - _ = m.Put(b) // can't fail + _ = m.Put(ctx, b) // can't fail } return nil } @@ -97,6 +97,6 @@ func (m MemBlockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) // HashOnRead specifies if every read block should be // rehashed to make sure it matches its CID. -func (m MemBlockstore) HashOnRead(enabled bool) { +func (m MemBlockstore) HashOnRead(ctx context.Context, enabled bool) { // no-op } diff --git a/blockstore/sync.go b/blockstore/sync.go index 848ccd19d..11a92359d 100644 --- a/blockstore/sync.go +++ b/blockstore/sync.go @@ -20,53 +20,53 @@ type SyncBlockstore struct { bs MemBlockstore // specifically use a memStore to save indirection overhead. } -func (m *SyncBlockstore) DeleteBlock(k cid.Cid) error { +func (m *SyncBlockstore) DeleteBlock(ctx context.Context, k cid.Cid) error { m.mu.Lock() defer m.mu.Unlock() - return m.bs.DeleteBlock(k) + return m.bs.DeleteBlock(ctx, k) } -func (m *SyncBlockstore) DeleteMany(ks []cid.Cid) error { +func (m *SyncBlockstore) DeleteMany(ctx context.Context, ks []cid.Cid) error { m.mu.Lock() defer m.mu.Unlock() - return m.bs.DeleteMany(ks) + return m.bs.DeleteMany(ctx, ks) } -func (m *SyncBlockstore) Has(k cid.Cid) (bool, error) { +func (m *SyncBlockstore) Has(ctx context.Context, k cid.Cid) (bool, error) { m.mu.RLock() defer m.mu.RUnlock() - return m.bs.Has(k) + return m.bs.Has(ctx, k) } -func (m *SyncBlockstore) View(k cid.Cid, callback func([]byte) error) error { +func (m *SyncBlockstore) View(ctx context.Context, k cid.Cid, callback func([]byte) error) error { m.mu.RLock() defer m.mu.RUnlock() - return m.bs.View(k, callback) + return m.bs.View(ctx, k, callback) } -func (m *SyncBlockstore) Get(k cid.Cid) (blocks.Block, error) { +func (m *SyncBlockstore) Get(ctx context.Context, k cid.Cid) (blocks.Block, error) { m.mu.RLock() defer m.mu.RUnlock() - return m.bs.Get(k) + return m.bs.Get(ctx, k) } -func (m *SyncBlockstore) GetSize(k cid.Cid) (int, error) { +func (m *SyncBlockstore) GetSize(ctx context.Context, k cid.Cid) (int, error) { m.mu.RLock() defer m.mu.RUnlock() - return m.bs.GetSize(k) + return m.bs.GetSize(ctx, k) } -func (m *SyncBlockstore) Put(b blocks.Block) error { +func (m *SyncBlockstore) Put(ctx context.Context, b blocks.Block) error { m.mu.Lock() defer m.mu.Unlock() - return m.bs.Put(b) + return m.bs.Put(ctx, b) } -func (m *SyncBlockstore) PutMany(bs []blocks.Block) error { +func (m *SyncBlockstore) PutMany(ctx context.Context, bs []blocks.Block) error { m.mu.Lock() defer m.mu.Unlock() - return m.bs.PutMany(bs) + return m.bs.PutMany(ctx, bs) } func (m *SyncBlockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) { @@ -76,6 +76,6 @@ func (m *SyncBlockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error return m.bs.AllKeysChan(ctx) } -func (m *SyncBlockstore) HashOnRead(enabled bool) { +func (m *SyncBlockstore) HashOnRead(ctx context.Context, enabled bool) { // noop } diff --git a/blockstore/timed.go b/blockstore/timed.go index b279943b6..4fee6b6dd 100644 --- a/blockstore/timed.go +++ b/blockstore/timed.go @@ -92,28 +92,28 @@ func (t *TimedCacheBlockstore) rotate() { t.mu.Unlock() } -func (t *TimedCacheBlockstore) Put(b blocks.Block) error { +func (t *TimedCacheBlockstore) Put(ctx context.Context, b blocks.Block) error { // Don't check the inactive set here. We want to keep this block for at // least one interval. t.mu.Lock() defer t.mu.Unlock() - return t.active.Put(b) + return t.active.Put(ctx, b) } -func (t *TimedCacheBlockstore) PutMany(bs []blocks.Block) error { +func (t *TimedCacheBlockstore) PutMany(ctx context.Context, bs []blocks.Block) error { t.mu.Lock() defer t.mu.Unlock() - return t.active.PutMany(bs) + return t.active.PutMany(ctx, bs) } -func (t *TimedCacheBlockstore) View(k cid.Cid, callback func([]byte) error) error { +func (t *TimedCacheBlockstore) View(ctx context.Context, k cid.Cid, callback func([]byte) error) error { // The underlying blockstore is always a "mem" blockstore so there's no difference, // from a performance perspective, between view & get. So we call Get to avoid // calling an arbitrary callback while holding a lock. t.mu.RLock() - block, err := t.active.Get(k) + block, err := t.active.Get(ctx, k) if err == ErrNotFound { - block, err = t.inactive.Get(k) + block, err = t.inactive.Get(ctx, k) } t.mu.RUnlock() @@ -123,51 +123,51 @@ func (t *TimedCacheBlockstore) View(k cid.Cid, callback func([]byte) error) erro return callback(block.RawData()) } -func (t *TimedCacheBlockstore) Get(k cid.Cid) (blocks.Block, error) { +func (t *TimedCacheBlockstore) Get(ctx context.Context, k cid.Cid) (blocks.Block, error) { t.mu.RLock() defer t.mu.RUnlock() - b, err := t.active.Get(k) + b, err := t.active.Get(ctx, k) if err == ErrNotFound { - b, err = t.inactive.Get(k) + b, err = t.inactive.Get(ctx, k) } return b, err } -func (t *TimedCacheBlockstore) GetSize(k cid.Cid) (int, error) { +func (t *TimedCacheBlockstore) GetSize(ctx context.Context, k cid.Cid) (int, error) { t.mu.RLock() defer t.mu.RUnlock() - size, err := t.active.GetSize(k) + size, err := t.active.GetSize(ctx, k) if err == ErrNotFound { - size, err = t.inactive.GetSize(k) + size, err = t.inactive.GetSize(ctx, k) } return size, err } -func (t *TimedCacheBlockstore) Has(k cid.Cid) (bool, error) { +func (t *TimedCacheBlockstore) Has(ctx context.Context, k cid.Cid) (bool, error) { t.mu.RLock() defer t.mu.RUnlock() - if has, err := t.active.Has(k); err != nil { + if has, err := t.active.Has(ctx, k); err != nil { return false, err } else if has { return true, nil } - return t.inactive.Has(k) + return t.inactive.Has(ctx, k) } -func (t *TimedCacheBlockstore) HashOnRead(_ bool) { +func (t *TimedCacheBlockstore) HashOnRead(ctx context.Context, _ bool) { // no-op } -func (t *TimedCacheBlockstore) DeleteBlock(k cid.Cid) error { +func (t *TimedCacheBlockstore) DeleteBlock(ctx context.Context, k cid.Cid) error { t.mu.Lock() defer t.mu.Unlock() - return multierr.Combine(t.active.DeleteBlock(k), t.inactive.DeleteBlock(k)) + return multierr.Combine(t.active.DeleteBlock(ctx, k), t.inactive.DeleteBlock(ctx, k)) } -func (t *TimedCacheBlockstore) DeleteMany(ks []cid.Cid) error { +func (t *TimedCacheBlockstore) DeleteMany(ctx context.Context, ks []cid.Cid) error { t.mu.Lock() defer t.mu.Unlock() - return multierr.Combine(t.active.DeleteMany(ks), t.inactive.DeleteMany(ks)) + return multierr.Combine(t.active.DeleteMany(ctx, ks), t.inactive.DeleteMany(ctx, ks)) } func (t *TimedCacheBlockstore) AllKeysChan(_ context.Context) (<-chan cid.Cid, error) { diff --git a/blockstore/timed_test.go b/blockstore/timed_test.go index d5fefff94..16795f047 100644 --- a/blockstore/timed_test.go +++ b/blockstore/timed_test.go @@ -19,6 +19,8 @@ func TestTimedCacheBlockstoreSimple(t *testing.T) { tc.clock = mClock tc.doneRotatingCh = make(chan struct{}) + ctx := context.Background() + _ = tc.Start(context.Background()) mClock.Add(1) // IDK why it is needed but it makes it work @@ -27,18 +29,18 @@ func TestTimedCacheBlockstoreSimple(t *testing.T) { }() b1 := blocks.NewBlock([]byte("foo")) - require.NoError(t, tc.Put(b1)) + require.NoError(t, tc.Put(ctx, b1)) b2 := blocks.NewBlock([]byte("bar")) - require.NoError(t, tc.Put(b2)) + require.NoError(t, tc.Put(ctx, b2)) b3 := blocks.NewBlock([]byte("baz")) - b1out, err := tc.Get(b1.Cid()) + b1out, err := tc.Get(ctx, b1.Cid()) require.NoError(t, err) require.Equal(t, b1.RawData(), b1out.RawData()) - has, err := tc.Has(b1.Cid()) + has, err := tc.Has(ctx, b1.Cid()) require.NoError(t, err) require.True(t, has) @@ -46,17 +48,17 @@ func TestTimedCacheBlockstoreSimple(t *testing.T) { <-tc.doneRotatingCh // We should still have everything. - has, err = tc.Has(b1.Cid()) + has, err = tc.Has(ctx, b1.Cid()) require.NoError(t, err) require.True(t, has) - has, err = tc.Has(b2.Cid()) + has, err = tc.Has(ctx, b2.Cid()) require.NoError(t, err) require.True(t, has) // extend b2, add b3. - require.NoError(t, tc.Put(b2)) - require.NoError(t, tc.Put(b3)) + require.NoError(t, tc.Put(ctx, b2)) + require.NoError(t, tc.Put(ctx, b3)) // all keys once. allKeys, err := tc.AllKeysChan(context.Background()) @@ -71,15 +73,15 @@ func TestTimedCacheBlockstoreSimple(t *testing.T) { <-tc.doneRotatingCh // should still have b2, and b3, but not b1 - has, err = tc.Has(b1.Cid()) + has, err = tc.Has(ctx, b1.Cid()) require.NoError(t, err) require.False(t, has) - has, err = tc.Has(b2.Cid()) + has, err = tc.Has(ctx, b2.Cid()) require.NoError(t, err) require.True(t, has) - has, err = tc.Has(b3.Cid()) + has, err = tc.Has(ctx, b3.Cid()) require.NoError(t, err) require.True(t, has) } diff --git a/blockstore/union.go b/blockstore/union.go index a99ba2591..e115458c2 100644 --- a/blockstore/union.go +++ b/blockstore/union.go @@ -19,72 +19,72 @@ func Union(stores ...Blockstore) Blockstore { return unionBlockstore(stores) } -func (m unionBlockstore) Has(cid cid.Cid) (has bool, err error) { +func (m unionBlockstore) Has(ctx context.Context, cid cid.Cid) (has bool, err error) { for _, bs := range m { - if has, err = bs.Has(cid); has || err != nil { + if has, err = bs.Has(ctx, cid); has || err != nil { break } } return has, err } -func (m unionBlockstore) Get(cid cid.Cid) (blk blocks.Block, err error) { +func (m unionBlockstore) Get(ctx context.Context, cid cid.Cid) (blk blocks.Block, err error) { for _, bs := range m { - if blk, err = bs.Get(cid); err == nil || err != ErrNotFound { + if blk, err = bs.Get(ctx, cid); err == nil || err != ErrNotFound { break } } return blk, err } -func (m unionBlockstore) View(cid cid.Cid, callback func([]byte) error) (err error) { +func (m unionBlockstore) View(ctx context.Context, cid cid.Cid, callback func([]byte) error) (err error) { for _, bs := range m { - if err = bs.View(cid, callback); err == nil || err != ErrNotFound { + if err = bs.View(ctx, cid, callback); err == nil || err != ErrNotFound { break } } return err } -func (m unionBlockstore) GetSize(cid cid.Cid) (size int, err error) { +func (m unionBlockstore) GetSize(ctx context.Context, cid cid.Cid) (size int, err error) { for _, bs := range m { - if size, err = bs.GetSize(cid); err == nil || err != ErrNotFound { + if size, err = bs.GetSize(ctx, cid); err == nil || err != ErrNotFound { break } } return size, err } -func (m unionBlockstore) Put(block blocks.Block) (err error) { +func (m unionBlockstore) Put(ctx context.Context, block blocks.Block) (err error) { for _, bs := range m { - if err = bs.Put(block); err != nil { + if err = bs.Put(ctx, block); err != nil { break } } return err } -func (m unionBlockstore) PutMany(blks []blocks.Block) (err error) { +func (m unionBlockstore) PutMany(ctx context.Context, blks []blocks.Block) (err error) { for _, bs := range m { - if err = bs.PutMany(blks); err != nil { + if err = bs.PutMany(ctx, blks); err != nil { break } } return err } -func (m unionBlockstore) DeleteBlock(cid cid.Cid) (err error) { +func (m unionBlockstore) DeleteBlock(ctx context.Context, cid cid.Cid) (err error) { for _, bs := range m { - if err = bs.DeleteBlock(cid); err != nil { + if err = bs.DeleteBlock(ctx, cid); err != nil { break } } return err } -func (m unionBlockstore) DeleteMany(cids []cid.Cid) (err error) { +func (m unionBlockstore) DeleteMany(ctx context.Context, cids []cid.Cid) (err error) { for _, bs := range m { - if err = bs.DeleteMany(cids); err != nil { + if err = bs.DeleteMany(ctx, cids); err != nil { break } } @@ -112,8 +112,8 @@ func (m unionBlockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error return outCh, nil } -func (m unionBlockstore) HashOnRead(enabled bool) { +func (m unionBlockstore) HashOnRead(ctx context.Context, enabled bool) { for _, bs := range m { - bs.HashOnRead(enabled) + bs.HashOnRead(ctx, enabled) } } diff --git a/blockstore/union_test.go b/blockstore/union_test.go index b62026892..3ae8c1d49 100644 --- a/blockstore/union_test.go +++ b/blockstore/union_test.go @@ -15,79 +15,81 @@ var ( ) func TestUnionBlockstore_Get(t *testing.T) { + ctx := context.Background() m1 := NewMemory() m2 := NewMemory() - _ = m1.Put(b1) - _ = m2.Put(b2) + _ = m1.Put(ctx, b1) + _ = m2.Put(ctx, b2) u := Union(m1, m2) - v1, err := u.Get(b1.Cid()) + v1, err := u.Get(ctx, b1.Cid()) require.NoError(t, err) require.Equal(t, b1.RawData(), v1.RawData()) - v2, err := u.Get(b2.Cid()) + v2, err := u.Get(ctx, b2.Cid()) require.NoError(t, err) require.Equal(t, b2.RawData(), v2.RawData()) } func TestUnionBlockstore_Put_PutMany_Delete_AllKeysChan(t *testing.T) { + ctx := context.Background() m1 := NewMemory() m2 := NewMemory() u := Union(m1, m2) - err := u.Put(b0) + err := u.Put(ctx, b0) require.NoError(t, err) var has bool // write was broadcasted to all stores. - has, _ = m1.Has(b0.Cid()) + has, _ = m1.Has(ctx, b0.Cid()) require.True(t, has) - has, _ = m2.Has(b0.Cid()) + has, _ = m2.Has(ctx, b0.Cid()) require.True(t, has) - has, _ = u.Has(b0.Cid()) + has, _ = u.Has(ctx, b0.Cid()) require.True(t, has) // put many. - err = u.PutMany([]blocks.Block{b1, b2}) + err = u.PutMany(ctx, []blocks.Block{b1, b2}) require.NoError(t, err) // write was broadcasted to all stores. - has, _ = m1.Has(b1.Cid()) + has, _ = m1.Has(ctx, b1.Cid()) require.True(t, has) - has, _ = m1.Has(b2.Cid()) + has, _ = m1.Has(ctx, b2.Cid()) require.True(t, has) - has, _ = m2.Has(b1.Cid()) + has, _ = m2.Has(ctx, b1.Cid()) require.True(t, has) - has, _ = m2.Has(b2.Cid()) + has, _ = m2.Has(ctx, b2.Cid()) require.True(t, has) // also in the union store. - has, _ = u.Has(b1.Cid()) + has, _ = u.Has(ctx, b1.Cid()) require.True(t, has) - has, _ = u.Has(b2.Cid()) + has, _ = u.Has(ctx, b2.Cid()) require.True(t, has) // deleted from all stores. - err = u.DeleteBlock(b1.Cid()) + err = u.DeleteBlock(ctx, b1.Cid()) require.NoError(t, err) - has, _ = u.Has(b1.Cid()) + has, _ = u.Has(ctx, b1.Cid()) require.False(t, has) - has, _ = m1.Has(b1.Cid()) + has, _ = m1.Has(ctx, b1.Cid()) require.False(t, has) - has, _ = m2.Has(b1.Cid()) + has, _ = m2.Has(ctx, b1.Cid()) require.False(t, has) // check that AllKeysChan returns b0 and b2, twice (once per backing store) diff --git a/go.mod b/go.mod index a580c738e..7c78769bb 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/containerd/cgroups v0.0.0-20201119153540-4cbc285b3327 github.com/coreos/go-systemd/v22 v22.3.2 github.com/detailyang/go-fallocate v0.0.0-20180908115635-432fa640bd2e - github.com/dgraph-io/badger/v2 v2.2007.2 + github.com/dgraph-io/badger/v2 v2.2007.3 github.com/docker/go-units v0.4.0 github.com/drand/drand v1.2.1 github.com/drand/kyber v1.1.4 @@ -27,14 +27,14 @@ require ( github.com/elastic/gosigar v0.14.1 github.com/etclabscore/go-openrpc-reflect v0.0.36 github.com/fatih/color v1.13.0 - github.com/filecoin-project/dagstore v0.4.3 + github.com/filecoin-project/dagstore v0.4.2 github.com/filecoin-project/filecoin-ffi v0.30.4-0.20200910194244-f640612a1a1f github.com/filecoin-project/go-address v0.0.6 github.com/filecoin-project/go-bitfield v0.2.4 github.com/filecoin-project/go-cbor-util v0.0.1 - github.com/filecoin-project/go-commp-utils v0.1.2 + github.com/filecoin-project/go-commp-utils v0.1.1-0.20210427191551-70bf140d31c7 github.com/filecoin-project/go-crypto v0.0.1 - github.com/filecoin-project/go-data-transfer v1.11.4 + github.com/filecoin-project/go-data-transfer v1.11.7-0.20211119001436-c0dbfa5fae4d github.com/filecoin-project/go-fil-commcid v0.1.0 github.com/filecoin-project/go-fil-commp-hashhash v0.1.0 github.com/filecoin-project/go-fil-markets v1.13.4 @@ -43,7 +43,7 @@ require ( github.com/filecoin-project/go-paramfetch v0.0.3-0.20220111000201-e42866db1a53 github.com/filecoin-project/go-state-types v0.1.1 github.com/filecoin-project/go-statemachine v1.0.1 - github.com/filecoin-project/go-statestore v0.1.1 + github.com/filecoin-project/go-statestore v0.1.2-0.20211118230537-43557b6c5ce5 github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b github.com/filecoin-project/specs-actors v0.9.14 github.com/filecoin-project/specs-actors/v2 v2.3.5 @@ -68,33 +68,33 @@ require ( github.com/icza/backscanner v0.0.0-20210726202459-ac2ffc679f94 github.com/influxdata/influxdb1-client v0.0.0-20200827194710-b269163b24ab github.com/ipfs/bbloom v0.0.4 - github.com/ipfs/go-bitswap v0.3.4 + github.com/ipfs/go-bitswap v0.5.1 github.com/ipfs/go-block-format v0.0.3 - github.com/ipfs/go-blockservice v0.1.7 + github.com/ipfs/go-blockservice v0.2.1 github.com/ipfs/go-cid v0.1.0 github.com/ipfs/go-cidutil v0.0.2 - github.com/ipfs/go-datastore v0.4.6 - github.com/ipfs/go-ds-badger2 v0.1.1-0.20200708190120-187fc06f714e - github.com/ipfs/go-ds-leveldb v0.4.2 + github.com/ipfs/go-datastore v0.5.0 + github.com/ipfs/go-ds-badger2 v0.1.2-0.20211119002906-7318f1b76158 + github.com/ipfs/go-ds-leveldb v0.5.0 github.com/ipfs/go-ds-measure v0.1.0 github.com/ipfs/go-ds-pebble v0.0.2-0.20200921225637-ce220f8ac459 github.com/ipfs/go-fs-lock v0.0.6 github.com/ipfs/go-graphsync v0.10.6 - github.com/ipfs/go-ipfs-blockstore v1.0.4 + github.com/ipfs/go-ipfs-blockstore v1.1.0 github.com/ipfs/go-ipfs-blocksutil v0.0.1 github.com/ipfs/go-ipfs-chunker v0.0.5 - github.com/ipfs/go-ipfs-ds-help v1.0.0 - github.com/ipfs/go-ipfs-exchange-interface v0.0.1 - github.com/ipfs/go-ipfs-exchange-offline v0.0.1 + github.com/ipfs/go-ipfs-ds-help v1.1.0 + github.com/ipfs/go-ipfs-exchange-interface v0.1.0 + github.com/ipfs/go-ipfs-exchange-offline v0.1.1 github.com/ipfs/go-ipfs-files v0.0.9 github.com/ipfs/go-ipfs-http-client v0.0.6 - github.com/ipfs/go-ipfs-routing v0.1.0 + github.com/ipfs/go-ipfs-routing v0.2.1 github.com/ipfs/go-ipfs-util v0.0.2 github.com/ipfs/go-ipld-cbor v0.0.5 github.com/ipfs/go-ipld-format v0.2.0 github.com/ipfs/go-ipld-legacy v0.1.1 // indirect github.com/ipfs/go-log/v2 v2.3.0 - github.com/ipfs/go-merkledag v0.4.1 + github.com/ipfs/go-merkledag v0.5.1 github.com/ipfs/go-metrics-interface v0.0.1 github.com/ipfs/go-metrics-prometheus v0.0.2 github.com/ipfs/go-path v0.0.7 @@ -114,7 +114,7 @@ require ( github.com/libp2p/go-libp2p-discovery v0.5.1 github.com/libp2p/go-libp2p-kad-dht v0.13.0 github.com/libp2p/go-libp2p-noise v0.2.2 - github.com/libp2p/go-libp2p-peerstore v0.3.0 + github.com/libp2p/go-libp2p-peerstore v0.4.0 github.com/libp2p/go-libp2p-pubsub v0.5.6 github.com/libp2p/go-libp2p-quic-transport v0.11.2 github.com/libp2p/go-libp2p-record v0.1.3 @@ -153,8 +153,7 @@ require ( go.uber.org/fx v1.9.0 go.uber.org/multierr v1.7.0 go.uber.org/zap v1.19.1 - golang.org/x/crypto v0.0.0-20211209193657-4570a0811e8b // indirect - golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 + golang.org/x/net v0.0.0-20210917221730-978cfadd31cf golang.org/x/sync v0.0.0-20210220032951-036812b2e83c golang.org/x/sys v0.0.0-20211209171907-798191bca915 golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac diff --git a/go.sum b/go.sum index d188bd414..3d41b3ce2 100644 --- a/go.sum +++ b/go.sum @@ -245,8 +245,8 @@ github.com/dgraph-io/badger v1.6.1/go.mod h1:FRmFw3uxvcpa8zG3Rxs0th+hCLIuaQg8HlN github.com/dgraph-io/badger v1.6.2 h1:mNw0qs90GVgGGWylh0umH5iag1j6n/PeJtNvL6KY/x8= github.com/dgraph-io/badger v1.6.2/go.mod h1:JW2yswe3V058sS0kZ2h/AXeDSqFjxnZcRrVH//y2UQE= github.com/dgraph-io/badger/v2 v2.0.3/go.mod h1:3KY8+bsP8wI0OEnQJAKpd4wIJW/Mm32yw2j/9FUVnIM= -github.com/dgraph-io/badger/v2 v2.2007.2 h1:EjjK0KqwaFMlPin1ajhP943VPENHJdEz1KLIegjaI3k= -github.com/dgraph-io/badger/v2 v2.2007.2/go.mod h1:26P/7fbL4kUZVEVKLAKXkBXKOydDmM2p1e+NhhnBCAE= +github.com/dgraph-io/badger/v2 v2.2007.3 h1:Sl9tQWz92WCbVSe8pj04Tkqlm2boW+KAxd+XSs58SQI= +github.com/dgraph-io/badger/v2 v2.2007.3/go.mod h1:26P/7fbL4kUZVEVKLAKXkBXKOydDmM2p1e+NhhnBCAE= github.com/dgraph-io/ristretto v0.0.2-0.20200115201040-8f368f2f2ab3/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E= github.com/dgraph-io/ristretto v0.0.2/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E= github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de h1:t0UHb5vdojIDUqktM6+xJAfScFBsVpXZmqC9dsgJmeA= @@ -302,9 +302,8 @@ github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= +github.com/filecoin-project/dagstore v0.4.2 h1:Ae2+O1DhKCI1JbOZCBkqUksKYofdbRbjkS7OF0A6Jw0= github.com/filecoin-project/dagstore v0.4.2/go.mod h1:WY5OoLfnwISCk6eASSF927KKPqLPIlTwmG1qHpA08KY= -github.com/filecoin-project/dagstore v0.4.3 h1:yeFl6+2BRY1gOVp/hrZuFa24s7LY0Qqkqx/Gh8lidZs= -github.com/filecoin-project/dagstore v0.4.3/go.mod h1:dm/91AO5UaDd3bABFjg/5fmRH99vvpS7g1mykqvz6KQ= github.com/filecoin-project/go-address v0.0.3/go.mod h1:jr8JxKsYx+lQlQZmF5i2U0Z+cGQ59wMIps/8YW/lDj8= github.com/filecoin-project/go-address v0.0.5/go.mod h1:jr8JxKsYx+lQlQZmF5i2U0Z+cGQ59wMIps/8YW/lDj8= github.com/filecoin-project/go-address v0.0.6 h1:DWQtj38ax+ogHwyH3VULRIoT8E6loyXqsk/p81xoY7M= @@ -321,15 +320,16 @@ github.com/filecoin-project/go-bitfield v0.2.4/go.mod h1:CNl9WG8hgR5mttCnUErjcQj github.com/filecoin-project/go-cbor-util v0.0.0-20191219014500-08c40a1e63a2/go.mod h1:pqTiPHobNkOVM5thSRsHYjyQfq7O5QSCMhvuu9JoDlg= github.com/filecoin-project/go-cbor-util v0.0.1 h1:E1LYZYTtjfAQwCReho0VXvbu8t3CYAVPiMx8EiV/VAs= github.com/filecoin-project/go-cbor-util v0.0.1/go.mod h1:pqTiPHobNkOVM5thSRsHYjyQfq7O5QSCMhvuu9JoDlg= +github.com/filecoin-project/go-commp-utils v0.1.1-0.20210427191551-70bf140d31c7 h1:U9Z+76pHCKBmtdxFV7JFZJj7OVm12I6dEKwtMVbq5p0= github.com/filecoin-project/go-commp-utils v0.1.1-0.20210427191551-70bf140d31c7/go.mod h1:6s95K91mCyHY51RPWECZieD3SGWTqIFLf1mPOes9l5U= -github.com/filecoin-project/go-commp-utils v0.1.2 h1:SKLRuGdx/6WlolaWKaUzzUYWGGePuARyO4guxOPxvt4= -github.com/filecoin-project/go-commp-utils v0.1.2/go.mod h1:6s95K91mCyHY51RPWECZieD3SGWTqIFLf1mPOes9l5U= github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03/go.mod h1:+viYnvGtUTgJRdy6oaeF4MTFKAfatX071MPDPBL11EQ= github.com/filecoin-project/go-crypto v0.0.1 h1:AcvpSGGCgjaY8y1az6AMfKQWreF/pWO2JJGLl6gCq6o= github.com/filecoin-project/go-crypto v0.0.1/go.mod h1:+viYnvGtUTgJRdy6oaeF4MTFKAfatX071MPDPBL11EQ= github.com/filecoin-project/go-data-transfer v1.0.1/go.mod h1:UxvfUAY9v3ub0a21BSK9u3pB2aq30Y0KMsG+w9/ysyo= -github.com/filecoin-project/go-data-transfer v1.11.4 h1:jKvlx0/C8HSyLRn/G1P9TjtfBtFU9jbCvCVFmWbyYVQ= github.com/filecoin-project/go-data-transfer v1.11.4/go.mod h1:2MitLI0ebCkLlPKM7NRggP/t9d+gCcREUKkCKqWRCwU= +github.com/filecoin-project/go-data-transfer v1.11.7-0.20211119001436-c0dbfa5fae4d h1:otSEh99T0inzVe6pblKBG5tSeSqbQq4BCi5GKoh1J7I= +github.com/filecoin-project/go-data-transfer v1.11.7-0.20211119001436-c0dbfa5fae4d/go.mod h1:Qj+yDFsualZ4c7Ndh5Cl1SJK46QeVzNMdRnfAJdDuhw= +github.com/filecoin-project/go-ds-versioning v0.0.0-20211119000042-d0cf38743fe7/go.mod h1:BVGOwN2WSCRKV3CDLFJ9u0L9M17WxHqw1KLA0l5ATnk= github.com/filecoin-project/go-ds-versioning v0.1.0 h1:y/X6UksYTsK8TLCI7rttCKEvl8btmWxyFMEeeWGUxIQ= github.com/filecoin-project/go-ds-versioning v0.1.0/go.mod h1:mp16rb4i2QPmxBnmanUx8i/XANp+PFCCJWiAb+VW4/s= github.com/filecoin-project/go-fil-commcid v0.0.0-20200716160307-8f644712406f/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ= @@ -369,8 +369,9 @@ github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe/g github.com/filecoin-project/go-statemachine v1.0.1 h1:LQ60+JDVjMdLxXmVFM2jjontzOYnfVE7u02CXV3WKSw= github.com/filecoin-project/go-statemachine v1.0.1/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54= github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI= -github.com/filecoin-project/go-statestore v0.1.1 h1:ufMFq00VqnT2CAuDpcGnwLnCX1I/c3OROw/kXVNSTZk= github.com/filecoin-project/go-statestore v0.1.1/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI= +github.com/filecoin-project/go-statestore v0.1.2-0.20211118230537-43557b6c5ce5 h1:xH09S8C+VhZCTmTkdudGm/cN5a8teKE+PXXvbPsXTO0= +github.com/filecoin-project/go-statestore v0.1.2-0.20211118230537-43557b6c5ce5/go.mod h1:8sjBYbS35HwPzct7iT4lIXjLlYyPor80aU7t7a/Kspo= github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b h1:fkRZSPrYpk42PV3/lIXiL0LHetxde7vyYYvSsttQtfg= github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b/go.mod h1:Q0GQOBtKf1oE10eSXSlhN45kDBdGvEcVOqMiffqX+N8= github.com/filecoin-project/specs-actors v0.9.12/go.mod h1:TS1AW/7LbG+615j4NsjMK1qlpAwaFsG9w0V2tg2gSao= @@ -677,8 +678,9 @@ github.com/ipfs/go-bitswap v0.0.9/go.mod h1:kAPf5qgn2W2DrgAcscZ3HrM9qh4pH+X8Fkk3 github.com/ipfs/go-bitswap v0.1.0/go.mod h1:FFJEf18E9izuCqUtHxbWEvq+reg7o4CW5wSAE1wsxj0= github.com/ipfs/go-bitswap v0.1.2/go.mod h1:qxSWS4NXGs7jQ6zQvoPY3+NmOfHHG47mhkiLzBpJQIs= github.com/ipfs/go-bitswap v0.1.8/go.mod h1:TOWoxllhccevbWFUR2N7B1MTSVVge1s6XSMiCSA4MzM= -github.com/ipfs/go-bitswap v0.3.4 h1:AhJhRrG8xkxh6x87b4wWs+4U4y3DVB3doI8yFNqgQME= github.com/ipfs/go-bitswap v0.3.4/go.mod h1:4T7fvNv/LmOys+21tnLzGKncMeeXUYUd1nUiJ2teMvI= +github.com/ipfs/go-bitswap v0.5.1 h1:721YAEDBnLIrvcIMkCHCdqp34hA8jwL9yKMkyJpSpco= +github.com/ipfs/go-bitswap v0.5.1/go.mod h1:P+ckC87ri1xFLvk74NlXdP0Kj9RmWAh4+H78sC6Qopo= github.com/ipfs/go-block-format v0.0.1/go.mod h1:DK/YYcsSUIVAFNwo/KZCdIIbpN0ROH/baNLgayt4pFc= github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY= github.com/ipfs/go-block-format v0.0.3 h1:r8t66QstRp/pd/or4dpnbVfXT5Gt7lOqRvC+/dDTpMc= @@ -688,8 +690,8 @@ github.com/ipfs/go-blockservice v0.1.0/go.mod h1:hzmMScl1kXHg3M2BjTymbVPjv627N7s github.com/ipfs/go-blockservice v0.1.3/go.mod h1:OTZhFpkgY48kNzbgyvcexW9cHrpjBYIjSR0KoDOFOLU= github.com/ipfs/go-blockservice v0.1.4-0.20200624145336-a978cec6e834/go.mod h1:OTZhFpkgY48kNzbgyvcexW9cHrpjBYIjSR0KoDOFOLU= github.com/ipfs/go-blockservice v0.1.5/go.mod h1:yLk8lBJCBRWRqerqCSVi3cE/Dncdt3vGC/PJMVKhLTY= -github.com/ipfs/go-blockservice v0.1.7 h1:yVe9te0M7ow8i+PPkx03YFSpxqzXx594d6h+34D6qMg= -github.com/ipfs/go-blockservice v0.1.7/go.mod h1:GmS+BAt4hrwBKkzE11AFDQUrnvqjwFatGS2MY7wOjEM= +github.com/ipfs/go-blockservice v0.2.1 h1:NJ4j/cwEfIg60rzAWcCIxRtOwbf6ZPK49MewNxObCPQ= +github.com/ipfs/go-blockservice v0.2.1/go.mod h1:k6SiwmgyYgs4M/qt+ww6amPeUH9EISLRBnvUurKJhi8= github.com/ipfs/go-cid v0.0.1/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= github.com/ipfs/go-cid v0.0.2/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= github.com/ipfs/go-cid v0.0.3/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= @@ -715,8 +717,10 @@ github.com/ipfs/go-datastore v0.4.1/go.mod h1:SX/xMIKoCszPqp+z9JhPYCmoOoXTvaa13X github.com/ipfs/go-datastore v0.4.2/go.mod h1:SX/xMIKoCszPqp+z9JhPYCmoOoXTvaa13XEbGtsFUhA= github.com/ipfs/go-datastore v0.4.4/go.mod h1:SX/xMIKoCszPqp+z9JhPYCmoOoXTvaa13XEbGtsFUhA= github.com/ipfs/go-datastore v0.4.5/go.mod h1:eXTcaaiN6uOlVCLS9GjJUJtlvJfM3xk23w3fyfrmmJs= -github.com/ipfs/go-datastore v0.4.6 h1:zU2cmweykxJ+ziXnA2cPtsLe8rdR/vrthOipLPuf6kc= github.com/ipfs/go-datastore v0.4.6/go.mod h1:XSipLSc64rFKSFRFGo1ecQl+WhYce3K7frtpHkyPFUc= +github.com/ipfs/go-datastore v0.4.7-0.20211013204805-28a3721c2e66/go.mod h1:9zhEApYMTl17C8YDp7JmU7sQZi2/wqiYh73hakZ90Bk= +github.com/ipfs/go-datastore v0.5.0 h1:rQicVCEacWyk4JZ6G5bD9TKR7lZEG1MWcG7UdWYrFAU= +github.com/ipfs/go-datastore v0.5.0/go.mod h1:9zhEApYMTl17C8YDp7JmU7sQZi2/wqiYh73hakZ90Bk= github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ6cOk= github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps= github.com/ipfs/go-ds-badger v0.0.2/go.mod h1:Y3QpeSFWQf6MopLTiZD+VT6IC1yZqaGmjvRcKeSGij8= @@ -725,16 +729,18 @@ github.com/ipfs/go-ds-badger v0.0.7/go.mod h1:qt0/fWzZDoPW6jpQeqUjR5kBfhDNB65jd9 github.com/ipfs/go-ds-badger v0.2.1/go.mod h1:Tx7l3aTph3FMFrRS838dcSJh+jjA7cX9DrGVwx/NOwE= github.com/ipfs/go-ds-badger v0.2.3/go.mod h1:pEYw0rgg3FIrywKKnL+Snr+w/LjJZVMTBRn4FS6UHUk= github.com/ipfs/go-ds-badger v0.2.6/go.mod h1:02rnztVKA4aZwDuaRPTf8mpqcKmXP7mLl6JPxd14JHA= -github.com/ipfs/go-ds-badger v0.2.7 h1:ju5REfIm+v+wgVnQ19xGLYPHYHbYLR6qJfmMbCDSK1I= github.com/ipfs/go-ds-badger v0.2.7/go.mod h1:02rnztVKA4aZwDuaRPTf8mpqcKmXP7mLl6JPxd14JHA= +github.com/ipfs/go-ds-badger v0.3.0 h1:xREL3V0EH9S219kFFueOYJJTcjgNSZ2HY1iSvN7U1Ro= +github.com/ipfs/go-ds-badger v0.3.0/go.mod h1:1ke6mXNqeV8K3y5Ak2bAA0osoTfmxUdupVCGm4QUIek= github.com/ipfs/go-ds-badger2 v0.1.0/go.mod h1:pbR1p817OZbdId9EvLOhKBgUVTM3BMCSTan78lDDVaw= -github.com/ipfs/go-ds-badger2 v0.1.1-0.20200708190120-187fc06f714e h1:Xi1nil8K2lBOorBS6Ys7+hmUCzH8fr3U9ipdL/IrcEI= -github.com/ipfs/go-ds-badger2 v0.1.1-0.20200708190120-187fc06f714e/go.mod h1:lJnws7amT9Ehqzta0gwMrRsURU04caT0iRPr1W8AsOU= +github.com/ipfs/go-ds-badger2 v0.1.2-0.20211119002906-7318f1b76158 h1:/8az/zYn1icEwiHAmpR11Io+8hrlICU10J+Ft0zSiog= +github.com/ipfs/go-ds-badger2 v0.1.2-0.20211119002906-7318f1b76158/go.mod h1:3FtQmDv6fMubygEfU43bsFelYpIiXX/XEYA54l9eCwg= github.com/ipfs/go-ds-leveldb v0.0.1/go.mod h1:feO8V3kubwsEF22n0YRQCffeb79OOYIykR4L04tMOYc= github.com/ipfs/go-ds-leveldb v0.1.0/go.mod h1:hqAW8y4bwX5LWcCtku2rFNX3vjDZCy5LZCg+cSZvYb8= github.com/ipfs/go-ds-leveldb v0.4.1/go.mod h1:jpbku/YqBSsBc1qgME8BkWS4AxzF2cEu1Ii2r79Hh9s= -github.com/ipfs/go-ds-leveldb v0.4.2 h1:QmQoAJ9WkPMUfBLnu1sBVy0xWWlJPg0m4kRAiJL9iaw= github.com/ipfs/go-ds-leveldb v0.4.2/go.mod h1:jpbku/YqBSsBc1qgME8BkWS4AxzF2cEu1Ii2r79Hh9s= +github.com/ipfs/go-ds-leveldb v0.5.0 h1:s++MEBbD3ZKc9/8/njrn4flZLnCuY9I79v94gBUNumo= +github.com/ipfs/go-ds-leveldb v0.5.0/go.mod h1:d3XG9RUDzQ6V4SHi8+Xgj9j1XuEk1z82lquxrVbml/Q= github.com/ipfs/go-ds-measure v0.1.0 h1:vE4TyY4aeLeVgnnPBC5QzKIjKrqzha0NCujTfgvVbVQ= github.com/ipfs/go-ds-measure v0.1.0/go.mod h1:1nDiFrhLlwArTME1Ees2XaBOl49OoCgd2A3f8EchMSY= github.com/ipfs/go-ds-pebble v0.0.2-0.20200921225637-ce220f8ac459 h1:W3YMLEvOXqdW+sYMiguhWP6txJwQvIQqhvpU8yAMGQs= @@ -747,17 +753,19 @@ github.com/ipfs/go-graphsync v0.1.0/go.mod h1:jMXfqIEDFukLPZHqDPp8tJMbHO9Rmeb9CE github.com/ipfs/go-graphsync v0.4.2/go.mod h1:/VmbZTUdUMTbNkgzAiCEucIIAU3BkLE2cZrDCVUhyi0= github.com/ipfs/go-graphsync v0.4.3/go.mod h1:mPOwDYv128gf8gxPFgXnz4fNrSYPsWyqisJ7ych+XDY= github.com/ipfs/go-graphsync v0.10.0/go.mod h1:cKIshzTaa5rCZjryH5xmSKZVGX9uk1wvwGvz2WEha5Y= +github.com/ipfs/go-graphsync v0.10.6-0.20211119000532-c416dad3bd56/go.mod h1:/wC15/mR2JyjVrO86tfZLLuhyvop0fLU+ewhYLkdgLM= github.com/ipfs/go-graphsync v0.10.6 h1:GkYan4EoDslceHaqYo/hxktWtuZ7VmsyRXLdSmoCcBQ= github.com/ipfs/go-graphsync v0.10.6/go.mod h1:tQMjWNDD/vSz80YLT/VvzrUmy58aF9lR1uCwSLzjWzI= github.com/ipfs/go-ipfs-blockstore v0.0.1/go.mod h1:d3WClOmRQKFnJ0Jz/jj/zmksX0ma1gROTlovZKBmN08= github.com/ipfs/go-ipfs-blockstore v0.1.0/go.mod h1:5aD0AvHPi7mZc6Ci1WCAhiBQu2IsfTduLl+422H6Rqw= github.com/ipfs/go-ipfs-blockstore v0.1.4/go.mod h1:Jxm3XMVjh6R17WvxFEiyKBLUGr86HgIYJW/D/MwqeYQ= -github.com/ipfs/go-ipfs-blockstore v0.1.6/go.mod h1:Jxm3XMVjh6R17WvxFEiyKBLUGr86HgIYJW/D/MwqeYQ= +github.com/ipfs/go-ipfs-blockstore v0.2.1/go.mod h1:jGesd8EtCM3/zPgx+qr0/feTXGUeRai6adgwC+Q+JvE= github.com/ipfs/go-ipfs-blockstore v1.0.0/go.mod h1:knLVdhVU9L7CC4T+T4nvGdeUIPAXlnd9zmXfp+9MIjU= github.com/ipfs/go-ipfs-blockstore v1.0.1/go.mod h1:MGNZlHNEnR4KGgPHM3/k8lBySIOK2Ve+0KjZubKlaOE= github.com/ipfs/go-ipfs-blockstore v1.0.3/go.mod h1:MGNZlHNEnR4KGgPHM3/k8lBySIOK2Ve+0KjZubKlaOE= -github.com/ipfs/go-ipfs-blockstore v1.0.4 h1:DZdeya9Vu4ttvlGheQPGrj6kWehXnYZRFCp9EsZQ1hI= github.com/ipfs/go-ipfs-blockstore v1.0.4/go.mod h1:uL7/gTJ8QIZ3MtA3dWf+s1a0U3fJy2fcEZAsovpRp+w= +github.com/ipfs/go-ipfs-blockstore v1.1.0 h1:ZIZ2qgHO5pftHW0oHTfx+LoO+Me2xHkVAexhVpgGL3I= +github.com/ipfs/go-ipfs-blockstore v1.1.0/go.mod h1:5QDUApRqpgPcfGstCxYeMnjt/DYQtXXdJVCvxHHuWVk= github.com/ipfs/go-ipfs-blocksutil v0.0.1 h1:Eh/H4pc1hsvhzsQoMEP3Bke/aW5P5rVM1IWFJMcGIPQ= github.com/ipfs/go-ipfs-blocksutil v0.0.1/go.mod h1:Yq4M86uIOmxmGPUHv/uI7uKqZNtLb449gwKqXjIsnRk= github.com/ipfs/go-ipfs-chunker v0.0.1/go.mod h1:tWewYK0we3+rMbOh7pPFGDyypCtvGcBFymgY4rSDLAw= @@ -772,12 +780,15 @@ github.com/ipfs/go-ipfs-delay v0.0.1 h1:r/UXYyRcddO6thwOnhiznIAiSvxMECGgtv35Xs1I github.com/ipfs/go-ipfs-delay v0.0.1/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw= github.com/ipfs/go-ipfs-ds-help v0.0.1/go.mod h1:gtP9xRaZXqIQRh1HRpp595KbBEdgqWFxefeVKOV8sxo= github.com/ipfs/go-ipfs-ds-help v0.1.1/go.mod h1:SbBafGJuGsPI/QL3j9Fc5YPLeAu+SzOkI0gFwAg+mOs= -github.com/ipfs/go-ipfs-ds-help v1.0.0 h1:bEQ8hMGs80h0sR8O4tfDgV6B01aaF9qeTrujrTLYV3g= github.com/ipfs/go-ipfs-ds-help v1.0.0/go.mod h1:ujAbkeIgkKAWtxxNkoZHWLCyk5JpPoKnGyCcsoF6ueE= -github.com/ipfs/go-ipfs-exchange-interface v0.0.1 h1:LJXIo9W7CAmugqI+uofioIpRb6rY30GUu7G6LUfpMvM= +github.com/ipfs/go-ipfs-ds-help v1.1.0 h1:yLE2w9RAsl31LtfMt91tRZcrx+e61O5mDxFRR994w4Q= +github.com/ipfs/go-ipfs-ds-help v1.1.0/go.mod h1:YR5+6EaebOhfcqVCyqemItCLthrpVNot+rsOU/5IatU= github.com/ipfs/go-ipfs-exchange-interface v0.0.1/go.mod h1:c8MwfHjtQjPoDyiy9cFquVtVHkO9b9Ob3FG91qJnWCM= -github.com/ipfs/go-ipfs-exchange-offline v0.0.1 h1:P56jYKZF7lDDOLx5SotVh5KFxoY6C81I1NSHW1FxGew= +github.com/ipfs/go-ipfs-exchange-interface v0.1.0 h1:TiMekCrOGQuWYtZO3mf4YJXDIdNgnKWZ9IE3fGlnWfo= +github.com/ipfs/go-ipfs-exchange-interface v0.1.0/go.mod h1:ych7WPlyHqFvCi/uQI48zLZuAWVP5iTQPXEfVaw5WEI= github.com/ipfs/go-ipfs-exchange-offline v0.0.1/go.mod h1:WhHSFCVYX36H/anEKQboAzpUws3x7UeEGkzQc3iNkM0= +github.com/ipfs/go-ipfs-exchange-offline v0.1.1 h1:mEiXWdbMN6C7vtDG21Fphx8TGCbZPpQnz/496w/PL4g= +github.com/ipfs/go-ipfs-exchange-offline v0.1.1/go.mod h1:vTiBRIbzSwDD0OWm+i3xeT0mO7jG2cbJYatp3HPk5XY= github.com/ipfs/go-ipfs-files v0.0.3/go.mod h1:INEFm0LL2LWXBhNJ2PMIIb2w45hpXgPjNoE7yA8Y1d4= github.com/ipfs/go-ipfs-files v0.0.4/go.mod h1:INEFm0LL2LWXBhNJ2PMIIb2w45hpXgPjNoE7yA8Y1d4= github.com/ipfs/go-ipfs-files v0.0.8/go.mod h1:wiN/jSG8FKyk7N0WyctKSvq3ljIa2NNTiZB55kpTdOs= @@ -791,8 +802,9 @@ github.com/ipfs/go-ipfs-pq v0.0.1/go.mod h1:LWIqQpqfRG3fNc5XsnIhz/wQ2XXGyugQwls7 github.com/ipfs/go-ipfs-pq v0.0.2 h1:e1vOOW6MuOwG2lqxcLA+wEn93i/9laCY8sXAw76jFOY= github.com/ipfs/go-ipfs-pq v0.0.2/go.mod h1:LWIqQpqfRG3fNc5XsnIhz/wQ2XXGyugQwls7BgUmUfY= github.com/ipfs/go-ipfs-routing v0.0.1/go.mod h1:k76lf20iKFxQTjcJokbPM9iBXVXVZhcOwc360N4nuKs= -github.com/ipfs/go-ipfs-routing v0.1.0 h1:gAJTT1cEeeLj6/DlLX6t+NxD9fQe2ymTO6qWRDI/HQQ= github.com/ipfs/go-ipfs-routing v0.1.0/go.mod h1:hYoUkJLyAUKhF58tysKpids8RNDPO42BVMgK5dNsoqY= +github.com/ipfs/go-ipfs-routing v0.2.1 h1:E+whHWhJkdN9YeoHZNj5itzc+OR292AJ2uE9FFiW0BY= +github.com/ipfs/go-ipfs-routing v0.2.1/go.mod h1:xiNNiwgjmLqPS1cimvAw6EyB9rkVDbiocA4yY+wRNLM= github.com/ipfs/go-ipfs-util v0.0.1/go.mod h1:spsl5z8KUnrve+73pOhSVZND1SIxPW5RyBCNzQxlJBc= github.com/ipfs/go-ipfs-util v0.0.2 h1:59Sswnk1MFaiq+VcaknX7aYEyGyGDAA73ilhEK2POp8= github.com/ipfs/go-ipfs-util v0.0.2/go.mod h1:CbPtkWJzjLdEcezDns2XYaehFVNXG9zrdrtMecczcsQ= @@ -835,8 +847,8 @@ github.com/ipfs/go-merkledag v0.2.3/go.mod h1:SQiXrtSts3KGNmgOzMICy5c0POOpUNQLvB github.com/ipfs/go-merkledag v0.2.4/go.mod h1:SQiXrtSts3KGNmgOzMICy5c0POOpUNQLvB3ClKnBAlk= github.com/ipfs/go-merkledag v0.3.1/go.mod h1:fvkZNNZixVW6cKSZ/JfLlON5OlgTXNdRLz0p6QG/I2M= github.com/ipfs/go-merkledag v0.3.2/go.mod h1:fvkZNNZixVW6cKSZ/JfLlON5OlgTXNdRLz0p6QG/I2M= -github.com/ipfs/go-merkledag v0.4.1 h1:CEEQZnwRkszN06oezuasHwDD823Xcr4p4zluUN9vXqs= -github.com/ipfs/go-merkledag v0.4.1/go.mod h1:56biPaS6e+IS0eXkEt6A8tG+BUQaEIFqDqJuFfQDBoE= +github.com/ipfs/go-merkledag v0.5.1 h1:tr17GPP5XtPhvPPiWtu20tSGZiZDuTaJRXBLcr79Umk= +github.com/ipfs/go-merkledag v0.5.1/go.mod h1:cLMZXx8J08idkp5+id62iVftUQV+HlYJ3PIhDfZsjA4= github.com/ipfs/go-metrics-interface v0.0.1 h1:j+cpbjYvu4R8zbleSs36gvB7jR+wsL2fGD6n0jO4kdg= github.com/ipfs/go-metrics-interface v0.0.1/go.mod h1:6s6euYU4zowdslK0GKHmqaIZ3j/b/tL7HTWtJ4VPgWY= github.com/ipfs/go-metrics-prometheus v0.0.2 h1:9i2iljLg12S78OhC6UAiXi176xvQGiZaGVF1CUVdE+s= @@ -847,8 +859,9 @@ github.com/ipfs/go-peertaskqueue v0.0.4/go.mod h1:03H8fhyeMfKNFWqzYEVyMbcPUeYrqP github.com/ipfs/go-peertaskqueue v0.1.0/go.mod h1:Jmk3IyCcfl1W3jTW3YpghSwSEC6IJ3Vzz/jUmWw8Z0U= github.com/ipfs/go-peertaskqueue v0.1.1/go.mod h1:Jmk3IyCcfl1W3jTW3YpghSwSEC6IJ3Vzz/jUmWw8Z0U= github.com/ipfs/go-peertaskqueue v0.2.0/go.mod h1:5/eNrBEbtSKWCG+kQK8K8fGNixoYUnr+P7jivavs9lY= -github.com/ipfs/go-peertaskqueue v0.6.0 h1:BT1/PuNViVomiz1PnnP5+WmKsTNHrxIDvkZrkj4JhOg= github.com/ipfs/go-peertaskqueue v0.6.0/go.mod h1:M/akTIE/z1jGNXMU7kFB4TeSEFvj68ow0Rrb04donIU= +github.com/ipfs/go-peertaskqueue v0.7.0 h1:VyO6G4sbzX80K58N60cCaHsSsypbUNs1GjO5seGNsQ0= +github.com/ipfs/go-peertaskqueue v0.7.0/go.mod h1:M/akTIE/z1jGNXMU7kFB4TeSEFvj68ow0Rrb04donIU= github.com/ipfs/go-todocounter v0.0.1/go.mod h1:l5aErvQc8qKE2r7NDMjmq5UNAvuZy0rC8BHOplkWvZ4= github.com/ipfs/go-unixfs v0.2.2-0.20190827150610-868af2e9e5cb/go.mod h1:IwAAgul1UQIcNZzKPYZWOCijryFBeCV79cNubPzol+k= github.com/ipfs/go-unixfs v0.2.4/go.mod h1:SUdisfUjNoSDzzhGVxvCL9QO/nKdwXdr+gbMUdqcbYw= @@ -868,7 +881,6 @@ github.com/ipld/go-car v0.1.1-0.20201119040415-11b6074b6d4d/go.mod h1:2Gys8L8MJ6 github.com/ipld/go-car v0.3.2-0.20211001225732-32d0d9933823 h1:8JMSJ0k71fU9lIUrpVwEdoX4KoxiTEX8cZG97v/hTDw= github.com/ipld/go-car v0.3.2-0.20211001225732-32d0d9933823/go.mod h1:jSlTph+i/q1jLFoiKKeN69KGG0fXpwrcD0izu5C1Tpo= github.com/ipld/go-car/v2 v2.0.0-beta1.0.20210721090610-5a9d1b217d25/go.mod h1:I2ACeeg6XNBe5pdh5TaR7Ambhfa7If9KXxmXgZsYENU= -github.com/ipld/go-car/v2 v2.0.2/go.mod h1:I2ACeeg6XNBe5pdh5TaR7Ambhfa7If9KXxmXgZsYENU= github.com/ipld/go-car/v2 v2.1.0 h1:t8R/WXUSkfu1K1gpPk76mytCxsEdMjGcMIgpOq3/Cnw= github.com/ipld/go-car/v2 v2.1.0/go.mod h1:Xr6GwkDhv8dtOtgHzOynAkIOg0t0YiPc5DxBPppWqZA= github.com/ipld/go-codec-dagpb v1.2.0/go.mod h1:6nBN7X7h8EOsEejZGqC7tej5drsdBAXbMHyBT+Fne5s= @@ -1023,6 +1035,7 @@ github.com/libp2p/go-libp2p v0.9.2/go.mod h1:cunHNLDVus66Ct9iXXcjKRLdmHdFdHVe1TA github.com/libp2p/go-libp2p v0.10.0/go.mod h1:yBJNpb+mGJdgrwbKAKrhPU0u3ogyNFTfjJ6bdM+Q/G8= github.com/libp2p/go-libp2p v0.13.0/go.mod h1:pM0beYdACRfHO1WcJlp65WXyG2A6NqYM+t2DTVAJxMo= github.com/libp2p/go-libp2p v0.14.0/go.mod h1:dsQrWLAoIn+GkHPN/U+yypizkHiB9tnv79Os+kSgQ4Q= +github.com/libp2p/go-libp2p v0.14.3/go.mod h1:d12V4PdKbpL0T1/gsUNN8DfgMuRPDX8bS2QxCZlwRH0= github.com/libp2p/go-libp2p v0.14.4/go.mod h1:EIRU0Of4J5S8rkockZM7eJp2S0UrCyi55m2kJVru3rM= github.com/libp2p/go-libp2p v0.15.0 h1:jbMbdmtizfpvl1+oQuGJzfGhttAtuxUCavF3enwFncg= github.com/libp2p/go-libp2p v0.15.0/go.mod h1:8Ljmwon0cZZYKrOCjFeLwQEK8bqR42dOheUZ1kSKhP0= @@ -1157,8 +1170,8 @@ github.com/libp2p/go-libp2p-peerstore v0.2.4/go.mod h1:ss/TWTgHZTMpsU/oKVVPQCGuD github.com/libp2p/go-libp2p-peerstore v0.2.6/go.mod h1:ss/TWTgHZTMpsU/oKVVPQCGuDHItOpf2W8RxAi50P2s= github.com/libp2p/go-libp2p-peerstore v0.2.7/go.mod h1:ss/TWTgHZTMpsU/oKVVPQCGuDHItOpf2W8RxAi50P2s= github.com/libp2p/go-libp2p-peerstore v0.2.8/go.mod h1:gGiPlXdz7mIHd2vfAsHzBNAMqSDkt2UBFwgcITgw1lA= -github.com/libp2p/go-libp2p-peerstore v0.3.0 h1:wp/G0+37+GLr7tu+wE+4GWNrA3uxKg6IPRigIMSS5oQ= -github.com/libp2p/go-libp2p-peerstore v0.3.0/go.mod h1:fNX9WlOENMvdx/YD7YO/5Hkrn8+lQIk5A39BHa1HIrM= +github.com/libp2p/go-libp2p-peerstore v0.4.0 h1:DOhRJLnM9Dc9lIXi3rPDZBf789LXy1BrzwIs7Tj0cKA= +github.com/libp2p/go-libp2p-peerstore v0.4.0/go.mod h1:rDJUFyzEWPpXpEwywkcTYYzDHlwza8riYMaUzaN6hX0= github.com/libp2p/go-libp2p-pnet v0.2.0 h1:J6htxttBipJujEjz1y0a5+eYoiPcFHhSYHH6na5f0/k= github.com/libp2p/go-libp2p-pnet v0.2.0/go.mod h1:Qqvq6JH/oMZGwqs3N1Fqhv8NVhrdYcO0BW4wssv21LA= github.com/libp2p/go-libp2p-protocol v0.0.1/go.mod h1:Af9n4PiruirSDjHycM1QuiMi/1VZNHYcK8cLgFJLZ4s= @@ -1296,6 +1309,7 @@ github.com/libp2p/go-tcp-transport v0.1.0/go.mod h1:oJ8I5VXryj493DEJ7OsBieu8fcg2 github.com/libp2p/go-tcp-transport v0.1.1/go.mod h1:3HzGvLbx6etZjnFlERyakbaYPdfjg2pWP97dFZworkY= github.com/libp2p/go-tcp-transport v0.2.0/go.mod h1:vX2U0CnWimU4h0SGSEsg++AzvBcroCGYw28kh94oLe0= github.com/libp2p/go-tcp-transport v0.2.1/go.mod h1:zskiJ70MEfWz2MKxvFB/Pv+tPIB1PpPUrHIWQ8aFw7M= +github.com/libp2p/go-tcp-transport v0.2.3/go.mod h1:9dvr03yqrPyYGIEN6Dy5UvdJZjyPFvl1S/igQ5QD1SU= github.com/libp2p/go-tcp-transport v0.2.4/go.mod h1:9dvr03yqrPyYGIEN6Dy5UvdJZjyPFvl1S/igQ5QD1SU= github.com/libp2p/go-tcp-transport v0.2.7/go.mod h1:lue9p1b3VmZj1MhhEGB/etmvF/nBQ0X9CW2DutBT3MM= github.com/libp2p/go-tcp-transport v0.2.8 h1:aLjX+Nkz+kIz3uA56WtlGKRSAnKDvnqKmv1qF4EyyE4= @@ -1997,9 +2011,8 @@ golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5 golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210813211128-0a44fdfbc16e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20210915214749-c084706c2272 h1:3erb+vDS8lU1sxfDHF4/hhWyaXnhIaO+7RgL4fDZORA= golang.org/x/crypto v0.0.0-20210915214749-c084706c2272/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20211209193657-4570a0811e8b h1:QAqMVf3pSa6eeTsuklijukjXBlj7Es2QQplab+/RbQ4= -golang.org/x/crypto v0.0.0-20211209193657-4570a0811e8b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20181106170214-d68db9428509/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -2114,9 +2127,8 @@ golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20210917221730-978cfadd31cf h1:R150MpwJIv1MpS0N/pc+NhTM8ajzvlmxlY5OYsrevXQ= golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= diff --git a/lib/backupds/backupds_test.go b/lib/backupds/backupds_test.go index f7bc36e22..c681491e3 100644 --- a/lib/backupds/backupds_test.go +++ b/lib/backupds/backupds_test.go @@ -2,6 +2,7 @@ package backupds import ( "bytes" + "context" "fmt" "io/ioutil" "os" @@ -17,14 +18,14 @@ const valSize = 512 << 10 func putVals(t *testing.T, ds datastore.Datastore, start, end int) { for i := start; i < end; i++ { - err := ds.Put(datastore.NewKey(fmt.Sprintf("%d", i)), []byte(fmt.Sprintf("%d-%s", i, strings.Repeat("~", valSize)))) + err := ds.Put(context.TODO(), datastore.NewKey(fmt.Sprintf("%d", i)), []byte(fmt.Sprintf("%d-%s", i, strings.Repeat("~", valSize)))) require.NoError(t, err) } } func checkVals(t *testing.T, ds datastore.Datastore, start, end int, exist bool) { for i := start; i < end; i++ { - v, err := ds.Get(datastore.NewKey(fmt.Sprintf("%d", i))) + v, err := ds.Get(context.TODO(), datastore.NewKey(fmt.Sprintf("%d", i))) if exist { require.NoError(t, err) expect := []byte(fmt.Sprintf("%d-%s", i, strings.Repeat("~", valSize))) @@ -44,7 +45,7 @@ func TestNoLogRestore(t *testing.T) { require.NoError(t, err) var bup bytes.Buffer - require.NoError(t, bds.Backup(&bup)) + require.NoError(t, bds.Backup(context.TODO(), &bup)) putVals(t, ds1, 10, 20) diff --git a/lib/backupds/datastore.go b/lib/backupds/datastore.go index 350988a50..f0ece10ba 100644 --- a/lib/backupds/datastore.go +++ b/lib/backupds/datastore.go @@ -1,6 +1,7 @@ package backupds import ( + "context" "crypto/sha256" "io" "sync" @@ -52,7 +53,7 @@ func Wrap(child datastore.Batching, logdir string) (*Datastore, error) { // Writes a datastore dump into the provided writer as // [array(*) of [key, value] tuples, checksum] -func (d *Datastore) Backup(out io.Writer) error { +func (d *Datastore) Backup(ctx context.Context, out io.Writer) error { scratch := make([]byte, 9) if err := cbg.WriteMajorTypeHeaderBuf(scratch, out, cbg.MajArray, 2); err != nil { @@ -75,7 +76,7 @@ func (d *Datastore) Backup(out io.Writer) error { log.Info("Starting datastore backup") defer log.Info("Datastore backup done") - qr, err := d.child.Query(query.Query{}) + qr, err := d.child.Query(ctx, query.Query{}) if err != nil { return xerrors.Errorf("query: %w", err) } @@ -132,23 +133,23 @@ func (d *Datastore) Backup(out io.Writer) error { // proxy -func (d *Datastore) Get(key datastore.Key) (value []byte, err error) { - return d.child.Get(key) +func (d *Datastore) Get(ctx context.Context, key datastore.Key) (value []byte, err error) { + return d.child.Get(ctx, key) } -func (d *Datastore) Has(key datastore.Key) (exists bool, err error) { - return d.child.Has(key) +func (d *Datastore) Has(ctx context.Context, key datastore.Key) (exists bool, err error) { + return d.child.Has(ctx, key) } -func (d *Datastore) GetSize(key datastore.Key) (size int, err error) { - return d.child.GetSize(key) +func (d *Datastore) GetSize(ctx context.Context, key datastore.Key) (size int, err error) { + return d.child.GetSize(ctx, key) } -func (d *Datastore) Query(q query.Query) (query.Results, error) { - return d.child.Query(q) +func (d *Datastore) Query(ctx context.Context, q query.Query) (query.Results, error) { + return d.child.Query(ctx, q) } -func (d *Datastore) Put(key datastore.Key, value []byte) error { +func (d *Datastore) Put(ctx context.Context, key datastore.Key, value []byte) error { d.backupLk.RLock() defer d.backupLk.RUnlock() @@ -160,21 +161,21 @@ func (d *Datastore) Put(key datastore.Key, value []byte) error { } } - return d.child.Put(key, value) + return d.child.Put(ctx, key, value) } -func (d *Datastore) Delete(key datastore.Key) error { +func (d *Datastore) Delete(ctx context.Context, key datastore.Key) error { d.backupLk.RLock() defer d.backupLk.RUnlock() - return d.child.Delete(key) + return d.child.Delete(ctx, key) } -func (d *Datastore) Sync(prefix datastore.Key) error { +func (d *Datastore) Sync(ctx context.Context, prefix datastore.Key) error { d.backupLk.RLock() defer d.backupLk.RUnlock() - return d.child.Sync(prefix) + return d.child.Sync(ctx, prefix) } func (d *Datastore) CloseLog() error { @@ -196,8 +197,8 @@ func (d *Datastore) Close() error { ) } -func (d *Datastore) Batch() (datastore.Batch, error) { - b, err := d.child.Batch() +func (d *Datastore) Batch(ctx context.Context) (datastore.Batch, error) { + b, err := d.child.Batch(ctx) if err != nil { return nil, err } @@ -215,7 +216,7 @@ type bbatch struct { rlk sync.Locker } -func (b *bbatch) Put(key datastore.Key, value []byte) error { +func (b *bbatch) Put(ctx context.Context, key datastore.Key, value []byte) error { if b.d.log != nil { b.d.log <- Entry{ Key: []byte(key.String()), @@ -224,18 +225,18 @@ func (b *bbatch) Put(key datastore.Key, value []byte) error { } } - return b.b.Put(key, value) + return b.b.Put(ctx, key, value) } -func (b *bbatch) Delete(key datastore.Key) error { - return b.b.Delete(key) +func (b *bbatch) Delete(ctx context.Context, key datastore.Key) error { + return b.b.Delete(ctx, key) } -func (b *bbatch) Commit() error { +func (b *bbatch) Commit(ctx context.Context) error { b.rlk.Lock() defer b.rlk.Unlock() - return b.b.Commit() + return b.b.Commit(ctx) } var _ datastore.Batch = &bbatch{} diff --git a/lib/backupds/log.go b/lib/backupds/log.go index b76dfbfe6..b89f410f0 100644 --- a/lib/backupds/log.go +++ b/lib/backupds/log.go @@ -1,6 +1,7 @@ package backupds import ( + "context" "fmt" "io" "io/ioutil" @@ -100,6 +101,7 @@ type logfile struct { var compactThresh = 2 func (d *Datastore) createLog(logdir string) (*logfile, string, error) { + ctx := context.TODO() p := filepath.Join(logdir, strconv.FormatInt(time.Now().Unix(), 10)+".log.cbor") log.Infow("creating log", "file", p) @@ -108,7 +110,7 @@ func (d *Datastore) createLog(logdir string) (*logfile, string, error) { return nil, "", err } - if err := d.Backup(f); err != nil { + if err := d.Backup(ctx, f); err != nil { return nil, "", xerrors.Errorf("writing log base: %w", err) } if err := f.Sync(); err != nil { @@ -122,8 +124,9 @@ func (d *Datastore) createLog(logdir string) (*logfile, string, error) { } func (d *Datastore) openLog(p string) (*logfile, string, error) { + ctx := context.TODO() log.Infow("opening log", "file", p) - lh, err := d.child.Get(loghead) + lh, err := d.child.Get(ctx, loghead) if err != nil { return nil, "", xerrors.Errorf("checking log head (logfile '%s'): %w", p, err) } @@ -212,6 +215,7 @@ func (d *Datastore) openLog(p string) (*logfile, string, error) { } func (l *logfile) writeLogHead(logname string, ds datastore.Batching) error { + ctx := context.TODO() lval := []byte(fmt.Sprintf("%s;%s;%d", logname, uuid.New(), time.Now().Unix())) err := l.writeEntry(&Entry{ @@ -223,7 +227,7 @@ func (l *logfile) writeLogHead(logname string, ds datastore.Batching) error { return xerrors.Errorf("writing loghead to the log: %w", err) } - if err := ds.Put(loghead, lval); err != nil { + if err := ds.Put(ctx, loghead, lval); err != nil { return xerrors.Errorf("writing loghead to the datastore: %w", err) } diff --git a/lib/backupds/read.go b/lib/backupds/read.go index a44442af1..af4f30888 100644 --- a/lib/backupds/read.go +++ b/lib/backupds/read.go @@ -2,6 +2,7 @@ package backupds import ( "bytes" + "context" "crypto/sha256" "io" "os" @@ -117,13 +118,13 @@ func ReadBackup(r io.Reader, cb func(key datastore.Key, value []byte, log bool) } func RestoreInto(r io.Reader, dest datastore.Batching) error { - batch, err := dest.Batch() + batch, err := dest.Batch(context.TODO()) if err != nil { return xerrors.Errorf("creating batch: %w", err) } _, err = ReadBackup(r, func(key datastore.Key, value []byte, _ bool) error { - if err := batch.Put(key, value); err != nil { + if err := batch.Put(context.TODO(), key, value); err != nil { return xerrors.Errorf("put key: %w", err) } @@ -133,7 +134,7 @@ func RestoreInto(r io.Reader, dest datastore.Batching) error { return xerrors.Errorf("reading backup: %w", err) } - if err := batch.Commit(); err != nil { + if err := batch.Commit(context.TODO()); err != nil { return xerrors.Errorf("committing batch: %w", err) }