From 4accc187d5cf6a100d6c10c0e0f35780f52871a0 Mon Sep 17 00:00:00 2001 From: Péter Szilágyi Date: Mon, 4 May 2015 13:59:51 +0300 Subject: eth, p2p: add trusted node list beside static list --- eth/backend.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'eth/backend.go') diff --git a/eth/backend.go b/eth/backend.go index 8aecfba5b..983dd8e4f 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -41,8 +41,8 @@ var ( discover.MustParseNode("enode://487611428e6c99a11a9795a6abe7b529e81315ca6aad66e2a2fc76e3adf263faba0d35466c2f8f68d561dbefa8878d4df5f1f2ddb1fbeab7f42ffb8cd328bd4a@5.1.83.226:30303"), } - // Path within to search for the static node list - staticNodes = "static-nodes.json" + staticNodes = "static-nodes.json" // Path within to search for the static node list + trustedNodes = "trusted-nodes.json" // Path within to search for the trusted node list ) type Config struct { @@ -102,23 +102,22 @@ func (cfg *Config) parseBootNodes() []*discover.Node { return ns } -// parseStaticNodes parses a list of discovery node URLs either given literally, -// or loaded from a .json file. -func (cfg *Config) parseStaticNodes() []*discover.Node { - // Short circuit if no static node config is present - path := filepath.Join(cfg.DataDir, staticNodes) +// parseNodes parses a list of discovery node URLs loaded from a .json file. +func (cfg *Config) parseNodes(file string) []*discover.Node { + // Short circuit if no node config is present + path := filepath.Join(cfg.DataDir, file) if _, err := os.Stat(path); err != nil { return nil } - // Load the static nodes from the config file + // Load the nodes from the config file blob, err := ioutil.ReadFile(path) if err != nil { - glog.V(logger.Error).Infof("Failed to access static nodes: %v", err) + glog.V(logger.Error).Infof("Failed to access nodes: %v", err) return nil } nodelist := []string{} if err := json.Unmarshal(blob, &nodelist); err != nil { - glog.V(logger.Error).Infof("Failed to load static nodes: %v", err) + glog.V(logger.Error).Infof("Failed to load nodes: %v", err) return nil } // Interpret the list as a discovery node array @@ -129,7 +128,7 @@ func (cfg *Config) parseStaticNodes() []*discover.Node { } node, err := discover.ParseNode(url) if err != nil { - glog.V(logger.Error).Infof("Static node URL %s: %v\n", url, err) + glog.V(logger.Error).Infof("Node URL %s: %v\n", url, err) continue } nodes = append(nodes, node) @@ -288,7 +287,8 @@ func New(config *Config) (*Ethereum, error) { NAT: config.NAT, NoDial: !config.Dial, BootstrapNodes: config.parseBootNodes(), - StaticNodes: config.parseStaticNodes(), + StaticNodes: config.parseNodes(staticNodes), + TrustedNodes: config.parseNodes(trustedNodes), NodeDatabase: nodeDb, } if len(config.Port) > 0 { -- cgit