From fcc26d7355bbcf74687c9f2735774cfbf401d6b9 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Thu, 23 Apr 2015 14:56:19 -0700 Subject: [PATCH] Resolve host for NetAddressFromString(). Test fix. --- binary/reflect.go | 2 +- cmd/barak/main.go | 1 + cmd/barak/seed0 | 15 +++++++++------ cmd/barak/seed1 | 15 +++++++++------ cmd/barak/seed2 | 15 +++++++++------ p2p/netaddress.go | 10 ++++++++++ 6 files changed, 39 insertions(+), 19 deletions(-) diff --git a/binary/reflect.go b/binary/reflect.go index a05539d84..a517c4ab4 100644 --- a/binary/reflect.go +++ b/binary/reflect.go @@ -170,7 +170,7 @@ func readReflect(rv reflect.Value, rt reflect.Type, r io.Reader, n *int64, err * } crt, ok := typeInfo.ByteToType[typeByte] if !ok { - *err = errors.New(Fmt("Unexpected type byte %X for type %v", typeByte, crt)) + *err = errors.New(Fmt("Unexpected type byte %X for type %v", typeByte, rt)) return } crv := reflect.New(crt).Elem() diff --git a/cmd/barak/main.go b/cmd/barak/main.go index a73c63868..554e2242f 100644 --- a/cmd/barak/main.go +++ b/cmd/barak/main.go @@ -86,6 +86,7 @@ func main() { if err != nil { panic(Fmt("Error creating barak rootDir: %v", err)) } + barak.registries = options.Registries // Write pid to file. err = AtomicWriteFile(barak.rootDir+"/pidfile", []byte(Fmt("%v", barak.pid))) diff --git a/cmd/barak/seed0 b/cmd/barak/seed0 index 4ad2cf7fa..198cb7f29 100644 --- a/cmd/barak/seed0 +++ b/cmd/barak/seed0 @@ -1,9 +1,12 @@ { - "ListenAddress": "0.0.0.0:46660", + "ListenAddress": "0.0.0.0:46660", "Validators": [ - { - "VotingPower": 1, - "PubKey": [1,"3A2C5C341FFC1D5F7AB518519FF8289D3BFAB82DFD6E167B926FAD72C1BF10F8"] - } - ] + { + "VotingPower": 1, + "PubKey": [1,"3A2C5C341FFC1D5F7AB518519FF8289D3BFAB82DFD6E167B926FAD72C1BF10F8"] + } + ], + "Registries": [ + "http://navytoad.chaintest.net:46660" + ] } diff --git a/cmd/barak/seed1 b/cmd/barak/seed1 index 60ecc02c0..da983a3e8 100644 --- a/cmd/barak/seed1 +++ b/cmd/barak/seed1 @@ -1,9 +1,12 @@ { - "ListenAddress": "0.0.0.0:46661", + "ListenAddress": "0.0.0.0:46661", "Validators": [ - { - "VotingPower": 1, - "PubKey": [1,"3A2C5C341FFC1D5F7AB518519FF8289D3BFAB82DFD6E167B926FAD72C1BF10F8"] - } - ] + { + "VotingPower": 1, + "PubKey": [1,"3A2C5C341FFC1D5F7AB518519FF8289D3BFAB82DFD6E167B926FAD72C1BF10F8"] + } + ], + "Registries": [ + "http://navytoad.chaintest.net:46660" + ] } diff --git a/cmd/barak/seed2 b/cmd/barak/seed2 index 58567d2ca..fbc2cb4fa 100644 --- a/cmd/barak/seed2 +++ b/cmd/barak/seed2 @@ -1,9 +1,12 @@ { - "ListenAddress": "0.0.0.0:46662", + "ListenAddress": "0.0.0.0:46662", "Validators": [ - { - "VotingPower": 1, - "PubKey": [1,"3A2C5C341FFC1D5F7AB518519FF8289D3BFAB82DFD6E167B926FAD72C1BF10F8"] - } - ] + { + "VotingPower": 1, + "PubKey": [1,"3A2C5C341FFC1D5F7AB518519FF8289D3BFAB82DFD6E167B926FAD72C1BF10F8"] + } + ], + "Registries": [ + "http://navytoad.chaintest.net:46660" + ] } diff --git a/p2p/netaddress.go b/p2p/netaddress.go index ff696a951..39979fdcd 100644 --- a/p2p/netaddress.go +++ b/p2p/netaddress.go @@ -28,12 +28,22 @@ func NewNetAddress(addr net.Addr) *NetAddress { return NewNetAddressIPPort(ip, port) } +// Also resolves the host if host is not an IP. func NewNetAddressString(addr string) *NetAddress { host, portStr, err := net.SplitHostPort(addr) if err != nil { panic(err) } ip := net.ParseIP(host) + if ip == nil { + if len(host) > 0 { + ips, err := net.LookupIP(host) + if err != nil { + panic(err) + } + ip = ips[0] + } + } port, err := strconv.ParseUint(portStr, 10, 16) if err != nil { panic(err)