aboutsummaryrefslogtreecommitdiffstats
path: root/node/config.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-08-16 00:38:32 +0800
committerFelix Lange <fjl@twurst.com>2016-08-17 23:39:03 +0800
commit312263c7d9457fe7c24aac8e42a4cf2efc6ccd8e (patch)
treee10f9cc260af1ce13cb67b02bbce9c17c3b09de2 /node/config.go
parentd6625ac34dad741f5659ca1dad3b0179603d37f0 (diff)
downloadgo-tangerine-312263c7d9457fe7c24aac8e42a4cf2efc6ccd8e.tar
go-tangerine-312263c7d9457fe7c24aac8e42a4cf2efc6ccd8e.tar.gz
go-tangerine-312263c7d9457fe7c24aac8e42a4cf2efc6ccd8e.tar.bz2
go-tangerine-312263c7d9457fe7c24aac8e42a4cf2efc6ccd8e.tar.lz
go-tangerine-312263c7d9457fe7c24aac8e42a4cf2efc6ccd8e.tar.xz
go-tangerine-312263c7d9457fe7c24aac8e42a4cf2efc6ccd8e.tar.zst
go-tangerine-312263c7d9457fe7c24aac8e42a4cf2efc6ccd8e.zip
cmd/utils, node: create account manager in package node
The account manager was previously created by packge cmd/utils as part of flag processing and then passed down into eth.Ethereum through its config struct. Since we are starting to create nodes which do not have eth.Ethereum as a registered service, the code was rearranged to register the account manager as its own service. Making it a service is ugly though and it doesn't really fix the root cause: creating nodes without eth.Ethereum requires duplicating lots of code. This commit splits utils.MakeSystemNode into three functions, making creation of other node/service configurations easier. It also moves the account manager into Node so it can be used by those configurations without requiring package eth.
Diffstat (limited to 'node/config.go')
-rw-r--r--node/config.go58
1 files changed, 54 insertions, 4 deletions
diff --git a/node/config.go b/node/config.go
index bc9fec618..432da7015 100644
--- a/node/config.go
+++ b/node/config.go
@@ -27,6 +27,7 @@ import (
"runtime"
"strings"
+ "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/logger"
@@ -36,10 +37,11 @@ import (
)
var (
- datadirPrivateKey = "nodekey" // Path within the datadir to the node's private key
- 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
+ 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
)
// Config represents a small collection of configuration values to fine tune the
@@ -53,6 +55,19 @@ type Config struct {
// in memory.
DataDir string
+ // 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.
+ KeyStoreDir string
+
+ // UseLightweightKDF lowers the memory and CPU requirements of the key store
+ // scrypt KDF at the expense of security.
+ UseLightweightKDF bool
+
// IPCPath is the requested location to place the IPC endpoint. If the path is
// 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
@@ -278,3 +293,38 @@ func (c *Config) parsePersistentNodes(file string) []*discover.Node {
}
return nodes
}
+
+func makeAccountManager(conf *Config) (am *accounts.Manager, ephemeralKeystore string, err error) {
+ scryptN := accounts.StandardScryptN
+ scryptP := accounts.StandardScryptP
+ if conf.UseLightweightKDF {
+ scryptN = accounts.LightScryptN
+ scryptP = accounts.LightScryptP
+ }
+
+ var keydir string
+ switch {
+ case filepath.IsAbs(conf.KeyStoreDir):
+ keydir = conf.KeyStoreDir
+ case conf.DataDir != "":
+ if conf.KeyStoreDir == "" {
+ keydir = filepath.Join(conf.DataDir, datadirDefaultKeyStore)
+ } else {
+ keydir, err = filepath.Abs(conf.KeyStoreDir)
+ }
+ case conf.KeyStoreDir != "":
+ keydir, err = filepath.Abs(conf.KeyStoreDir)
+ default:
+ // There is no datadir.
+ keydir, err = ioutil.TempDir("", "go-ethereum-keystore")
+ ephemeralKeystore = keydir
+ }
+ if err != nil {
+ return nil, "", err
+ }
+ if err := os.MkdirAll(keydir, 0700); err != nil {
+ return nil, "", err
+ }
+
+ return accounts.NewManager(keydir, scryptN, scryptP), ephemeralKeystore, nil
+}