Commit afee5e33 authored by Jeromy's avatar Jeromy

remove context from HasBlock, use bitswap process instead

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>
parent f62acec4
...@@ -228,7 +228,7 @@ func (bs *Bitswap) CancelWants(ks []key.Key) { ...@@ -228,7 +228,7 @@ func (bs *Bitswap) CancelWants(ks []key.Key) {
// HasBlock announces the existance of a block to this bitswap service. The // HasBlock announces the existance of a block to this bitswap service. The
// service will potentially notify its peers. // service will potentially notify its peers.
func (bs *Bitswap) HasBlock(ctx context.Context, blk *blocks.Block) error { func (bs *Bitswap) HasBlock(blk *blocks.Block) error {
select { select {
case <-bs.process.Closing(): case <-bs.process.Closing():
return errors.New("bitswap is closed") return errors.New("bitswap is closed")
...@@ -246,8 +246,8 @@ func (bs *Bitswap) HasBlock(ctx context.Context, blk *blocks.Block) error { ...@@ -246,8 +246,8 @@ func (bs *Bitswap) HasBlock(ctx context.Context, blk *blocks.Block) error {
select { select {
case bs.newBlocks <- blk: case bs.newBlocks <- blk:
// send block off to be reprovided // send block off to be reprovided
case <-ctx.Done(): case <-bs.process.Closing():
return ctx.Err() return bs.process.Close()
} }
return nil return nil
} }
...@@ -328,9 +328,7 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg ...@@ -328,9 +328,7 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg
log.Event(ctx, "Bitswap.GetBlockRequest.End", &k) log.Event(ctx, "Bitswap.GetBlockRequest.End", &k)
log.Debugf("got block %s from %s", b, p) log.Debugf("got block %s from %s", b, p)
hasBlockCtx, cancel := context.WithTimeout(ctx, hasBlockTimeout) if err := bs.HasBlock(b); err != nil {
defer cancel()
if err := bs.HasBlock(hasBlockCtx, b); err != nil {
log.Warningf("ReceiveMessage HasBlock error: %s", err) log.Warningf("ReceiveMessage HasBlock error: %s", err)
} }
}(block) }(block)
......
...@@ -70,7 +70,7 @@ func TestGetBlockFromPeerAfterPeerAnnounces(t *testing.T) { ...@@ -70,7 +70,7 @@ func TestGetBlockFromPeerAfterPeerAnnounces(t *testing.T) {
hasBlock := peers[0] hasBlock := peers[0]
defer hasBlock.Exchange.Close() defer hasBlock.Exchange.Close()
if err := hasBlock.Exchange.HasBlock(context.Background(), block); err != nil { if err := hasBlock.Exchange.HasBlock(block); err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -162,7 +162,7 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) { ...@@ -162,7 +162,7 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
first := instances[0] first := instances[0]
for _, b := range blocks { for _, b := range blocks {
blkeys = append(blkeys, b.Key()) blkeys = append(blkeys, b.Key())
first.Exchange.HasBlock(ctx, b) first.Exchange.HasBlock(b)
} }
t.Log("Distribute!") t.Log("Distribute!")
...@@ -224,7 +224,6 @@ func TestSendToWantingPeer(t *testing.T) { ...@@ -224,7 +224,6 @@ func TestSendToWantingPeer(t *testing.T) {
t.Logf("Session %v\n", peerA.Peer) t.Logf("Session %v\n", peerA.Peer)
t.Logf("Session %v\n", peerB.Peer) t.Logf("Session %v\n", peerB.Peer)
timeout := time.Second
waitTime := time.Second * 5 waitTime := time.Second * 5
alpha := bg.Next() alpha := bg.Next()
...@@ -237,9 +236,7 @@ func TestSendToWantingPeer(t *testing.T) { ...@@ -237,9 +236,7 @@ func TestSendToWantingPeer(t *testing.T) {
} }
// peerB announces to the network that he has block alpha // peerB announces to the network that he has block alpha
ctx, cancel = context.WithTimeout(context.Background(), timeout) err = peerB.Exchange.HasBlock(alpha)
defer cancel()
err = peerB.Exchange.HasBlock(ctx, alpha)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -266,7 +263,7 @@ func TestBasicBitswap(t *testing.T) { ...@@ -266,7 +263,7 @@ func TestBasicBitswap(t *testing.T) {
instances := sg.Instances(2) instances := sg.Instances(2)
blocks := bg.Blocks(1) blocks := bg.Blocks(1)
err := instances[0].Exchange.HasBlock(context.Background(), blocks[0]) err := instances[0].Exchange.HasBlock(blocks[0])
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment