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
This commit is contained in:
committed by
Felix Lange
parent
60e27b51bc
commit
a5d08c893d
@ -39,26 +39,28 @@ type LesTxRelay struct {
|
||||
reqDist *requestDistributor
|
||||
}
|
||||
|
||||
func NewLesTxRelay() *LesTxRelay {
|
||||
return &LesTxRelay{
|
||||
func NewLesTxRelay(ps *peerSet, reqDist *requestDistributor) *LesTxRelay {
|
||||
r := &LesTxRelay{
|
||||
txSent: make(map[common.Hash]*ltrInfo),
|
||||
txPending: make(map[common.Hash]struct{}),
|
||||
ps: ps,
|
||||
reqDist: reqDist,
|
||||
}
|
||||
ps.notify(r)
|
||||
return r
|
||||
}
|
||||
|
||||
func (self *LesTxRelay) addPeer(p *peer) {
|
||||
func (self *LesTxRelay) registerPeer(p *peer) {
|
||||
self.lock.Lock()
|
||||
defer self.lock.Unlock()
|
||||
|
||||
self.ps.Register(p)
|
||||
self.peerList = self.ps.AllPeers()
|
||||
}
|
||||
|
||||
func (self *LesTxRelay) removePeer(id string) {
|
||||
func (self *LesTxRelay) unregisterPeer(p *peer) {
|
||||
self.lock.Lock()
|
||||
defer self.lock.Unlock()
|
||||
|
||||
self.ps.Unregister(id)
|
||||
self.peerList = self.ps.AllPeers()
|
||||
}
|
||||
|
||||
@ -112,7 +114,7 @@ func (self *LesTxRelay) send(txs types.Transactions, count int) {
|
||||
pp := p
|
||||
ll := list
|
||||
|
||||
reqID := getNextReqID()
|
||||
reqID := genReqID()
|
||||
rq := &distReq{
|
||||
getCost: func(dp distPeer) uint64 {
|
||||
peer := dp.(*peer)
|
||||
|
Reference in New Issue
Block a user