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

enable non-public address port mapping announcement #771

Merged
merged 1 commit into from
Jan 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions p2p/host/basic/basic_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,20 +732,23 @@ func (h *BasicHost) AllAddrs() []ma.Multiaddr {
continue
}

extMaddr := mappedMaddr
if rest != nil {
extMaddr = ma.Join(extMaddr, rest)
}

// Add in the mapped addr.
finalAddrs = append(finalAddrs, extMaddr)

// Did the router give us a routable public addr?
if manet.IsPublicAddr(mappedMaddr) {
// Yes, use it.
extMaddr := mappedMaddr
if rest != nil {
extMaddr = ma.Join(extMaddr, rest)
}

// Add in the mapped addr.
finalAddrs = append(finalAddrs, extMaddr)
//well done
continue
}

// No. Ok, let's try our observed addresses.
// No.
// in case router give us a wrong address.
// also add observed addresses

// Now, check if we have any observed addresses that
// differ from the one reported by the router. Routers
Expand Down Expand Up @@ -776,6 +779,7 @@ func (h *BasicHost) AllAddrs() []ma.Multiaddr {
}
finalAddrs = append(finalAddrs, observedAddrs...)
}

return dedupAddrs(finalAddrs)
}

Expand Down