From 1b1552b0ef268ff7be2dd89f915a24f6768e183d Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Sat, 26 Jan 2019 18:38:13 +0100 Subject: [PATCH] les: fixed freeClientPool test --- les/freeclient.go | 9 ++++----- les/server.go | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/les/freeclient.go b/les/freeclient.go index e745e4abc9..d859337c26 100644 --- a/les/freeclient.go +++ b/les/freeclient.go @@ -91,7 +91,9 @@ func (f *freeClientPool) stop() { // registerPeer implements clientPool func (f *freeClientPool) registerPeer(p *peer) { 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 { log.Debug("Client rejected", "address", address) - go f.removePeer(id) return false } e := f.addressMap[address] @@ -119,7 +120,6 @@ func (f *freeClientPool) connect(address, id string) bool { } else { if e.connected { log.Debug("Client already connected", "address", address) - go f.removePeer(id) return false } 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 f.connPool.Push(i, i.linUsage) log.Debug("Client rejected", "address", address) - go f.removePeer(id) return false } } @@ -206,7 +205,7 @@ func (f *freeClientPool) dropClient(i *freeClientPoolEntry, now mclock.AbsTime) i.connected = false f.disconnPool.Push(i, -i.logUsage) 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 diff --git a/les/server.go b/les/server.go index 197d229837..db6586c963 100644 --- a/les/server.go +++ b/les/server.go @@ -200,7 +200,7 @@ func (s *LesServer) Start(srvr *p2p.Server) { 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.protocolManager.peers.notify(s.priorityClientPool)