Skip to content

Commit

Permalink
fix(network): disconnect from peers that has no protocol (#1243)
Browse files Browse the repository at this point in the history
  • Loading branch information
b00f authored and themantre committed Apr 24, 2024
1 parent af79d2c commit 3e28047
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 1 addition & 3 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
lp2prcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager"
lp2pconnmgr "github.com/libp2p/go-libp2p/p2p/net/connmgr"
lp2pproto "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/proto"
lp2pnoise "github.com/libp2p/go-libp2p/p2p/security/noise"
lp2quic "github.com/libp2p/go-libp2p/p2p/transport/quic"
lp2ptcp "github.com/libp2p/go-libp2p/p2p/transport/tcp"
"github.com/multiformats/go-multiaddr"
Expand Down Expand Up @@ -147,9 +146,8 @@ func newNetwork(conf *Config, log *logger.SubLogger, opts []lp2p.Option) (*netwo
lp2p.UserAgent(version.NodeAgent.String()),
lp2p.ResourceManager(resMgr),
lp2p.ConnectionManager(connMgr),
lp2p.Ping(false),
lp2p.Ping(true),
lp2p.Transport(lp2ptcp.NewTCPTransport),
lp2p.Security(lp2pnoise.ID, lp2pnoise.New),
)

if conf.EnableUDP {
Expand Down
8 changes: 8 additions & 0 deletions network/peermgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ func (mgr *peerMgr) CheckConnectivity() {

net := mgr.host.Network()

// 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 {
Expand Down

0 comments on commit 3e28047

Please sign in to comment.