@@ -23,11 +23,13 @@ import (
2323 "path/filepath"
2424 "runtime"
2525 "strings"
26+ "sync"
2627
2728 "github.com/ethereum/go-ethereum/common"
2829 "github.com/ethereum/go-ethereum/crypto"
2930 "github.com/ethereum/go-ethereum/log"
3031 "github.com/ethereum/go-ethereum/p2p"
32+ "github.com/ethereum/go-ethereum/p2p/enode"
3133 "github.com/ethereum/go-ethereum/rpc"
3234)
3335
@@ -192,6 +194,10 @@ type Config struct {
192194 // Logger is a custom logger to use with the p2p.Server.
193195 Logger log.Logger `toml:",omitempty"`
194196
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)
195201 oldGethResourceWarning bool
196202
197203 // AllowUnprotectedTxs allows non EIP-155 protected transactions to be send over RPC.
@@ -341,10 +347,17 @@ func (c *Config) ResolvePath(path string) string {
341347 oldpath = filepath .Join (c .DataDir , path )
342348 }
343349 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 )
347359 }
360+ // MODIFIED by Jakub Pajek END (revert revert drop support for static & trusted node list files)
348361 return oldpath
349362 }
350363 }
@@ -396,13 +409,27 @@ func (c *Config) NodeKey() *ecdsa.PrivateKey {
396409 return key
397410}
398411
412+ // MODIFIED by Jakub Pajek BEG (revert revert drop support for static & trusted node list files)
399413// CheckLegacyFiles inspects the datadir for signs of legacy static-nodes
400414// and trusted-nodes files. If they exist it raises an error.
415+ /*
401416func (c *Config) checkLegacyFiles() {
402417 c.checkLegacyFile(c.ResolvePath(datadirStaticNodes))
403418 c.checkLegacyFile(c.ResolvePath(datadirTrustedNodes))
404419}
420+ */
405421
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+ /*
406433// checkLegacyFile will only raise an error if a file at the given path exists.
407434func (c *Config) checkLegacyFile(path string) {
408435 // Short circuit if no node config is present
@@ -426,6 +453,43 @@ func (c *Config) checkLegacyFile(path string) {
426453 logger.Error("Ignoring deprecated file.", "file", path)
427454 }
428455}
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)
429493
430494// KeyDirConfig determines the settings for keydirectory
431495func (c * Config ) KeyDirConfig () (string , error ) {
@@ -471,3 +535,23 @@ func getKeyStoreDir(conf *Config) (string, bool, error) {
471535
472536 return keydir , isEphemeral , nil
473537}
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