@@ -161,8 +161,7 @@ func (sws *sessionWantSender) Cancel(ks []cid.Cid) {
161
161
// Update is called when the session receives a message with incoming blocks
162
162
// or HAVE / DONT_HAVE
163
163
func (sws * sessionWantSender ) Update (from peer.ID , ks []cid.Cid , haves []cid.Cid , dontHaves []cid.Cid ) {
164
- hasUpdate := len (ks ) > 0 || len (haves ) > 0 || len (dontHaves ) > 0
165
- if ! hasUpdate {
164
+ if len (ks ) == 0 && len (haves ) == 0 && len (dontHaves ) == 0 {
166
165
return
167
166
}
168
167
@@ -270,7 +269,7 @@ func (sws *sessionWantSender) onChange(changes []change) {
270
269
if chng .update .from != "" {
271
270
// If the update includes blocks or haves, treat it as signaling that
272
271
// the peer is available
273
- if len (chng .update .ks ) > 0 || len (chng .update .haves ) > 0 {
272
+ if len (chng .update .ks ) != 0 || len (chng .update .haves ) != 0 {
274
273
p := chng .update .from
275
274
availability [p ] = true
276
275
@@ -296,7 +295,7 @@ func (sws *sessionWantSender) onChange(changes []change) {
296
295
sws .checkForExhaustedWants (dontHaves , newlyUnavailable )
297
296
298
297
// If there are any cancels, send them
299
- if len (cancels ) > 0 {
298
+ if len (cancels ) != 0 {
300
299
sws .canceller .CancelSessionWants (sws .sessionID , cancels )
301
300
}
302
301
@@ -349,8 +348,7 @@ func (sws *sessionWantSender) trackWant(c cid.Cid) {
349
348
}
350
349
351
350
// Create the want info
352
- wi := newWantInfo (sws .peerRspTrkr )
353
- sws .wants [c ] = wi
351
+ sws .wants [c ] = newWantInfo (sws .peerRspTrkr )
354
352
355
353
// For each available peer, register any information we know about
356
354
// whether the peer has the block
@@ -451,7 +449,7 @@ func (sws *sessionWantSender) processUpdates(updates []update) []cid.Cid {
451
449
}
452
450
}
453
451
}
454
- if len (prunePeers ) > 0 {
452
+ if len (prunePeers ) != 0 {
455
453
go func () {
456
454
for p := range prunePeers {
457
455
// Peer doesn't have anything we want, so remove it
@@ -479,11 +477,13 @@ func (sws *sessionWantSender) checkForExhaustedWants(dontHaves []cid.Cid, newlyU
479
477
480
478
// If a peer just became unavailable, then we need to check all wants
481
479
// (because it may be the last peer who hadn't sent a DONT_HAVE for a CID)
482
- if len (newlyUnavailable ) > 0 {
480
+ if len (newlyUnavailable ) != 0 {
483
481
// Collect all pending wants
484
482
wants = make ([]cid.Cid , len (sws .wants ))
483
+ var i int
485
484
for c := range sws .wants {
486
- wants = append (wants , c )
485
+ wants [i ] = c
486
+ i ++
487
487
}
488
488
489
489
// If the last available peer in the session has become unavailable
@@ -496,7 +496,7 @@ func (sws *sessionWantSender) checkForExhaustedWants(dontHaves []cid.Cid, newlyU
496
496
497
497
// If all available peers for a cid sent a DONT_HAVE, signal to the session
498
498
// that we've exhausted available peers
499
- if len (wants ) > 0 {
499
+ if len (wants ) != 0 {
500
500
exhausted := sws .bpm .AllPeersDoNotHaveBlock (sws .spm .Peers (), wants )
501
501
sws .processExhaustedWants (exhausted )
502
502
}
@@ -506,7 +506,7 @@ func (sws *sessionWantSender) checkForExhaustedWants(dontHaves []cid.Cid, newlyU
506
506
// already been marked as exhausted are passed to onPeersExhausted()
507
507
func (sws * sessionWantSender ) processExhaustedWants (exhausted []cid.Cid ) {
508
508
newlyExhausted := sws .newlyExhausted (exhausted )
509
- if len (newlyExhausted ) > 0 {
509
+ if len (newlyExhausted ) != 0 {
510
510
sws .onPeersExhausted (newlyExhausted )
511
511
}
512
512
}
0 commit comments