p2p/nat: limit UPNP request concurrency (#21390)
This adds a lock around requests because some routers can't handle concurrent requests. Requests are also rate-limited. The Map function request a new mapping exactly when the map timeout occurs instead of 5 minutes earlier. This should prevent duplicate mappings.
This commit is contained in:
@ -91,15 +91,14 @@ func Parse(spec string) (Interface, error) {
|
||||
}
|
||||
|
||||
const (
|
||||
mapTimeout = 20 * time.Minute
|
||||
mapUpdateInterval = 15 * time.Minute
|
||||
mapTimeout = 10 * time.Minute
|
||||
)
|
||||
|
||||
// Map adds a port mapping on m and keeps it alive until c is closed.
|
||||
// This function is typically invoked in its own goroutine.
|
||||
func Map(m Interface, c chan struct{}, protocol string, extport, intport int, name string) {
|
||||
func Map(m Interface, c <-chan struct{}, protocol string, extport, intport int, name string) {
|
||||
log := log.New("proto", protocol, "extport", extport, "intport", intport, "interface", m)
|
||||
refresh := time.NewTimer(mapUpdateInterval)
|
||||
refresh := time.NewTimer(mapTimeout)
|
||||
defer func() {
|
||||
refresh.Stop()
|
||||
log.Debug("Deleting port mapping")
|
||||
@ -121,7 +120,7 @@ func Map(m Interface, c chan struct{}, protocol string, extport, intport int, na
|
||||
if err := m.AddMapping(protocol, extport, intport, name, mapTimeout); err != nil {
|
||||
log.Debug("Couldn't add port mapping", "err", err)
|
||||
}
|
||||
refresh.Reset(mapUpdateInterval)
|
||||
refresh.Reset(mapTimeout)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user