Skip to content

Commit

Permalink
Always send cancels even if peer has no interest (#829)
Browse files Browse the repository at this point in the history
* Always send cancels even if peer has no interest
* increase max send delay
  • Loading branch information
gammazero authored Feb 4, 2025
1 parent 49f6c15 commit 9e257a7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ The following emojis are used to highlight certain changes:

### Fixed

- Fix memory leak due to not cleaning up wantlists [#829](https://github.com/ipfs/boxo/pull/829)

### Security


Expand Down
2 changes: 1 addition & 1 deletion bitswap/client/internal/messagequeue/messagequeue.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const (
sendTimeout = 30 * time.Second

defaultPerPeerDelay = time.Millisecond / 8
maxSendMessageDelay = time.Second
maxSendMessageDelay = 2 * time.Second
minSendMessageDelay = 20 * time.Millisecond
)

Expand Down
8 changes: 5 additions & 3 deletions bitswap/client/internal/sessionmanager/sessionmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ func (sm *SessionManager) GetNextSessionID() uint64 {
// their contents. If the caller needs to preserve a copy of the lists it
// should make a copy before calling ReceiveFrom.
func (sm *SessionManager) ReceiveFrom(ctx context.Context, p peer.ID, blks []cid.Cid, haves []cid.Cid, dontHaves []cid.Cid) {
// Send CANCEL to all peers with want-have / want-block. This needs to be
// done before filtering out CIDs that peers are no longer interested in,
// to ensure they are removed from PeerManager and PeerQueue want lists.
sm.peerManager.SendCancels(ctx, blks)

// Keep only the keys that at least one session wants
keys := sm.sessionInterestManager.FilterInterests(blks, haves, dontHaves)
blks = keys[0]
Expand All @@ -179,9 +184,6 @@ func (sm *SessionManager) ReceiveFrom(ctx context.Context, p peer.ID, blks []cid
sess.ReceiveFrom(p, blks, haves, dontHaves)
}
}

// Send CANCEL to all peers with want-have / want-block
sm.peerManager.SendCancels(ctx, blks)
}

// CancelSessionWants is called when a session cancels wants because a call to
Expand Down

0 comments on commit 9e257a7

Please sign in to comment.