node: add DefaultConfig, use it for geth

This commit is contained in:
Felix Lange 2017-04-12 00:53:43 +02:00
parent 85b38613b2
commit 087d06f836
2 changed files with 28 additions and 11 deletions

View file

@ -32,7 +32,6 @@ import (
"github.com/ethereum/go-ethereum/contracts/release" "github.com/ethereum/go-ethereum/contracts/release"
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/naoina/toml" "github.com/naoina/toml"
) )
@ -53,15 +52,6 @@ var (
} }
) )
var defaultNodeConfig = node.Config{
Name: clientIdentifier,
Version: params.VersionWithCommit(gitCommit),
DataDir: node.DefaultDataDir(),
P2P: p2p.Config{MaxPeers: 25},
HTTPModules: []string{"eth", "net", "web3"},
WSModules: []string{"eth", "net", "web3"},
}
// These settings ensure that TOML keys use the same names as Go struct fields. // These settings ensure that TOML keys use the same names as Go struct fields.
var tomlSettings = toml.Config{ var tomlSettings = toml.Config{
NormFieldName: func(rt reflect.Type, key string) string { NormFieldName: func(rt reflect.Type, key string) string {
@ -104,11 +94,20 @@ func loadConfig(file string, cfg *gethConfig) error {
return err return err
} }
func defaultNodeConfig() node.Config {
cfg := node.DefaultConfig
cfg.Name = clientIdentifier
cfg.Version = params.VersionWithCommit(gitCommit)
cfg.HTTPModules = append(cfg.HTTPModules, "eth")
cfg.WSModules = append(cfg.WSModules, "eth")
return cfg
}
func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) { func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
// Load defaults. // Load defaults.
cfg := gethConfig{ cfg := gethConfig{
Eth: eth.DefaultConfig, Eth: eth.DefaultConfig,
Node: defaultNodeConfig, Node: defaultNodeConfig(),
} }
// Load config file. // Load config file.

View file

@ -21,6 +21,9 @@ import (
"os/user" "os/user"
"path/filepath" "path/filepath"
"runtime" "runtime"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/nat"
) )
const ( const (
@ -31,6 +34,21 @@ const (
DefaultWSPort = 8546 // Default TCP port for the websocket RPC server DefaultWSPort = 8546 // Default TCP port for the websocket RPC server
) )
// DefaultConfig contains reasonable default settings.
var DefaultConfig = Config{
DataDir: DefaultDataDir(),
HTTPPort: DefaultHTTPPort,
HTTPModules: []string{"net", "web3"},
WSPort: DefaultWSPort,
WSModules: []string{"net", "web3"},
IPCPath: DefaultIPCSocket,
P2P: p2p.Config{
ListenAddr: ":30303",
MaxPeers: 25,
NAT: nat.Any(),
},
}
// DefaultDataDir is the default data directory to use for the databases and other // DefaultDataDir is the default data directory to use for the databases and other
// persistence requirements. // persistence requirements.
func DefaultDataDir() string { func DefaultDataDir() string {