p2p/discover: wake from slowdown sleep when table is closed

This commit is contained in:
Felix Lange 2019-11-26 10:06:24 +01:00
parent 88fe4b58f6
commit e277669ae1

View file

@ -111,7 +111,7 @@ func (it *lookup) startQueries() bool {
// for the table to fill in this case, but there is no good mechanism for that
// yet.
if len(closest.entries) == 0 {
time.Sleep(1 * time.Second)
it.slowdown()
}
it.queries = 1
it.replyCh <- closest.entries
@ -131,6 +131,15 @@ func (it *lookup) startQueries() bool {
return it.queries > 0
}
func (it *lookup) slowdown() {
sleep := time.NewTimer(1 * time.Second)
defer sleep.Stop()
select {
case <-sleep.C:
case <-it.tab.closeReq:
}
}
func (it *lookup) query(n *node, reply chan<- []*node) {
fails := it.tab.db.FindFails(n.ID(), n.IP())
r, err := it.queryfunc(n)