Skip to content

Commit

Permalink
minimize peermanager lock scope (#860)
Browse files Browse the repository at this point in the history
  • Loading branch information
gammazero authored Feb 28, 2025
1 parent a52633b commit 3f0c94f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions bitswap/client/internal/peermanager/peermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,35 +82,36 @@ func (pm *PeerManager) ConnectedPeers() []peer.ID {
// of wants.
func (pm *PeerManager) Connected(p peer.ID) {
pm.pqLk.Lock()
defer pm.pqLk.Unlock()

pq := pm.getOrCreate(p)

// Inform the peer want manager that there's a new peer
pm.pwm.addPeer(pq, p)

pm.pqLk.Unlock()

// Inform the sessions that the peer has connected
pm.signalAvailability(p, true)
}

// Disconnected is called to remove a peer from the pool.
func (pm *PeerManager) Disconnected(p peer.ID) {
pm.pqLk.Lock()
defer pm.pqLk.Unlock()

pq, ok := pm.peerQueues[p]

if !ok {
pm.pqLk.Unlock()
return
}
// Clean up the peer
delete(pm.peerQueues, p)
pm.pwm.removePeer(p)

pm.pqLk.Unlock()

// Inform the sessions that the peer has disconnected
pm.signalAvailability(p, false)

// Clean up the peer
delete(pm.peerQueues, p)
pq.Shutdown()
pm.pwm.removePeer(p)
}

// ResponseReceived is called when a message is received from the network.
Expand Down

0 comments on commit 3f0c94f

Please sign in to comment.