Skip to content

Commit

Permalink
fix: close connections with peers that have no supported protocol (#1181
Browse files Browse the repository at this point in the history
)
  • Loading branch information
b00f authored Mar 26, 2024
1 parent 65f874c commit 6c7ff75
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions network/peermgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (mgr *peerMgr) Start() {
mgr.CheckConnectivity()

go func() {
ticker := time.NewTicker(20 * time.Second)
ticker := time.NewTicker(60 * time.Second)
defer ticker.Stop()

for {
Expand Down Expand Up @@ -153,7 +153,15 @@ func (mgr *peerMgr) CheckConnectivity() {

net := mgr.host.Network()

// Let's check if some peers are disconnected
// Close connections with peers that have no supported protocol.
for pid := range mgr.peers {
prtcls, _ := mgr.host.Peerstore().GetProtocols(pid)
if len(prtcls) == 0 {
_ = net.ClosePeer(pid)
}
}

// Check if some peers are disconnected
var connectedPeers []lp2ppeer.ID
for pid := range mgr.peers {
connectedness := net.Connectedness(pid)
Expand Down

0 comments on commit 6c7ff75

Please sign in to comment.