@cryptotaxi247 / kubo / commits / f66d94aaf

fix: move the check into the function.

function should be a no-op when passed an empty slice License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>

Brian Tiger Chow committed Dec 16, 2014 at 20:35 UTC f66d94aaf14106efc2b7855828f285f7f7b0db5a
1 file changed +6 -5
exchange/bitswap/bitswap.go
+6 -5
@@ -315,19 +315,20 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
315 log.Error(err)
316 }
317 }
318 - var blkeys []u.Key
318 + var keys []u.Key
319 for _, block := range incoming.Blocks() {
320 - blkeys = append(blkeys, block.Key())
321 - }
322 - if len(blkeys) > 0 {
323 - bs.cancelBlocks(ctx, blkeys)
320 + keys = append(keys, block.Key())
321 }
322 + bs.cancelBlocks(ctx, keys)
323
324 // TODO: consider changing this function to not return anything
325 return nil, nil
326 }
327
328 func (bs *bitswap) cancelBlocks(ctx context.Context, bkeys []u.Key) {
329 + if len(bkeys) < 1 {
330 + return
331 + }
332 message := bsmsg.New()
333 message.SetFull(false)
334 for _, k := range bkeys {