|
@ -87,7 +87,7 @@ func NewDefaultListener(protocol string, lAddr string, skipUPNP bool, logger log |
|
|
} |
|
|
} |
|
|
// Otherwise just use the local address...
|
|
|
// Otherwise just use the local address...
|
|
|
if extAddr == nil { |
|
|
if extAddr == nil { |
|
|
extAddr = getNaiveExternalAddress(listenerPort) |
|
|
|
|
|
|
|
|
extAddr = getNaiveExternalAddress(listenerPort, false, logger) |
|
|
} |
|
|
} |
|
|
if extAddr == nil { |
|
|
if extAddr == nil { |
|
|
cmn.PanicCrisis("Could not determine external address!") |
|
|
cmn.PanicCrisis("Could not determine external address!") |
|
@ -197,7 +197,7 @@ func getUPNPExternalAddress(externalPort, internalPort int, logger log.Logger) * |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// TODO: use syscalls: http://pastebin.com/9exZG4rh
|
|
|
// TODO: use syscalls: http://pastebin.com/9exZG4rh
|
|
|
func getNaiveExternalAddress(port int) *NetAddress { |
|
|
|
|
|
|
|
|
func getNaiveExternalAddress(port int, settleForLocal bool, logger log.Logger) *NetAddress { |
|
|
addrs, err := net.InterfaceAddrs() |
|
|
addrs, err := net.InterfaceAddrs() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
cmn.PanicCrisis(cmn.Fmt("Could not fetch interface addresses: %v", err)) |
|
|
cmn.PanicCrisis(cmn.Fmt("Could not fetch interface addresses: %v", err)) |
|
@ -209,10 +209,13 @@ func getNaiveExternalAddress(port int) *NetAddress { |
|
|
continue |
|
|
continue |
|
|
} |
|
|
} |
|
|
v4 := ipnet.IP.To4() |
|
|
v4 := ipnet.IP.To4() |
|
|
if v4 == nil || v4[0] == 127 { |
|
|
|
|
|
|
|
|
if v4 == nil || (!settleForLocal && v4[0] == 127) { |
|
|
continue |
|
|
continue |
|
|
} // loopback
|
|
|
} // loopback
|
|
|
return NewNetAddressIPPort(ipnet.IP, uint16(port)) |
|
|
return NewNetAddressIPPort(ipnet.IP, uint16(port)) |
|
|
} |
|
|
} |
|
|
return nil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// try again, but settle for local
|
|
|
|
|
|
logger.Info("Node may not be connected to internet. Settling for local address") |
|
|
|
|
|
return getNaiveExternalAddress(port, true, logger) |
|
|
} |
|
|
} |