@@ -237,25 +237,20 @@ func (pwm *peerWantManager) sendCancels(cancelKs []cid.Cid) {
237
237
return
238
238
}
239
239
240
- // Record how many peers have a pending want-block and want-have for each
241
- // key to be cancelled
240
+ // Track cancellation state: peerCounts tracks per-CID want counts across
241
+ // peers, while broadcastCancels collects CIDs wants that were broadcasted
242
+ // and need cancellation across all peers
242
243
peerCounts := make (map [cid.Cid ]wantPeerCnts , len (cancelKs ))
243
- for _ , c := range cancelKs {
244
- peerCounts [c ] = pwm .wantPeerCounts (c )
245
- }
246
-
247
- // Create a buffer to use for filtering cancels per peer, with the
248
- // broadcast wants at the front of the buffer (broadcast wants are sent to
249
- // all peers)
250
244
broadcastCancels := make ([]cid.Cid , 0 , len (cancelKs ))
251
245
for _ , c := range cancelKs {
252
- if pwm .broadcastWants .Has (c ) {
246
+ peerCounts [c ] = pwm .wantPeerCounts (c )
247
+ if peerCounts [c ].isBroadcast {
253
248
broadcastCancels = append (broadcastCancels , c )
254
249
}
255
250
}
256
251
257
252
// Send cancels to a particular peer
258
- send := func (p peer. ID , pws * peerWant ) {
253
+ send := func (pws * peerWant ) {
259
254
// Start from the broadcast cancels
260
255
toCancel := broadcastCancels
261
256
@@ -301,8 +296,8 @@ func (pwm *peerWantManager) sendCancels(cancelKs []cid.Cid) {
301
296
if len (broadcastCancels ) > 0 {
302
297
// If a broadcast want is being cancelled, send the cancel to all
303
298
// peers
304
- for p , pws := range pwm .peerWants {
305
- send (p , pws )
299
+ for _ , pws := range pwm .peerWants {
300
+ send (pws )
306
301
}
307
302
308
303
// Remove cancelled broadcast wants
@@ -323,7 +318,7 @@ func (pwm *peerWantManager) sendCancels(cancelKs []cid.Cid) {
323
318
log .Errorf ("sendCancels - peerWantManager index missing peer %s" , p )
324
319
continue
325
320
}
326
- send (p , pws )
321
+ send (pws )
327
322
}
328
323
329
324
clearWantsForCID (c )
0 commit comments