2016-04-14 16:18:24 +00:00
|
|
|
// Copyright 2014 The go-ethereum Authors
|
2015-11-05 21:57:57 +00:00
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2022-05-26 05:27:44 +00:00
|
|
|
package nodecfg
|
2015-11-05 21:57:57 +00:00
|
|
|
|
|
|
|
import (
|
2016-02-05 11:45:36 +00:00
|
|
|
"fmt"
|
2015-11-05 21:57:57 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2016-02-02 17:06:43 +00:00
|
|
|
"runtime"
|
|
|
|
"strings"
|
2018-12-07 13:43:27 +00:00
|
|
|
"sync"
|
2015-11-05 21:57:57 +00:00
|
|
|
|
2022-02-12 08:23:06 +00:00
|
|
|
"github.com/c2h5oh/datasize"
|
2022-11-20 03:41:30 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/common/datadir"
|
2021-07-29 11:53:13 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
2022-02-16 17:38:54 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/cli/httpcfg"
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/common"
|
|
|
|
"github.com/ledgerwatch/erigon/common/paths"
|
|
|
|
"github.com/ledgerwatch/erigon/p2p"
|
|
|
|
"github.com/ledgerwatch/erigon/p2p/enode"
|
2022-05-30 10:08:49 +00:00
|
|
|
"github.com/ledgerwatch/erigon/rpc/rpccfg"
|
2021-07-29 10:23:23 +00:00
|
|
|
"github.com/ledgerwatch/log/v3"
|
2015-11-05 21:57:57 +00:00
|
|
|
)
|
|
|
|
|
2017-08-06 16:43:43 +00:00
|
|
|
const (
|
2021-03-26 18:05:42 +00:00
|
|
|
datadirStaticNodes = "static-nodes.json" // Path within the datadir to the static node list
|
|
|
|
datadirTrustedNodes = "trusted-nodes.json" // Path within the datadir to the trusted node list
|
|
|
|
datadirNodeDatabase = "nodes" // Path within the datadir to store the node infos
|
2015-11-05 21:57:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config represents a small collection of configuration values to fine tune the
|
|
|
|
// P2P network layer of a protocol stack. These values can be further extended by
|
|
|
|
// all registered services.
|
|
|
|
type Config struct {
|
2016-08-18 11:28:17 +00:00
|
|
|
// Name sets the instance name of the node. It must not contain the / character and is
|
2021-05-26 10:35:39 +00:00
|
|
|
// used in the devp2p node identifier. The instance name of Erigon is "erigon". If no
|
2016-08-18 11:28:17 +00:00
|
|
|
// value is specified, the basename of the current executable is used.
|
2017-04-12 14:27:23 +00:00
|
|
|
Name string `toml:"-"`
|
2016-08-18 11:28:17 +00:00
|
|
|
|
|
|
|
// UserIdent, if set, is used as an additional component in the devp2p node identifier.
|
2017-04-12 14:27:23 +00:00
|
|
|
UserIdent string `toml:",omitempty"`
|
2016-08-18 11:28:17 +00:00
|
|
|
|
|
|
|
// Version should be set to the version number of the program. It is used
|
|
|
|
// in the devp2p node identifier.
|
2017-04-12 14:27:23 +00:00
|
|
|
Version string `toml:"-"`
|
2016-08-18 11:28:17 +00:00
|
|
|
|
2022-06-07 04:54:04 +00:00
|
|
|
// Dirs is the file system folder the node should use for any data storage
|
2015-11-05 21:57:57 +00:00
|
|
|
// requirements. The configured data directory will not be directly shared with
|
|
|
|
// registered services, instead those can use utility methods to create/access
|
|
|
|
// databases or flat files. This enables ephemeral nodes which can fully reside
|
|
|
|
// in memory.
|
2022-06-07 04:54:04 +00:00
|
|
|
Dirs datadir.Dirs
|
2015-11-05 21:57:57 +00:00
|
|
|
|
2017-04-12 14:27:23 +00:00
|
|
|
// Configuration of peer-to-peer networking.
|
|
|
|
P2P p2p.Config
|
|
|
|
|
2016-02-09 11:24:42 +00:00
|
|
|
// IPCPath is the requested location to place the IPC endpoint. If the path is
|
2016-02-02 17:06:43 +00:00
|
|
|
// a simple file name, it is placed inside the data directory (or on the root
|
|
|
|
// pipe path on Windows), whereas if it's a resolvable path name (absolute or
|
|
|
|
// relative), then that specific path is enforced. An empty path disables IPC.
|
2020-07-06 20:09:30 +00:00
|
|
|
IPCPath string
|
2016-02-05 11:45:36 +00:00
|
|
|
|
2023-02-20 11:23:06 +00:00
|
|
|
// GraphQLEnabled decides if we enable the GraphQL endpoint or not.
|
|
|
|
GraphQLEnabled bool
|
|
|
|
|
2016-02-09 11:24:42 +00:00
|
|
|
// HTTPHost is the host interface on which to start the HTTP RPC server. If this
|
2016-02-05 11:45:36 +00:00
|
|
|
// field is empty, no HTTP API endpoint will be started.
|
2020-07-06 20:09:30 +00:00
|
|
|
HTTPHost string
|
2016-02-05 11:45:36 +00:00
|
|
|
|
2016-02-09 11:24:42 +00:00
|
|
|
// HTTPPort is the TCP port number on which to start the HTTP RPC server. The
|
2016-02-05 11:45:36 +00:00
|
|
|
// default zero value is/ valid and will pick a port number randomly (useful
|
|
|
|
// for ephemeral nodes).
|
2017-04-12 14:27:23 +00:00
|
|
|
HTTPPort int `toml:",omitempty"`
|
2016-02-05 11:45:36 +00:00
|
|
|
|
2016-02-09 11:24:42 +00:00
|
|
|
// HTTPCors is the Cross-Origin Resource Sharing header to send to requesting
|
2016-02-05 11:45:36 +00:00
|
|
|
// clients. Please be aware that CORS is a browser enforced security, it's fully
|
|
|
|
// useless for custom HTTP clients.
|
2017-04-12 21:04:14 +00:00
|
|
|
HTTPCors []string `toml:",omitempty"`
|
2016-02-05 11:45:36 +00:00
|
|
|
|
2018-02-12 12:52:07 +00:00
|
|
|
// HTTPVirtualHosts is the list of virtual hostnames which are allowed on incoming requests.
|
|
|
|
// This is by default {'localhost'}. Using this prevents attacks like
|
|
|
|
// DNS rebinding, which bypasses SOP by simply masquerading as being within the same
|
|
|
|
// origin. These attacks do not utilize CORS, since they are not cross-domain.
|
|
|
|
// By explicitly checking the Host-header, the server will not allow requests
|
|
|
|
// made against the server with a malicious host domain.
|
|
|
|
// Requests using ip address directly are not affected
|
|
|
|
HTTPVirtualHosts []string `toml:",omitempty"`
|
|
|
|
|
2016-02-09 11:24:42 +00:00
|
|
|
// HTTPModules is a list of API modules to expose via the HTTP RPC interface.
|
2016-02-05 11:45:36 +00:00
|
|
|
// If the module list is empty, all RPC API endpoints designated public will be
|
|
|
|
// exposed.
|
2020-07-06 20:09:30 +00:00
|
|
|
HTTPModules []string
|
2016-02-05 13:08:48 +00:00
|
|
|
|
2018-07-31 09:16:14 +00:00
|
|
|
// HTTPTimeouts allows for customization of the timeout values used by the HTTP RPC
|
|
|
|
// interface.
|
2022-05-30 10:08:49 +00:00
|
|
|
HTTPTimeouts rpccfg.HTTPTimeouts
|
2018-07-31 09:16:14 +00:00
|
|
|
|
2021-02-02 09:05:46 +00:00
|
|
|
// HTTPPathPrefix specifies a path prefix on which http-rpc is to be served.
|
|
|
|
HTTPPathPrefix string `toml:",omitempty"`
|
|
|
|
|
2016-02-09 11:24:42 +00:00
|
|
|
// WSHost is the host interface on which to start the websocket RPC server. If
|
2016-02-05 13:08:48 +00:00
|
|
|
// this field is empty, no websocket API endpoint will be started.
|
2020-07-06 20:09:30 +00:00
|
|
|
WSHost string
|
2016-02-05 13:08:48 +00:00
|
|
|
|
2016-02-09 11:24:42 +00:00
|
|
|
// WSPort is the TCP port number on which to start the websocket RPC server. The
|
2016-02-05 13:08:48 +00:00
|
|
|
// default zero value is/ valid and will pick a port number randomly (useful for
|
|
|
|
// ephemeral nodes).
|
2017-04-12 14:27:23 +00:00
|
|
|
WSPort int `toml:",omitempty"`
|
2016-02-05 13:08:48 +00:00
|
|
|
|
2021-02-02 09:05:46 +00:00
|
|
|
// WSPathPrefix specifies a path prefix on which ws-rpc is to be served.
|
|
|
|
WSPathPrefix string `toml:",omitempty"`
|
|
|
|
|
2016-03-14 08:38:54 +00:00
|
|
|
// WSOrigins is the list of domain to accept websocket requests from. Please be
|
2016-02-09 11:24:42 +00:00
|
|
|
// aware that the server can only act upon the HTTP request the client sends and
|
|
|
|
// cannot verify the validity of the request header.
|
2017-04-12 21:04:14 +00:00
|
|
|
WSOrigins []string `toml:",omitempty"`
|
2016-02-05 13:08:48 +00:00
|
|
|
|
2016-02-09 11:24:42 +00:00
|
|
|
// WSModules is a list of API modules to expose via the websocket RPC interface.
|
2016-02-05 13:08:48 +00:00
|
|
|
// If the module list is empty, all RPC API endpoints designated public will be
|
|
|
|
// exposed.
|
2020-07-06 20:09:30 +00:00
|
|
|
WSModules []string
|
2017-09-25 08:08:07 +00:00
|
|
|
|
|
|
|
// WSExposeAll exposes all API modules via the WebSocket RPC interface rather
|
|
|
|
// than just the public ones.
|
|
|
|
//
|
|
|
|
// *WARNING* Only set this if the node is running in a trusted network, exposing
|
|
|
|
// private APIs to untrusted users is a major security risk.
|
|
|
|
WSExposeAll bool `toml:",omitempty"`
|
2017-12-01 11:49:04 +00:00
|
|
|
|
2021-07-28 02:47:38 +00:00
|
|
|
DatabaseVerbosity kv.DBVerbosityLvl
|
2019-11-21 15:12:38 +00:00
|
|
|
|
2019-12-02 13:47:00 +00:00
|
|
|
// Address to listen to when launchig listener for remote database access
|
|
|
|
// empty string means not to start the listener
|
2021-03-23 07:28:04 +00:00
|
|
|
PrivateApiAddr string
|
|
|
|
PrivateApiRateLimit uint32
|
2019-12-02 13:47:00 +00:00
|
|
|
|
2021-03-26 18:05:42 +00:00
|
|
|
staticNodesWarning bool
|
|
|
|
trustedNodesWarning bool
|
2020-09-11 20:17:37 +00:00
|
|
|
|
2022-06-01 21:48:24 +00:00
|
|
|
SentryLogPeerInfo bool
|
|
|
|
|
2020-09-11 20:17:37 +00:00
|
|
|
TLSConnection bool
|
|
|
|
TLSCertFile string
|
2023-10-08 01:18:14 +00:00
|
|
|
|
|
|
|
TLSKeyFile string
|
|
|
|
TLSCACert string
|
2021-09-27 11:43:24 +00:00
|
|
|
|
2023-04-17 12:48:57 +00:00
|
|
|
MdbxPageSize datasize.ByteSize
|
|
|
|
MdbxDBSizeLimit datasize.ByteSize
|
2023-07-02 21:37:23 +00:00
|
|
|
MdbxGrowthStep datasize.ByteSize
|
2021-12-06 12:03:46 +00:00
|
|
|
// HealthCheck enables standard grpc health check
|
|
|
|
HealthCheck bool
|
2022-02-16 17:38:54 +00:00
|
|
|
|
|
|
|
Http httpcfg.HttpCfg
|
2015-11-05 21:57:57 +00:00
|
|
|
}
|
|
|
|
|
2016-02-09 11:24:42 +00:00
|
|
|
// IPCEndpoint resolves an IPC endpoint based on a configured value, taking into
|
2016-02-02 17:06:43 +00:00
|
|
|
// account the set data folders as well as the designated platform we're currently
|
|
|
|
// running on.
|
2016-02-09 11:24:42 +00:00
|
|
|
func (c *Config) IPCEndpoint() string {
|
2016-02-02 17:06:43 +00:00
|
|
|
// Short circuit if IPC has not been enabled
|
2016-02-09 11:24:42 +00:00
|
|
|
if c.IPCPath == "" {
|
2016-02-02 17:06:43 +00:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
// On windows we can only use plain top-level pipes
|
|
|
|
if runtime.GOOS == "windows" {
|
2016-02-09 11:24:42 +00:00
|
|
|
if strings.HasPrefix(c.IPCPath, `\\.\pipe\`) {
|
|
|
|
return c.IPCPath
|
2016-02-02 17:06:43 +00:00
|
|
|
}
|
2016-02-09 11:24:42 +00:00
|
|
|
return `\\.\pipe\` + c.IPCPath
|
2016-02-02 17:06:43 +00:00
|
|
|
}
|
|
|
|
// Resolve names into the data directory full paths otherwise
|
2016-02-09 11:24:42 +00:00
|
|
|
if filepath.Base(c.IPCPath) == c.IPCPath {
|
2022-06-07 04:54:04 +00:00
|
|
|
if c.Dirs.DataDir == "" {
|
2016-02-09 11:24:42 +00:00
|
|
|
return filepath.Join(os.TempDir(), c.IPCPath)
|
2016-02-02 17:06:43 +00:00
|
|
|
}
|
2022-06-07 05:08:24 +00:00
|
|
|
return filepath.Join(c.Dirs.RelativeDataDir, c.IPCPath)
|
2016-02-02 17:06:43 +00:00
|
|
|
}
|
2016-02-09 11:24:42 +00:00
|
|
|
return c.IPCPath
|
2016-02-02 17:06:43 +00:00
|
|
|
}
|
|
|
|
|
2016-08-18 11:28:17 +00:00
|
|
|
// NodeDB returns the path to the discovery node database.
|
2021-05-08 08:45:40 +00:00
|
|
|
func (c *Config) NodeDB() string {
|
cmd, dashboard, log: log collection and exploration (#17097)
* cmd, dashboard, internal, log, node: logging feature
* cmd, dashboard, internal, log: requested changes
* dashboard, vendor: gofmt, govendor, use vendored file watcher
* dashboard, log: gofmt -s -w, goimports
* dashboard, log: gosimple
2018-07-11 07:59:04 +00:00
|
|
|
return c.ResolvePath(datadirNodeDatabase)
|
2016-08-18 11:28:17 +00:00
|
|
|
}
|
|
|
|
|
2016-02-09 11:24:42 +00:00
|
|
|
// DefaultIPCEndpoint returns the IPC path used by default.
|
2016-08-18 11:28:17 +00:00
|
|
|
func DefaultIPCEndpoint(clientIdentifier string) string {
|
|
|
|
if clientIdentifier == "" {
|
|
|
|
clientIdentifier = strings.TrimSuffix(filepath.Base(os.Args[0]), ".exe")
|
|
|
|
if clientIdentifier == "" {
|
|
|
|
panic("empty executable name")
|
|
|
|
}
|
|
|
|
}
|
2022-06-07 04:54:04 +00:00
|
|
|
config := &Config{Dirs: datadir.New(paths.DefaultDataDir()), IPCPath: clientIdentifier + ".ipc"}
|
2016-02-09 11:24:42 +00:00
|
|
|
return config.IPCEndpoint()
|
2016-02-02 17:06:43 +00:00
|
|
|
}
|
|
|
|
|
2016-02-09 11:24:42 +00:00
|
|
|
// HTTPEndpoint resolves an HTTP endpoint based on the configured host interface
|
2016-02-05 11:45:36 +00:00
|
|
|
// and port parameters.
|
2016-02-09 11:24:42 +00:00
|
|
|
func (c *Config) HTTPEndpoint() string {
|
|
|
|
if c.HTTPHost == "" {
|
2016-02-05 11:45:36 +00:00
|
|
|
return ""
|
|
|
|
}
|
2016-02-09 11:24:42 +00:00
|
|
|
return fmt.Sprintf("%s:%d", c.HTTPHost, c.HTTPPort)
|
2016-02-05 11:45:36 +00:00
|
|
|
}
|
|
|
|
|
2016-02-09 11:24:42 +00:00
|
|
|
// DefaultHTTPEndpoint returns the HTTP endpoint used by default.
|
|
|
|
func DefaultHTTPEndpoint() string {
|
2016-09-16 09:53:50 +00:00
|
|
|
config := &Config{HTTPHost: DefaultHTTPHost, HTTPPort: DefaultHTTPPort}
|
2016-02-09 11:24:42 +00:00
|
|
|
return config.HTTPEndpoint()
|
2016-02-05 11:45:36 +00:00
|
|
|
}
|
|
|
|
|
2018-04-19 13:32:02 +00:00
|
|
|
// WSEndpoint resolves a websocket endpoint based on the configured host interface
|
2016-02-05 13:08:48 +00:00
|
|
|
// and port parameters.
|
2016-02-09 11:24:42 +00:00
|
|
|
func (c *Config) WSEndpoint() string {
|
|
|
|
if c.WSHost == "" {
|
2016-02-05 13:08:48 +00:00
|
|
|
return ""
|
|
|
|
}
|
2016-02-09 11:24:42 +00:00
|
|
|
return fmt.Sprintf("%s:%d", c.WSHost, c.WSPort)
|
2016-02-05 13:08:48 +00:00
|
|
|
}
|
|
|
|
|
2016-02-09 11:24:42 +00:00
|
|
|
// DefaultWSEndpoint returns the websocket endpoint used by default.
|
|
|
|
func DefaultWSEndpoint() string {
|
2016-09-16 09:53:50 +00:00
|
|
|
config := &Config{WSHost: DefaultWSHost, WSPort: DefaultWSPort}
|
2016-02-09 11:24:42 +00:00
|
|
|
return config.WSEndpoint()
|
2016-02-05 13:08:48 +00:00
|
|
|
}
|
|
|
|
|
2019-04-04 11:03:10 +00:00
|
|
|
// ExtRPCEnabled returns the indicator whether node enables the external
|
2021-03-26 02:08:01 +00:00
|
|
|
// RPC(http or ws).
|
2019-04-04 11:03:10 +00:00
|
|
|
func (c *Config) ExtRPCEnabled() bool {
|
2020-08-03 17:40:46 +00:00
|
|
|
return c.HTTPHost != "" || c.WSHost != ""
|
2019-04-04 11:03:10 +00:00
|
|
|
}
|
|
|
|
|
2016-08-18 11:28:17 +00:00
|
|
|
// NodeName returns the devp2p node identifier.
|
|
|
|
func (c *Config) NodeName() string {
|
|
|
|
name := c.name()
|
|
|
|
if c.UserIdent != "" {
|
|
|
|
name += "/" + c.UserIdent
|
|
|
|
}
|
|
|
|
if c.Version != "" {
|
|
|
|
name += "/v" + c.Version
|
|
|
|
}
|
2017-04-05 19:51:01 +00:00
|
|
|
name += "/" + runtime.GOOS + "-" + runtime.GOARCH
|
2016-08-18 11:28:17 +00:00
|
|
|
name += "/" + runtime.Version()
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) name() string {
|
|
|
|
if c.Name == "" {
|
|
|
|
progname := strings.TrimSuffix(filepath.Base(os.Args[0]), ".exe")
|
|
|
|
if progname == "" {
|
|
|
|
panic("empty executable name, set Config.Name")
|
|
|
|
}
|
|
|
|
return progname
|
|
|
|
}
|
|
|
|
return c.Name
|
|
|
|
}
|
|
|
|
|
cmd, dashboard, log: log collection and exploration (#17097)
* cmd, dashboard, internal, log, node: logging feature
* cmd, dashboard, internal, log: requested changes
* dashboard, vendor: gofmt, govendor, use vendored file watcher
* dashboard, log: gofmt -s -w, goimports
* dashboard, log: gosimple
2018-07-11 07:59:04 +00:00
|
|
|
// ResolvePath resolves path in the instance directory.
|
2021-05-08 08:45:40 +00:00
|
|
|
func (c *Config) ResolvePath(path string) string {
|
2016-08-18 11:28:17 +00:00
|
|
|
if filepath.IsAbs(path) {
|
2021-05-08 08:45:40 +00:00
|
|
|
return path
|
2016-08-18 11:28:17 +00:00
|
|
|
}
|
2022-06-07 04:54:04 +00:00
|
|
|
if c.Dirs.DataDir == "" {
|
2021-05-08 08:45:40 +00:00
|
|
|
return ""
|
2016-08-18 11:28:17 +00:00
|
|
|
}
|
2022-06-07 04:54:04 +00:00
|
|
|
return filepath.Join(c.Dirs.DataDir, path)
|
2016-08-18 11:28:17 +00:00
|
|
|
}
|
|
|
|
|
2015-11-05 21:57:57 +00:00
|
|
|
// StaticNodes returns a list of node enode URLs configured as static nodes.
|
2023-05-07 06:28:15 +00:00
|
|
|
func (c *Config) StaticNodes(logger log.Logger) ([]*enode.Node, error) {
|
2021-05-08 08:45:40 +00:00
|
|
|
dbPath := c.ResolvePath(datadirStaticNodes)
|
2023-05-07 06:28:15 +00:00
|
|
|
return c.parsePersistentNodes(&c.staticNodesWarning, dbPath, logger), nil
|
2015-11-05 21:57:57 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 08:58:46 +00:00
|
|
|
// TrustedNodes returns a list of node enode URLs configured as trusted nodes.
|
2023-05-07 06:28:15 +00:00
|
|
|
func (c *Config) TrustedNodes(logger log.Logger) ([]*enode.Node, error) {
|
2021-05-08 08:45:40 +00:00
|
|
|
dbPath := c.ResolvePath(datadirTrustedNodes)
|
2023-05-07 06:28:15 +00:00
|
|
|
return c.parsePersistentNodes(&c.trustedNodesWarning, dbPath, logger), nil
|
2015-11-05 21:57:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// parsePersistentNodes parses a list of discovery node URLs loaded from a .json
|
|
|
|
// file from within the data directory.
|
2023-05-07 06:28:15 +00:00
|
|
|
func (c *Config) parsePersistentNodes(w *bool, path string, logger log.Logger) []*enode.Node {
|
2015-11-05 21:57:57 +00:00
|
|
|
// Short circuit if no node config is present
|
2022-06-07 04:54:04 +00:00
|
|
|
if c.Dirs.DataDir == "" {
|
2015-11-05 21:57:57 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if _, err := os.Stat(path); err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
2023-05-07 06:28:15 +00:00
|
|
|
c.warnOnce(logger, w, "Found deprecated node list file %s, please use the TOML config file instead.", path)
|
2018-12-07 13:43:27 +00:00
|
|
|
|
2016-08-18 11:28:17 +00:00
|
|
|
// Load the nodes from the config file.
|
|
|
|
var nodelist []string
|
|
|
|
if err := common.LoadJSON(path, &nodelist); err != nil {
|
2018-12-07 13:43:27 +00:00
|
|
|
log.Error(fmt.Sprintf("Can't load node list file: %v", err))
|
2015-11-05 21:57:57 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
// Interpret the list as a discovery node array
|
2022-08-26 03:04:36 +00:00
|
|
|
nodes := make([]*enode.Node, 0, len(nodelist))
|
2015-11-05 21:57:57 +00:00
|
|
|
for _, url := range nodelist {
|
|
|
|
if url == "" {
|
|
|
|
continue
|
|
|
|
}
|
2019-06-07 13:31:00 +00:00
|
|
|
node, err := enode.Parse(enode.ValidSchemes, url)
|
2015-11-05 21:57:57 +00:00
|
|
|
if err != nil {
|
2017-02-22 12:10:07 +00:00
|
|
|
log.Error(fmt.Sprintf("Node URL %s: %v\n", url, err))
|
2015-11-05 21:57:57 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
nodes = append(nodes, node)
|
|
|
|
}
|
|
|
|
return nodes
|
|
|
|
}
|
2016-08-15 16:38:32 +00:00
|
|
|
|
2018-12-07 13:43:27 +00:00
|
|
|
var warnLock sync.Mutex
|
|
|
|
|
2023-05-07 06:28:15 +00:00
|
|
|
func (c *Config) warnOnce(logger log.Logger, w *bool, format string, args ...interface{}) {
|
2018-12-07 13:43:27 +00:00
|
|
|
warnLock.Lock()
|
|
|
|
defer warnLock.Unlock()
|
|
|
|
|
|
|
|
if *w {
|
|
|
|
return
|
|
|
|
}
|
2023-05-07 06:28:15 +00:00
|
|
|
logger.Warn(fmt.Sprintf(format, args...))
|
2018-12-07 13:43:27 +00:00
|
|
|
*w = true
|
|
|
|
}
|