From 05f6cf9bb2ea29bd4b450a7c538f7877b620b941 Mon Sep 17 00:00:00 2001 From: Poh Zi How Date: Wed, 3 Oct 2018 04:38:20 +0800 Subject: [PATCH] look up IP if host is FQDN (#544) Fixes #147 --- p2p/discover/node.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/p2p/discover/node.go b/p2p/discover/node.go index 711b940e7..0cdadc49a 100644 --- a/p2p/discover/node.go +++ b/p2p/discover/node.go @@ -145,7 +145,7 @@ var incompleteNodeURL = regexp.MustCompile("(?i)^(?:enode://)?([0-9a-f]+)$") // // For complete nodes, the node ID is encoded in the username portion // of the URL, separated from the host by an @ sign. The hostname can -// only be given as an IP address, DNS domain names are not allowed. +// be given as an IP address or a DNS domain name. // The port in the host name section is the TCP listening port. If the // TCP and UDP (discovery) ports differ, the UDP port is specified as // query parameter "discport". @@ -192,7 +192,13 @@ func parseComplete(rawurl string) (*Node, error) { return nil, fmt.Errorf("invalid host: %v", err) } if ip = net.ParseIP(host); ip == nil { - return nil, errors.New("invalid IP address") + // 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] } // Ensure the IP is 4 bytes long for IPv4 addresses. if ipv4 := ip.To4(); ipv4 != nil {