From e3e086b47044045e1e496896103d1d442d76adb0 Mon Sep 17 00:00:00 2001 From: Edwin Date: Fri, 11 Aug 2017 15:55:19 +0800 Subject: [PATCH 1/2] # This is a combination of 2 commits. # The first commit's message is: core: add host and port in static node file # This is the 2nd commit message: refactor --- core/cluster.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/cluster.go b/core/cluster.go index 6f6e3663..7f37ca62 100644 --- a/core/cluster.go +++ b/core/cluster.go @@ -38,7 +38,7 @@ const ( defaultLocalDir = "/tmp/gdata" datadirPrivateKey = "nodekey" - defaultIP = "localhost" + defaultIP = net.IPv4(127, 0, 0, 1) clientIdentifier = "geth" staticNodeJson = "static-nodes.json" @@ -134,7 +134,7 @@ func saveNodeKey(key *ecdsa.PrivateKey) (string, error) { return instanceDir, nil } -func saveStaticNode(dataDir string, nodes []*discover.Node) error { +func saveStaticNode(dataDir string, nodes []string) error { filePath := filepath.Join(dataDir, clientIdentifier) keyPath := filepath.Join(filePath, staticNodeJson) @@ -146,12 +146,12 @@ func saveStaticNode(dataDir string, nodes []*discover.Node) error { return ioutil.WriteFile(keyPath, raw, 0600) } -func transformToStaticNodes(envs []*Env) []*discover.Node { - nodes := make([]*discover.Node, len(envs)) +func transformToStaticNodes(envs []*Env) []string { + nodes := make([]string, len(envs)) for i, env := range envs { nodeID := discover.PubkeyID(&env.Key.PublicKey) - nodes[i] = discover.NewNode(nodeID, net.ParseIP(defaultIP), 0, env.HttpPort) + nodes[i] = discover.NewNode(nodeID, defaultIP, 0, env.HttpPort).String() } return nodes } From b85e6faa19c966e139442f64d6f83451eea82549 Mon Sep 17 00:00:00 2001 From: Edwin Date: Fri, 11 Aug 2017 15:55:19 +0800 Subject: [PATCH 2/2] core: add host and port in static node file --- core/cluster.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/cluster.go b/core/cluster.go index 7f37ca62..e1542e21 100644 --- a/core/cluster.go +++ b/core/cluster.go @@ -38,13 +38,16 @@ const ( defaultLocalDir = "/tmp/gdata" datadirPrivateKey = "nodekey" - defaultIP = net.IPv4(127, 0, 0, 1) clientIdentifier = "geth" staticNodeJson = "static-nodes.json" genesisJson = "genesis.json" ) +var ( + defaultIP = net.IPv4(127, 0, 0, 1) +) + func GenerateClusterKeys(numbers int) []*ecdsa.PrivateKey { keys := make([]*ecdsa.PrivateKey, numbers) for i := 0; i < len(keys); i++ {