address comments from CR
Jeromy committed
May 6, 2015 at 00:50 UTC
9049dae6742e3b75d06c16705adcde55381ff819
1 file changed
+17
-9
exchange/bitswap/bitswap.go
+17
-9
@@ -349,7 +349,8 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg
349
keys = append(keys, block.Key())
350
}
351
352
- return bs.cancelBlocks(ctx, keys)
352
+ bs.cancelBlocks(ctx, keys)
353
+ return nil
354
}
355
356
// Connected/Disconnected warns bitswap about peer connections
@@ -369,9 +370,9 @@ func (bs *Bitswap) PeerDisconnected(p peer.ID) {
370
bs.engine.PeerDisconnected(p)
371
}
372
372
-func (bs *Bitswap) cancelBlocks(ctx context.Context, bkeys []u.Key) error {
373
+func (bs *Bitswap) cancelBlocks(ctx context.Context, bkeys []u.Key) {
374
if len(bkeys) < 1 {
374
- return nil
375
+ return
376
}
377
message := bsmsg.New()
378
message.SetFull(false)
@@ -379,14 +380,21 @@ func (bs *Bitswap) cancelBlocks(ctx context.Context, bkeys []u.Key) error {
380
log.Debug("cancel block: %s", k)
381
message.Cancel(k)
382
}
383
+
384
+ wg := sync.WaitGroup{}
385
for _, p := range bs.engine.Peers() {
383
- err := bs.send(ctx, p, message)
384
- if err != nil {
385
- log.Debugf("Error sending message: %s", err)
386
- return err
387
- }
386
+ wg.Add(1)
387
+ go func(p peer.ID) {
388
+ defer wg.Done()
389
+ err := bs.send(ctx, p, message)
390
+ if err != nil {
391
+ log.Warningf("Error sending message: %s", err)
392
+ return
393
+ }
394
+ }(p)
395
}
389
- return nil
396
+ wg.Wait()
397
+ return
398
}
399
400
func (bs *Bitswap) wantNewBlocks(ctx context.Context, bkeys []u.Key) {