diff --git a/blockservice/blockservice.go b/blockservice/blockservice.go index 3018ae0d87e80803bae99236a3e400564d2b2af7..e3c7402bd64c0e488e561cebe90e5a1461ec0e20 100644 --- a/blockservice/blockservice.go +++ b/blockservice/blockservice.go @@ -43,7 +43,8 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) { return k, err } if s.Remote != nil { - err = s.Remote.HasBlock(*b) + ctx := context.TODO() + err = s.Remote.HasBlock(ctx, *b) } return k, err } diff --git a/exchange/bitswap/bitswap.go b/exchange/bitswap/bitswap.go index 62ff1cd28653f94bf8c5ca2557f19a31c7063a7a..35a1a90b55acc028733cf770e0acc29a62c53d34 100644 --- a/exchange/bitswap/bitswap.go +++ b/exchange/bitswap/bitswap.go @@ -128,8 +128,7 @@ func (bs *bitswap) sendToPeersThatWant(ctx context.Context, block blocks.Block) // HasBlock announces the existance of a block to bitswap, potentially sending // it to peers (Partners) whose WantLists include it. -func (bs *bitswap) HasBlock(blk blocks.Block) error { - ctx := context.TODO() +func (bs *bitswap) HasBlock(ctx context.Context, blk blocks.Block) error { go bs.sendToPeersThatWant(ctx, blk) return bs.routing.Provide(blk.Key()) } diff --git a/exchange/bitswap/offline.go b/exchange/bitswap/offline.go index e35cce2fcc6232cc99d1f0ecb6bce2d972cd9700..9695b0b56859bb78dee541f43b972cb7bcfdcda9 100644 --- a/exchange/bitswap/offline.go +++ b/exchange/bitswap/offline.go @@ -27,6 +27,6 @@ func (_ *offlineExchange) Block(context.Context, u.Key) (*blocks.Block, error) { } // HasBlock always returns nil. -func (_ *offlineExchange) HasBlock(blocks.Block) error { +func (_ *offlineExchange) HasBlock(context.Context, blocks.Block) error { return nil } diff --git a/exchange/bitswap/offline_test.go b/exchange/bitswap/offline_test.go index 19b040cd55ce7de66a086f88d864b0cbe94f8e9e..26821f2c8a33fd177d26065aec348d07fb828346 100644 --- a/exchange/bitswap/offline_test.go +++ b/exchange/bitswap/offline_test.go @@ -11,7 +11,7 @@ import ( func TestBlockReturnsErr(t *testing.T) { off := NewOfflineExchange() - _, err := off.Block(context.TODO(), u.Key("foo")) + _, err := off.Block(context.Background(), u.Key("foo")) if err != nil { return // as desired } @@ -21,7 +21,7 @@ func TestBlockReturnsErr(t *testing.T) { func TestHasBlockReturnsNil(t *testing.T) { off := NewOfflineExchange() block := testutil.NewBlockOrFail(t, "data") - err := off.HasBlock(block) + err := off.HasBlock(context.Background(), block) if err != nil { t.Fatal("") } diff --git a/exchange/interface.go b/exchange/interface.go index 7e06e1ed14a38c35b2ac12009647b760b5058bdf..a96094eaa8d2ef5f6854553dfbe520ad92ccac44 100644 --- a/exchange/interface.go +++ b/exchange/interface.go @@ -12,13 +12,9 @@ import ( type Interface interface { // Block returns the block associated with a given key. - // TODO(brian): pass a context instead of a timeout Block(context.Context, u.Key) (*blocks.Block, error) - // HasBlock asserts the existence of this block - // TODO(brian): rename -> HasBlock - // TODO(brian): accept a value, not a pointer - // TODO(brian): remove error return value. Should callers be concerned with - // whether the block was made available on the network? - HasBlock(blocks.Block) error + // TODO Should callers be concerned with whether the block was made + // available on the network? + HasBlock(context.Context, blocks.Block) error }