mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 15:47:21 +00:00
p2p/discover: trigger refresh in lookupIterator
This commit is contained in:
parent
e58e7f7927
commit
721c8de738
1 changed files with 30 additions and 11 deletions
|
|
@ -142,11 +142,12 @@ func (it *lookup) query(n *enode.Node, reply chan<- []*enode.Node) {
|
||||||
// lookupIterator performs lookup operations and iterates over all seen nodes.
|
// lookupIterator performs lookup operations and iterates over all seen nodes.
|
||||||
// When a lookup finishes, a new one is created through nextLookup.
|
// When a lookup finishes, a new one is created through nextLookup.
|
||||||
type lookupIterator struct {
|
type lookupIterator struct {
|
||||||
buffer []*enode.Node
|
buffer []*enode.Node
|
||||||
nextLookup lookupFunc
|
nextLookup lookupFunc
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel func()
|
cancel func()
|
||||||
lookup *lookup
|
lookup *lookup
|
||||||
|
tabRefreshing <-chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type lookupFunc func(ctx context.Context) *lookup
|
type lookupFunc func(ctx context.Context) *lookup
|
||||||
|
|
@ -187,11 +188,11 @@ func (it *lookupIterator) Next() bool {
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !it.lookup.advance() {
|
newNodes := it.lookup.advance()
|
||||||
it.lookup = nil
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
it.buffer = it.lookup.replyBuffer
|
it.buffer = it.lookup.replyBuffer
|
||||||
|
if !newNodes {
|
||||||
|
it.lookup = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
@ -201,9 +202,27 @@ func (it *lookupIterator) Next() bool {
|
||||||
func (it *lookupIterator) lookupFailed(tab *Table) {
|
func (it *lookupIterator) lookupFailed(tab *Table) {
|
||||||
timeout, cancel := context.WithTimeout(it.ctx, 1*time.Minute)
|
timeout, cancel := context.WithTimeout(it.ctx, 1*time.Minute)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
tab.waitForNodes(timeout, 1)
|
|
||||||
|
|
||||||
// TODO: here we need to trigger a table refresh somehow
|
// Wait for Table initialization to complete, in case it is still in progress.
|
||||||
|
select {
|
||||||
|
case <-tab.initDone:
|
||||||
|
case <-timeout.Done():
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for ongoing refresh operation, or trigger one.
|
||||||
|
if it.tabRefreshing == nil {
|
||||||
|
it.tabRefreshing = tab.refresh()
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-it.tabRefreshing:
|
||||||
|
it.tabRefreshing = nil
|
||||||
|
case <-timeout.Done():
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for the table to fill.
|
||||||
|
tab.waitForNodes(timeout, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close ends the iterator.
|
// Close ends the iterator.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue