chore(constants): internal/constants/vpn package
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
"net"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
@@ -25,7 +25,7 @@ func PickConnection(connections []models.Connection,
|
||||
return connection, ErrNoConnectionToPickFrom
|
||||
}
|
||||
|
||||
if len(selection.TargetIP) > 0 && selection.VPN == constants.Wireguard {
|
||||
if len(selection.TargetIP) > 0 && selection.VPN == vpn.Wireguard {
|
||||
// we need the right public key
|
||||
return getTargetIPConnection(connections, selection.TargetIP)
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@ package utils
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||
)
|
||||
|
||||
func GetPort(selection settings.ServerSelection,
|
||||
defaultOpenVPNTCP, defaultOpenVPNUDP, defaultWireguard uint16) (port uint16) {
|
||||
switch selection.VPN {
|
||||
case constants.Wireguard:
|
||||
case vpn.Wireguard:
|
||||
customPort := *selection.Wireguard.EndpointPort
|
||||
if customPort > 0 {
|
||||
return customPort
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -30,7 +30,7 @@ func Test_GetPort(t *testing.T) {
|
||||
},
|
||||
"OpenVPN UDP": {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
VPN: vpn.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
CustomPort: uint16Ptr(0),
|
||||
TCP: boolPtr(false),
|
||||
@@ -40,7 +40,7 @@ func Test_GetPort(t *testing.T) {
|
||||
},
|
||||
"OpenVPN TCP": {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
VPN: vpn.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
CustomPort: uint16Ptr(0),
|
||||
TCP: boolPtr(true),
|
||||
@@ -50,7 +50,7 @@ func Test_GetPort(t *testing.T) {
|
||||
},
|
||||
"OpenVPN custom port": {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
VPN: vpn.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
CustomPort: uint16Ptr(1234),
|
||||
},
|
||||
@@ -59,13 +59,13 @@ func Test_GetPort(t *testing.T) {
|
||||
},
|
||||
"Wireguard": {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.Wireguard,
|
||||
VPN: vpn.Wireguard,
|
||||
}.WithDefaults(""),
|
||||
port: defaultWireguard,
|
||||
},
|
||||
"Wireguard custom port": {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.Wireguard,
|
||||
VPN: vpn.Wireguard,
|
||||
Wireguard: settings.WireguardSelection{
|
||||
EndpointPort: uint16Ptr(1234),
|
||||
},
|
||||
|
||||
@@ -3,10 +3,11 @@ package utils
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||
)
|
||||
|
||||
func GetProtocol(selection settings.ServerSelection) (protocol string) {
|
||||
if selection.VPN == constants.OpenVPN && *selection.OpenVPN.TCP {
|
||||
if selection.VPN == vpn.OpenVPN && *selection.OpenVPN.TCP {
|
||||
return constants.TCP
|
||||
}
|
||||
return constants.UDP
|
||||
@@ -15,7 +16,7 @@ func GetProtocol(selection settings.ServerSelection) (protocol string) {
|
||||
func FilterByProtocol(selection settings.ServerSelection,
|
||||
serverTCP, serverUDP bool) (filtered bool) {
|
||||
switch selection.VPN {
|
||||
case constants.Wireguard:
|
||||
case vpn.Wireguard:
|
||||
return !serverUDP
|
||||
default: // OpenVPN
|
||||
wantTCP := *selection.OpenVPN.TCP
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -20,7 +21,7 @@ func Test_GetProtocol(t *testing.T) {
|
||||
},
|
||||
"OpenVPN UDP": {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
VPN: vpn.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(false),
|
||||
},
|
||||
@@ -29,7 +30,7 @@ func Test_GetProtocol(t *testing.T) {
|
||||
},
|
||||
"OpenVPN TCP": {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
VPN: vpn.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(true),
|
||||
},
|
||||
@@ -38,7 +39,7 @@ func Test_GetProtocol(t *testing.T) {
|
||||
},
|
||||
"Wireguard": {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.Wireguard,
|
||||
VPN: vpn.Wireguard,
|
||||
},
|
||||
protocol: constants.UDP,
|
||||
},
|
||||
@@ -67,21 +68,21 @@ func Test_FilterByProtocol(t *testing.T) {
|
||||
}{
|
||||
"Wireguard and server has UDP": {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.Wireguard,
|
||||
VPN: vpn.Wireguard,
|
||||
},
|
||||
serverUDP: true,
|
||||
filtered: false,
|
||||
},
|
||||
"Wireguard and server has not UDP": {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.Wireguard,
|
||||
VPN: vpn.Wireguard,
|
||||
},
|
||||
serverUDP: false,
|
||||
filtered: true,
|
||||
},
|
||||
"OpenVPN UDP and server has UDP": {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
VPN: vpn.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(false),
|
||||
},
|
||||
@@ -91,7 +92,7 @@ func Test_FilterByProtocol(t *testing.T) {
|
||||
},
|
||||
"OpenVPN UDP and server has not UDP": {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
VPN: vpn.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(false),
|
||||
},
|
||||
@@ -101,7 +102,7 @@ func Test_FilterByProtocol(t *testing.T) {
|
||||
},
|
||||
"OpenVPN TCP and server has TCP": {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
VPN: vpn.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(true),
|
||||
},
|
||||
@@ -111,7 +112,7 @@ func Test_FilterByProtocol(t *testing.T) {
|
||||
},
|
||||
"OpenVPN TCP and server has not TCP": {
|
||||
selection: settings.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
VPN: vpn.OpenVPN,
|
||||
OpenVPN: settings.OpenVPNSelection{
|
||||
TCP: boolPtr(true),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user