p2p/server_nat: set stun IP to localnode

This commit is contained in:
fearlessfe 2025-02-01 19:46:28 +08:00
parent 8daefeb890
commit ea8e272e1a
2 changed files with 5 additions and 3 deletions

View file

@ -36,6 +36,9 @@ const requestLimit = 3
var errSTUNFailed = errors.New("STUN requests failed")
type STUN struct {
stun
}
type stun struct {
serverList []string
}
@ -77,7 +80,7 @@ func (stun) DeleteMapping(string, int, int) error {
return nil
}
func (s *stun) ExternalIP() (net.IP, error) {
func (s stun) ExternalIP() (net.IP, error) {
for _, server := range s.randomServers(requestLimit) {
ip, err := s.externalIP(server)
if err != nil {

View file

@ -57,8 +57,7 @@ func (srv *Server) setupPortMapping() {
// No NAT interface configured.
srv.loopWG.Add(1)
go srv.consumePortMappingRequests()
case nat.ExtIP:
case nat.ExtIP, nat.STUN:
// ExtIP doesn't block, set the IP right away.
ip, _ := srv.NAT.ExternalIP()
srv.localnode.SetStaticIP(ip)