1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-10 05:52:20 +08:00

p2p/nat: re-factors nat object

- allow retrieving addresses
- allow notifications on mapping changes
- allow lifecycle mgmt (future commit will manage it)
This commit is contained in:
Juan Batiz-Benet
2015-01-26 09:09:43 -08:00
parent 913a733e9b
commit 332d350196
2 changed files with 314 additions and 74 deletions

View File

@ -432,10 +432,14 @@ func constructPeerHost(ctx context.Context, cfg *config.Config, id peer.ID, ps p
}
log.Infof("Swarm listening at: %s", addrs)
mapAddrs := inat.MapAddrs(filteredAddrs)
if len(mapAddrs) > 0 {
log.Infof("NAT mapping addrs: %s", mapAddrs)
addrs = append(addrs, mapAddrs...)
nat := inat.DiscoverGateway()
if nat != nil {
nat.PortMapAddrs(filteredAddrs)
mapAddrs := nat.ExternalAddrs()
if len(mapAddrs) > 0 {
log.Infof("NAT mapping addrs: %s", mapAddrs)
addrs = append(addrs, mapAddrs...)
}
}
ps.AddAddresses(id, addrs)