mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
les: fixed freeClientPool test
This commit is contained in:
parent
9a60499f9f
commit
1b1552b0ef
2 changed files with 5 additions and 6 deletions
|
|
@ -91,7 +91,9 @@ func (f *freeClientPool) stop() {
|
||||||
// registerPeer implements clientPool
|
// registerPeer implements clientPool
|
||||||
func (f *freeClientPool) registerPeer(p *peer) {
|
func (f *freeClientPool) registerPeer(p *peer) {
|
||||||
if addr, ok := p.RemoteAddr().(*net.TCPAddr); ok {
|
if addr, ok := p.RemoteAddr().(*net.TCPAddr); ok {
|
||||||
f.connect(addr.IP.String(), p.id)
|
if !f.connect(addr.IP.String(), p.id) {
|
||||||
|
f.removePeer(p.id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,7 +109,6 @@ func (f *freeClientPool) connect(address, id string) bool {
|
||||||
|
|
||||||
if f.connectedLimit == 0 {
|
if f.connectedLimit == 0 {
|
||||||
log.Debug("Client rejected", "address", address)
|
log.Debug("Client rejected", "address", address)
|
||||||
go f.removePeer(id)
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
e := f.addressMap[address]
|
e := f.addressMap[address]
|
||||||
|
|
@ -119,7 +120,6 @@ func (f *freeClientPool) connect(address, id string) bool {
|
||||||
} else {
|
} else {
|
||||||
if e.connected {
|
if e.connected {
|
||||||
log.Debug("Client already connected", "address", address)
|
log.Debug("Client already connected", "address", address)
|
||||||
go f.removePeer(id)
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
recentUsage = int64(math.Exp(float64(e.logUsage-f.logOffset(now)) / fixedPointMultiplier))
|
recentUsage = int64(math.Exp(float64(e.logUsage-f.logOffset(now)) / fixedPointMultiplier))
|
||||||
|
|
@ -135,7 +135,6 @@ func (f *freeClientPool) connect(address, id string) bool {
|
||||||
// keep the old client and reject the new one
|
// keep the old client and reject the new one
|
||||||
f.connPool.Push(i, i.linUsage)
|
f.connPool.Push(i, i.linUsage)
|
||||||
log.Debug("Client rejected", "address", address)
|
log.Debug("Client rejected", "address", address)
|
||||||
go f.removePeer(id)
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -206,7 +205,7 @@ func (f *freeClientPool) dropClient(i *freeClientPoolEntry, now mclock.AbsTime)
|
||||||
i.connected = false
|
i.connected = false
|
||||||
f.disconnPool.Push(i, -i.logUsage)
|
f.disconnPool.Push(i, -i.logUsage)
|
||||||
log.Debug("Client kicked out", "address", i.address)
|
log.Debug("Client kicked out", "address", i.address)
|
||||||
go f.removePeer(i.id)
|
f.removePeer(i.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// logOffset calculates the time-dependent offset for the logarithmic
|
// logOffset calculates the time-dependent offset for the logarithmic
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,7 @@ func (s *LesServer) Start(srvr *p2p.Server) {
|
||||||
log.Warn("Light peer count limited", "specified", s.maxPeers, "allowed", freePeers)
|
log.Warn("Light peer count limited", "specified", s.maxPeers, "allowed", freePeers)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.freeClientPool = newFreeClientPool(s.chainDb, s.freeClientCap, 10000, mclock.System{}, s.protocolManager.removePeer)
|
s.freeClientPool = newFreeClientPool(s.chainDb, s.freeClientCap, 10000, mclock.System{}, func(id string) { go s.protocolManager.removePeer(id) })
|
||||||
s.priorityClientPool = newPriorityClientPool(s.freeClientCap, s.protocolManager.peers, s.freeClientPool)
|
s.priorityClientPool = newPriorityClientPool(s.freeClientCap, s.protocolManager.peers, s.freeClientPool)
|
||||||
|
|
||||||
s.protocolManager.peers.notify(s.priorityClientPool)
|
s.protocolManager.peers.notify(s.priorityClientPool)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue