mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
les: freeClientPool.stop
This commit is contained in:
parent
36bfbc620e
commit
b005cd5610
3 changed files with 16 additions and 22 deletions
|
|
@ -64,7 +64,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// newFreeClientPool creates a new free client pool
|
// newFreeClientPool creates a new free client pool
|
||||||
func newFreeClientPool(db ethdb.Database, connectedLimit, totalLimit int, quit chan struct{}, wg *sync.WaitGroup, clock mclock.Clock) *freeClientPool {
|
func newFreeClientPool(db ethdb.Database, connectedLimit, totalLimit int, clock mclock.Clock) *freeClientPool {
|
||||||
pool := &freeClientPool{
|
pool := &freeClientPool{
|
||||||
db: db,
|
db: db,
|
||||||
clock: clock,
|
clock: clock,
|
||||||
|
|
@ -75,19 +75,16 @@ func newFreeClientPool(db ethdb.Database, connectedLimit, totalLimit int, quit c
|
||||||
totalLimit: totalLimit,
|
totalLimit: totalLimit,
|
||||||
}
|
}
|
||||||
pool.loadFromDb()
|
pool.loadFromDb()
|
||||||
wg.Add(1)
|
|
||||||
go func() {
|
|
||||||
<-quit
|
|
||||||
pool.lock.Lock()
|
|
||||||
pool.closed = true
|
|
||||||
pool.saveToDb()
|
|
||||||
pool.lock.Unlock()
|
|
||||||
wg.Done()
|
|
||||||
}()
|
|
||||||
|
|
||||||
return pool
|
return pool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *freeClientPool) stop() {
|
||||||
|
f.lock.Lock()
|
||||||
|
f.closed = true
|
||||||
|
f.saveToDb()
|
||||||
|
f.lock.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
// connect should be called after a successful handshake. If the connection was
|
// connect should be called after a successful handshake. If the connection was
|
||||||
// rejected, there is no need to call disconnect.
|
// rejected, there is no need to call disconnect.
|
||||||
//
|
//
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ package les
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"sync"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -45,11 +44,9 @@ const testFreeClientPoolTicks = 500000
|
||||||
|
|
||||||
func testFreeClientPool(t *testing.T, connLimit, clientCount int) {
|
func testFreeClientPool(t *testing.T, connLimit, clientCount int) {
|
||||||
var (
|
var (
|
||||||
quit = make(chan struct{})
|
|
||||||
clock mclock.Simulated
|
clock mclock.Simulated
|
||||||
wg sync.WaitGroup
|
|
||||||
db = ethdb.NewMemDatabase()
|
db = ethdb.NewMemDatabase()
|
||||||
pool = newFreeClientPool(db, connLimit, 10000, quit, &wg, &clock)
|
pool = newFreeClientPool(db, connLimit, 10000, &clock)
|
||||||
connected = make([]bool, clientCount)
|
connected = make([]bool, clientCount)
|
||||||
connTicks = make([]int, clientCount)
|
connTicks = make([]int, clientCount)
|
||||||
disconnCh = make(chan int, clientCount)
|
disconnCh = make(chan int, clientCount)
|
||||||
|
|
@ -127,11 +124,8 @@ func testFreeClientPool(t *testing.T, connLimit, clientCount int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// close and restart pool
|
// close and restart pool
|
||||||
close(quit)
|
pool.stop()
|
||||||
wg.Wait()
|
pool = newFreeClientPool(db, connLimit, 10000, &clock)
|
||||||
quit2 := make(chan struct{})
|
|
||||||
var wg2 sync.WaitGroup
|
|
||||||
pool = newFreeClientPool(db, connLimit, 10000, quit2, &wg2, &clock)
|
|
||||||
|
|
||||||
// try connecting all known peers (connLimit should be filled up)
|
// try connecting all known peers (connLimit should be filled up)
|
||||||
for i := 0; i < clientCount; i++ {
|
for i := 0; i < clientCount; i++ {
|
||||||
|
|
@ -141,5 +135,5 @@ func testFreeClientPool(t *testing.T, connLimit, clientCount int) {
|
||||||
if !pool.connect("newPeer2", func() {}) {
|
if !pool.connect("newPeer2", func() {}) {
|
||||||
t.Errorf("Previously unknown peer rejected after restarting pool")
|
t.Errorf("Previously unknown peer rejected after restarting pool")
|
||||||
}
|
}
|
||||||
close(quit2)
|
pool.stop()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -228,7 +228,7 @@ func (pm *ProtocolManager) Start(maxPeers int) {
|
||||||
if pm.lightSync {
|
if pm.lightSync {
|
||||||
go pm.syncer()
|
go pm.syncer()
|
||||||
} else {
|
} else {
|
||||||
pm.clientPool = newFreeClientPool(pm.chainDb, maxPeers, 10000, pm.quitSync, pm.wg, mclock.System{})
|
pm.clientPool = newFreeClientPool(pm.chainDb, maxPeers, 10000, mclock.System{})
|
||||||
go func() {
|
go func() {
|
||||||
for range pm.newPeerCh {
|
for range pm.newPeerCh {
|
||||||
}
|
}
|
||||||
|
|
@ -246,6 +246,9 @@ func (pm *ProtocolManager) Stop() {
|
||||||
pm.noMorePeers <- struct{}{}
|
pm.noMorePeers <- struct{}{}
|
||||||
|
|
||||||
close(pm.quitSync) // quits syncer, fetcher
|
close(pm.quitSync) // quits syncer, fetcher
|
||||||
|
if pm.clientPool != nil {
|
||||||
|
pm.clientPool.stop()
|
||||||
|
}
|
||||||
|
|
||||||
// Disconnect existing sessions.
|
// Disconnect existing sessions.
|
||||||
// This also closes the gate for any new registrations on the peer set.
|
// This also closes the gate for any new registrations on the peer set.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue