mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
p2p/enode: fix ipv6 address used as extip results in 127.0.0.1 being used
This commit is contained in:
parent
6154f87c33
commit
57164d4d8c
1 changed files with 18 additions and 11 deletions
|
|
@ -101,19 +101,26 @@ func (n *Node) Load(k enr.Entry) error {
|
|||
|
||||
// IP returns the IP address of the node. This prefers IPv4 addresses.
|
||||
func (n *Node) IP() net.IP {
|
||||
var (
|
||||
ip4 enr.IPv4
|
||||
ip6 enr.IPv6
|
||||
)
|
||||
if n.Load(&ip4) == nil {
|
||||
return net.IP(ip4)
|
||||
}
|
||||
if n.Load(&ip6) == nil {
|
||||
return net.IP(ip6)
|
||||
}
|
||||
return nil
|
||||
var (
|
||||
ip4 enr.IPv4
|
||||
ip6 enr.IPv6
|
||||
)
|
||||
if n.Load(&ip4) == nil {
|
||||
ipv4Addr := net.IP(ip4)
|
||||
if !ipv4Addr.IsLoopback() {
|
||||
return ipv4Addr
|
||||
}
|
||||
}
|
||||
if n.Load(&ip6) == nil {
|
||||
return net.IP(ip6)
|
||||
}
|
||||
if net.IP(ip4).IsLoopback() {
|
||||
return net.IP(ip4)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
// UDP returns the UDP port of the node.
|
||||
func (n *Node) UDP() int {
|
||||
var port enr.UDP
|
||||
|
|
|
|||
Loading…
Reference in a new issue