diff options
author | Felföldi Zsolt <zsfelfoldi@gmail.com> | 2018-02-05 21:41:53 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-02-05 21:41:53 +0800 |
commit | c3f238dd5371961d309350fb0f9d5136c9fc6afa (patch) | |
tree | 8879532944de4818030c0e8630613e52885695b6 /les/handler.go | |
parent | bc0666fb277be5e7d1fd7c5523a3b335b310a154 (diff) | |
download | dexon-c3f238dd5371961d309350fb0f9d5136c9fc6afa.tar.gz dexon-c3f238dd5371961d309350fb0f9d5136c9fc6afa.tar.zst dexon-c3f238dd5371961d309350fb0f9d5136c9fc6afa.zip |
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
Diffstat (limited to 'les/handler.go')
-rw-r--r-- | les/handler.go | 9 |
1 files changed, 8 insertions, 1 deletions
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 |