mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
les/flowcontrol: regularly update total capacity
This commit is contained in:
parent
28dcf5f177
commit
77ccd372f7
2 changed files with 24 additions and 0 deletions
|
|
@ -61,6 +61,7 @@ type ClientManager struct {
|
||||||
clock mclock.Clock
|
clock mclock.Clock
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
enabledCh chan struct{}
|
enabledCh chan struct{}
|
||||||
|
stop chan chan struct{}
|
||||||
|
|
||||||
curve PieceWiseLinear
|
curve PieceWiseLinear
|
||||||
sumRecharge, totalRecharge, totalConnected uint64
|
sumRecharge, totalRecharge, totalConnected uint64
|
||||||
|
|
@ -109,13 +110,35 @@ func NewClientManager(curve PieceWiseLinear, clock mclock.Clock) *ClientManager
|
||||||
clock: clock,
|
clock: clock,
|
||||||
rcQueue: prque.New(func(a interface{}, i int) { a.(*ClientNode).queueIndex = i }),
|
rcQueue: prque.New(func(a interface{}, i int) { a.(*ClientNode).queueIndex = i }),
|
||||||
capLastUpdate: clock.Now(),
|
capLastUpdate: clock.Now(),
|
||||||
|
stop: make(chan chan struct{}),
|
||||||
}
|
}
|
||||||
if curve != nil {
|
if curve != nil {
|
||||||
cm.SetRechargeCurve(curve)
|
cm.SetRechargeCurve(curve)
|
||||||
}
|
}
|
||||||
|
go func() {
|
||||||
|
// regularly recalculate and update total capacity
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-time.After(time.Minute):
|
||||||
|
cm.lock.Lock()
|
||||||
|
cm.updateTotalCapacity(cm.clock.Now(), true)
|
||||||
|
cm.lock.Unlock()
|
||||||
|
case stop := <-cm.stop:
|
||||||
|
close(stop)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
return cm
|
return cm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop stops the client manager
|
||||||
|
func (cm *ClientManager) Stop() {
|
||||||
|
stop := make(chan struct{})
|
||||||
|
cm.stop <- stop
|
||||||
|
<-stop
|
||||||
|
}
|
||||||
|
|
||||||
// SetRechargeCurve updates the recharge curve
|
// SetRechargeCurve updates the recharge curve
|
||||||
func (cm *ClientManager) SetRechargeCurve(curve PieceWiseLinear) {
|
func (cm *ClientManager) SetRechargeCurve(curve PieceWiseLinear) {
|
||||||
cm.lock.Lock()
|
cm.lock.Lock()
|
||||||
|
|
|
||||||
|
|
@ -290,6 +290,7 @@ func (s *LesServer) SetBloomBitsIndexer(bloomIndexer *core.ChainIndexer) {
|
||||||
|
|
||||||
// Stop stops the LES service
|
// Stop stops the LES service
|
||||||
func (s *LesServer) Stop() {
|
func (s *LesServer) Stop() {
|
||||||
|
s.fcManager.Stop()
|
||||||
s.chtIndexer.Close()
|
s.chtIndexer.Close()
|
||||||
// bloom trie indexer is closed by parent bloombits indexer
|
// bloom trie indexer is closed by parent bloombits indexer
|
||||||
go func() {
|
go func() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue