From c3f238dd5371961d309350fb0f9d5136c9fc6afa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felf=C3=B6ldi=20Zsolt?= Date: Mon, 5 Feb 2018 14:41:53 +0100 Subject: les: limit LES peer count and improve peer configuration logic (#16010) * les: limit number of LES connections * eth, cmd/utils: light vs max peer configuration logic --- les/handler.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'les/handler.go') diff --git a/les/handler.go b/les/handler.go index ad2e8058f..8cd37c7ab 100644 --- a/les/handler.go +++ b/les/handler.go @@ -109,6 +109,7 @@ type ProtocolManager struct { downloader *downloader.Downloader fetcher *lightFetcher peers *peerSet + maxPeers int SubProtocols []p2p.Protocol @@ -216,7 +217,9 @@ func (pm *ProtocolManager) removePeer(id string) { pm.peers.Unregister(id) } -func (pm *ProtocolManager) Start() { +func (pm *ProtocolManager) Start(maxPeers int) { + pm.maxPeers = maxPeers + if pm.lightSync { go pm.syncer() } else { @@ -257,6 +260,10 @@ func (pm *ProtocolManager) newPeer(pv int, nv uint64, p *p2p.Peer, rw p2p.MsgRea // handle is the callback invoked to manage the life cycle of a les peer. When // this function terminates, the peer is disconnected. func (pm *ProtocolManager) handle(p *peer) error { + if pm.peers.Len() >= pm.maxPeers { + return p2p.DiscTooManyPeers + } + p.Log().Debug("Light Ethereum peer connected", "name", p.Name()) // Execute the LES handshake -- cgit v1.2.3