@@ -24,6 +24,7 @@ import (
24
24
"path/filepath"
25
25
"runtime"
26
26
"strings"
27
+ "sync"
27
28
28
29
"github.com/ethereum/go-ethereum/accounts"
29
30
"github.com/ethereum/go-ethereum/accounts/keystore"
@@ -152,6 +153,10 @@ type Config struct {
152
153
153
154
// Logger is a custom logger to use with the p2p.Server.
154
155
Logger log.Logger `toml:",omitempty"`
156
+
157
+ staticNodesWarning bool
158
+ trustedNodesWarning bool
159
+ oldGethResourceWarning bool
155
160
}
156
161
157
162
// IPCEndpoint resolves an IPC endpoint based on a configured value, taking into
@@ -263,8 +268,8 @@ var isOldGethResource = map[string]bool{
263
268
"chaindata" : true ,
264
269
"nodes" : true ,
265
270
"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.
268
273
}
269
274
270
275
// ResolvePath resolves path in the instance directory.
@@ -277,13 +282,15 @@ func (c *Config) ResolvePath(path string) string {
277
282
}
278
283
// Backwards-compatibility: ensure that data directory files created
279
284
// by geth 1.4 are used if they exist.
280
- if c . name () == "geth" && isOldGethResource [path ] {
285
+ if warn , isOld := isOldGethResource [path ]; isOld {
281
286
oldpath := ""
282
- if c .Name == "geth" {
287
+ if c .name () == "geth" {
283
288
oldpath = filepath .Join (c .DataDir , path )
284
289
}
285
290
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
+ }
287
294
return oldpath
288
295
}
289
296
}
@@ -337,28 +344,30 @@ func (c *Config) NodeKey() *ecdsa.PrivateKey {
337
344
338
345
// StaticNodes returns a list of node enode URLs configured as static nodes.
339
346
func (c * Config ) StaticNodes () []* enode.Node {
340
- return c .parsePersistentNodes (c .ResolvePath (datadirStaticNodes ))
347
+ return c .parsePersistentNodes (& c . staticNodesWarning , c .ResolvePath (datadirStaticNodes ))
341
348
}
342
349
343
350
// TrustedNodes returns a list of node enode URLs configured as trusted nodes.
344
351
func (c * Config ) TrustedNodes () []* enode.Node {
345
- return c .parsePersistentNodes (c .ResolvePath (datadirTrustedNodes ))
352
+ return c .parsePersistentNodes (& c . trustedNodesWarning , c .ResolvePath (datadirTrustedNodes ))
346
353
}
347
354
348
355
// parsePersistentNodes parses a list of discovery node URLs loaded from a .json
349
356
// 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 {
351
358
// Short circuit if no node config is present
352
359
if c .DataDir == "" {
353
360
return nil
354
361
}
355
362
if _ , err := os .Stat (path ); err != nil {
356
363
return nil
357
364
}
365
+ c .warnOnce (w , "Found deprecated node list file %s, please use the TOML config file instead." , path )
366
+
358
367
// Load the nodes from the config file.
359
368
var nodelist []string
360
369
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 ))
362
371
return nil
363
372
}
364
373
// Interpret the list as a discovery node array
@@ -440,3 +449,20 @@ func makeAccountManager(conf *Config) (*accounts.Manager, string, error) {
440
449
}
441
450
return accounts .NewManager (backends ... ), ephemeral , nil
442
451
}
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