mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-16 18:37:51 +01:00
Minor UPnP improvement: Run discovery of each network in parallel.
This commit is contained in:
@@ -4,7 +4,6 @@ Copyright: 2021 Peernet s.r.o.
|
||||
Author: Peter Kleissner
|
||||
|
||||
Currently only supports IPv4 networks.
|
||||
TODO: Limit mapping to X hours. Auto remap upon expiration.
|
||||
*/
|
||||
|
||||
package core
|
||||
@@ -60,15 +59,6 @@ func (network *Network) upnpAuto() {
|
||||
return
|
||||
}
|
||||
|
||||
// Only allow 1 UPnP worker at a time.
|
||||
upnpMutex.Lock()
|
||||
defer upnpMutex.Unlock()
|
||||
|
||||
// If there is already a running UPnP on the adapter, skip.
|
||||
if _, ok := upnpListInterfaces[network.GetAdapterName()]; ok {
|
||||
return
|
||||
}
|
||||
|
||||
nat, err := upnp.Discover(network.address.IP)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -83,6 +73,15 @@ func (network *Network) upnpAuto() {
|
||||
|
||||
network.ipExternal = externalIP
|
||||
|
||||
// Only allow 1 UPnP worker at a time for registering the adapter.
|
||||
upnpMutex.Lock()
|
||||
defer upnpMutex.Unlock()
|
||||
|
||||
// If there is already a running UPnP on the adapter, skip.
|
||||
if _, ok := upnpListInterfaces[network.GetAdapterName()]; ok {
|
||||
return
|
||||
}
|
||||
|
||||
if err := network.upnpTryPortForward(); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -163,3 +162,5 @@ func (network *Network) upnpValidate() (err error) {
|
||||
// TODO: Send special message which validates the UPnP mapping
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: Function to check if there is an existing port forward
|
||||
|
||||
@@ -241,8 +241,8 @@ func GetNetworks(networkType int) (networks []*Network) {
|
||||
}
|
||||
|
||||
// GetListen returns connectivity information
|
||||
func (network *Network) GetListen() (listen *net.UDPAddr, multicastIPv6 net.IP, broadcastIPv4 []net.IP, portExternal uint16) {
|
||||
return network.address, network.multicastIP, network.broadcastIPv4, network.portExternal
|
||||
func (network *Network) GetListen() (listen *net.UDPAddr, multicastIPv6 net.IP, broadcastIPv4 []net.IP, ipExternal net.IP, portExternal uint16) {
|
||||
return network.address, network.multicastIP, network.broadcastIPv4, network.ipExternal, network.portExternal
|
||||
}
|
||||
|
||||
// GetAdapterName returns the adapter name, if available
|
||||
|
||||
Reference in New Issue
Block a user