Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading