|
@ -52,6 +52,7 @@ func DiscoverNAT() *NAT { |
|
|
// service that will periodically renew port mappings,
|
|
|
// service that will periodically renew port mappings,
|
|
|
// and keep an up-to-date list of all the external addresses.
|
|
|
// and keep an up-to-date list of all the external addresses.
|
|
|
type NAT struct { |
|
|
type NAT struct { |
|
|
|
|
|
natmu sync.Mutex |
|
|
nat nat.NAT |
|
|
nat nat.NAT |
|
|
proc goprocess.Process // manages nat mappings lifecycle
|
|
|
proc goprocess.Process // manages nat mappings lifecycle
|
|
|
|
|
|
|
|
@ -170,11 +171,13 @@ func (nat *NAT) establishMapping(m *mapping) { |
|
|
comment = "libp2p-" + m.comment |
|
|
comment = "libp2p-" + m.comment |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
nat.natmu.Lock() |
|
|
newport, err := nat.nat.AddPortMapping(m.Protocol(), m.InternalPort(), comment, MappingDuration) |
|
|
newport, err := nat.nat.AddPortMapping(m.Protocol(), m.InternalPort(), comment, MappingDuration) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
// Some hardware does not support mappings with timeout, so try that
|
|
|
// Some hardware does not support mappings with timeout, so try that
|
|
|
newport, err = nat.nat.AddPortMapping(m.Protocol(), m.InternalPort(), comment, 0) |
|
|
newport, err = nat.nat.AddPortMapping(m.Protocol(), m.InternalPort(), comment, 0) |
|
|
} |
|
|
} |
|
|
|
|
|
nat.natmu.Lock() |
|
|
|
|
|
|
|
|
failure := func() { |
|
|
failure := func() { |
|
|
m.setExternalPort(0) // clear mapping
|
|
|
m.setExternalPort(0) // clear mapping
|
|
|