mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-23 12:07:17 +00:00
cmd/geth, cmd/utils, eth: internalize trusted node config file
This commit is contained in:
parent
de0549fabb
commit
679c90b873
@ -233,7 +233,6 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
|
|||||||
utils.UnlockedAccountFlag,
|
utils.UnlockedAccountFlag,
|
||||||
utils.PasswordFileFlag,
|
utils.PasswordFileFlag,
|
||||||
utils.BootNodesFlag,
|
utils.BootNodesFlag,
|
||||||
utils.TrustedNodesFlag,
|
|
||||||
utils.DataDirFlag,
|
utils.DataDirFlag,
|
||||||
utils.BlockchainVersionFlag,
|
utils.BlockchainVersionFlag,
|
||||||
utils.JSpathFlag,
|
utils.JSpathFlag,
|
||||||
|
@ -207,11 +207,6 @@ var (
|
|||||||
Usage: "Space-separated enode URLs for p2p discovery bootstrap",
|
Usage: "Space-separated enode URLs for p2p discovery bootstrap",
|
||||||
Value: "",
|
Value: "",
|
||||||
}
|
}
|
||||||
TrustedNodesFlag = cli.StringFlag{
|
|
||||||
Name: "trustednodes",
|
|
||||||
Usage: "List of trusted nodes (either an enode list or path to a json file of enodes)",
|
|
||||||
Value: "",
|
|
||||||
}
|
|
||||||
NodeKeyFileFlag = cli.StringFlag{
|
NodeKeyFileFlag = cli.StringFlag{
|
||||||
Name: "nodekey",
|
Name: "nodekey",
|
||||||
Usage: "P2P node key file",
|
Usage: "P2P node key file",
|
||||||
@ -298,7 +293,6 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
|
|||||||
Shh: ctx.GlobalBool(WhisperEnabledFlag.Name),
|
Shh: ctx.GlobalBool(WhisperEnabledFlag.Name),
|
||||||
Dial: true,
|
Dial: true,
|
||||||
BootNodes: ctx.GlobalString(BootNodesFlag.Name),
|
BootNodes: ctx.GlobalString(BootNodesFlag.Name),
|
||||||
TrustedNodes: ctx.GlobalString(TrustedNodesFlag.Name),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -39,6 +40,9 @@ var (
|
|||||||
// ETH/DEV cpp-ethereum (poc-9.ethdev.com)
|
// ETH/DEV cpp-ethereum (poc-9.ethdev.com)
|
||||||
discover.MustParseNode("enode://487611428e6c99a11a9795a6abe7b529e81315ca6aad66e2a2fc76e3adf263faba0d35466c2f8f68d561dbefa8878d4df5f1f2ddb1fbeab7f42ffb8cd328bd4a@5.1.83.226:30303"),
|
discover.MustParseNode("enode://487611428e6c99a11a9795a6abe7b529e81315ca6aad66e2a2fc76e3adf263faba0d35466c2f8f68d561dbefa8878d4df5f1f2ddb1fbeab7f42ffb8cd328bd4a@5.1.83.226:30303"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Path within <datadir> to search for the trusted node list
|
||||||
|
trustedNodes = "trusted-nodes.json"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@ -62,10 +66,6 @@ type Config struct {
|
|||||||
// Space-separated list of discovery node URLs
|
// Space-separated list of discovery node URLs
|
||||||
BootNodes string
|
BootNodes string
|
||||||
|
|
||||||
// Either a space-separated list of discovery node URLs, or a path to a json
|
|
||||||
// file containing such a list.
|
|
||||||
TrustedNodes string
|
|
||||||
|
|
||||||
// This key is used to identify the node on the network.
|
// This key is used to identify the node on the network.
|
||||||
// If nil, an ephemeral key is used.
|
// If nil, an ephemeral key is used.
|
||||||
NodeKey *ecdsa.PrivateKey
|
NodeKey *ecdsa.PrivateKey
|
||||||
@ -105,30 +105,27 @@ func (cfg *Config) parseBootNodes() []*discover.Node {
|
|||||||
// parseTrustedNodes parses a list of discovery node URLs either given literally,
|
// parseTrustedNodes parses a list of discovery node URLs either given literally,
|
||||||
// or loaded from a .json file.
|
// or loaded from a .json file.
|
||||||
func (cfg *Config) parseTrustedNodes() []*discover.Node {
|
func (cfg *Config) parseTrustedNodes() []*discover.Node {
|
||||||
// Short circuit if no trusted nodes were given
|
// Short circuit if no trusted node config is present
|
||||||
if cfg.TrustedNodes == "" {
|
path := filepath.Join(cfg.DataDir, trustedNodes)
|
||||||
|
if _, err := os.Stat(path); err != nil {
|
||||||
|
fmt.Println("nodes", nil)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// Try to interpret the trusted node config as a .json file
|
// Load the trusted nodes from the config file
|
||||||
if _, err := os.Stat(cfg.TrustedNodes); err == nil {
|
blob, err := ioutil.ReadFile(path)
|
||||||
// Load the file from disk
|
if err != nil {
|
||||||
blob, err := ioutil.ReadFile(cfg.TrustedNodes)
|
glog.V(logger.Error).Infof("Failed to access trusted nodes: %v", err)
|
||||||
if err != nil {
|
return nil
|
||||||
glog.V(logger.Error).Infof("Failed to access trusted nodes: %v", err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
// Interpret the json contents
|
|
||||||
list := []string{}
|
|
||||||
if err := json.Unmarshal(blob, &list); err != nil {
|
|
||||||
glog.V(logger.Error).Infof("Failed to load trusted nodes: %v", err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
// Swap out the configuration for the actual nodes
|
|
||||||
cfg.TrustedNodes = strings.Join(list, " ")
|
|
||||||
}
|
}
|
||||||
|
nodelist := []string{}
|
||||||
|
if err := json.Unmarshal(blob, &nodelist); err != nil {
|
||||||
|
glog.V(logger.Error).Infof("Failed to load trusted nodes: %v", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
fmt.Println("nodes", nodelist)
|
||||||
// Interpret the list as a discovery node array
|
// Interpret the list as a discovery node array
|
||||||
var nodes []*discover.Node
|
var nodes []*discover.Node
|
||||||
for _, url := range strings.Split(cfg.TrustedNodes, " ") {
|
for _, url := range nodelist {
|
||||||
if url == "" {
|
if url == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user