mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 01:43:47 +00:00
p2p/sim: fix comment and update ExternalIP
This commit is contained in:
parent
96e374efe5
commit
7328021a7c
2 changed files with 10 additions and 20 deletions
|
|
@ -99,7 +99,7 @@ func (d *DockerAdapter) NewNode(config *NodeConfig) (Node, error) {
|
||||||
conf.Stack.P2P.NAT = nil
|
conf.Stack.P2P.NAT = nil
|
||||||
conf.Stack.NoUSB = true
|
conf.Stack.NoUSB = true
|
||||||
|
|
||||||
// listen on a localhost port, which we set when we
|
// listen on all interfaces on a given port, which we set when we
|
||||||
// initialise NodeConfig (usually a random port)
|
// initialise NodeConfig (usually a random port)
|
||||||
conf.Stack.P2P.ListenAddr = fmt.Sprintf(":%d", config.Port)
|
conf.Stack.P2P.ListenAddr = fmt.Sprintf(":%d", config.Port)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -340,27 +340,17 @@ type execNodeConfig struct {
|
||||||
|
|
||||||
// ExternalIP gets an external IP address so that Enode URL is usable
|
// ExternalIP gets an external IP address so that Enode URL is usable
|
||||||
func ExternalIP() net.IP {
|
func ExternalIP() net.IP {
|
||||||
//addrs, err := net.InterfaceAddrs()
|
addrs, err := net.InterfaceAddrs()
|
||||||
//if err != nil {
|
|
||||||
//log.Crit("error getting IP address", "err", err)
|
|
||||||
//}
|
|
||||||
//for _, addr := range addrs {
|
|
||||||
//if ip, ok := addr.(*net.IPNet); ok && !ip.IP.IsLoopback() {
|
|
||||||
//return ip.IP
|
|
||||||
//}
|
|
||||||
//}
|
|
||||||
//log.Crit("unable to determine explicit IP address")
|
|
||||||
//return net.IP{127, 0, 0, 1}
|
|
||||||
|
|
||||||
conn, err := net.Dial("udp", "8.8.8.8:80")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Crit("error getting IP address", "err", err)
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
for _, addr := range addrs {
|
||||||
|
if ip, ok := addr.(*net.IPNet); ok && !ip.IP.IsLoopback() && !ip.IP.IsLinkLocalUnicast() {
|
||||||
localAddr := conn.LocalAddr().(*net.UDPAddr)
|
return ip.IP
|
||||||
|
}
|
||||||
return localAddr.IP
|
}
|
||||||
|
log.Crit("unable to determine explicit IP address")
|
||||||
|
return net.IP{127, 0, 0, 1}
|
||||||
}
|
}
|
||||||
|
|
||||||
// execP2PNode starts a devp2p node when the current binary is executed with
|
// execP2PNode starts a devp2p node when the current binary is executed with
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue