Commit 1f178a6f authored by Jeromy's avatar Jeromy

address comments from CR

parent b9fa4eed
...@@ -349,7 +349,8 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg ...@@ -349,7 +349,8 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg
keys = append(keys, block.Key()) keys = append(keys, block.Key())
} }
return bs.cancelBlocks(ctx, keys) bs.cancelBlocks(ctx, keys)
return nil
} }
// Connected/Disconnected warns bitswap about peer connections // Connected/Disconnected warns bitswap about peer connections
...@@ -369,9 +370,9 @@ func (bs *Bitswap) PeerDisconnected(p peer.ID) { ...@@ -369,9 +370,9 @@ func (bs *Bitswap) PeerDisconnected(p peer.ID) {
bs.engine.PeerDisconnected(p) bs.engine.PeerDisconnected(p)
} }
func (bs *Bitswap) cancelBlocks(ctx context.Context, bkeys []u.Key) error { func (bs *Bitswap) cancelBlocks(ctx context.Context, bkeys []u.Key) {
if len(bkeys) < 1 { if len(bkeys) < 1 {
return nil return
} }
message := bsmsg.New() message := bsmsg.New()
message.SetFull(false) message.SetFull(false)
...@@ -379,14 +380,21 @@ func (bs *Bitswap) cancelBlocks(ctx context.Context, bkeys []u.Key) error { ...@@ -379,14 +380,21 @@ func (bs *Bitswap) cancelBlocks(ctx context.Context, bkeys []u.Key) error {
log.Debug("cancel block: %s", k) log.Debug("cancel block: %s", k)
message.Cancel(k) message.Cancel(k)
} }
wg := sync.WaitGroup{}
for _, p := range bs.engine.Peers() { for _, p := range bs.engine.Peers() {
wg.Add(1)
go func(p peer.ID) {
defer wg.Done()
err := bs.send(ctx, p, message) err := bs.send(ctx, p, message)
if err != nil { if err != nil {
log.Debugf("Error sending message: %s", err) log.Warningf("Error sending message: %s", err)
return err return
} }
}(p)
} }
return nil wg.Wait()
return
} }
func (bs *Bitswap) wantNewBlocks(ctx context.Context, bkeys []u.Key) { func (bs *Bitswap) wantNewBlocks(ctx context.Context, bkeys []u.Key) {
......
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