mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
p2p/enode: simplify parseComplete
This commit is contained in:
parent
9040b4c284
commit
7a21dc1265
1 changed files with 4 additions and 12 deletions
|
|
@ -119,25 +119,17 @@ func parseComplete(rawurl string) (*Node, error) {
|
|||
return nil, fmt.Errorf("invalid node ID (%v)", err)
|
||||
}
|
||||
// Parse the IP address.
|
||||
host, port, err := net.SplitHostPort(u.Host)
|
||||
ips, err := net.LookupIP(u.Hostname())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid host: %v", err)
|
||||
}
|
||||
if ip = net.ParseIP(host); ip == nil {
|
||||
// attempt to look up IP addresses if host is a FQDN
|
||||
lookupIPs, err := net.LookupIP(host)
|
||||
if err != nil {
|
||||
return nil, errors.New("invalid IP address")
|
||||
}
|
||||
// set to first ip by default
|
||||
ip = lookupIPs[0]
|
||||
return nil, err
|
||||
}
|
||||
ip := ips[0]
|
||||
// Ensure the IP is 4 bytes long for IPv4 addresses.
|
||||
if ipv4 := ip.To4(); ipv4 != nil {
|
||||
ip = ipv4
|
||||
}
|
||||
// Parse the port numbers.
|
||||
if tcpPort, err = strconv.ParseUint(port, 10, 16); err != nil {
|
||||
if tcpPort, err = strconv.ParseUint(u.Port(), 10, 16); err != nil {
|
||||
return nil, errors.New("invalid port")
|
||||
}
|
||||
udpPort = tcpPort
|
||||
|
|
|
|||
Loading…
Reference in a new issue