aboutsummaryrefslogtreecommitdiffstats
path: root/les
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
parentbc0666fb277be5e7d1fd7c5523a3b335b310a154 (diff)
downloaddexon-c3f238dd5371961d309350fb0f9d5136c9fc6afa.tar
dexon-c3f238dd5371961d309350fb0f9d5136c9fc6afa.tar.gz
dexon-c3f238dd5371961d309350fb0f9d5136c9fc6afa.tar.bz2
dexon-c3f238dd5371961d309350fb0f9d5136c9fc6afa.tar.lz
dexon-c3f238dd5371961d309350fb0f9d5136c9fc6afa.tar.xz
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')
-rw-r--r--les/backend.go5
-rw-r--r--les/handler.go9
-rw-r--r--les/helper_test.go2
-rw-r--r--les/server.go4
4 files changed, 16 insertions, 4 deletions
diff --git a/les/backend.go b/les/backend.go
index 798e44e85..6a324cb04 100644
--- a/les/backend.go
+++ b/les/backend.go
@@ -46,6 +46,8 @@ import (
)
type LightEthereum struct {
+ config *eth.Config
+
odr *LesOdr
relay *LesTxRelay
chainConfig *params.ChainConfig
@@ -92,6 +94,7 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
quitSync := make(chan struct{})
leth := &LightEthereum{
+ config: config,
chainConfig: chainConfig,
chainDb: chainDb,
eventMux: ctx.EventMux,
@@ -224,7 +227,7 @@ func (s *LightEthereum) Start(srvr *p2p.Server) error {
// clients are searching for the first advertised protocol in the list
protocolVersion := AdvertiseProtocolVersions[0]
s.serverPool.start(srvr, lesTopic(s.blockchain.Genesis().Hash(), protocolVersion))
- s.protocolManager.Start()
+ s.protocolManager.Start(s.config.LightPeers)
return nil
}
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
diff --git a/les/helper_test.go b/les/helper_test.go
index 57e693996..1c1de64ad 100644
--- a/les/helper_test.go
+++ b/les/helper_test.go
@@ -176,7 +176,7 @@ func newTestProtocolManager(lightSync bool, blocks int, generator func(int, *cor
srv.fcManager = flowcontrol.NewClientManager(50, 10, 1000000000)
srv.fcCostStats = newCostStats(nil)
}
- pm.Start()
+ pm.Start(1000)
return pm, nil
}
diff --git a/les/server.go b/les/server.go
index ec2e44fec..85ebbf898 100644
--- a/les/server.go
+++ b/les/server.go
@@ -38,6 +38,7 @@ import (
)
type LesServer struct {
+ config *eth.Config
protocolManager *ProtocolManager
fcManager *flowcontrol.ClientManager // nil if our node is client only
fcCostStats *requestCostStats
@@ -62,6 +63,7 @@ func NewLesServer(eth *eth.Ethereum, config *eth.Config) (*LesServer, error) {
}
srv := &LesServer{
+ config: config,
protocolManager: pm,
quitSync: quitSync,
lesTopics: lesTopics,
@@ -108,7 +110,7 @@ func (s *LesServer) Protocols() []p2p.Protocol {
// Start starts the LES server
func (s *LesServer) Start(srvr *p2p.Server) {
- s.protocolManager.Start()
+ s.protocolManager.Start(s.config.LightPeers)
for _, topic := range s.lesTopics {
topic := topic
go func() {