@@ -23,13 +23,11 @@ import (
23
23
"path/filepath"
24
24
"runtime"
25
25
"strings"
26
- "sync"
27
26
28
27
"github.com/ethereum/go-ethereum/common"
29
28
"github.com/ethereum/go-ethereum/crypto"
30
29
"github.com/ethereum/go-ethereum/log"
31
30
"github.com/ethereum/go-ethereum/p2p"
32
- "github.com/ethereum/go-ethereum/p2p/enode"
33
31
"github.com/ethereum/go-ethereum/rpc"
34
32
)
35
33
@@ -194,8 +192,6 @@ type Config struct {
194
192
// Logger is a custom logger to use with the p2p.Server.
195
193
Logger log.Logger `toml:",omitempty"`
196
194
197
- staticNodesWarning bool
198
- trustedNodesWarning bool
199
195
oldGethResourceWarning bool
200
196
201
197
// AllowUnprotectedTxs allows non EIP-155 protected transactions to be send over RPC.
@@ -340,8 +336,9 @@ func (c *Config) ResolvePath(path string) string {
340
336
oldpath = filepath .Join (c .DataDir , path )
341
337
}
342
338
if oldpath != "" && common .FileExist (oldpath ) {
343
- if warn {
344
- c .warnOnce (& c .oldGethResourceWarning , "Using deprecated resource file %s, please move this file to the 'geth' subdirectory of datadir." , oldpath )
339
+ if warn && ! c .oldGethResourceWarning {
340
+ c .oldGethResourceWarning = true
341
+ log .Warn ("Using deprecated resource file, please move this file to the 'geth' subdirectory of datadir." , "file" , oldpath )
345
342
}
346
343
return oldpath
347
344
}
@@ -394,48 +391,35 @@ func (c *Config) NodeKey() *ecdsa.PrivateKey {
394
391
return key
395
392
}
396
393
397
- // StaticNodes returns a list of node enode URLs configured as static nodes.
398
- func (c * Config ) StaticNodes () []* enode.Node {
399
- return c .parsePersistentNodes (& c .staticNodesWarning , c .ResolvePath (datadirStaticNodes ))
394
+ // CheckLegacyFiles inspects the datadir for signs of legacy static-nodes
395
+ // and trusted-nodes files. If they exist it raises an error.
396
+ func (c * Config ) checkLegacyFiles () {
397
+ c .checkLegacyFile (c .ResolvePath (datadirStaticNodes ))
398
+ c .checkLegacyFile (c .ResolvePath (datadirTrustedNodes ))
400
399
}
401
400
402
- // TrustedNodes returns a list of node enode URLs configured as trusted nodes.
403
- func (c * Config ) TrustedNodes () []* enode.Node {
404
- return c .parsePersistentNodes (& c .trustedNodesWarning , c .ResolvePath (datadirTrustedNodes ))
405
- }
406
-
407
- // parsePersistentNodes parses a list of discovery node URLs loaded from a .json
408
- // file from within the data directory.
409
- func (c * Config ) parsePersistentNodes (w * bool , path string ) []* enode.Node {
401
+ // checkLegacyFile will only raise an error if a file at the given path exists.
402
+ func (c * Config ) checkLegacyFile (path string ) {
410
403
// Short circuit if no node config is present
411
404
if c .DataDir == "" {
412
- return nil
405
+ return
413
406
}
414
407
if _ , err := os .Stat (path ); err != nil {
415
- return nil
408
+ return
416
409
}
417
- c .warnOnce (w , "Found deprecated node list file %s, please use the TOML config file instead." , path )
418
-
419
- // Load the nodes from the config file.
420
- var nodelist []string
421
- if err := common .LoadJSON (path , & nodelist ); err != nil {
422
- log .Error (fmt .Sprintf ("Can't load node list file: %v" , err ))
423
- return nil
410
+ logger := c .Logger
411
+ if logger == nil {
412
+ logger = log .Root ()
424
413
}
425
- // Interpret the list as a discovery node array
426
- var nodes []* enode.Node
427
- for _ , url := range nodelist {
428
- if url == "" {
429
- continue
430
- }
431
- node , err := enode .Parse (enode .ValidSchemes , url )
432
- if err != nil {
433
- log .Error (fmt .Sprintf ("Node URL %s: %v\n " , url , err ))
434
- continue
435
- }
436
- nodes = append (nodes , node )
414
+ switch fname := filepath .Base (path ); fname {
415
+ case "static-nodes.json" :
416
+ logger .Error ("The static-nodes.json file is deprecated and ignored. Use P2P.StaticNodes in config.toml instead." )
417
+ case "trusted-nodes.json" :
418
+ logger .Error ("The trusted-nodes.json file is deprecated and ignored. Use P2P.TrustedNodes in config.toml instead." )
419
+ default :
420
+ // We shouldn't wind up here, but better print something just in case.
421
+ logger .Error ("Ignoring deprecated file." , "file" , path )
437
422
}
438
- return nodes
439
423
}
440
424
441
425
// KeyDirConfig determines the settings for keydirectory
@@ -482,20 +466,3 @@ func getKeyStoreDir(conf *Config) (string, bool, error) {
482
466
483
467
return keydir , isEphemeral , nil
484
468
}
485
-
486
- var warnLock sync.Mutex
487
-
488
- func (c * Config ) warnOnce (w * bool , format string , args ... interface {}) {
489
- warnLock .Lock ()
490
- defer warnLock .Unlock ()
491
-
492
- if * w {
493
- return
494
- }
495
- l := c .Logger
496
- if l == nil {
497
- l = log .Root ()
498
- }
499
- l .Warn (fmt .Sprintf (format , args ... ))
500
- * w = true
501
- }
0 commit comments