File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
bitswap/internal/peermanager Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,16 @@ func (pwm *peerWantManager) addPeer(p peer.ID) {
50
50
51
51
// RemovePeer removes a peer and its associated wants from tracking
52
52
func (pwm * peerWantManager ) removePeer (p peer.ID ) {
53
+ pws , ok := pwm .peerWants [p ]
54
+ if ! ok {
55
+ return
56
+ }
57
+
58
+ // Decrement the gauge by the number of pending want-blocks to the peer
59
+ for range pws .wantBlocks .Keys () {
60
+ pwm .wantBlockGauge .Dec ()
61
+ }
62
+
53
63
delete (pwm .peerWants , p )
54
64
}
55
65
Original file line number Diff line number Diff line change @@ -289,4 +289,10 @@ func TestStats(t *testing.T) {
289
289
if g .count != 3 {
290
290
t .Fatal ("Expected 3 want-blocks" , g .count )
291
291
}
292
+
293
+ pwm .removePeer (p0 )
294
+
295
+ if g .count != 0 {
296
+ t .Fatal ("Expected all want-blocks to be removed with peer" , g .count )
297
+ }
292
298
}
You can’t perform that action at this time.
0 commit comments