@@ -24,6 +24,7 @@ import (
2424 "path/filepath"
2525 "runtime"
2626 "strings"
27+ "sync"
2728
2829 "github.com/ethereum/go-ethereum/accounts"
2930 "github.com/ethereum/go-ethereum/accounts/keystore"
@@ -152,6 +153,10 @@ type Config struct {
152153
153154 // Logger is a custom logger to use with the p2p.Server.
154155 Logger log.Logger `toml:",omitempty"`
156+
157+ staticNodesWarning bool
158+ trustedNodesWarning bool
159+ oldGethResourceWarning bool
155160}
156161
157162// IPCEndpoint resolves an IPC endpoint based on a configured value, taking into
@@ -263,8 +268,8 @@ var isOldGethResource = map[string]bool{
263268 "chaindata" : true ,
264269 "nodes" : true ,
265270 "nodekey" : true ,
266- "static-nodes.json" : true ,
267- "trusted-nodes.json" : true ,
271+ "static-nodes.json" : false , // no warning for these because they have their
272+ "trusted-nodes.json" : false , // own separate warning.
268273}
269274
270275// ResolvePath resolves path in the instance directory.
@@ -277,13 +282,15 @@ func (c *Config) ResolvePath(path string) string {
277282 }
278283 // Backwards-compatibility: ensure that data directory files created
279284 // by geth 1.4 are used if they exist.
280- if c . name () == "geth" && isOldGethResource [path ] {
285+ if warn , isOld := isOldGethResource [path ]; isOld {
281286 oldpath := ""
282- if c .Name == "geth" {
287+ if c .name () == "geth" {
283288 oldpath = filepath .Join (c .DataDir , path )
284289 }
285290 if oldpath != "" && common .FileExist (oldpath ) {
286- // TODO: print warning
291+ if warn {
292+ c .warnOnce (& c .oldGethResourceWarning , "Using deprecated resource file %s, please move this file to the 'geth' subdirectory of datadir." , oldpath )
293+ }
287294 return oldpath
288295 }
289296 }
@@ -337,28 +344,30 @@ func (c *Config) NodeKey() *ecdsa.PrivateKey {
337344
338345// StaticNodes returns a list of node enode URLs configured as static nodes.
339346func (c * Config ) StaticNodes () []* enode.Node {
340- return c .parsePersistentNodes (c .ResolvePath (datadirStaticNodes ))
347+ return c .parsePersistentNodes (& c . staticNodesWarning , c .ResolvePath (datadirStaticNodes ))
341348}
342349
343350// TrustedNodes returns a list of node enode URLs configured as trusted nodes.
344351func (c * Config ) TrustedNodes () []* enode.Node {
345- return c .parsePersistentNodes (c .ResolvePath (datadirTrustedNodes ))
352+ return c .parsePersistentNodes (& c . trustedNodesWarning , c .ResolvePath (datadirTrustedNodes ))
346353}
347354
348355// parsePersistentNodes parses a list of discovery node URLs loaded from a .json
349356// file from within the data directory.
350- func (c * Config ) parsePersistentNodes (path string ) []* enode.Node {
357+ func (c * Config ) parsePersistentNodes (w * bool , path string ) []* enode.Node {
351358 // Short circuit if no node config is present
352359 if c .DataDir == "" {
353360 return nil
354361 }
355362 if _ , err := os .Stat (path ); err != nil {
356363 return nil
357364 }
365+ c .warnOnce (w , "Found deprecated node list file %s, please use the TOML config file instead." , path )
366+
358367 // Load the nodes from the config file.
359368 var nodelist []string
360369 if err := common .LoadJSON (path , & nodelist ); err != nil {
361- log .Error (fmt .Sprintf ("Can't load node file %s : %v" , path , err ))
370+ log .Error (fmt .Sprintf ("Can't load node list file : %v" , err ))
362371 return nil
363372 }
364373 // Interpret the list as a discovery node array
@@ -440,3 +449,20 @@ func makeAccountManager(conf *Config) (*accounts.Manager, string, error) {
440449 }
441450 return accounts .NewManager (backends ... ), ephemeral , nil
442451}
452+
453+ var warnLock sync.Mutex
454+
455+ func (c * Config ) warnOnce (w * bool , format string , args ... interface {}) {
456+ warnLock .Lock ()
457+ defer warnLock .Unlock ()
458+
459+ if * w {
460+ return
461+ }
462+ l := c .Logger
463+ if l == nil {
464+ l = log .Root ()
465+ }
466+ l .Warn (fmt .Sprintf (format , args ... ))
467+ * w = true
468+ }
0 commit comments