diff --git a/internal/configuration/settings/provider.go b/internal/configuration/settings/provider.go index f39ed1fc..1e237511 100644 --- a/internal/configuration/settings/provider.go +++ b/internal/configuration/settings/provider.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/qdm12/gluetun/internal/configuration/settings/helpers" - "github.com/qdm12/gluetun/internal/constants" "github.com/qdm12/gluetun/internal/constants/providers" + "github.com/qdm12/gluetun/internal/constants/vpn" "github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gotree" ) @@ -26,7 +26,7 @@ type Provider struct { func (p *Provider) validate(vpnType string, allServers models.AllServers) (err error) { // Validate Name var validNames []string - if vpnType == constants.OpenVPN { + if vpnType == vpn.OpenVPN { validNames = providers.All() validNames = append(validNames, "pia") // Retro-compatibility } else { // Wireguard diff --git a/internal/configuration/settings/serverselection.go b/internal/configuration/settings/serverselection.go index bd1b954c..a8b84390 100644 --- a/internal/configuration/settings/serverselection.go +++ b/internal/configuration/settings/serverselection.go @@ -8,8 +8,8 @@ import ( "github.com/qdm12/gluetun/internal/configuration/settings/helpers" "github.com/qdm12/gluetun/internal/configuration/settings/validation" - "github.com/qdm12/gluetun/internal/constants" "github.com/qdm12/gluetun/internal/constants/providers" + "github.com/qdm12/gluetun/internal/constants/vpn" "github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gotree" ) @@ -70,7 +70,7 @@ var ( func (ss *ServerSelection) validate(vpnServiceProvider string, allServers models.AllServers) (err error) { switch ss.VPN { - case constants.OpenVPN, constants.Wireguard: + case vpn.OpenVPN, vpn.Wireguard: default: return fmt.Errorf("%w: %s", ErrVPNTypeNotValid, ss.VPN) } @@ -120,7 +120,7 @@ func (ss *ServerSelection) validate(vpnServiceProvider string, ErrMultiHopOnlyNotSupported, vpnServiceProvider) } - if ss.VPN == constants.OpenVPN { + if ss.VPN == vpn.OpenVPN { err = ss.OpenVPN.validate(vpnServiceProvider) if err != nil { return fmt.Errorf("OpenVPN server selection settings: %w", err) @@ -348,7 +348,7 @@ func (ss *ServerSelection) overrideWith(other ServerSelection) { } func (ss *ServerSelection) setDefaults(vpnProvider string) { - ss.VPN = helpers.DefaultString(ss.VPN, constants.OpenVPN) + ss.VPN = helpers.DefaultString(ss.VPN, vpn.OpenVPN) ss.TargetIP = helpers.DefaultIP(ss.TargetIP, net.IP{}) ss.OwnedOnly = helpers.DefaultBool(ss.OwnedOnly, false) ss.FreeOnly = helpers.DefaultBool(ss.FreeOnly, false) @@ -416,7 +416,7 @@ func (ss ServerSelection) toLinesNode() (node *gotree.Node) { node.Appendf("Multi-hop only servers: yes") } - if ss.VPN == constants.OpenVPN { + if ss.VPN == vpn.OpenVPN { node.AppendNode(ss.OpenVPN.toLinesNode()) } else { node.AppendNode(ss.Wireguard.toLinesNode()) diff --git a/internal/configuration/settings/vpn.go b/internal/configuration/settings/vpn.go index 10f28a8c..fb8cfe2d 100644 --- a/internal/configuration/settings/vpn.go +++ b/internal/configuration/settings/vpn.go @@ -5,7 +5,7 @@ import ( "strings" "github.com/qdm12/gluetun/internal/configuration/settings/helpers" - "github.com/qdm12/gluetun/internal/constants" + "github.com/qdm12/gluetun/internal/constants/vpn" "github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gotree" ) @@ -23,7 +23,7 @@ type VPN struct { // TODO v4 remove pointer for receiver (because of Surfshark). func (v *VPN) validate(allServers models.AllServers) (err error) { // Validate Type - validVPNTypes := []string{constants.OpenVPN, constants.Wireguard} + validVPNTypes := []string{vpn.OpenVPN, vpn.Wireguard} if !helpers.IsOneOf(v.Type, validVPNTypes...) { return fmt.Errorf("%w: %q and can only be one of %s", ErrVPNTypeNotValid, v.Type, strings.Join(validVPNTypes, ", ")) @@ -34,7 +34,7 @@ func (v *VPN) validate(allServers models.AllServers) (err error) { return fmt.Errorf("provider settings: %w", err) } - if v.Type == constants.OpenVPN { + if v.Type == vpn.OpenVPN { err := v.OpenVPN.validate(*v.Provider.Name) if err != nil { return fmt.Errorf("OpenVPN settings: %w", err) @@ -73,7 +73,7 @@ func (v *VPN) overrideWith(other VPN) { } func (v *VPN) setDefaults() { - v.Type = helpers.DefaultString(v.Type, constants.OpenVPN) + v.Type = helpers.DefaultString(v.Type, vpn.OpenVPN) v.Provider.setDefaults() v.OpenVPN.setDefaults(*v.Provider.Name) v.Wireguard.setDefaults() @@ -88,7 +88,7 @@ func (v VPN) toLinesNode() (node *gotree.Node) { node.AppendNode(v.Provider.toLinesNode()) - if v.Type == constants.OpenVPN { + if v.Type == vpn.OpenVPN { node.AppendNode(v.OpenVPN.toLinesNode()) } else { node.AppendNode(v.Wireguard.toLinesNode()) diff --git a/internal/configuration/sources/env/provider.go b/internal/configuration/sources/env/provider.go index 059c6b8c..8cc498e3 100644 --- a/internal/configuration/sources/env/provider.go +++ b/internal/configuration/sources/env/provider.go @@ -6,8 +6,8 @@ import ( "strings" "github.com/qdm12/gluetun/internal/configuration/settings" - "github.com/qdm12/gluetun/internal/constants" "github.com/qdm12/gluetun/internal/constants/providers" + "github.com/qdm12/gluetun/internal/constants/vpn" ) func (r *Reader) readProvider(vpnType string) (provider settings.Provider, err error) { @@ -34,7 +34,7 @@ func (r *Reader) readVPNServiceProvider(vpnType string) (vpnProviderPtr *string) _, s := r.getEnvWithRetro("VPN_SERVICE_PROVIDER", "VPNSP") s = strings.ToLower(s) switch { - case vpnType != constants.Wireguard && + case vpnType != vpn.Wireguard && os.Getenv("OPENVPN_CUSTOM_CONFIG") != "": // retro compatibility return stringPtr(providers.Custom) case s == "": diff --git a/internal/constants/vpn.go b/internal/constants/protocol.go similarity index 76% rename from internal/constants/vpn.go rename to internal/constants/protocol.go index 0b973b06..41b403bf 100644 --- a/internal/constants/vpn.go +++ b/internal/constants/protocol.go @@ -1,10 +1,5 @@ package constants -const ( - OpenVPN = "openvpn" - Wireguard = "wireguard" -) - const ( // TCP is a network protocol (reliable and slower than UDP). TCP string = "tcp" diff --git a/internal/constants/vpn/protocol.go b/internal/constants/vpn/protocol.go new file mode 100644 index 00000000..1fd36b88 --- /dev/null +++ b/internal/constants/vpn/protocol.go @@ -0,0 +1,6 @@ +package vpn + +const ( + OpenVPN = "openvpn" + Wireguard = "wireguard" +) diff --git a/internal/provider/custom/connection.go b/internal/provider/custom/connection.go index 770a30b8..4e85ee3c 100644 --- a/internal/provider/custom/connection.go +++ b/internal/provider/custom/connection.go @@ -6,6 +6,7 @@ import ( "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" "github.com/qdm12/gluetun/internal/openvpn/extract" "github.com/qdm12/gluetun/internal/provider/utils" @@ -19,9 +20,9 @@ var ( func (p *Provider) GetConnection(selection settings.ServerSelection) ( connection models.Connection, err error) { switch selection.VPN { - case constants.OpenVPN: + case vpn.OpenVPN: return getOpenVPNConnection(p.extractor, selection) - case constants.Wireguard: + case vpn.Wireguard: return getWireguardConnection(selection), nil default: return connection, fmt.Errorf("%w: %s", ErrVPNTypeNotSupported, selection.VPN) @@ -44,7 +45,7 @@ func getWireguardConnection(selection settings.ServerSelection) ( connection models.Connection) { port := getPort(*selection.Wireguard.EndpointPort, selection) return models.Connection{ - Type: constants.Wireguard, + Type: vpn.Wireguard, IP: selection.Wireguard.EndpointIP, Port: port, Protocol: constants.UDP, diff --git a/internal/provider/expressvpn/connection_test.go b/internal/provider/expressvpn/connection_test.go index 239f669b..f53d6a7a 100644 --- a/internal/provider/expressvpn/connection_test.go +++ b/internal/provider/expressvpn/connection_test.go @@ -9,6 +9,7 @@ import ( "github.com/qdm12/gluetun/internal/configuration/settings" "github.com/qdm12/gluetun/internal/constants" "github.com/qdm12/gluetun/internal/constants/providers" + "github.com/qdm12/gluetun/internal/constants/vpn" "github.com/qdm12/gluetun/internal/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -35,7 +36,7 @@ func Test_Provider_GetConnection(t *testing.T) { }, selection: settings.ServerSelection{}.WithDefaults(providers.Expressvpn), connection: models.Connection{ - Type: constants.OpenVPN, + Type: vpn.OpenVPN, IP: net.IPv4(1, 1, 1, 1), Port: 1195, Protocol: constants.UDP, @@ -51,7 +52,7 @@ func Test_Provider_GetConnection(t *testing.T) { {IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true}, }, connection: models.Connection{ - Type: constants.OpenVPN, + Type: vpn.OpenVPN, IP: net.IPv4(2, 2, 2, 2), Port: 1195, Protocol: constants.UDP, @@ -67,7 +68,7 @@ func Test_Provider_GetConnection(t *testing.T) { {Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true}, }, connection: models.Connection{ - Type: constants.OpenVPN, + Type: vpn.OpenVPN, IP: net.IPv4(2, 2, 2, 2), Port: 1195, Protocol: constants.UDP, diff --git a/internal/provider/ivpn/connection_test.go b/internal/provider/ivpn/connection_test.go index c7c185ae..6e6bf813 100644 --- a/internal/provider/ivpn/connection_test.go +++ b/internal/provider/ivpn/connection_test.go @@ -9,6 +9,7 @@ import ( "github.com/qdm12/gluetun/internal/configuration/settings" "github.com/qdm12/gluetun/internal/constants" "github.com/qdm12/gluetun/internal/constants/providers" + "github.com/qdm12/gluetun/internal/constants/vpn" "github.com/qdm12/gluetun/internal/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -29,13 +30,13 @@ func Test_Ivpn_GetConnection(t *testing.T) { }, "no filter": { servers: []models.Server{ - {VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true}, - {VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true}, - {VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true}, + {VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true}, + {VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true}, + {VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true}, }, selection: settings.ServerSelection{}.WithDefaults(providers.Ivpn), connection: models.Connection{ - Type: constants.OpenVPN, + Type: vpn.OpenVPN, IP: net.IPv4(1, 1, 1, 1), Port: 1194, Protocol: constants.UDP, @@ -46,12 +47,12 @@ func Test_Ivpn_GetConnection(t *testing.T) { TargetIP: net.IPv4(2, 2, 2, 2), }.WithDefaults(providers.Ivpn), servers: []models.Server{ - {VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true}, - {VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true}, - {VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true}, + {VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true}, + {VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true}, + {VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true}, }, connection: models.Connection{ - Type: constants.OpenVPN, + Type: vpn.OpenVPN, IP: net.IPv4(2, 2, 2, 2), Port: 1194, Protocol: constants.UDP, @@ -62,12 +63,12 @@ func Test_Ivpn_GetConnection(t *testing.T) { Hostnames: []string{"b"}, }.WithDefaults(providers.Ivpn), servers: []models.Server{ - {VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true}, - {VPN: constants.OpenVPN, Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true}, - {VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true}, + {VPN: vpn.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true}, + {VPN: vpn.OpenVPN, Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true}, + {VPN: vpn.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true}, }, connection: models.Connection{ - Type: constants.OpenVPN, + Type: vpn.OpenVPN, IP: net.IPv4(2, 2, 2, 2), Port: 1194, Protocol: constants.UDP, diff --git a/internal/provider/ivpn/filter_test.go b/internal/provider/ivpn/filter_test.go index fccddbca..b6f6088b 100644 --- a/internal/provider/ivpn/filter_test.go +++ b/internal/provider/ivpn/filter_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/qdm12/gluetun/internal/configuration/settings" - "github.com/qdm12/gluetun/internal/constants" "github.com/qdm12/gluetun/internal/constants/providers" + "github.com/qdm12/gluetun/internal/constants/vpn" "github.com/qdm12/gluetun/internal/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -30,15 +30,15 @@ func Test_Ivpn_filterServers(t *testing.T) { }, "no filter": { servers: []models.Server{ - {VPN: constants.OpenVPN, Hostname: "a", UDP: true}, - {VPN: constants.OpenVPN, Hostname: "b", UDP: true}, - {VPN: constants.OpenVPN, Hostname: "c", UDP: true}, + {VPN: vpn.OpenVPN, Hostname: "a", UDP: true}, + {VPN: vpn.OpenVPN, Hostname: "b", UDP: true}, + {VPN: vpn.OpenVPN, Hostname: "c", UDP: true}, }, selection: settings.ServerSelection{}.WithDefaults(providers.Ivpn), filtered: []models.Server{ - {VPN: constants.OpenVPN, Hostname: "a", UDP: true}, - {VPN: constants.OpenVPN, Hostname: "b", UDP: true}, - {VPN: constants.OpenVPN, Hostname: "c", UDP: true}, + {VPN: vpn.OpenVPN, Hostname: "a", UDP: true}, + {VPN: vpn.OpenVPN, Hostname: "b", UDP: true}, + {VPN: vpn.OpenVPN, Hostname: "c", UDP: true}, }, }, "filter by country": { @@ -46,12 +46,12 @@ func Test_Ivpn_filterServers(t *testing.T) { Countries: []string{"b"}, }.WithDefaults(providers.Ivpn), servers: []models.Server{ - {VPN: constants.OpenVPN, Country: "a", UDP: true}, - {VPN: constants.OpenVPN, Country: "b", UDP: true}, - {VPN: constants.OpenVPN, Country: "c", UDP: true}, + {VPN: vpn.OpenVPN, Country: "a", UDP: true}, + {VPN: vpn.OpenVPN, Country: "b", UDP: true}, + {VPN: vpn.OpenVPN, Country: "c", UDP: true}, }, filtered: []models.Server{ - {VPN: constants.OpenVPN, Country: "b", UDP: true}, + {VPN: vpn.OpenVPN, Country: "b", UDP: true}, }, }, "filter by city": { @@ -59,12 +59,12 @@ func Test_Ivpn_filterServers(t *testing.T) { Cities: []string{"b"}, }.WithDefaults(providers.Ivpn), servers: []models.Server{ - {VPN: constants.OpenVPN, City: "a", UDP: true}, - {VPN: constants.OpenVPN, City: "b", UDP: true}, - {VPN: constants.OpenVPN, City: "c", UDP: true}, + {VPN: vpn.OpenVPN, City: "a", UDP: true}, + {VPN: vpn.OpenVPN, City: "b", UDP: true}, + {VPN: vpn.OpenVPN, City: "c", UDP: true}, }, filtered: []models.Server{ - {VPN: constants.OpenVPN, City: "b", UDP: true}, + {VPN: vpn.OpenVPN, City: "b", UDP: true}, }, }, "filter by ISP": { @@ -72,12 +72,12 @@ func Test_Ivpn_filterServers(t *testing.T) { ISPs: []string{"b"}, }.WithDefaults(providers.Ivpn), servers: []models.Server{ - {VPN: constants.OpenVPN, ISP: "a", UDP: true}, - {VPN: constants.OpenVPN, ISP: "b", UDP: true}, - {VPN: constants.OpenVPN, ISP: "c", UDP: true}, + {VPN: vpn.OpenVPN, ISP: "a", UDP: true}, + {VPN: vpn.OpenVPN, ISP: "b", UDP: true}, + {VPN: vpn.OpenVPN, ISP: "c", UDP: true}, }, filtered: []models.Server{ - {VPN: constants.OpenVPN, ISP: "b", UDP: true}, + {VPN: vpn.OpenVPN, ISP: "b", UDP: true}, }, }, "filter by hostname": { @@ -85,12 +85,12 @@ func Test_Ivpn_filterServers(t *testing.T) { Hostnames: []string{"b"}, }.WithDefaults(providers.Ivpn), servers: []models.Server{ - {VPN: constants.OpenVPN, Hostname: "a", UDP: true}, - {VPN: constants.OpenVPN, Hostname: "b", UDP: true}, - {VPN: constants.OpenVPN, Hostname: "c", UDP: true}, + {VPN: vpn.OpenVPN, Hostname: "a", UDP: true}, + {VPN: vpn.OpenVPN, Hostname: "b", UDP: true}, + {VPN: vpn.OpenVPN, Hostname: "c", UDP: true}, }, filtered: []models.Server{ - {VPN: constants.OpenVPN, Hostname: "b", UDP: true}, + {VPN: vpn.OpenVPN, Hostname: "b", UDP: true}, }, }, "filter by protocol": { @@ -100,12 +100,12 @@ func Test_Ivpn_filterServers(t *testing.T) { }, }.WithDefaults(providers.Ivpn), servers: []models.Server{ - {VPN: constants.OpenVPN, Hostname: "a", UDP: true}, - {VPN: constants.OpenVPN, Hostname: "b", UDP: true, TCP: true}, - {VPN: constants.OpenVPN, Hostname: "c", UDP: true}, + {VPN: vpn.OpenVPN, Hostname: "a", UDP: true}, + {VPN: vpn.OpenVPN, Hostname: "b", UDP: true, TCP: true}, + {VPN: vpn.OpenVPN, Hostname: "c", UDP: true}, }, filtered: []models.Server{ - {VPN: constants.OpenVPN, Hostname: "b", UDP: true, TCP: true}, + {VPN: vpn.OpenVPN, Hostname: "b", UDP: true, TCP: true}, }, }, } diff --git a/internal/provider/mullvad/connection_test.go b/internal/provider/mullvad/connection_test.go index 551ec87e..d90c9fab 100644 --- a/internal/provider/mullvad/connection_test.go +++ b/internal/provider/mullvad/connection_test.go @@ -9,6 +9,7 @@ import ( "github.com/qdm12/gluetun/internal/configuration/settings" "github.com/qdm12/gluetun/internal/constants" "github.com/qdm12/gluetun/internal/constants/providers" + "github.com/qdm12/gluetun/internal/constants/vpn" "github.com/qdm12/gluetun/internal/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -29,13 +30,13 @@ func Test_Mullvad_GetConnection(t *testing.T) { }, "no filter": { servers: []models.Server{ - {VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}}, - {VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}}, - {VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}}, + {VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}}, + {VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}}, + {VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}}, }, selection: settings.ServerSelection{}.WithDefaults(providers.Mullvad), connection: models.Connection{ - Type: constants.OpenVPN, + Type: vpn.OpenVPN, IP: net.IPv4(1, 1, 1, 1), Port: 1194, Protocol: constants.UDP, @@ -46,12 +47,12 @@ func Test_Mullvad_GetConnection(t *testing.T) { TargetIP: net.IPv4(2, 2, 2, 2), }.WithDefaults(providers.Mullvad), servers: []models.Server{ - {VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}}, - {VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}}, - {VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}}, + {VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}}, + {VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}}, + {VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}}, }, connection: models.Connection{ - Type: constants.OpenVPN, + Type: vpn.OpenVPN, IP: net.IPv4(2, 2, 2, 2), Port: 1194, Protocol: constants.UDP, @@ -62,12 +63,12 @@ func Test_Mullvad_GetConnection(t *testing.T) { Hostnames: []string{"b"}, }.WithDefaults(providers.Mullvad), servers: []models.Server{ - {VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}}, - {VPN: constants.OpenVPN, Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}}, - {VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}}, + {VPN: vpn.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}}, + {VPN: vpn.OpenVPN, Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}}, + {VPN: vpn.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}}, }, connection: models.Connection{ - Type: constants.OpenVPN, + Type: vpn.OpenVPN, IP: net.IPv4(2, 2, 2, 2), Port: 1194, Protocol: constants.UDP, diff --git a/internal/provider/mullvad/filter_test.go b/internal/provider/mullvad/filter_test.go index df3c1b1d..f63ddb27 100644 --- a/internal/provider/mullvad/filter_test.go +++ b/internal/provider/mullvad/filter_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/qdm12/gluetun/internal/configuration/settings" - "github.com/qdm12/gluetun/internal/constants" "github.com/qdm12/gluetun/internal/constants/providers" + "github.com/qdm12/gluetun/internal/constants/vpn" "github.com/qdm12/gluetun/internal/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -30,28 +30,28 @@ func Test_Mullvad_filterServers(t *testing.T) { }, "no filter": { servers: []models.Server{ - {VPN: constants.OpenVPN, Hostname: "a"}, - {VPN: constants.OpenVPN, Hostname: "b"}, - {VPN: constants.OpenVPN, Hostname: "c"}, + {VPN: vpn.OpenVPN, Hostname: "a"}, + {VPN: vpn.OpenVPN, Hostname: "b"}, + {VPN: vpn.OpenVPN, Hostname: "c"}, }, selection: settings.ServerSelection{}.WithDefaults(providers.Mullvad), filtered: []models.Server{ - {VPN: constants.OpenVPN, Hostname: "a"}, - {VPN: constants.OpenVPN, Hostname: "b"}, - {VPN: constants.OpenVPN, Hostname: "c"}, + {VPN: vpn.OpenVPN, Hostname: "a"}, + {VPN: vpn.OpenVPN, Hostname: "b"}, + {VPN: vpn.OpenVPN, Hostname: "c"}, }, }, "filter OpenVPN out": { selection: settings.ServerSelection{ - VPN: constants.Wireguard, + VPN: vpn.Wireguard, }.WithDefaults(providers.Mullvad), servers: []models.Server{ - {VPN: constants.OpenVPN, Hostname: "a"}, - {VPN: constants.Wireguard, Hostname: "b"}, - {VPN: constants.OpenVPN, Hostname: "c"}, + {VPN: vpn.OpenVPN, Hostname: "a"}, + {VPN: vpn.Wireguard, Hostname: "b"}, + {VPN: vpn.OpenVPN, Hostname: "c"}, }, filtered: []models.Server{ - {VPN: constants.Wireguard, Hostname: "b"}, + {VPN: vpn.Wireguard, Hostname: "b"}, }, }, "filter by country": { @@ -59,12 +59,12 @@ func Test_Mullvad_filterServers(t *testing.T) { Countries: []string{"b"}, }.WithDefaults(providers.Mullvad), servers: []models.Server{ - {VPN: constants.OpenVPN, Country: "a"}, - {VPN: constants.OpenVPN, Country: "b"}, - {VPN: constants.OpenVPN, Country: "c"}, + {VPN: vpn.OpenVPN, Country: "a"}, + {VPN: vpn.OpenVPN, Country: "b"}, + {VPN: vpn.OpenVPN, Country: "c"}, }, filtered: []models.Server{ - {VPN: constants.OpenVPN, Country: "b"}, + {VPN: vpn.OpenVPN, Country: "b"}, }, }, "filter by city": { @@ -72,12 +72,12 @@ func Test_Mullvad_filterServers(t *testing.T) { Cities: []string{"b"}, }.WithDefaults(providers.Mullvad), servers: []models.Server{ - {VPN: constants.OpenVPN, City: "a"}, - {VPN: constants.OpenVPN, City: "b"}, - {VPN: constants.OpenVPN, City: "c"}, + {VPN: vpn.OpenVPN, City: "a"}, + {VPN: vpn.OpenVPN, City: "b"}, + {VPN: vpn.OpenVPN, City: "c"}, }, filtered: []models.Server{ - {VPN: constants.OpenVPN, City: "b"}, + {VPN: vpn.OpenVPN, City: "b"}, }, }, "filter by ISP": { @@ -85,12 +85,12 @@ func Test_Mullvad_filterServers(t *testing.T) { ISPs: []string{"b"}, }.WithDefaults(providers.Mullvad), servers: []models.Server{ - {VPN: constants.OpenVPN, ISP: "a"}, - {VPN: constants.OpenVPN, ISP: "b"}, - {VPN: constants.OpenVPN, ISP: "c"}, + {VPN: vpn.OpenVPN, ISP: "a"}, + {VPN: vpn.OpenVPN, ISP: "b"}, + {VPN: vpn.OpenVPN, ISP: "c"}, }, filtered: []models.Server{ - {VPN: constants.OpenVPN, ISP: "b"}, + {VPN: vpn.OpenVPN, ISP: "b"}, }, }, "filter by hostname": { @@ -98,12 +98,12 @@ func Test_Mullvad_filterServers(t *testing.T) { Hostnames: []string{"b"}, }.WithDefaults(providers.Mullvad), servers: []models.Server{ - {VPN: constants.OpenVPN, Hostname: "a"}, - {VPN: constants.OpenVPN, Hostname: "b"}, - {VPN: constants.OpenVPN, Hostname: "c"}, + {VPN: vpn.OpenVPN, Hostname: "a"}, + {VPN: vpn.OpenVPN, Hostname: "b"}, + {VPN: vpn.OpenVPN, Hostname: "c"}, }, filtered: []models.Server{ - {VPN: constants.OpenVPN, Hostname: "b"}, + {VPN: vpn.OpenVPN, Hostname: "b"}, }, }, "filter by owned": { @@ -111,12 +111,12 @@ func Test_Mullvad_filterServers(t *testing.T) { OwnedOnly: boolPtr(true), }.WithDefaults(providers.Mullvad), servers: []models.Server{ - {VPN: constants.OpenVPN, Hostname: "a"}, - {VPN: constants.OpenVPN, Hostname: "b", Owned: true}, - {VPN: constants.OpenVPN, Hostname: "c"}, + {VPN: vpn.OpenVPN, Hostname: "a"}, + {VPN: vpn.OpenVPN, Hostname: "b", Owned: true}, + {VPN: vpn.OpenVPN, Hostname: "c"}, }, filtered: []models.Server{ - {VPN: constants.OpenVPN, Hostname: "b", Owned: true}, + {VPN: vpn.OpenVPN, Hostname: "b", Owned: true}, }, }, } diff --git a/internal/provider/utils/pick.go b/internal/provider/utils/pick.go index 6b804b7a..d594a8a0 100644 --- a/internal/provider/utils/pick.go +++ b/internal/provider/utils/pick.go @@ -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) } diff --git a/internal/provider/utils/port.go b/internal/provider/utils/port.go index 6644adea..588d3b58 100644 --- a/internal/provider/utils/port.go +++ b/internal/provider/utils/port.go @@ -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 diff --git a/internal/provider/utils/port_test.go b/internal/provider/utils/port_test.go index e2719451..47c2f7a6 100644 --- a/internal/provider/utils/port_test.go +++ b/internal/provider/utils/port_test.go @@ -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), }, diff --git a/internal/provider/utils/protocol.go b/internal/provider/utils/protocol.go index fe0a997f..56071e52 100644 --- a/internal/provider/utils/protocol.go +++ b/internal/provider/utils/protocol.go @@ -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 diff --git a/internal/provider/utils/protocol_test.go b/internal/provider/utils/protocol_test.go index 6d6ecfa1..b8a40870 100644 --- a/internal/provider/utils/protocol_test.go +++ b/internal/provider/utils/protocol_test.go @@ -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), }, diff --git a/internal/provider/wevpn/connection_test.go b/internal/provider/wevpn/connection_test.go index 0a75aafd..25042389 100644 --- a/internal/provider/wevpn/connection_test.go +++ b/internal/provider/wevpn/connection_test.go @@ -9,6 +9,7 @@ import ( "github.com/qdm12/gluetun/internal/configuration/settings" "github.com/qdm12/gluetun/internal/constants" "github.com/qdm12/gluetun/internal/constants/providers" + "github.com/qdm12/gluetun/internal/constants/vpn" "github.com/qdm12/gluetun/internal/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -25,7 +26,7 @@ func Test_Wevpn_GetConnection(t *testing.T) { }{ "no server available": { selection: settings.ServerSelection{ - VPN: constants.OpenVPN, + VPN: vpn.OpenVPN, }.WithDefaults(providers.Wevpn), err: errors.New("no server found: for VPN openvpn; protocol udp"), }, @@ -37,7 +38,7 @@ func Test_Wevpn_GetConnection(t *testing.T) { }, selection: settings.ServerSelection{}.WithDefaults(providers.Wevpn), connection: models.Connection{ - Type: constants.OpenVPN, + Type: vpn.OpenVPN, IP: net.IPv4(1, 1, 1, 1), Port: 1194, Protocol: constants.UDP, @@ -53,7 +54,7 @@ func Test_Wevpn_GetConnection(t *testing.T) { {UDP: true, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}}, }, connection: models.Connection{ - Type: constants.OpenVPN, + Type: vpn.OpenVPN, IP: net.IPv4(2, 2, 2, 2), Port: 1194, Protocol: constants.UDP, @@ -69,7 +70,7 @@ func Test_Wevpn_GetConnection(t *testing.T) { {UDP: true, Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}}, }, connection: models.Connection{ - Type: constants.OpenVPN, + Type: vpn.OpenVPN, IP: net.IPv4(2, 2, 2, 2), Port: 1194, Protocol: constants.UDP, diff --git a/internal/provider/windscribe/connection_test.go b/internal/provider/windscribe/connection_test.go index b13dd898..ced6dd89 100644 --- a/internal/provider/windscribe/connection_test.go +++ b/internal/provider/windscribe/connection_test.go @@ -9,6 +9,7 @@ import ( "github.com/qdm12/gluetun/internal/configuration/settings" "github.com/qdm12/gluetun/internal/constants" "github.com/qdm12/gluetun/internal/constants/providers" + "github.com/qdm12/gluetun/internal/constants/vpn" "github.com/qdm12/gluetun/internal/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -29,13 +30,13 @@ func Test_Windscribe_GetConnection(t *testing.T) { }, "no filter": { servers: []models.Server{ - {VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}}, - {VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}}, - {VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}}, + {VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}}, + {VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}}, + {VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}}, }, selection: settings.ServerSelection{}.WithDefaults(providers.Windscribe), connection: models.Connection{ - Type: constants.OpenVPN, + Type: vpn.OpenVPN, IP: net.IPv4(1, 1, 1, 1), Port: 1194, Protocol: constants.UDP, @@ -46,12 +47,12 @@ func Test_Windscribe_GetConnection(t *testing.T) { TargetIP: net.IPv4(2, 2, 2, 2), }.WithDefaults(providers.Windscribe), servers: []models.Server{ - {VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}}, - {VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}}, - {VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}}, + {VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}}, + {VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}}, + {VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}}, }, connection: models.Connection{ - Type: constants.OpenVPN, + Type: vpn.OpenVPN, IP: net.IPv4(2, 2, 2, 2), Port: 1194, Protocol: constants.UDP, @@ -62,12 +63,12 @@ func Test_Windscribe_GetConnection(t *testing.T) { Hostnames: []string{"b"}, }.WithDefaults(providers.Windscribe), servers: []models.Server{ - {VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}}, - {VPN: constants.OpenVPN, Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}}, - {VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}}, + {VPN: vpn.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}}, + {VPN: vpn.OpenVPN, Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}}, + {VPN: vpn.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}}, }, connection: models.Connection{ - Type: constants.OpenVPN, + Type: vpn.OpenVPN, IP: net.IPv4(2, 2, 2, 2), Port: 1194, Protocol: constants.UDP, diff --git a/internal/provider/windscribe/filter_test.go b/internal/provider/windscribe/filter_test.go index 3f1ecd1e..dbb836db 100644 --- a/internal/provider/windscribe/filter_test.go +++ b/internal/provider/windscribe/filter_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/qdm12/gluetun/internal/configuration/settings" - "github.com/qdm12/gluetun/internal/constants" "github.com/qdm12/gluetun/internal/constants/providers" + "github.com/qdm12/gluetun/internal/constants/vpn" "github.com/qdm12/gluetun/internal/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -28,28 +28,28 @@ func Test_Windscribe_filterServers(t *testing.T) { }, "no filter": { servers: []models.Server{ - {VPN: constants.OpenVPN, Hostname: "a"}, - {VPN: constants.OpenVPN, Hostname: "b"}, - {VPN: constants.OpenVPN, Hostname: "c"}, + {VPN: vpn.OpenVPN, Hostname: "a"}, + {VPN: vpn.OpenVPN, Hostname: "b"}, + {VPN: vpn.OpenVPN, Hostname: "c"}, }, selection: settings.ServerSelection{}.WithDefaults(providers.Windscribe), filtered: []models.Server{ - {VPN: constants.OpenVPN, Hostname: "a"}, - {VPN: constants.OpenVPN, Hostname: "b"}, - {VPN: constants.OpenVPN, Hostname: "c"}, + {VPN: vpn.OpenVPN, Hostname: "a"}, + {VPN: vpn.OpenVPN, Hostname: "b"}, + {VPN: vpn.OpenVPN, Hostname: "c"}, }, }, "filter OpenVPN out": { selection: settings.ServerSelection{ - VPN: constants.Wireguard, + VPN: vpn.Wireguard, }.WithDefaults(providers.Windscribe), servers: []models.Server{ - {VPN: constants.OpenVPN, Hostname: "a"}, - {VPN: constants.Wireguard, Hostname: "b"}, - {VPN: constants.OpenVPN, Hostname: "c"}, + {VPN: vpn.OpenVPN, Hostname: "a"}, + {VPN: vpn.Wireguard, Hostname: "b"}, + {VPN: vpn.OpenVPN, Hostname: "c"}, }, filtered: []models.Server{ - {VPN: constants.Wireguard, Hostname: "b"}, + {VPN: vpn.Wireguard, Hostname: "b"}, }, }, "filter by region": { @@ -57,12 +57,12 @@ func Test_Windscribe_filterServers(t *testing.T) { Regions: []string{"b"}, }.WithDefaults(providers.Windscribe), servers: []models.Server{ - {VPN: constants.OpenVPN, Region: "a"}, - {VPN: constants.OpenVPN, Region: "b"}, - {VPN: constants.OpenVPN, Region: "c"}, + {VPN: vpn.OpenVPN, Region: "a"}, + {VPN: vpn.OpenVPN, Region: "b"}, + {VPN: vpn.OpenVPN, Region: "c"}, }, filtered: []models.Server{ - {VPN: constants.OpenVPN, Region: "b"}, + {VPN: vpn.OpenVPN, Region: "b"}, }, }, "filter by city": { @@ -70,12 +70,12 @@ func Test_Windscribe_filterServers(t *testing.T) { Cities: []string{"b"}, }.WithDefaults(providers.Windscribe), servers: []models.Server{ - {VPN: constants.OpenVPN, City: "a"}, - {VPN: constants.OpenVPN, City: "b"}, - {VPN: constants.OpenVPN, City: "c"}, + {VPN: vpn.OpenVPN, City: "a"}, + {VPN: vpn.OpenVPN, City: "b"}, + {VPN: vpn.OpenVPN, City: "c"}, }, filtered: []models.Server{ - {VPN: constants.OpenVPN, City: "b"}, + {VPN: vpn.OpenVPN, City: "b"}, }, }, "filter by hostname": { @@ -83,12 +83,12 @@ func Test_Windscribe_filterServers(t *testing.T) { Hostnames: []string{"b"}, }.WithDefaults(providers.Windscribe), servers: []models.Server{ - {VPN: constants.OpenVPN, Hostname: "a"}, - {VPN: constants.OpenVPN, Hostname: "b"}, - {VPN: constants.OpenVPN, Hostname: "c"}, + {VPN: vpn.OpenVPN, Hostname: "a"}, + {VPN: vpn.OpenVPN, Hostname: "b"}, + {VPN: vpn.OpenVPN, Hostname: "c"}, }, filtered: []models.Server{ - {VPN: constants.OpenVPN, Hostname: "b"}, + {VPN: vpn.OpenVPN, Hostname: "b"}, }, }, } diff --git a/internal/updater/providers/ivpn/servers.go b/internal/updater/providers/ivpn/servers.go index 064769d2..60cdb167 100644 --- a/internal/updater/providers/ivpn/servers.go +++ b/internal/updater/providers/ivpn/servers.go @@ -8,7 +8,7 @@ import ( "fmt" "net/http" - "github.com/qdm12/gluetun/internal/constants" + "github.com/qdm12/gluetun/internal/constants/vpn" "github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/updater/resolver" ) @@ -51,12 +51,12 @@ func GetServers(ctx context.Context, client *http.Client, servers = make([]models.Server, 0, len(hosts)) for _, serverData := range data.Servers { - vpnType := constants.OpenVPN + vpnType := vpn.OpenVPN hostname := serverData.Hostnames.OpenVPN tcp := true wgPubKey := "" if hostname == "" { - vpnType = constants.Wireguard + vpnType = vpn.Wireguard hostname = serverData.Hostnames.Wireguard tcp = false wgPubKey = serverData.WgPubKey diff --git a/internal/updater/providers/ivpn/servers_test.go b/internal/updater/providers/ivpn/servers_test.go index 47107e96..28e8547d 100644 --- a/internal/updater/providers/ivpn/servers_test.go +++ b/internal/updater/providers/ivpn/servers_test.go @@ -10,7 +10,7 @@ import ( "testing" "github.com/golang/mock/gomock" - "github.com/qdm12/gluetun/internal/constants" + "github.com/qdm12/gluetun/internal/constants/vpn" "github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/updater/resolver" "github.com/qdm12/gluetun/internal/updater/resolver/mock_resolver" @@ -85,13 +85,13 @@ func Test_GetServers(t *testing.T) { }, resolveWarnings: []string{"resolve warning"}, servers: []models.Server{ - {VPN: constants.OpenVPN, Country: "Country1", + {VPN: vpn.OpenVPN, Country: "Country1", City: "City A", Hostname: "hosta", TCP: true, UDP: true, IPs: []net.IP{{1, 1, 1, 1}, {2, 2, 2, 2}}}, - {VPN: constants.OpenVPN, Country: "Country2", + {VPN: vpn.OpenVPN, Country: "Country2", City: "City B", Hostname: "hostb", TCP: true, UDP: true, IPs: []net.IP{{3, 3, 3, 3}, {4, 4, 4, 4}}}, - {VPN: constants.Wireguard, + {VPN: vpn.Wireguard, Country: "Country3", City: "City C", Hostname: "hostc", UDP: true, WgPubKey: "xyz", diff --git a/internal/updater/providers/mullvad/hosttoserver.go b/internal/updater/providers/mullvad/hosttoserver.go index 7f05724e..92326dca 100644 --- a/internal/updater/providers/mullvad/hosttoserver.go +++ b/internal/updater/providers/mullvad/hosttoserver.go @@ -6,7 +6,7 @@ import ( "net" "strings" - "github.com/qdm12/gluetun/internal/constants" + "github.com/qdm12/gluetun/internal/constants/vpn" "github.com/qdm12/gluetun/internal/models" ) @@ -35,9 +35,9 @@ func (hts hostToServer) add(data serverData) (err error) { switch data.Type { case "openvpn": - server.VPN = constants.OpenVPN + server.VPN = vpn.OpenVPN case "wireguard": - server.VPN = constants.Wireguard + server.VPN = vpn.Wireguard case "bridge": // ignore bridge servers return nil diff --git a/internal/updater/providers/windscribe/servers.go b/internal/updater/providers/windscribe/servers.go index 80288c00..ca2b0ebb 100644 --- a/internal/updater/providers/windscribe/servers.go +++ b/internal/updater/providers/windscribe/servers.go @@ -9,7 +9,7 @@ import ( "net" "net/http" - "github.com/qdm12/gluetun/internal/constants" + "github.com/qdm12/gluetun/internal/constants/vpn" "github.com/qdm12/gluetun/internal/models" ) @@ -40,7 +40,7 @@ func GetServers(ctx context.Context, client *http.Client, minServers int) ( ips = append(ips, node.IP2) } server := models.Server{ - VPN: constants.OpenVPN, + VPN: vpn.OpenVPN, Region: region, City: city, Hostname: node.Hostname, @@ -55,7 +55,7 @@ func GetServers(ctx context.Context, client *http.Client, minServers int) ( return nil, fmt.Errorf("%w: for node %s", ErrNoWireguardKey, node.Hostname) } - server.VPN = constants.Wireguard + server.VPN = vpn.Wireguard server.OvpnX509 = "" server.WgPubKey = wgPubKey server.IPs = []net.IP{node.IP3} diff --git a/internal/vpn/run.go b/internal/vpn/run.go index 29e0bec4..9e40bd8d 100644 --- a/internal/vpn/run.go +++ b/internal/vpn/run.go @@ -5,6 +5,7 @@ import ( "time" "github.com/qdm12/gluetun/internal/constants" + "github.com/qdm12/gluetun/internal/constants/vpn" "github.com/qdm12/gluetun/internal/provider" "github.com/qdm12/log" ) @@ -36,7 +37,7 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) { var serverName, vpnInterface string var err error subLogger := l.logger.New(log.SetComponent(settings.Type)) - if settings.Type == constants.OpenVPN { + if settings.Type == vpn.OpenVPN { vpnInterface = settings.OpenVPN.Interface vpnRunner, serverName, err = setupOpenVPN(ctx, l.fw, l.openvpnConf, providerConf, settings, l.starter, subLogger)