@@ -23,13 +23,11 @@ import (
23
23
"path/filepath"
24
24
"runtime"
25
25
"strings"
26
- "sync"
27
26
28
27
"github.com/XinFinOrg/XDPoSChain/common"
29
28
"github.com/XinFinOrg/XDPoSChain/crypto"
30
29
"github.com/XinFinOrg/XDPoSChain/log"
31
30
"github.com/XinFinOrg/XDPoSChain/p2p"
32
- "github.com/XinFinOrg/XDPoSChain/p2p/discover"
33
31
"github.com/XinFinOrg/XDPoSChain/rpc"
34
32
)
35
33
@@ -177,8 +175,6 @@ type Config struct {
177
175
// Logger is a custom logger to use with the p2p.Server.
178
176
Logger log.Logger `toml:",omitempty"`
179
177
180
- staticNodesWarning bool
181
- trustedNodesWarning bool
182
178
oldGethResourceWarning bool
183
179
184
180
AnnounceTxs bool `toml:",omitempty"`
@@ -329,8 +325,9 @@ func (c *Config) ResolvePath(path string) string {
329
325
oldpath = filepath .Join (c .DataDir , path )
330
326
}
331
327
if oldpath != "" && common .FileExist (oldpath ) {
332
- if warn {
333
- c .warnOnce (& c .oldGethResourceWarning , "Using deprecated resource file %s, please move this file to the 'geth' subdirectory of datadir." , oldpath )
328
+ if warn && ! c .oldGethResourceWarning {
329
+ c .oldGethResourceWarning = true
330
+ log .Warn ("Using deprecated resource file, please move this file to the 'geth' subdirectory of datadir." , "file" , oldpath )
334
331
}
335
332
return oldpath
336
333
}
@@ -383,48 +380,35 @@ func (c *Config) NodeKey() *ecdsa.PrivateKey {
383
380
return key
384
381
}
385
382
386
- // StaticNodes returns a list of node enode URLs configured as static nodes.
387
- func (c * Config ) StaticNodes () []* discover.Node {
388
- return c .parsePersistentNodes (& c .staticNodesWarning , c .ResolvePath (datadirStaticNodes ))
383
+ // CheckLegacyFiles inspects the datadir for signs of legacy static-nodes
384
+ // and trusted-nodes files. If they exist it raises an error.
385
+ func (c * Config ) checkLegacyFiles () {
386
+ c .checkLegacyFile (c .ResolvePath (datadirStaticNodes ))
387
+ c .checkLegacyFile (c .ResolvePath (datadirTrustedNodes ))
389
388
}
390
389
391
- // TrustedNodes returns a list of node enode URLs configured as trusted nodes.
392
- func (c * Config ) TrustedNodes () []* discover.Node {
393
- return c .parsePersistentNodes (& c .trustedNodesWarning , c .ResolvePath (datadirTrustedNodes ))
394
- }
395
-
396
- // parsePersistentNodes parses a list of discovery node URLs loaded from a .json
397
- // file from within the data directory.
398
- func (c * Config ) parsePersistentNodes (w * bool , path string ) []* discover.Node {
390
+ // checkLegacyFile will only raise an error if a file at the given path exists.
391
+ func (c * Config ) checkLegacyFile (path string ) {
399
392
// Short circuit if no node config is present
400
393
if c .DataDir == "" {
401
- return nil
394
+ return
402
395
}
403
396
if _ , err := os .Stat (path ); err != nil {
404
- return nil
397
+ return
405
398
}
406
- c .warnOnce (w , "Found deprecated node list file %s, please use the TOML config file instead." , path )
407
-
408
- // Load the nodes from the config file.
409
- var nodelist []string
410
- if err := common .LoadJSON (path , & nodelist ); err != nil {
411
- log .Error (fmt .Sprintf ("Can't load node list file: %v" , err ))
412
- return nil
399
+ logger := c .Logger
400
+ if logger == nil {
401
+ logger = log .Root ()
413
402
}
414
- // Interpret the list as a discovery node array
415
- var nodes []* discover.Node
416
- for _ , url := range nodelist {
417
- if url == "" {
418
- continue
419
- }
420
- node , err := discover .ParseNode (url )
421
- if err != nil {
422
- log .Error (fmt .Sprintf ("Node URL %s: %v\n " , url , err ))
423
- continue
424
- }
425
- nodes = append (nodes , node )
403
+ switch fname := filepath .Base (path ); fname {
404
+ case "static-nodes.json" :
405
+ logger .Error ("The static-nodes.json file is deprecated and ignored. Use P2P.StaticNodes in config.toml instead." )
406
+ case "trusted-nodes.json" :
407
+ logger .Error ("The trusted-nodes.json file is deprecated and ignored. Use P2P.TrustedNodes in config.toml instead." )
408
+ default :
409
+ // We shouldn't wind up here, but better print something just in case.
410
+ logger .Error ("Ignoring deprecated file." , "file" , path )
426
411
}
427
- return nodes
428
412
}
429
413
430
414
// KeyDirConfig determines the settings for keydirectory
@@ -471,20 +455,3 @@ func getKeyStoreDir(conf *Config) (string, bool, error) {
471
455
472
456
return keydir , isEphemeral , nil
473
457
}
474
-
475
- var warnLock sync.Mutex
476
-
477
- func (c * Config ) warnOnce (w * bool , format string , args ... interface {}) {
478
- warnLock .Lock ()
479
- defer warnLock .Unlock ()
480
-
481
- if * w {
482
- return
483
- }
484
- l := c .Logger
485
- if l == nil {
486
- l = log .Root ()
487
- }
488
- l .Warn (fmt .Sprintf (format , args ... ))
489
- * w = true
490
- }
0 commit comments