@@ -23,11 +23,13 @@ import (
23
23
"path/filepath"
24
24
"runtime"
25
25
"strings"
26
+ "sync"
26
27
27
28
"github.com/ethereum/go-ethereum/common"
28
29
"github.com/ethereum/go-ethereum/crypto"
29
30
"github.com/ethereum/go-ethereum/log"
30
31
"github.com/ethereum/go-ethereum/p2p"
32
+ "github.com/ethereum/go-ethereum/p2p/enode"
31
33
"github.com/ethereum/go-ethereum/rpc"
32
34
)
33
35
@@ -192,6 +194,10 @@ type Config struct {
192
194
// Logger is a custom logger to use with the p2p.Server.
193
195
Logger log.Logger `toml:",omitempty"`
194
196
197
+ // MODIFIED by Jakub Pajek BEG (revert revert drop support for static & trusted node list files)
198
+ staticNodesWarning bool
199
+ trustedNodesWarning bool
200
+ // MODIFIED by Jakub Pajek END (revert revert drop support for static & trusted node list files)
195
201
oldGethResourceWarning bool
196
202
197
203
// AllowUnprotectedTxs allows non EIP-155 protected transactions to be send over RPC.
@@ -341,10 +347,17 @@ func (c *Config) ResolvePath(path string) string {
341
347
oldpath = filepath .Join (c .DataDir , path )
342
348
}
343
349
if oldpath != "" && common .FileExist (oldpath ) {
344
- if warn && ! c .oldGethResourceWarning {
345
- c .oldGethResourceWarning = true
346
- log .Warn ("Using deprecated resource file, please move this file to the 'geth' subdirectory of datadir." , "file" , oldpath )
350
+ // MODIFIED by Jakub Pajek BEG (revert revert drop support for static & trusted node list files)
351
+ /*
352
+ if warn && !c.oldGethResourceWarning {
353
+ c.oldGethResourceWarning = true
354
+ log.Warn("Using deprecated resource file, please move this file to the 'geth' subdirectory of datadir.", "file", oldpath)
355
+ }
356
+ */
357
+ if warn {
358
+ c .warnOnce (& c .oldGethResourceWarning , "Using deprecated resource file %s, please move this file to the 'geth' subdirectory of datadir." , oldpath )
347
359
}
360
+ // MODIFIED by Jakub Pajek END (revert revert drop support for static & trusted node list files)
348
361
return oldpath
349
362
}
350
363
}
@@ -396,13 +409,27 @@ func (c *Config) NodeKey() *ecdsa.PrivateKey {
396
409
return key
397
410
}
398
411
412
+ // MODIFIED by Jakub Pajek BEG (revert revert drop support for static & trusted node list files)
399
413
// CheckLegacyFiles inspects the datadir for signs of legacy static-nodes
400
414
// and trusted-nodes files. If they exist it raises an error.
415
+ /*
401
416
func (c *Config) checkLegacyFiles() {
402
417
c.checkLegacyFile(c.ResolvePath(datadirStaticNodes))
403
418
c.checkLegacyFile(c.ResolvePath(datadirTrustedNodes))
404
419
}
420
+ */
405
421
422
+ // StaticNodes returns a list of node enode URLs configured as static nodes.
423
+ func (c * Config ) StaticNodes () []* enode.Node {
424
+ return c .parsePersistentNodes (& c .staticNodesWarning , c .ResolvePath (datadirStaticNodes ))
425
+ }
426
+
427
+ // TrustedNodes returns a list of node enode URLs configured as trusted nodes.
428
+ func (c * Config ) TrustedNodes () []* enode.Node {
429
+ return c .parsePersistentNodes (& c .trustedNodesWarning , c .ResolvePath (datadirTrustedNodes ))
430
+ }
431
+
432
+ /*
406
433
// checkLegacyFile will only raise an error if a file at the given path exists.
407
434
func (c *Config) checkLegacyFile(path string) {
408
435
// Short circuit if no node config is present
@@ -426,6 +453,43 @@ func (c *Config) checkLegacyFile(path string) {
426
453
logger.Error("Ignoring deprecated file.", "file", path)
427
454
}
428
455
}
456
+ */
457
+
458
+ // parsePersistentNodes parses a list of discovery node URLs loaded from a .json
459
+ // file from within the data directory.
460
+ func (c * Config ) parsePersistentNodes (w * bool , path string ) []* enode.Node {
461
+ // Short circuit if no node config is present
462
+ if c .DataDir == "" {
463
+ return nil
464
+ }
465
+ if _ , err := os .Stat (path ); err != nil {
466
+ return nil
467
+ }
468
+ c .warnOnce (w , "Found deprecated node list file %s, please use the TOML config file instead." , path )
469
+
470
+ // Load the nodes from the config file.
471
+ var nodelist []string
472
+ if err := common .LoadJSON (path , & nodelist ); err != nil {
473
+ log .Error (fmt .Sprintf ("Can't load node list file: %v" , err ))
474
+ return nil
475
+ }
476
+ // Interpret the list as a discovery node array
477
+ var nodes []* enode.Node
478
+ for _ , url := range nodelist {
479
+ if url == "" {
480
+ continue
481
+ }
482
+ node , err := enode .Parse (enode .ValidSchemes , url )
483
+ if err != nil {
484
+ log .Error (fmt .Sprintf ("Node URL %s: %v\n " , url , err ))
485
+ continue
486
+ }
487
+ nodes = append (nodes , node )
488
+ }
489
+ return nodes
490
+ }
491
+
492
+ // MODIFIED by Jakub Pajek END (revert revert drop support for static & trusted node list files)
429
493
430
494
// KeyDirConfig determines the settings for keydirectory
431
495
func (c * Config ) KeyDirConfig () (string , error ) {
@@ -471,3 +535,23 @@ func getKeyStoreDir(conf *Config) (string, bool, error) {
471
535
472
536
return keydir , isEphemeral , nil
473
537
}
538
+
539
+ // MODIFIED by Jakub Pajek BEG (revert revert drop support for static & trusted node list files)
540
+ var warnLock sync.Mutex
541
+
542
+ func (c * Config ) warnOnce (w * bool , format string , args ... interface {}) {
543
+ warnLock .Lock ()
544
+ defer warnLock .Unlock ()
545
+
546
+ if * w {
547
+ return
548
+ }
549
+ l := c .Logger
550
+ if l == nil {
551
+ l = log .Root ()
552
+ }
553
+ l .Warn (fmt .Sprintf (format , args ... ))
554
+ * w = true
555
+ }
556
+
557
+ // MODIFIED by Jakub Pajek END (revert revert drop support for static & trusted node list files)
0 commit comments