mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
1
This commit is contained in:
parent
c0b6ff20d1
commit
848683a203
1 changed files with 19 additions and 16 deletions
|
|
@ -180,6 +180,7 @@ func newClientPool(db ethdb.Database, minCap, freeClientCap uint64, clock mclock
|
|||
connectedMap: make(map[enode.ID]*clientInfo),
|
||||
activeQueue: prque.NewLazyQueue(connSetIndex, connPriority, connMaxPriority, clock, lazyQueueRefresh),
|
||||
inactiveQueue: prque.New(connSetIndex),
|
||||
dropInactivePeers: make(map[uint64][]*clientInfo),
|
||||
minCap: minCap,
|
||||
freeClientCap: freeClientCap,
|
||||
removePeer: removePeer,
|
||||
|
|
@ -416,7 +417,7 @@ func (f *clientPool) disconnect(p clientPeer) {
|
|||
}
|
||||
tryActivate := e.active
|
||||
if e.active {
|
||||
f.deactivateClient(e)
|
||||
f.deactivateClient(e, false)
|
||||
}
|
||||
f.finalizeBalance(e, f.clock.Now())
|
||||
f.inactiveQueue.Remove(e.queueIndex)
|
||||
|
|
@ -488,7 +489,7 @@ func (f *clientPool) capAvailable(id enode.ID, freeID string, capacity uint64, m
|
|||
}
|
||||
for _, c := range popList {
|
||||
if kick && c != client {
|
||||
f.deactivateClient(c)
|
||||
f.deactivateClient(c, true)
|
||||
} else {
|
||||
f.activeQueue.Push(c)
|
||||
}
|
||||
|
|
@ -529,7 +530,7 @@ func (f *clientPool) setDefaultFactors(posFactors, negFactors priceFactors) {
|
|||
f.defaultNegFactors = negFactors
|
||||
}
|
||||
|
||||
func (f *clientPool) deactivateClient(e *clientInfo) {
|
||||
func (f *clientPool) deactivateClient(e *clientInfo, scheduleDrop bool) {
|
||||
if _, ok := f.connectedMap[e.id]; !ok || !e.active {
|
||||
return
|
||||
}
|
||||
|
|
@ -543,8 +544,10 @@ func (f *clientPool) deactivateClient(e *clientInfo) {
|
|||
e.peer.updateCapacity(0)
|
||||
totalConnectedGauge.Update(int64(f.activeCap))
|
||||
f.inactiveQueue.Push(e, -connPriority(e, f.clock.Now()))
|
||||
if scheduleDrop {
|
||||
f.dropInactivePeers[f.dropInactiveCounter+dropInactiveCycles] = append(f.dropInactivePeers[f.dropInactiveCounter+dropInactiveCycles], e)
|
||||
}
|
||||
}
|
||||
|
||||
func (f *clientPool) tryActivateClients() {
|
||||
now := f.clock.Now()
|
||||
|
|
@ -650,7 +653,7 @@ func (f *clientPool) setLimits(totalConn int, totalCap uint64) {
|
|||
f.capLimit = totalCap
|
||||
if f.activeCap > f.capLimit || f.activeQueue.Size() > f.activeLimit {
|
||||
f.activeQueue.MultiPop(func(data interface{}, priority int64) bool {
|
||||
f.deactivateClient(data.(*clientInfo))
|
||||
f.deactivateClient(data.(*clientInfo), true)
|
||||
return f.activeCap > f.capLimit || f.activeQueue.Size() > f.activeLimit
|
||||
})
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue