aboutsummaryrefslogtreecommitdiffstats
path: root/les/handler.go
diff options
context:
space:
mode:
authorFelföldi Zsolt <zsfelfoldi@gmail.com>2018-02-05 21:41:53 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-02-05 21:41:53 +0800
commitc3f238dd5371961d309350fb0f9d5136c9fc6afa (patch)
tree8879532944de4818030c0e8630613e52885695b6 /les/handler.go
parentbc0666fb277be5e7d1fd7c5523a3b335b310a154 (diff)
downloadgo-tangerine-c3f238dd5371961d309350fb0f9d5136c9fc6afa.tar
go-tangerine-c3f238dd5371961d309350fb0f9d5136c9fc6afa.tar.gz
go-tangerine-c3f238dd5371961d309350fb0f9d5136c9fc6afa.tar.bz2
go-tangerine-c3f238dd5371961d309350fb0f9d5136c9fc6afa.tar.lz
go-tangerine-c3f238dd5371961d309350fb0f9d5136c9fc6afa.tar.xz
go-tangerine-c3f238dd5371961d309350fb0f9d5136c9fc6afa.tar.zst
go-tangerine-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.go9
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