Commit c867321f authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 99b8a6f4
...@@ -107,28 +107,34 @@ func (addr Address) String() string { ...@@ -107,28 +107,34 @@ func (addr Address) String() string {
switch addr.Port { switch addr.Port {
case 0: case 0:
return addr.Host return addr.Host
default: default:
return net.JoinHostPort(addr.Host, fmt.Sprintf("%d", addr.Port)) return net.JoinHostPort(addr.Host, fmt.Sprintf("%d", addr.Port))
} }
} }
// ParseAddress parses networked address (XXX of form host:port) into NEO Address // ParseAddress parses networked address (XXX of form host:port) into NEO Address
func ParseAddress(addr string) (Address, error) { //func ParseAddress(addr string) (Address, error) {
// e.g. on unix, pipenet, etc there is no host/port split - the address func ConvAddress(addr net.Addr) (Address, error) {
// is single string which we put into .Host and set .Port=0 addrstr := addr.String()
// TODO detect :port presence ? // e.g. on unix, pipenet, etc networks there is no host/port split - the address
// XXX pass net.Addr() here instead of string? // is single string which we put into .Host and set .Port=0 to indicate such cases
switch addr.Network() {
host, portstr, err := net.SplitHostPort(hostport) default:
if err != nil { return Address{Host: addrstr, Port: 0}, nil
return Address{}, err
} case "tcp", "tcp4", "tcp6", "udp", "udp4", "udp6":
// XXX also lookup portstr in /etc/services (net.LookupPort) ? host, portstr, err := net.SplitHostPort(addrstr)
port, err := strconv.ParseUint(portstr, 10, 16) if err != nil {
if err != nil { return Address{}, err
return Address{}, &net.AddrError{Err: "invalid port", Addr: hostport} }
// XXX also lookup portstr in /etc/services (net.LookupPort) ?
port, err := strconv.ParseUint(portstr, 10, 16)
if err != nil {
return Address{}, &net.AddrError{Err: "invalid port", Addr: addrstr}
}
return Address{Host: host, Port: uint16(port)}, nil
} }
return Address{Host: host, Port: uint16(port)}, nil
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment