mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
p2p: avoid goroutine for nat.ExtIP
This makes the node URL in logs correct immediately after startup.
This commit is contained in:
parent
47d29f2c9b
commit
b4a7d56fe3
2 changed files with 14 additions and 13 deletions
|
|
@ -129,21 +129,15 @@ func Map(m Interface, c chan struct{}, protocol string, extport, intport int, na
|
||||||
// ExtIP assumes that the local machine is reachable on the given
|
// ExtIP assumes that the local machine is reachable on the given
|
||||||
// external IP address, and that any required ports were mapped manually.
|
// external IP address, and that any required ports were mapped manually.
|
||||||
// Mapping operations will not return an error but won't actually do anything.
|
// Mapping operations will not return an error but won't actually do anything.
|
||||||
func ExtIP(ip net.IP) Interface {
|
type ExtIP net.IP
|
||||||
if ip == nil {
|
|
||||||
panic("IP must not be nil")
|
|
||||||
}
|
|
||||||
return extIP(ip)
|
|
||||||
}
|
|
||||||
|
|
||||||
type extIP net.IP
|
func (n ExtIP) ExternalIP() (net.IP, error) { return net.IP(n), nil }
|
||||||
|
func (n ExtIP) String() string { return fmt.Sprintf("ExtIP(%v)", net.IP(n)) }
|
||||||
func (n extIP) ExternalIP() (net.IP, error) { return net.IP(n), nil }
|
|
||||||
func (n extIP) String() string { return fmt.Sprintf("ExtIP(%v)", net.IP(n)) }
|
|
||||||
|
|
||||||
// These do nothing.
|
// These do nothing.
|
||||||
func (extIP) AddMapping(string, int, int, string, time.Duration) error { return nil }
|
|
||||||
func (extIP) DeleteMapping(string, int, int) error { return nil }
|
func (ExtIP) AddMapping(string, int, int, string, time.Duration) error { return nil }
|
||||||
|
func (ExtIP) DeleteMapping(string, int, int) error { return nil }
|
||||||
|
|
||||||
// Any returns a port mapper that tries to discover any supported
|
// Any returns a port mapper that tries to discover any supported
|
||||||
// mechanism on the local network.
|
// mechanism on the local network.
|
||||||
|
|
|
||||||
|
|
@ -488,7 +488,14 @@ func (srv *Server) setupLocalNode() error {
|
||||||
srv.localnode.Set(e)
|
srv.localnode.Set(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if srv.NAT != nil {
|
switch srv.NAT.(type) {
|
||||||
|
case nil:
|
||||||
|
// No NAT interface, do nothing.
|
||||||
|
case nat.ExtIP:
|
||||||
|
// ExtIP doesn't block, set the IP right away.
|
||||||
|
ip, _ := srv.NAT.ExternalIP()
|
||||||
|
srv.localnode.SetStaticIP(ip)
|
||||||
|
default:
|
||||||
// Ask the router about the IP. This takes a while and blocks startup,
|
// Ask the router about the IP. This takes a while and blocks startup,
|
||||||
// do it in the background.
|
// do it in the background.
|
||||||
srv.loopWG.Add(1)
|
srv.loopWG.Add(1)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue