2016-04-14 11:18:24 -05:00
|
|
|
// Copyright 2014 The go-ethereum Authors
|
2015-11-05 15:57:57 -06: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/>.
|
|
|
|
|
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
2016-02-05 05:45:36 -06:00
|
|
|
"fmt"
|
2015-11-05 15:57:57 -06:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2016-02-02 11:06:43 -06:00
|
|
|
"runtime"
|
|
|
|
"strings"
|
2018-12-07 07:43:27 -06:00
|
|
|
"sync"
|
2015-11-05 15:57:57 -06:00
|
|
|
|
2016-08-15 11:38:32 -05:00
|
|
|
"github.com/ethereum/go-ethereum/accounts"
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 04:23:57 -06:00
|
|
|
"github.com/ethereum/go-ethereum/accounts/external"
|
2017-01-24 03:49:20 -06:00
|
|
|
"github.com/ethereum/go-ethereum/accounts/keystore"
|
2018-01-07 12:38:11 -06:00
|
|
|
"github.com/ethereum/go-ethereum/accounts/scwallet"
|
2017-01-23 01:58:05 -06:00
|
|
|
"github.com/ethereum/go-ethereum/accounts/usbwallet"
|
2016-02-02 11:06:43 -06:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2015-11-05 15:57:57 -06:00
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
2017-02-22 06:10:07 -06:00
|
|
|
"github.com/ethereum/go-ethereum/log"
|
2017-04-12 09:27:23 -05:00
|
|
|
"github.com/ethereum/go-ethereum/p2p"
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
2018-07-31 04:16:14 -05:00
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
2015-11-05 15:57:57 -06:00
|
|
|
)
|
|
|
|
|
2017-08-06 11:43:43 -05:00
|
|
|
const (
|
2016-08-15 11:38:32 -05:00
|
|
|
datadirPrivateKey = "nodekey" // Path within the datadir to the node's private key
|
|
|
|
datadirDefaultKeyStore = "keystore" // Path within the datadir to the keystore
|
|
|
|
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 15:57:57 -06: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 06:28:17 -05:00
|
|
|
// Name sets the instance name of the node. It must not contain the / character and is
|
|
|
|
// used in the devp2p node identifier. The instance name of geth is "geth". If no
|
|
|
|
// value is specified, the basename of the current executable is used.
|
2017-04-12 09:27:23 -05:00
|
|
|
Name string `toml:"-"`
|
2016-08-18 06:28:17 -05:00
|
|
|
|
|
|
|
// UserIdent, if set, is used as an additional component in the devp2p node identifier.
|
2017-04-12 09:27:23 -05:00
|
|
|
UserIdent string `toml:",omitempty"`
|
2016-08-18 06:28:17 -05:00
|
|
|
|
|
|
|
// Version should be set to the version number of the program. It is used
|
|
|
|
// in the devp2p node identifier.
|
2017-04-12 09:27:23 -05:00
|
|
|
Version string `toml:"-"`
|
2016-08-18 06:28:17 -05:00
|
|
|
|
2015-11-05 15:57:57 -06:00
|
|
|
// DataDir is the file system folder the node should use for any data storage
|
|
|
|
// 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.
|
|
|
|
DataDir string
|
|
|
|
|
2017-04-12 09:27:23 -05:00
|
|
|
// Configuration of peer-to-peer networking.
|
|
|
|
P2P p2p.Config
|
|
|
|
|
2016-08-15 11:38:32 -05:00
|
|
|
// KeyStoreDir is the file system folder that contains private keys. The directory can
|
|
|
|
// be specified as a relative path, in which case it is resolved relative to the
|
|
|
|
// current directory.
|
|
|
|
//
|
|
|
|
// If KeyStoreDir is empty, the default location is the "keystore" subdirectory of
|
|
|
|
// DataDir. If DataDir is unspecified and KeyStoreDir is empty, an ephemeral directory
|
|
|
|
// is created by New and destroyed when the node is stopped.
|
2017-04-12 09:27:23 -05:00
|
|
|
KeyStoreDir string `toml:",omitempty"`
|
2016-08-15 11:38:32 -05:00
|
|
|
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 04:23:57 -06:00
|
|
|
// ExternalSigner specifies an external URI for a clef-type signer
|
|
|
|
ExternalSigner string `toml:"omitempty"`
|
|
|
|
|
2016-08-15 11:38:32 -05:00
|
|
|
// UseLightweightKDF lowers the memory and CPU requirements of the key store
|
|
|
|
// scrypt KDF at the expense of security.
|
2017-04-12 09:27:23 -05:00
|
|
|
UseLightweightKDF bool `toml:",omitempty"`
|
2016-08-15 11:38:32 -05:00
|
|
|
|
2019-04-04 06:03:10 -05:00
|
|
|
// InsecureUnlockAllowed allows user to unlock accounts in unsafe http environment.
|
|
|
|
InsecureUnlockAllowed bool `toml:",omitempty"`
|
|
|
|
|
2017-04-20 06:01:51 -05:00
|
|
|
// NoUSB disables hardware wallet monitoring and connectivity.
|
|
|
|
NoUSB bool `toml:",omitempty"`
|
|
|
|
|
2016-02-09 05:24:42 -06:00
|
|
|
// IPCPath is the requested location to place the IPC endpoint. If the path is
|
2016-02-02 11:06:43 -06: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.
|
2017-04-12 09:27:23 -05:00
|
|
|
IPCPath string `toml:",omitempty"`
|
2016-02-05 05:45:36 -06:00
|
|
|
|
2016-02-09 05:24:42 -06:00
|
|
|
// HTTPHost is the host interface on which to start the HTTP RPC server. If this
|
2016-02-05 05:45:36 -06:00
|
|
|
// field is empty, no HTTP API endpoint will be started.
|
2017-04-12 09:27:23 -05:00
|
|
|
HTTPHost string `toml:",omitempty"`
|
2016-02-05 05:45:36 -06:00
|
|
|
|
2016-02-09 05:24:42 -06:00
|
|
|
// HTTPPort is the TCP port number on which to start the HTTP RPC server. The
|
2016-02-05 05:45:36 -06:00
|
|
|
// default zero value is/ valid and will pick a port number randomly (useful
|
|
|
|
// for ephemeral nodes).
|
2017-04-12 09:27:23 -05:00
|
|
|
HTTPPort int `toml:",omitempty"`
|
2016-02-05 05:45:36 -06:00
|
|
|
|
2016-02-09 05:24:42 -06:00
|
|
|
// HTTPCors is the Cross-Origin Resource Sharing header to send to requesting
|
2016-02-05 05:45:36 -06:00
|
|
|
// clients. Please be aware that CORS is a browser enforced security, it's fully
|
|
|
|
// useless for custom HTTP clients.
|
2017-04-12 16:04:14 -05:00
|
|
|
HTTPCors []string `toml:",omitempty"`
|
2016-02-05 05:45:36 -06:00
|
|
|
|
2018-02-12 06:52:07 -06: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 05:24:42 -06:00
|
|
|
// HTTPModules is a list of API modules to expose via the HTTP RPC interface.
|
2016-02-05 05:45:36 -06:00
|
|
|
// If the module list is empty, all RPC API endpoints designated public will be
|
|
|
|
// exposed.
|
2017-04-12 09:27:23 -05:00
|
|
|
HTTPModules []string `toml:",omitempty"`
|
2016-02-05 07:08:48 -06:00
|
|
|
|
2018-07-31 04:16:14 -05:00
|
|
|
// HTTPTimeouts allows for customization of the timeout values used by the HTTP RPC
|
|
|
|
// interface.
|
|
|
|
HTTPTimeouts rpc.HTTPTimeouts
|
|
|
|
|
2016-02-09 05:24:42 -06:00
|
|
|
// WSHost is the host interface on which to start the websocket RPC server. If
|
2016-02-05 07:08:48 -06:00
|
|
|
// this field is empty, no websocket API endpoint will be started.
|
2017-04-12 09:27:23 -05:00
|
|
|
WSHost string `toml:",omitempty"`
|
2016-02-05 07:08:48 -06:00
|
|
|
|
2016-02-09 05:24:42 -06:00
|
|
|
// WSPort is the TCP port number on which to start the websocket RPC server. The
|
2016-02-05 07:08:48 -06:00
|
|
|
// default zero value is/ valid and will pick a port number randomly (useful for
|
|
|
|
// ephemeral nodes).
|
2017-04-12 09:27:23 -05:00
|
|
|
WSPort int `toml:",omitempty"`
|
2016-02-05 07:08:48 -06:00
|
|
|
|
2016-03-14 03:38:54 -05:00
|
|
|
// WSOrigins is the list of domain to accept websocket requests from. Please be
|
2016-02-09 05:24:42 -06: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 16:04:14 -05:00
|
|
|
WSOrigins []string `toml:",omitempty"`
|
2016-02-05 07:08:48 -06:00
|
|
|
|
2016-02-09 05:24:42 -06:00
|
|
|
// WSModules is a list of API modules to expose via the websocket RPC interface.
|
2016-02-05 07:08:48 -06:00
|
|
|
// If the module list is empty, all RPC API endpoints designated public will be
|
|
|
|
// exposed.
|
2017-04-12 09:27:23 -05:00
|
|
|
WSModules []string `toml:",omitempty"`
|
2017-09-25 03:08:07 -05: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 05:49:04 -06:00
|
|
|
|
2019-04-04 06:03:10 -05:00
|
|
|
// GraphQLHost is the host interface on which to start the GraphQL server. If this
|
|
|
|
// field is empty, no GraphQL API endpoint will be started.
|
|
|
|
GraphQLHost string `toml:",omitempty"`
|
|
|
|
|
|
|
|
// GraphQLPort is the TCP port number on which to start the GraphQL server. The
|
|
|
|
// default zero value is/ valid and will pick a port number randomly (useful
|
|
|
|
// for ephemeral nodes).
|
|
|
|
GraphQLPort int `toml:",omitempty"`
|
|
|
|
|
|
|
|
// GraphQLCors is the Cross-Origin Resource Sharing header to send to requesting
|
|
|
|
// clients. Please be aware that CORS is a browser enforced security, it's fully
|
|
|
|
// useless for custom HTTP clients.
|
|
|
|
GraphQLCors []string `toml:",omitempty"`
|
|
|
|
|
|
|
|
// GraphQLVirtualHosts 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
|
|
|
|
GraphQLVirtualHosts []string `toml:",omitempty"`
|
|
|
|
|
2017-12-01 05:49:04 -06:00
|
|
|
// Logger is a custom logger to use with the p2p.Server.
|
2018-02-12 06:52:07 -06:00
|
|
|
Logger log.Logger `toml:",omitempty"`
|
2018-12-07 07:43:27 -06:00
|
|
|
|
|
|
|
staticNodesWarning bool
|
|
|
|
trustedNodesWarning bool
|
|
|
|
oldGethResourceWarning bool
|
2015-11-05 15:57:57 -06:00
|
|
|
}
|
|
|
|
|
2016-02-09 05:24:42 -06:00
|
|
|
// IPCEndpoint resolves an IPC endpoint based on a configured value, taking into
|
2016-02-02 11:06:43 -06:00
|
|
|
// account the set data folders as well as the designated platform we're currently
|
|
|
|
// running on.
|
2016-02-09 05:24:42 -06:00
|
|
|
func (c *Config) IPCEndpoint() string {
|
2016-02-02 11:06:43 -06:00
|
|
|
// Short circuit if IPC has not been enabled
|
2016-02-09 05:24:42 -06:00
|
|
|
if c.IPCPath == "" {
|
2016-02-02 11:06:43 -06:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
// On windows we can only use plain top-level pipes
|
|
|
|
if runtime.GOOS == "windows" {
|
2016-02-09 05:24:42 -06:00
|
|
|
if strings.HasPrefix(c.IPCPath, `\\.\pipe\`) {
|
|
|
|
return c.IPCPath
|
2016-02-02 11:06:43 -06:00
|
|
|
}
|
2016-02-09 05:24:42 -06:00
|
|
|
return `\\.\pipe\` + c.IPCPath
|
2016-02-02 11:06:43 -06:00
|
|
|
}
|
|
|
|
// Resolve names into the data directory full paths otherwise
|
2016-02-09 05:24:42 -06:00
|
|
|
if filepath.Base(c.IPCPath) == c.IPCPath {
|
2016-02-02 11:06:43 -06:00
|
|
|
if c.DataDir == "" {
|
2016-02-09 05:24:42 -06:00
|
|
|
return filepath.Join(os.TempDir(), c.IPCPath)
|
2016-02-02 11:06:43 -06:00
|
|
|
}
|
2016-02-09 05:24:42 -06:00
|
|
|
return filepath.Join(c.DataDir, c.IPCPath)
|
2016-02-02 11:06:43 -06:00
|
|
|
}
|
2016-02-09 05:24:42 -06:00
|
|
|
return c.IPCPath
|
2016-02-02 11:06:43 -06:00
|
|
|
}
|
|
|
|
|
2016-08-18 06:28:17 -05:00
|
|
|
// NodeDB returns the path to the discovery node database.
|
|
|
|
func (c *Config) NodeDB() string {
|
|
|
|
if c.DataDir == "" {
|
|
|
|
return "" // ephemeral
|
|
|
|
}
|
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 02:59:04 -05:00
|
|
|
return c.ResolvePath(datadirNodeDatabase)
|
2016-08-18 06:28:17 -05:00
|
|
|
}
|
|
|
|
|
2016-02-09 05:24:42 -06:00
|
|
|
// DefaultIPCEndpoint returns the IPC path used by default.
|
2016-08-18 06:28:17 -05:00
|
|
|
func DefaultIPCEndpoint(clientIdentifier string) string {
|
|
|
|
if clientIdentifier == "" {
|
|
|
|
clientIdentifier = strings.TrimSuffix(filepath.Base(os.Args[0]), ".exe")
|
|
|
|
if clientIdentifier == "" {
|
|
|
|
panic("empty executable name")
|
|
|
|
}
|
|
|
|
}
|
2016-09-16 04:53:50 -05:00
|
|
|
config := &Config{DataDir: DefaultDataDir(), IPCPath: clientIdentifier + ".ipc"}
|
2016-02-09 05:24:42 -06:00
|
|
|
return config.IPCEndpoint()
|
2016-02-02 11:06:43 -06:00
|
|
|
}
|
|
|
|
|
2016-02-09 05:24:42 -06:00
|
|
|
// HTTPEndpoint resolves an HTTP endpoint based on the configured host interface
|
2016-02-05 05:45:36 -06:00
|
|
|
// and port parameters.
|
2016-02-09 05:24:42 -06:00
|
|
|
func (c *Config) HTTPEndpoint() string {
|
|
|
|
if c.HTTPHost == "" {
|
2016-02-05 05:45:36 -06:00
|
|
|
return ""
|
|
|
|
}
|
2016-02-09 05:24:42 -06:00
|
|
|
return fmt.Sprintf("%s:%d", c.HTTPHost, c.HTTPPort)
|
2016-02-05 05:45:36 -06:00
|
|
|
}
|
|
|
|
|
2019-01-21 08:38:13 -06:00
|
|
|
// GraphQLEndpoint resolves a GraphQL endpoint based on the configured host interface
|
|
|
|
// and port parameters.
|
|
|
|
func (c *Config) GraphQLEndpoint() string {
|
|
|
|
if c.GraphQLHost == "" {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s:%d", c.GraphQLHost, c.GraphQLPort)
|
|
|
|
}
|
|
|
|
|
2016-02-09 05:24:42 -06:00
|
|
|
// DefaultHTTPEndpoint returns the HTTP endpoint used by default.
|
|
|
|
func DefaultHTTPEndpoint() string {
|
2016-09-16 04:53:50 -05:00
|
|
|
config := &Config{HTTPHost: DefaultHTTPHost, HTTPPort: DefaultHTTPPort}
|
2016-02-09 05:24:42 -06:00
|
|
|
return config.HTTPEndpoint()
|
2016-02-05 05:45:36 -06:00
|
|
|
}
|
|
|
|
|
2018-04-19 08:32:02 -05:00
|
|
|
// WSEndpoint resolves a websocket endpoint based on the configured host interface
|
2016-02-05 07:08:48 -06:00
|
|
|
// and port parameters.
|
2016-02-09 05:24:42 -06:00
|
|
|
func (c *Config) WSEndpoint() string {
|
|
|
|
if c.WSHost == "" {
|
2016-02-05 07:08:48 -06:00
|
|
|
return ""
|
|
|
|
}
|
2016-02-09 05:24:42 -06:00
|
|
|
return fmt.Sprintf("%s:%d", c.WSHost, c.WSPort)
|
2016-02-05 07:08:48 -06:00
|
|
|
}
|
|
|
|
|
2016-02-09 05:24:42 -06:00
|
|
|
// DefaultWSEndpoint returns the websocket endpoint used by default.
|
|
|
|
func DefaultWSEndpoint() string {
|
2016-09-16 04:53:50 -05:00
|
|
|
config := &Config{WSHost: DefaultWSHost, WSPort: DefaultWSPort}
|
2016-02-09 05:24:42 -06:00
|
|
|
return config.WSEndpoint()
|
2016-02-05 07:08:48 -06:00
|
|
|
}
|
|
|
|
|
2019-04-04 06:03:10 -05:00
|
|
|
// ExtRPCEnabled returns the indicator whether node enables the external
|
|
|
|
// RPC(http, ws or graphql).
|
|
|
|
func (c *Config) ExtRPCEnabled() bool {
|
|
|
|
return c.HTTPHost != "" || c.WSHost != "" || c.GraphQLHost != ""
|
|
|
|
}
|
|
|
|
|
2016-08-18 06:28:17 -05:00
|
|
|
// NodeName returns the devp2p node identifier.
|
|
|
|
func (c *Config) NodeName() string {
|
|
|
|
name := c.name()
|
|
|
|
// Backwards compatibility: previous versions used title-cased "Geth", keep that.
|
|
|
|
if name == "geth" || name == "geth-testnet" {
|
|
|
|
name = "Geth"
|
|
|
|
}
|
|
|
|
if c.UserIdent != "" {
|
|
|
|
name += "/" + c.UserIdent
|
|
|
|
}
|
|
|
|
if c.Version != "" {
|
|
|
|
name += "/v" + c.Version
|
|
|
|
}
|
2017-04-05 14:51:01 -05:00
|
|
|
name += "/" + runtime.GOOS + "-" + runtime.GOARCH
|
2016-08-18 06:28:17 -05: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
|
|
|
|
}
|
|
|
|
|
2016-11-10 10:03:24 -06:00
|
|
|
// These resources are resolved differently for "geth" instances.
|
2016-08-18 06:28:17 -05:00
|
|
|
var isOldGethResource = map[string]bool{
|
|
|
|
"chaindata": true,
|
|
|
|
"nodes": true,
|
|
|
|
"nodekey": true,
|
2018-12-07 07:43:27 -06:00
|
|
|
"static-nodes.json": false, // no warning for these because they have their
|
|
|
|
"trusted-nodes.json": false, // own separate warning.
|
2016-08-18 06:28:17 -05:00
|
|
|
}
|
|
|
|
|
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 02:59:04 -05:00
|
|
|
// ResolvePath resolves path in the instance directory.
|
|
|
|
func (c *Config) ResolvePath(path string) string {
|
2016-08-18 06:28:17 -05:00
|
|
|
if filepath.IsAbs(path) {
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
if c.DataDir == "" {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
// Backwards-compatibility: ensure that data directory files created
|
|
|
|
// by geth 1.4 are used if they exist.
|
2018-12-07 07:43:27 -06:00
|
|
|
if warn, isOld := isOldGethResource[path]; isOld {
|
2016-08-18 06:28:17 -05:00
|
|
|
oldpath := ""
|
2018-12-07 07:43:27 -06:00
|
|
|
if c.name() == "geth" {
|
2016-08-18 06:28:17 -05:00
|
|
|
oldpath = filepath.Join(c.DataDir, path)
|
|
|
|
}
|
|
|
|
if oldpath != "" && common.FileExist(oldpath) {
|
2018-12-07 07:43:27 -06:00
|
|
|
if warn {
|
|
|
|
c.warnOnce(&c.oldGethResourceWarning, "Using deprecated resource file %s, please move this file to the 'geth' subdirectory of datadir.", oldpath)
|
|
|
|
}
|
2016-08-18 06:28:17 -05:00
|
|
|
return oldpath
|
|
|
|
}
|
|
|
|
}
|
2016-11-10 10:03:24 -06:00
|
|
|
return filepath.Join(c.instanceDir(), path)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) instanceDir() string {
|
|
|
|
if c.DataDir == "" {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return filepath.Join(c.DataDir, c.name())
|
2016-08-18 06:28:17 -05:00
|
|
|
}
|
|
|
|
|
2015-11-05 15:57:57 -06:00
|
|
|
// NodeKey retrieves the currently configured private key of the node, checking
|
|
|
|
// first any manually set key, falling back to the one found in the configured
|
|
|
|
// data folder. If no key can be found, a new one is generated.
|
|
|
|
func (c *Config) NodeKey() *ecdsa.PrivateKey {
|
2016-08-18 06:28:17 -05:00
|
|
|
// Use any specifically configured key.
|
2017-04-12 09:27:23 -05:00
|
|
|
if c.P2P.PrivateKey != nil {
|
|
|
|
return c.P2P.PrivateKey
|
2015-11-05 15:57:57 -06:00
|
|
|
}
|
2016-08-18 06:28:17 -05:00
|
|
|
// Generate ephemeral key if no datadir is being used.
|
2015-11-05 15:57:57 -06:00
|
|
|
if c.DataDir == "" {
|
|
|
|
key, err := crypto.GenerateKey()
|
|
|
|
if err != nil {
|
2017-02-22 06:10:07 -06:00
|
|
|
log.Crit(fmt.Sprintf("Failed to generate ephemeral node key: %v", err))
|
2015-11-05 15:57:57 -06:00
|
|
|
}
|
|
|
|
return key
|
|
|
|
}
|
2016-08-18 06:28:17 -05:00
|
|
|
|
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 02:59:04 -05:00
|
|
|
keyfile := c.ResolvePath(datadirPrivateKey)
|
2015-11-05 15:57:57 -06:00
|
|
|
if key, err := crypto.LoadECDSA(keyfile); err == nil {
|
|
|
|
return key
|
|
|
|
}
|
2016-08-18 06:28:17 -05:00
|
|
|
// No persistent key found, generate and store a new one.
|
2015-11-05 15:57:57 -06:00
|
|
|
key, err := crypto.GenerateKey()
|
|
|
|
if err != nil {
|
2017-02-22 06:10:07 -06:00
|
|
|
log.Crit(fmt.Sprintf("Failed to generate node key: %v", err))
|
2015-11-05 15:57:57 -06:00
|
|
|
}
|
2016-08-18 06:28:17 -05:00
|
|
|
instanceDir := filepath.Join(c.DataDir, c.name())
|
|
|
|
if err := os.MkdirAll(instanceDir, 0700); err != nil {
|
2017-02-22 06:10:07 -06:00
|
|
|
log.Error(fmt.Sprintf("Failed to persist node key: %v", err))
|
2016-08-18 06:28:17 -05:00
|
|
|
return key
|
|
|
|
}
|
|
|
|
keyfile = filepath.Join(instanceDir, datadirPrivateKey)
|
2015-11-05 15:57:57 -06:00
|
|
|
if err := crypto.SaveECDSA(keyfile, key); err != nil {
|
2017-02-22 06:10:07 -06:00
|
|
|
log.Error(fmt.Sprintf("Failed to persist node key: %v", err))
|
2015-11-05 15:57:57 -06:00
|
|
|
}
|
|
|
|
return key
|
|
|
|
}
|
|
|
|
|
|
|
|
// StaticNodes returns a list of node enode URLs configured as static nodes.
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
func (c *Config) StaticNodes() []*enode.Node {
|
2018-12-07 07:43:27 -06:00
|
|
|
return c.parsePersistentNodes(&c.staticNodesWarning, c.ResolvePath(datadirStaticNodes))
|
2015-11-05 15:57:57 -06:00
|
|
|
}
|
|
|
|
|
2017-07-18 03:58:46 -05:00
|
|
|
// TrustedNodes returns a list of node enode URLs configured as trusted nodes.
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
func (c *Config) TrustedNodes() []*enode.Node {
|
2018-12-07 07:43:27 -06:00
|
|
|
return c.parsePersistentNodes(&c.trustedNodesWarning, c.ResolvePath(datadirTrustedNodes))
|
2015-11-05 15:57:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// parsePersistentNodes parses a list of discovery node URLs loaded from a .json
|
|
|
|
// file from within the data directory.
|
2018-12-07 07:43:27 -06:00
|
|
|
func (c *Config) parsePersistentNodes(w *bool, path string) []*enode.Node {
|
2015-11-05 15:57:57 -06:00
|
|
|
// Short circuit if no node config is present
|
|
|
|
if c.DataDir == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if _, err := os.Stat(path); err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
2018-12-07 07:43:27 -06:00
|
|
|
c.warnOnce(w, "Found deprecated node list file %s, please use the TOML config file instead.", path)
|
|
|
|
|
2016-08-18 06:28:17 -05:00
|
|
|
// Load the nodes from the config file.
|
|
|
|
var nodelist []string
|
|
|
|
if err := common.LoadJSON(path, &nodelist); err != nil {
|
2018-12-07 07:43:27 -06:00
|
|
|
log.Error(fmt.Sprintf("Can't load node list file: %v", err))
|
2015-11-05 15:57:57 -06:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
// Interpret the list as a discovery node array
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
var nodes []*enode.Node
|
2015-11-05 15:57:57 -06:00
|
|
|
for _, url := range nodelist {
|
|
|
|
if url == "" {
|
|
|
|
continue
|
|
|
|
}
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
node, err := enode.ParseV4(url)
|
2015-11-05 15:57:57 -06:00
|
|
|
if err != nil {
|
2017-02-22 06:10:07 -06:00
|
|
|
log.Error(fmt.Sprintf("Node URL %s: %v\n", url, err))
|
2015-11-05 15:57:57 -06:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
nodes = append(nodes, node)
|
|
|
|
}
|
|
|
|
return nodes
|
|
|
|
}
|
2016-08-15 11:38:32 -05:00
|
|
|
|
2017-11-20 10:39:53 -06:00
|
|
|
// AccountConfig determines the settings for scrypt and keydirectory
|
|
|
|
func (c *Config) AccountConfig() (int, int, string, error) {
|
2017-01-24 03:49:20 -06:00
|
|
|
scryptN := keystore.StandardScryptN
|
|
|
|
scryptP := keystore.StandardScryptP
|
2017-11-20 10:39:53 -06:00
|
|
|
if c.UseLightweightKDF {
|
2017-01-24 03:49:20 -06:00
|
|
|
scryptN = keystore.LightScryptN
|
|
|
|
scryptP = keystore.LightScryptP
|
2016-08-15 11:38:32 -05:00
|
|
|
}
|
|
|
|
|
2017-02-07 04:47:34 -06:00
|
|
|
var (
|
2017-11-20 10:39:53 -06:00
|
|
|
keydir string
|
|
|
|
err error
|
2017-02-07 04:47:34 -06:00
|
|
|
)
|
2016-08-15 11:38:32 -05:00
|
|
|
switch {
|
2017-11-20 10:39:53 -06:00
|
|
|
case filepath.IsAbs(c.KeyStoreDir):
|
|
|
|
keydir = c.KeyStoreDir
|
|
|
|
case c.DataDir != "":
|
|
|
|
if c.KeyStoreDir == "" {
|
|
|
|
keydir = filepath.Join(c.DataDir, datadirDefaultKeyStore)
|
2016-08-15 11:38:32 -05:00
|
|
|
} else {
|
2017-11-20 10:39:53 -06:00
|
|
|
keydir, err = filepath.Abs(c.KeyStoreDir)
|
2016-08-15 11:38:32 -05:00
|
|
|
}
|
2017-11-20 10:39:53 -06:00
|
|
|
case c.KeyStoreDir != "":
|
|
|
|
keydir, err = filepath.Abs(c.KeyStoreDir)
|
|
|
|
}
|
|
|
|
return scryptN, scryptP, keydir, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeAccountManager(conf *Config) (*accounts.Manager, string, error) {
|
|
|
|
scryptN, scryptP, keydir, err := conf.AccountConfig()
|
|
|
|
var ephemeral string
|
|
|
|
if keydir == "" {
|
2016-08-15 11:38:32 -05:00
|
|
|
// There is no datadir.
|
|
|
|
keydir, err = ioutil.TempDir("", "go-ethereum-keystore")
|
2017-02-07 04:47:34 -06:00
|
|
|
ephemeral = keydir
|
2016-08-15 11:38:32 -05:00
|
|
|
}
|
2017-11-20 10:39:53 -06:00
|
|
|
|
2016-08-15 11:38:32 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, "", err
|
|
|
|
}
|
|
|
|
if err := os.MkdirAll(keydir, 0700); err != nil {
|
|
|
|
return nil, "", err
|
|
|
|
}
|
2017-01-23 01:58:05 -06:00
|
|
|
// Assemble the account manager and supported backends
|
2019-02-18 05:31:22 -06:00
|
|
|
var backends []accounts.Backend
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 04:23:57 -06:00
|
|
|
if len(conf.ExternalSigner) > 0 {
|
|
|
|
log.Info("Using external signer", "url", conf.ExternalSigner)
|
|
|
|
if extapi, err := external.NewExternalBackend(conf.ExternalSigner); err == nil {
|
|
|
|
backends = append(backends, extapi)
|
2017-04-20 06:01:51 -05:00
|
|
|
} else {
|
2019-04-12 03:18:03 -05:00
|
|
|
return nil, "", fmt.Errorf("error connecting to external signer: %v", err)
|
2017-04-20 06:01:51 -05:00
|
|
|
}
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 04:23:57 -06:00
|
|
|
}
|
|
|
|
if len(backends) == 0 {
|
|
|
|
// For now, we're using EITHER external signer OR local signers.
|
|
|
|
// If/when we implement some form of lockfile for USB and keystore wallets,
|
|
|
|
// we can have both, but it's very confusing for the user to see the same
|
|
|
|
// accounts in both externally and locally, plus very racey.
|
|
|
|
backends = append(backends, keystore.NewKeyStore(keydir, scryptN, scryptP))
|
|
|
|
if !conf.NoUSB {
|
|
|
|
// Start a USB hub for Ledger hardware wallets
|
|
|
|
if ledgerhub, err := usbwallet.NewLedgerHub(); err != nil {
|
|
|
|
log.Warn(fmt.Sprintf("Failed to start Ledger hub, disabling: %v", err))
|
|
|
|
} else {
|
|
|
|
backends = append(backends, ledgerhub)
|
|
|
|
}
|
|
|
|
// Start a USB hub for Trezor hardware wallets
|
|
|
|
if trezorhub, err := usbwallet.NewTrezorHub(); err != nil {
|
|
|
|
log.Warn(fmt.Sprintf("Failed to start Trezor hub, disabling: %v", err))
|
|
|
|
} else {
|
|
|
|
backends = append(backends, trezorhub)
|
|
|
|
}
|
2017-08-01 10:45:17 -05:00
|
|
|
}
|
2018-01-07 12:38:11 -06:00
|
|
|
// Start a smart card hub
|
|
|
|
if schub, err := scwallet.NewHub(scwallet.Scheme, keydir); err != nil {
|
|
|
|
log.Warn(fmt.Sprintf("Failed to start smart card hub, disabling: %v", err))
|
|
|
|
} else {
|
|
|
|
backends = append(backends, schub)
|
|
|
|
}
|
2017-01-23 01:58:05 -06:00
|
|
|
}
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 04:23:57 -06:00
|
|
|
|
2019-04-04 06:03:10 -05:00
|
|
|
return accounts.NewManager(&accounts.Config{InsecureUnlockAllowed: conf.InsecureUnlockAllowed}, backends...), ephemeral, nil
|
2016-08-15 11:38:32 -05:00
|
|
|
}
|
2018-12-07 07:43:27 -06:00
|
|
|
|
|
|
|
var warnLock sync.Mutex
|
|
|
|
|
|
|
|
func (c *Config) warnOnce(w *bool, format string, args ...interface{}) {
|
|
|
|
warnLock.Lock()
|
|
|
|
defer warnLock.Unlock()
|
|
|
|
|
|
|
|
if *w {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
l := c.Logger
|
|
|
|
if l == nil {
|
|
|
|
l = log.Root()
|
|
|
|
}
|
|
|
|
l.Warn(fmt.Sprintf(format, args...))
|
|
|
|
*w = true
|
|
|
|
}
|