ipv6 address used as extip results in 127.0.0.1

This commit is contained in:
smin-k 2024-05-09 16:37:06 +09:00
parent d35a62e05a
commit 7b5fceb603

View file

@ -99,6 +99,7 @@ func (n *Node) Load(k enr.Entry) error {
return n.r.Load(k) return n.r.Load(k)
} }
// IP returns the IP address of the node. This prefers IPv4 addresses.
// IP returns the IP address of the node. This prefers IPv4 addresses. // IP returns the IP address of the node. This prefers IPv4 addresses.
func (n *Node) IP() net.IP { func (n *Node) IP() net.IP {
var ( var (
@ -114,13 +115,15 @@ func (n *Node) IP() net.IP {
if n.Load(&ip6) == nil { if n.Load(&ip6) == nil {
return net.IP(ip6) return net.IP(ip6)
} }
if ipv4Addr := net.IP(ip4); ipv4Addr.IsLoopback() { if n.Load(&ip4) == nil {
ipv4Addr := net.IP(ip4)
if ipv4Addr.IsLoopback() {
return ipv4Addr return ipv4Addr
} }
}
return nil return nil
} }
// UDP returns the UDP port of the node. // UDP returns the UDP port of the node.
func (n *Node) UDP() int { func (n *Node) UDP() int {
var port enr.UDP var port enr.UDP