From 9049dae6742e3b75d06c16705adcde55381ff819 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Wed, 6 May 2015 00:50:44 -0700 Subject: [PATCH] address comments from CR --- exchange/bitswap/bitswap.go | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/exchange/bitswap/bitswap.go b/exchange/bitswap/bitswap.go index 61854c79a..757c9067e 100644 --- a/exchange/bitswap/bitswap.go +++ b/exchange/bitswap/bitswap.go @@ -349,7 +349,8 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg keys = append(keys, block.Key()) } - return bs.cancelBlocks(ctx, keys) + bs.cancelBlocks(ctx, keys) + return nil } // Connected/Disconnected warns bitswap about peer connections @@ -369,9 +370,9 @@ func (bs *Bitswap) PeerDisconnected(p peer.ID) { 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 { - return nil + return } message := bsmsg.New() message.SetFull(false) @@ -379,14 +380,21 @@ func (bs *Bitswap) cancelBlocks(ctx context.Context, bkeys []u.Key) error { log.Debug("cancel block: %s", k) message.Cancel(k) } + + wg := sync.WaitGroup{} for _, p := range bs.engine.Peers() { - err := bs.send(ctx, p, message) - if err != nil { - log.Debugf("Error sending message: %s", err) - return err - } + wg.Add(1) + go func(p peer.ID) { + defer wg.Done() + err := bs.send(ctx, p, message) + if err != nil { + log.Warningf("Error sending message: %s", err) + return + } + }(p) } - return nil + wg.Wait() + return } func (bs *Bitswap) wantNewBlocks(ctx context.Context, bkeys []u.Key) {