mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
p2p/server_nat: set stun IP to localnode
This commit is contained in:
parent
8daefeb890
commit
ea8e272e1a
2 changed files with 5 additions and 3 deletions
|
|
@ -36,6 +36,9 @@ const requestLimit = 3
|
||||||
|
|
||||||
var errSTUNFailed = errors.New("STUN requests failed")
|
var errSTUNFailed = errors.New("STUN requests failed")
|
||||||
|
|
||||||
|
type STUN struct {
|
||||||
|
stun
|
||||||
|
}
|
||||||
type stun struct {
|
type stun struct {
|
||||||
serverList []string
|
serverList []string
|
||||||
}
|
}
|
||||||
|
|
@ -77,7 +80,7 @@ func (stun) DeleteMapping(string, int, int) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stun) ExternalIP() (net.IP, error) {
|
func (s stun) ExternalIP() (net.IP, error) {
|
||||||
for _, server := range s.randomServers(requestLimit) {
|
for _, server := range s.randomServers(requestLimit) {
|
||||||
ip, err := s.externalIP(server)
|
ip, err := s.externalIP(server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -57,8 +57,7 @@ func (srv *Server) setupPortMapping() {
|
||||||
// No NAT interface configured.
|
// No NAT interface configured.
|
||||||
srv.loopWG.Add(1)
|
srv.loopWG.Add(1)
|
||||||
go srv.consumePortMappingRequests()
|
go srv.consumePortMappingRequests()
|
||||||
|
case nat.ExtIP, nat.STUN:
|
||||||
case nat.ExtIP:
|
|
||||||
// ExtIP doesn't block, set the IP right away.
|
// ExtIP doesn't block, set the IP right away.
|
||||||
ip, _ := srv.NAT.ExternalIP()
|
ip, _ := srv.NAT.ExternalIP()
|
||||||
srv.localnode.SetStaticIP(ip)
|
srv.localnode.SetStaticIP(ip)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue