2021-08-23 16:07:47 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
|
|
import (
|
2022-01-06 06:40:23 -05:00
|
|
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
2021-08-23 16:07:47 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/constants"
|
2022-04-18 09:15:20 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
2021-08-23 16:07:47 +00:00
|
|
|
)
|
|
|
|
|
|
2022-01-06 06:40:23 -05:00
|
|
|
func GetProtocol(selection settings.ServerSelection) (protocol string) {
|
2022-04-18 09:15:20 +00:00
|
|
|
if selection.VPN == vpn.OpenVPN && *selection.OpenVPN.TCP {
|
2021-08-23 16:07:47 +00:00
|
|
|
return constants.TCP
|
|
|
|
|
}
|
|
|
|
|
return constants.UDP
|
|
|
|
|
}
|
2021-08-23 20:16:29 +00:00
|
|
|
|
2022-01-06 06:40:23 -05:00
|
|
|
func FilterByProtocol(selection settings.ServerSelection,
|
2021-08-23 20:16:29 +00:00
|
|
|
serverTCP, serverUDP bool) (filtered bool) {
|
|
|
|
|
switch selection.VPN {
|
2022-04-18 09:15:20 +00:00
|
|
|
case vpn.Wireguard:
|
2021-08-23 20:16:29 +00:00
|
|
|
return !serverUDP
|
|
|
|
|
default: // OpenVPN
|
2022-01-06 06:40:23 -05:00
|
|
|
wantTCP := *selection.OpenVPN.TCP
|
2021-08-23 20:16:29 +00:00
|
|
|
wantUDP := !wantTCP
|
|
|
|
|
return (wantTCP && !serverTCP) || (wantUDP && !serverUDP)
|
|
|
|
|
}
|
|
|
|
|
}
|