File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ package discover
18
18
19
19
import (
20
20
"context"
21
+ "time"
21
22
22
23
"github.com/ethereum/go-ethereum/p2p/enode"
23
24
)
@@ -106,6 +107,12 @@ func (it *lookup) startQueries() bool {
106
107
it .tab .mutex .Lock ()
107
108
closest := it .tab .closest (it .result .target , bucketSize , false )
108
109
it .tab .mutex .Unlock ()
110
+ // Avoid finishing the lookup too quickly if table is empty. It'd be better to wait
111
+ // for the table to fill in this case, but there is no good mechanism for that
112
+ // yet.
113
+ if len (closest .entries ) == 0 {
114
+ it .slowdown ()
115
+ }
109
116
it .queries = 1
110
117
it .replyCh <- closest .entries
111
118
return true
@@ -124,6 +131,15 @@ func (it *lookup) startQueries() bool {
124
131
return it .queries > 0
125
132
}
126
133
134
+ func (it * lookup ) slowdown () {
135
+ sleep := time .NewTimer (1 * time .Second )
136
+ defer sleep .Stop ()
137
+ select {
138
+ case <- sleep .C :
139
+ case <- it .tab .closeReq :
140
+ }
141
+ }
142
+
127
143
func (it * lookup ) query (n * node , reply chan <- []* node ) {
128
144
fails := it .tab .db .FindFails (n .ID (), n .IP ())
129
145
r , err := it .queryfunc (n )
You can’t perform that action at this time.
0 commit comments