# 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
This commit is contained in:
Edwin 2017-08-11 15:55:19 +08:00
parent 01db708a51
commit e3e086b470
1 changed files with 5 additions and 5 deletions

View File

@ -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
}