@@ -125,7 +125,6 @@ type serverPool struct {
125
125
discLookups chan bool
126
126
127
127
entries map [discover.NodeID ]* poolEntry
128
- lock sync.Mutex
129
128
timeout , enableRetry chan * poolEntry
130
129
adjustStats chan poolStatAdjust
131
130
@@ -174,9 +173,8 @@ func (pool *serverPool) start(server *p2p.Server, topic discv5.Topic) {
174
173
pool .discLookups = make (chan bool , 100 )
175
174
go pool .server .DiscV5 .SearchTopic (pool .topic , pool .discSetPeriod , pool .discNodes , pool .discLookups )
176
175
}
177
-
178
- go pool .eventLoop ()
179
176
pool .checkDial ()
177
+ go pool .eventLoop ()
180
178
}
181
179
182
180
// connect should be called upon any incoming connection. If the connection has been
@@ -223,24 +221,14 @@ func (pool *serverPool) disconnect(entry *poolEntry) {
223
221
if stopped {
224
222
// Request is emitted by ourselves, handle the logic here since eventloop doesn't
225
223
// serve requests anymore.
226
- pool .lock .Lock ()
227
- defer pool .lock .Unlock ()
228
-
229
224
if entry .state == psRegistered {
230
- connTime := mclock .Now () - entry .regTime
231
- connAdjust := float64 (connTime ) / float64 (targetConnTime )
225
+ connAdjust := float64 (mclock .Now ()- entry .regTime ) / float64 (targetConnTime )
232
226
if connAdjust > 1 {
233
227
connAdjust = 1
234
228
}
235
229
entry .connectStats .add (1 , connAdjust )
236
230
}
237
231
entry .state = psNotConnected
238
- if entry .knownSelected {
239
- pool .knownSelected --
240
- } else {
241
- pool .newSelected --
242
- }
243
- pool .setRetryDial (entry )
244
232
pool .connWg .Done ()
245
233
} else {
246
234
// Request is emitted by the server side
@@ -297,22 +285,17 @@ func (pool *serverPool) eventLoop() {
297
285
for {
298
286
select {
299
287
case entry := <- pool .timeout :
300
- pool .lock .Lock ()
301
288
if ! entry .removed {
302
289
pool .checkDialTimeout (entry )
303
290
}
304
- pool .lock .Unlock ()
305
291
306
292
case entry := <- pool .enableRetry :
307
- pool .lock .Lock ()
308
293
if ! entry .removed {
309
294
entry .delayedRetry = false
310
295
pool .updateCheckDial (entry )
311
296
}
312
- pool .lock .Unlock ()
313
297
314
298
case adj := <- pool .adjustStats :
315
- pool .lock .Lock ()
316
299
switch adj .adjustType {
317
300
case pseBlockDelay :
318
301
adj .entry .delayStats .add (float64 (adj .time ), 1 )
@@ -322,13 +305,10 @@ func (pool *serverPool) eventLoop() {
322
305
case pseResponseTimeout :
323
306
adj .entry .timeoutStats .add (1 , 1 )
324
307
}
325
- pool .lock .Unlock ()
326
308
327
309
case node := <- pool .discNodes :
328
- pool .lock .Lock ()
329
310
entry := pool .findOrNewNode (discover .NodeID (node .ID ), node .IP , node .TCP )
330
311
pool .updateCheckDial (entry )
331
- pool .lock .Unlock ()
332
312
333
313
case conv := <- pool .discLookups :
334
314
if conv {
@@ -350,7 +330,6 @@ func (pool *serverPool) eventLoop() {
350
330
if entry == nil {
351
331
entry = pool .findOrNewNode (req .p .ID (), req .ip , req .port )
352
332
}
353
- req .p .Log ().Debug ("Connecting to new peer" , "state" , entry .state )
354
333
if entry .state == psConnected || entry .state == psRegistered {
355
334
req .cont <- nil
356
335
continue
@@ -387,15 +366,14 @@ func (pool *serverPool) eventLoop() {
387
366
// Handle peer disconnection requests.
388
367
entry := req .entry
389
368
if entry .state == psRegistered {
390
- connTime := mclock .Now () - entry .regTime
391
- connAdjust := float64 (connTime ) / float64 (targetConnTime )
369
+ connAdjust := float64 (mclock .Now ()- entry .regTime ) / float64 (targetConnTime )
392
370
if connAdjust > 1 {
393
371
connAdjust = 1
394
372
}
395
373
entry .connectStats .add (connAdjust , 1 )
396
374
}
397
-
398
375
entry .state = psNotConnected
376
+
399
377
if entry .knownSelected {
400
378
pool .knownSelected --
401
379
} else {
0 commit comments