@@ -95,13 +95,11 @@ func newRelayFinder(host *basic.BasicHost, peerChan <-chan peer.AddrInfo, conf *
95
95
}
96
96
97
97
func (rf * relayFinder ) background (ctx context.Context ) {
98
- if len (rf .conf .staticRelays ) == 0 {
99
- rf .refCount .Add (1 )
100
- go func () {
101
- defer rf .refCount .Done ()
102
- rf .findNodes (ctx )
103
- }()
104
- }
98
+ rf .refCount .Add (1 )
99
+ go func () {
100
+ defer rf .refCount .Done ()
101
+ rf .findNodes (ctx )
102
+ }()
105
103
106
104
subConnectedness , err := rf .host .EventBus ().Subscribe (new (event.EvtPeerConnectednessChanged ))
107
105
if err != nil {
@@ -138,10 +136,8 @@ func (rf *relayFinder) background(ctx context.Context) {
138
136
}
139
137
rf .relayMx .Unlock ()
140
138
case <- rf .candidateFound :
141
- log .Debugf ("candidate found" )
142
139
rf .handleNewCandidate (ctx )
143
140
case <- bootDelayTimer .C :
144
- log .Debugf ("boot delay timer" )
145
141
rf .handleNewCandidate (ctx )
146
142
case <- rf .relayUpdated :
147
143
push = true
@@ -163,7 +159,7 @@ func (rf *relayFinder) background(ctx context.Context) {
163
159
}
164
160
165
161
// findNodes accepts nodes from the channel and tests if they support relaying.
166
- // It is run on both public and private nodes (but not when static relays are set) .
162
+ // It is run on both public and private nodes.
167
163
// It garbage collects old entries, so that nodes doesn't overflow.
168
164
// This makes sure that as soon as we need to find relay candidates, we have them available.
169
165
func (rf * relayFinder ) findNodes (ctx context.Context ) {
@@ -189,6 +185,13 @@ func (rf *relayFinder) findNodes(ctx context.Context) {
189
185
}
190
186
}
191
187
188
+ func (rf * relayFinder ) notifyNewCandidate () {
189
+ select {
190
+ case rf .candidateFound <- struct {}{}:
191
+ default :
192
+ }
193
+ }
194
+
192
195
// handleNewNode tests if a peer supports circuit v1 or v2.
193
196
// This method is only run on private nodes.
194
197
// If a peer does, it is added to the candidates map.
@@ -220,13 +223,6 @@ func (rf *relayFinder) handleNewNode(ctx context.Context, pi peer.AddrInfo) {
220
223
rf .notifyNewCandidate ()
221
224
}
222
225
223
- func (rf * relayFinder ) notifyNewCandidate () {
224
- select {
225
- case rf .candidateFound <- struct {}{}:
226
- default :
227
- }
228
- }
229
-
230
226
// tryNode checks if a peer actually supports either circuit v1 or circuit v2.
231
227
// It does not modify any internal state.
232
228
func (rf * relayFinder ) tryNode (ctx context.Context , pi peer.AddrInfo ) (supportsRelayV1 bool , err error ) {
@@ -293,10 +289,16 @@ func (rf *relayFinder) handleNewCandidate(ctx context.Context) {
293
289
if len (rf .relays ) == rf .conf .desiredRelays {
294
290
return
295
291
}
296
- // During the startup phase, we don't want to connect to the first candidate that we find.
297
- // Instead, we wait until we've found at least minCandidates, and then select the best of those.
298
- // However, if that takes too long (longer than bootDelay),
299
- if len (rf .relays ) == 0 && len (rf .candidates ) < rf .conf .minCandidates && time .Since (rf .bootTime ) < rf .conf .bootDelay {
292
+
293
+ if len (rf .conf .staticRelays ) != 0 {
294
+ // make sure we read all static relays before continuing
295
+ if len (rf .peerChan ) > 0 && len (rf .candidates ) < rf .conf .minCandidates && time .Since (rf .bootTime ) < rf .conf .bootDelay {
296
+ return
297
+ }
298
+ } else if len (rf .relays ) == 0 && len (rf .candidates ) < rf .conf .minCandidates && time .Since (rf .bootTime ) < rf .conf .bootDelay {
299
+ // During the startup phase, we don't want to connect to the first candidate that we find.
300
+ // Instead, we wait until we've found at least minCandidates, and then select the best of those.
301
+ // However, if that takes too long (longer than bootDelay), we still go ahead.
300
302
return
301
303
}
302
304
0 commit comments