Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing NAT establish mapping logic #2583

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions p2p/net/nat/nat.go
Expand Up @@ -236,6 +236,16 @@ func (nat *NAT) establishMapping(ctx context.Context, protocol string, internalP
if err != nil || externalPort == 0 {
// TODO: log.Event
if err != nil {
natInstance, errorDiscover := discoverGateway(ctx)
if errorDiscover == nil {
var extAddr netip.Addr
extIP, errorGetAddress := natInstance.GetExternalAddress()
if errorGetAddress == nil {
extAddr, _ = netip.AddrFromSlice(extIP)
}
nat.extAddr = extAddr
nat.nat = natInstance
}
log.Warnf("failed to establish port mapping: %s", err)
} else {
log.Warnf("failed to establish port mapping: newport = 0")
Expand Down