@@ -17,10 +17,9 @@ const (
17
17
// redialing a certain node.
18
18
dialHistoryExpiration = 30 * time .Second
19
19
20
- // Discovery lookup tasks will wait for this long when
21
- // no results are returned. This can happen if the table
22
- // becomes empty (i.e. not often).
23
- emptyLookupDelay = 10 * time .Second
20
+ // Discovery lookups are throttled and can only run
21
+ // once every few seconds.
22
+ lookupInterval = 4 * time .Second
24
23
)
25
24
26
25
// dialstate schedules dials and discovery lookups.
@@ -206,18 +205,19 @@ func (t *dialTask) String() string {
206
205
func (t * discoverTask ) Do (srv * Server ) {
207
206
if t .bootstrap {
208
207
srv .ntab .Bootstrap (srv .BootstrapNodes )
209
- } else {
210
- var target discover.NodeID
211
- rand .Read (target [:])
212
- t .results = srv .ntab .Lookup (target )
213
- // newTasks generates a lookup task whenever dynamic dials are
214
- // necessary. Lookups need to take some time, otherwise the
215
- // event loop spins too fast. An empty result can only be
216
- // returned if the table is empty.
217
- if len (t .results ) == 0 {
218
- time .Sleep (emptyLookupDelay )
219
- }
208
+ return
209
+ }
210
+ // newTasks generates a lookup task whenever dynamic dials are
211
+ // necessary. Lookups need to take some time, otherwise the
212
+ // event loop spins too fast.
213
+ next := srv .lastLookup .Add (lookupInterval )
214
+ if now := time .Now (); now .Before (next ) {
215
+ time .Sleep (next .Sub (now ))
220
216
}
217
+ srv .lastLookup = time .Now ()
218
+ var target discover.NodeID
219
+ rand .Read (target [:])
220
+ t .results = srv .ntab .Lookup (target )
221
221
}
222
222
223
223
func (t * discoverTask ) String () (s string ) {
0 commit comments