mirror of
https://github.com/logos-messaging/go-discover.git
synced 2026-01-04 05:53:10 +00:00
fix: reseed bootnodes when routing table is empty
This commit is contained in:
parent
2f43d5f6c7
commit
7525c68dc3
@ -53,12 +53,13 @@ const (
|
|||||||
bucketIPLimit, bucketSubnet = 2, 24 // at most 2 addresses from the same /24
|
bucketIPLimit, bucketSubnet = 2, 24 // at most 2 addresses from the same /24
|
||||||
tableIPLimit, tableSubnet = 10, 24
|
tableIPLimit, tableSubnet = 10, 24
|
||||||
|
|
||||||
refreshInterval = 30 * time.Minute
|
refreshInterval = 30 * time.Minute
|
||||||
revalidateInterval = 10 * time.Second
|
revalidateInterval = 10 * time.Second
|
||||||
copyNodesInterval = 30 * time.Second
|
copyNodesInterval = 30 * time.Second
|
||||||
seedMinTableTime = 5 * time.Minute
|
reseedBootnodesInterval = 15 * time.Second
|
||||||
seedCount = 30
|
seedMinTableTime = 5 * time.Minute
|
||||||
seedMaxAge = 5 * 24 * time.Hour
|
seedCount = 30
|
||||||
|
seedMaxAge = 5 * 24 * time.Hour
|
||||||
)
|
)
|
||||||
|
|
||||||
// Table is the 'node table', a Kademlia-like index of neighbor nodes. The table keeps
|
// Table is the 'node table', a Kademlia-like index of neighbor nodes. The table keeps
|
||||||
@ -223,6 +224,7 @@ func (tab *Table) loop() {
|
|||||||
revalidate = time.NewTimer(tab.nextRevalidateTime())
|
revalidate = time.NewTimer(tab.nextRevalidateTime())
|
||||||
refresh = time.NewTicker(refreshInterval)
|
refresh = time.NewTicker(refreshInterval)
|
||||||
copyNodes = time.NewTicker(copyNodesInterval)
|
copyNodes = time.NewTicker(copyNodesInterval)
|
||||||
|
reseed = time.NewTicker(reseedBootnodesInterval)
|
||||||
refreshDone = make(chan struct{}) // where doRefresh reports completion
|
refreshDone = make(chan struct{}) // where doRefresh reports completion
|
||||||
revalidateDone chan struct{} // where doRevalidate reports completion
|
revalidateDone chan struct{} // where doRevalidate reports completion
|
||||||
waiting = []chan struct{}{tab.initDone} // holds waiting callers while doRefresh runs
|
waiting = []chan struct{}{tab.initDone} // holds waiting callers while doRefresh runs
|
||||||
@ -230,6 +232,7 @@ func (tab *Table) loop() {
|
|||||||
defer refresh.Stop()
|
defer refresh.Stop()
|
||||||
defer revalidate.Stop()
|
defer revalidate.Stop()
|
||||||
defer copyNodes.Stop()
|
defer copyNodes.Stop()
|
||||||
|
defer reseed.Stop()
|
||||||
|
|
||||||
// Start initial refresh.
|
// Start initial refresh.
|
||||||
go tab.doRefresh(refreshDone)
|
go tab.doRefresh(refreshDone)
|
||||||
@ -262,6 +265,8 @@ loop:
|
|||||||
revalidateDone = nil
|
revalidateDone = nil
|
||||||
case <-copyNodes.C:
|
case <-copyNodes.C:
|
||||||
go tab.copyLiveNodes()
|
go tab.copyLiveNodes()
|
||||||
|
case <-reseed.C:
|
||||||
|
go tab.doReseedBootnodes()
|
||||||
case <-tab.closeReq:
|
case <-tab.closeReq:
|
||||||
break loop
|
break loop
|
||||||
}
|
}
|
||||||
@ -303,6 +308,13 @@ func (tab *Table) doRefresh(done chan struct{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// doReseedNodes checks if the table is empty and inserts the initial bootstrap nodes.
|
||||||
|
func (tab *Table) doReseedBootnodes() {
|
||||||
|
if tab.len() == 0 {
|
||||||
|
tab.loadSeedNodes()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (tab *Table) loadSeedNodes() {
|
func (tab *Table) loadSeedNodes() {
|
||||||
seeds := wrapNodes(tab.db.QuerySeeds(seedCount, seedMaxAge))
|
seeds := wrapNodes(tab.db.QuerySeeds(seedCount, seedMaxAge))
|
||||||
seeds = append(seeds, tab.nursery...)
|
seeds = append(seeds, tab.nursery...)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user