2021-08-23 16:13:20 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
|
|
import (
|
2022-01-06 06:40:23 -05:00
|
|
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
2022-04-18 09:15:20 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
2021-08-23 16:13:20 +00:00
|
|
|
)
|
|
|
|
|
|
2022-01-06 06:40:23 -05:00
|
|
|
func GetPort(selection settings.ServerSelection,
|
2021-08-23 16:13:20 +00:00
|
|
|
defaultOpenVPNTCP, defaultOpenVPNUDP, defaultWireguard uint16) (port uint16) {
|
|
|
|
|
switch selection.VPN {
|
2022-04-18 09:15:20 +00:00
|
|
|
case vpn.Wireguard:
|
2022-01-06 06:40:23 -05:00
|
|
|
customPort := *selection.Wireguard.EndpointPort
|
2021-08-23 16:13:20 +00:00
|
|
|
if customPort > 0 {
|
|
|
|
|
return customPort
|
|
|
|
|
}
|
|
|
|
|
return defaultWireguard
|
|
|
|
|
default: // OpenVPN
|
2022-01-06 06:40:23 -05:00
|
|
|
customPort := *selection.OpenVPN.CustomPort
|
2021-08-23 16:13:20 +00:00
|
|
|
if customPort > 0 {
|
|
|
|
|
return customPort
|
|
|
|
|
}
|
2022-01-06 06:40:23 -05:00
|
|
|
if *selection.OpenVPN.TCP {
|
2021-08-23 16:13:20 +00:00
|
|
|
return defaultOpenVPNTCP
|
|
|
|
|
}
|
|
|
|
|
return defaultOpenVPNUDP
|
|
|
|
|
}
|
|
|
|
|
}
|