misc(bitswap): shorten comment and rename var
Brian Tiger Chow committed
Jan 18, 2015 at 20:39 UTC
bb89e0d8d739cbd7a65d9a488b0f6bc9576c7f2c
1 file changed
+7
-11
exchange/bitswap/bitswap.go
+7
-11
@@ -290,23 +290,19 @@ func (bs *bitswap) clientWorker(parent context.Context) {
290
case <-broadcastSignal: // resend unfulfilled wantlist keys
291
bs.sendWantlistToProviders(ctx)
292
broadcastSignal = time.After(rebroadcastDelay.Get())
293
- case ks := <-bs.batchRequests:
294
- if len(ks) == 0 {
293
+ case keys := <-bs.batchRequests:
294
+ if len(keys) == 0 {
295
log.Warning("Received batch request for zero blocks")
296
continue
297
}
298
- for i, k := range ks {
298
+ for i, k := range keys {
299
bs.wantlist.Add(k, kMaxPriority-i)
300
}
301
- // NB: send want list to providers for the first peer in this list.
302
- // the assumption is made that the providers of the first key in
303
- // the set are likely to have others as well.
304
- // This currently holds true in most every situation, since when
305
- // pinning a file, you store and provide all blocks associated with
306
- // it. Later, this assumption may not hold as true if we implement
307
- // newer bitswap strategies.
301
+ // NB: Optimization. Assumes that providers of key[0] are likely to
302
+ // be able to provide for all keys. This currently holds true in most
303
+ // every situation. Later, this assumption may not hold as true.
304
child, _ := context.WithTimeout(ctx, providerRequestTimeout)
309
- providers := bs.network.FindProvidersAsync(child, ks[0], maxProvidersPerRequest)
305
+ providers := bs.network.FindProvidersAsync(child, keys[0], maxProvidersPerRequest)
306
err := bs.sendWantlistToPeers(ctx, providers)
307
if err != nil {
308
log.Errorf("error sending wantlist: %s", err)