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) {
// HasBlock announces the existance of a block to this bitswap service. The
// 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 {
case <-bs.process.Closing():
return errors.New("bitswap is closed")
......@@ -246,8 +246,8 @@ func (bs *Bitswap) HasBlock(ctx context.Context, blk *blocks.Block) error {
select {
case bs.newBlocks <- blk:
// send block off to be reprovided
case <-ctx.Done():
return ctx.Err()
case <-bs.process.Closing():
return bs.process.Close()
}
return nil
}
......@@ -328,9 +328,7 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg
log.Event(ctx, "Bitswap.GetBlockRequest.End", &k)
log.Debugf("got block %s from %s", b, p)
hasBlockCtx, cancel := context.WithTimeout(ctx, hasBlockTimeout)
defer cancel()
if err := bs.HasBlock(hasBlockCtx, b); err != nil {
if err := bs.HasBlock(b); err != nil {
log.Warningf("ReceiveMessage HasBlock error: %s", err)
}
}(block)
......
......@@ -70,7 +70,7 @@ func TestGetBlockFromPeerAfterPeerAnnounces(t *testing.T) {
hasBlock := peers[0]
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)
}
......@@ -162,7 +162,7 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
first := instances[0]
for _, b := range blocks {
blkeys = append(blkeys, b.Key())
first.Exchange.HasBlock(ctx, b)
first.Exchange.HasBlock(b)
}
t.Log("Distribute!")
......@@ -224,7 +224,6 @@ func TestSendToWantingPeer(t *testing.T) {
t.Logf("Session %v\n", peerA.Peer)
t.Logf("Session %v\n", peerB.Peer)
timeout := time.Second
waitTime := time.Second * 5
alpha := bg.Next()
......@@ -237,9 +236,7 @@ func TestSendToWantingPeer(t *testing.T) {
}
// peerB announces to the network that he has block alpha
ctx, cancel = context.WithTimeout(context.Background(), timeout)
defer cancel()
err = peerB.Exchange.HasBlock(ctx, alpha)
err = peerB.Exchange.HasBlock(alpha)
if err != nil {
t.Fatal(err)
}
......@@ -266,7 +263,7 @@ func TestBasicBitswap(t *testing.T) {
instances := sg.Instances(2)
blocks := bg.Blocks(1)
err := instances[0].Exchange.HasBlock(context.Background(), blocks[0])
err := instances[0].Exchange.HasBlock(blocks[0])
if err != nil {
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