diff options
author | Felföldi Zsolt <zsfelfoldi@gmail.com> | 2017-06-21 18:27:38 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2017-06-21 18:27:38 +0800 |
commit | a5d08c893d61f66d60d8a91216aee5347b78f93e (patch) | |
tree | 500f3a788ecd4f299692ce1d1069f2efdc79d73d /les/server.go | |
parent | 60e27b51bc5643bc6a76151020a9e1a245340b70 (diff) | |
download | dexon-a5d08c893d61f66d60d8a91216aee5347b78f93e.tar dexon-a5d08c893d61f66d60d8a91216aee5347b78f93e.tar.gz dexon-a5d08c893d61f66d60d8a91216aee5347b78f93e.tar.bz2 dexon-a5d08c893d61f66d60d8a91216aee5347b78f93e.tar.lz dexon-a5d08c893d61f66d60d8a91216aee5347b78f93e.tar.xz dexon-a5d08c893d61f66d60d8a91216aee5347b78f93e.tar.zst dexon-a5d08c893d61f66d60d8a91216aee5347b78f93e.zip |
les: code refactoring (#14416)
This commit does various code refactorings:
- generalizes and moves the request retrieval/timeout/resend logic out of LesOdr
(will be used by a subsequent PR)
- reworks the peer management logic so that all services can register with
peerSet to get notified about added/dropped peers (also gets rid of the ugly
getAllPeers callback in requestDistributor)
- moves peerSet, LesOdr, requestDistributor and retrieveManager initialization
out of ProtocolManager because I believe they do not really belong there and the
whole init process was ugly and ad-hoc
Diffstat (limited to 'les/server.go')
-rw-r--r-- | les/server.go | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/les/server.go b/les/server.go index 22fe59b7a..2ff715ea8 100644 --- a/les/server.go +++ b/les/server.go @@ -32,6 +32,7 @@ import ( "github.com/ethereum/go-ethereum/light" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/p2p" + "github.com/ethereum/go-ethereum/p2p/discv5" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/trie" ) @@ -41,17 +42,24 @@ type LesServer struct { fcManager *flowcontrol.ClientManager // nil if our node is client only fcCostStats *requestCostStats defParams *flowcontrol.ServerParams + lesTopic discv5.Topic + quitSync chan struct{} stopped bool } func NewLesServer(eth *eth.Ethereum, config *eth.Config) (*LesServer, error) { - pm, err := NewProtocolManager(eth.BlockChain().Config(), false, config.NetworkId, eth.EventMux(), eth.Engine(), eth.BlockChain(), eth.TxPool(), eth.ChainDb(), nil, nil) + quitSync := make(chan struct{}) + pm, err := NewProtocolManager(eth.BlockChain().Config(), false, config.NetworkId, eth.EventMux(), eth.Engine(), newPeerSet(), eth.BlockChain(), eth.TxPool(), eth.ChainDb(), nil, nil, quitSync, new(sync.WaitGroup)) if err != nil { return nil, err } pm.blockLoop() - srv := &LesServer{protocolManager: pm} + srv := &LesServer{ + protocolManager: pm, + quitSync: quitSync, + lesTopic: lesTopic(eth.BlockChain().Genesis().Hash()), + } pm.server = srv srv.defParams = &flowcontrol.ServerParams{ @@ -69,7 +77,14 @@ func (s *LesServer) Protocols() []p2p.Protocol { // Start starts the LES server func (s *LesServer) Start(srvr *p2p.Server) { - s.protocolManager.Start(srvr) + s.protocolManager.Start() + go func() { + logger := log.New("topic", s.lesTopic) + logger.Info("Starting topic registration") + defer logger.Info("Terminated topic registration") + + srvr.DiscV5.RegisterTopic(s.lesTopic, s.quitSync) + }() } // Stop stops the LES service |