chore(constants): internal/constants/vpn package
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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 == "":
|
||||
|
||||
@@ -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"
|
||||
6
internal/constants/vpn/protocol.go
Normal file
6
internal/constants/vpn/protocol.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package vpn
|
||||
|
||||
const (
|
||||
OpenVPN = "openvpn"
|
||||
Wireguard = "wireguard"
|
||||
)
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
},
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user