@cryptotaxi247 / kubo / commits / e907b2e03

feat(exchange) pass ctx to exchange.HasBlock(...)

Brian Tiger Chow committed Sep 18, 2014 at 19:43 UTC e907b2e03ccf6ac9f4d828e97fea866e7c3b22c0
5 files changed +9 -13
blockservice/blockservice.go
+2 -1
@@ -43,7 +43,8 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
43 return k, err
44 }
45 if s.Remote != nil {
46 - err = s.Remote.HasBlock(*b)
46 + ctx := context.TODO()
47 + err = s.Remote.HasBlock(ctx, *b)
48 }
49 return k, err
50 }
exchange/bitswap/bitswap.go
+1 -2
@@ -128,8 +128,7 @@ func (bs *bitswap) sendToPeersThatWant(ctx context.Context, block blocks.Block)
128
129 // HasBlock announces the existance of a block to bitswap, potentially sending
130 // it to peers (Partners) whose WantLists include it.
131 -func (bs *bitswap) HasBlock(blk blocks.Block) error {
132 - ctx := context.TODO()
131 +func (bs *bitswap) HasBlock(ctx context.Context, blk blocks.Block) error {
132 go bs.sendToPeersThatWant(ctx, blk)
133 return bs.routing.Provide(blk.Key())
134 }
exchange/bitswap/offline.go
+1 -1
@@ -27,6 +27,6 @@ func (_ *offlineExchange) Block(context.Context, u.Key) (*blocks.Block, error) {
27 }
28
29 // HasBlock always returns nil.
30 -func (_ *offlineExchange) HasBlock(blocks.Block) error {
30 +func (_ *offlineExchange) HasBlock(context.Context, blocks.Block) error {
31 return nil
32 }
exchange/bitswap/offline_test.go
+2 -2
@@ -11,7 +11,7 @@ import (
11
12 func TestBlockReturnsErr(t *testing.T) {
13 off := NewOfflineExchange()
14 - _, err := off.Block(context.TODO(), u.Key("foo"))
14 + _, err := off.Block(context.Background(), u.Key("foo"))
15 if err != nil {
16 return // as desired
17 }
@@ -21,7 +21,7 @@ func TestBlockReturnsErr(t *testing.T) {
21 func TestHasBlockReturnsNil(t *testing.T) {
22 off := NewOfflineExchange()
23 block := testutil.NewBlockOrFail(t, "data")
24 - err := off.HasBlock(block)
24 + err := off.HasBlock(context.Background(), block)
25 if err != nil {
26 t.Fatal("")
27 }
exchange/interface.go
+3 -7
@@ -12,13 +12,9 @@ import (
12 type Interface interface {
13
14 // Block returns the block associated with a given key.
15 - // TODO(brian): pass a context instead of a timeout
15 Block(context.Context, u.Key) (*blocks.Block, error)
16
18 - // HasBlock asserts the existence of this block
19 - // TODO(brian): rename -> HasBlock
20 - // TODO(brian): accept a value, not a pointer
21 - // TODO(brian): remove error return value. Should callers be concerned with
22 - // whether the block was made available on the network?
23 - HasBlock(blocks.Block) error
17 + // TODO Should callers be concerned with whether the block was made
18 + // available on the network?
19 + HasBlock(context.Context, blocks.Block) error
20 }