Maint: common GetPort for OpenVPN+Wireguard providers

This commit is contained in:
Quentin McGaw (desktop)
2021-08-23 16:13:20 +00:00
parent dbf5c569ea
commit 8b52af0d03
8 changed files with 127 additions and 249 deletions

View File

@@ -2,7 +2,6 @@ package mullvad
import (
"github.com/qdm12/gluetun/internal/configuration"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
)
@@ -39,23 +38,11 @@ func (m *Mullvad) GetConnection(selection configuration.ServerSelection) (
}
func getPort(selection configuration.ServerSelection) (port uint16) {
switch selection.VPN {
case constants.Wireguard:
customPort := selection.Wireguard.CustomPort
if customPort > 0 {
return customPort
}
const defaultPort = 51820
return defaultPort
default: // OpenVPN
customPort := selection.OpenVPN.CustomPort
if customPort > 0 {
return customPort
}
port = 1194
if selection.OpenVPN.TCP {
port = 443
}
return port
}
const (
defaultOpenVPNTCP = 443
defaultOpenVPNUDP = 1194
defaultWireguard = 51820
)
return utils.GetPort(selection, defaultOpenVPNTCP,
defaultOpenVPNUDP, defaultWireguard)
}