@@ -64,15 +64,13 @@ type Config = ethconfig.Config
64
64
65
65
// Ethereum implements the Ethereum full node service.
66
66
type Ethereum struct {
67
- config * ethconfig.Config
67
+ // core protocol objects
68
+ config * ethconfig.Config
69
+ txPool * txpool.TxPool
70
+ blockchain * core.BlockChain
68
71
69
- // Handlers
70
- txPool * txpool.TxPool
71
-
72
- blockchain * core.BlockChain
73
- handler * handler
74
- ethDialCandidates enode.Iterator
75
- snapDialCandidates enode.Iterator
72
+ handler * handler
73
+ discmix * enode.FairMix
76
74
77
75
// DB interfaces
78
76
chainDb ethdb.Database // Block chain database
@@ -162,6 +160,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
162
160
bloomRequests : make (chan chan * bloombits.Retrieval ),
163
161
bloomIndexer : core .NewBloomIndexer (chainDb , params .BloomBitsBlocks , params .BloomConfirms ),
164
162
p2pServer : stack .Server (),
163
+ discmix : enode .NewFairMix (0 ),
165
164
shutdownTracker : shutdowncheck .NewShutdownTracker (chainDb ),
166
165
}
167
166
bcVersion := rawdb .ReadDatabaseVersion (chainDb )
@@ -266,17 +265,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
266
265
}
267
266
eth .APIBackend .gpo = gasprice .NewOracle (eth .APIBackend , config .GPO , config .Miner .GasPrice )
268
267
269
- // Setup DNS discovery iterators.
270
- dnsclient := dnsdisc .NewClient (dnsdisc.Config {})
271
- eth .ethDialCandidates , err = dnsclient .NewIterator (eth .config .EthDiscoveryURLs ... )
272
- if err != nil {
273
- return nil , err
274
- }
275
- eth .snapDialCandidates , err = dnsclient .NewIterator (eth .config .SnapDiscoveryURLs ... )
276
- if err != nil {
277
- return nil , err
278
- }
279
-
280
268
// Start the RPC service
281
269
eth .netRPCService = ethapi .NewNetAPI (eth .p2pServer , networkID )
282
270
@@ -359,17 +347,17 @@ func (s *Ethereum) BloomIndexer() *core.ChainIndexer { return s.bloomIndexer }
359
347
// Protocols returns all the currently configured
360
348
// network protocols to start.
361
349
func (s * Ethereum ) Protocols () []p2p.Protocol {
362
- protos := eth .MakeProtocols ((* ethHandler )(s .handler ), s .networkID , s .ethDialCandidates )
350
+ protos := eth .MakeProtocols ((* ethHandler )(s .handler ), s .networkID , s .discmix )
363
351
if s .config .SnapshotCache > 0 {
364
- protos = append (protos , snap .MakeProtocols ((* snapHandler )(s .handler ), s . snapDialCandidates )... )
352
+ protos = append (protos , snap .MakeProtocols ((* snapHandler )(s .handler ))... )
365
353
}
366
354
return protos
367
355
}
368
356
369
357
// Start implements node.Lifecycle, starting all internal goroutines needed by the
370
358
// Ethereum protocol implementation.
371
359
func (s * Ethereum ) Start () error {
372
- eth . StartENRUpdater ( s . blockchain , s . p2pServer . LocalNode () )
360
+ s . setupDiscovery ( )
373
361
374
362
// Start the bloom bits servicing goroutines
375
363
s .startBloomHandlers (params .BloomBitsBlocks )
@@ -382,12 +370,43 @@ func (s *Ethereum) Start() error {
382
370
return nil
383
371
}
384
372
373
+ func (s * Ethereum ) setupDiscovery () error {
374
+ eth .StartENRUpdater (s .blockchain , s .p2pServer .LocalNode ())
375
+
376
+ // Add eth nodes from DNS.
377
+ dnsclient := dnsdisc .NewClient (dnsdisc.Config {})
378
+ if len (s .config .EthDiscoveryURLs ) > 0 {
379
+ iter , err := dnsclient .NewIterator (s .config .EthDiscoveryURLs ... )
380
+ if err != nil {
381
+ return err
382
+ }
383
+ s .discmix .AddSource (iter )
384
+ }
385
+
386
+ // Add snap nodes from DNS.
387
+ if len (s .config .SnapDiscoveryURLs ) > 0 {
388
+ iter , err := dnsclient .NewIterator (s .config .SnapDiscoveryURLs ... )
389
+ if err != nil {
390
+ return err
391
+ }
392
+ s .discmix .AddSource (iter )
393
+ }
394
+
395
+ // Add DHT nodes from discv5.
396
+ if s .p2pServer .DiscoveryV5 () != nil {
397
+ filter := eth .NewNodeFilter (s .blockchain )
398
+ iter := enode .Filter (s .p2pServer .DiscoveryV5 ().RandomNodes (), filter )
399
+ s .discmix .AddSource (iter )
400
+ }
401
+
402
+ return nil
403
+ }
404
+
385
405
// Stop implements node.Lifecycle, terminating all internal goroutines used by the
386
406
// Ethereum protocol.
387
407
func (s * Ethereum ) Stop () error {
388
408
// Stop all the peer-related stuff first.
389
- s .ethDialCandidates .Close ()
390
- s .snapDialCandidates .Close ()
409
+ s .discmix .Close ()
391
410
s .handler .Stop ()
392
411
393
412
// Then stop everything else.
0 commit comments