Skip to content
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
7 changes: 4 additions & 3 deletions p2p/nat/natupnp.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (n *upnp) ExternalIP() (addr net.IP, err error) {
func (n *upnp) AddMapping(protocol string, extport, intport int, desc string, lifetime time.Duration) (uint16, error) {
ip, err := n.internalAddress()
if err != nil {
return 0, nil // TODO: Shouldn't we return the error?
return 0, err
}
protocol = strings.ToUpper(protocol)
lifetimeS := uint32(lifetime / time.Second)
Expand All @@ -94,14 +94,15 @@ func (n *upnp) AddMapping(protocol string, extport, intport int, desc string, li
if err == nil {
return uint16(extport), nil
}

return uint16(extport), n.withRateLimit(func() error {
// Try addAnyPortMapping if mapping specified port didn't work.
err = n.withRateLimit(func() error {
p, err := n.addAnyPortMapping(protocol, extport, intport, ip, desc, lifetimeS)
if err == nil {
extport = int(p)
}
return err
})
return uint16(extport), err
}

func (n *upnp) addAnyPortMapping(protocol string, extport, intport int, ip net.IP, desc string, lifetimeS uint32) (uint16, error) {
Expand Down