chore(constants): internal/constants/vpn package
This commit is contained in:
@@ -4,8 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"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/providers"
|
||||||
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
)
|
)
|
||||||
@@ -26,7 +26,7 @@ type Provider struct {
|
|||||||
func (p *Provider) validate(vpnType string, allServers models.AllServers) (err error) {
|
func (p *Provider) validate(vpnType string, allServers models.AllServers) (err error) {
|
||||||
// Validate Name
|
// Validate Name
|
||||||
var validNames []string
|
var validNames []string
|
||||||
if vpnType == constants.OpenVPN {
|
if vpnType == vpn.OpenVPN {
|
||||||
validNames = providers.All()
|
validNames = providers.All()
|
||||||
validNames = append(validNames, "pia") // Retro-compatibility
|
validNames = append(validNames, "pia") // Retro-compatibility
|
||||||
} else { // Wireguard
|
} else { // Wireguard
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import (
|
|||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/validation"
|
"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/providers"
|
||||||
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
)
|
)
|
||||||
@@ -70,7 +70,7 @@ var (
|
|||||||
func (ss *ServerSelection) validate(vpnServiceProvider string,
|
func (ss *ServerSelection) validate(vpnServiceProvider string,
|
||||||
allServers models.AllServers) (err error) {
|
allServers models.AllServers) (err error) {
|
||||||
switch ss.VPN {
|
switch ss.VPN {
|
||||||
case constants.OpenVPN, constants.Wireguard:
|
case vpn.OpenVPN, vpn.Wireguard:
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("%w: %s", ErrVPNTypeNotValid, ss.VPN)
|
return fmt.Errorf("%w: %s", ErrVPNTypeNotValid, ss.VPN)
|
||||||
}
|
}
|
||||||
@@ -120,7 +120,7 @@ func (ss *ServerSelection) validate(vpnServiceProvider string,
|
|||||||
ErrMultiHopOnlyNotSupported, vpnServiceProvider)
|
ErrMultiHopOnlyNotSupported, vpnServiceProvider)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ss.VPN == constants.OpenVPN {
|
if ss.VPN == vpn.OpenVPN {
|
||||||
err = ss.OpenVPN.validate(vpnServiceProvider)
|
err = ss.OpenVPN.validate(vpnServiceProvider)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("OpenVPN server selection settings: %w", err)
|
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) {
|
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.TargetIP = helpers.DefaultIP(ss.TargetIP, net.IP{})
|
||||||
ss.OwnedOnly = helpers.DefaultBool(ss.OwnedOnly, false)
|
ss.OwnedOnly = helpers.DefaultBool(ss.OwnedOnly, false)
|
||||||
ss.FreeOnly = helpers.DefaultBool(ss.FreeOnly, 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")
|
node.Appendf("Multi-hop only servers: yes")
|
||||||
}
|
}
|
||||||
|
|
||||||
if ss.VPN == constants.OpenVPN {
|
if ss.VPN == vpn.OpenVPN {
|
||||||
node.AppendNode(ss.OpenVPN.toLinesNode())
|
node.AppendNode(ss.OpenVPN.toLinesNode())
|
||||||
} else {
|
} else {
|
||||||
node.AppendNode(ss.Wireguard.toLinesNode())
|
node.AppendNode(ss.Wireguard.toLinesNode())
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"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/gluetun/internal/models"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
)
|
)
|
||||||
@@ -23,7 +23,7 @@ type VPN struct {
|
|||||||
// TODO v4 remove pointer for receiver (because of Surfshark).
|
// TODO v4 remove pointer for receiver (because of Surfshark).
|
||||||
func (v *VPN) validate(allServers models.AllServers) (err error) {
|
func (v *VPN) validate(allServers models.AllServers) (err error) {
|
||||||
// Validate Type
|
// Validate Type
|
||||||
validVPNTypes := []string{constants.OpenVPN, constants.Wireguard}
|
validVPNTypes := []string{vpn.OpenVPN, vpn.Wireguard}
|
||||||
if !helpers.IsOneOf(v.Type, validVPNTypes...) {
|
if !helpers.IsOneOf(v.Type, validVPNTypes...) {
|
||||||
return fmt.Errorf("%w: %q and can only be one of %s",
|
return fmt.Errorf("%w: %q and can only be one of %s",
|
||||||
ErrVPNTypeNotValid, v.Type, strings.Join(validVPNTypes, ", "))
|
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)
|
return fmt.Errorf("provider settings: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.Type == constants.OpenVPN {
|
if v.Type == vpn.OpenVPN {
|
||||||
err := v.OpenVPN.validate(*v.Provider.Name)
|
err := v.OpenVPN.validate(*v.Provider.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("OpenVPN settings: %w", err)
|
return fmt.Errorf("OpenVPN settings: %w", err)
|
||||||
@@ -73,7 +73,7 @@ func (v *VPN) overrideWith(other VPN) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *VPN) setDefaults() {
|
func (v *VPN) setDefaults() {
|
||||||
v.Type = helpers.DefaultString(v.Type, constants.OpenVPN)
|
v.Type = helpers.DefaultString(v.Type, vpn.OpenVPN)
|
||||||
v.Provider.setDefaults()
|
v.Provider.setDefaults()
|
||||||
v.OpenVPN.setDefaults(*v.Provider.Name)
|
v.OpenVPN.setDefaults(*v.Provider.Name)
|
||||||
v.Wireguard.setDefaults()
|
v.Wireguard.setDefaults()
|
||||||
@@ -88,7 +88,7 @@ func (v VPN) toLinesNode() (node *gotree.Node) {
|
|||||||
|
|
||||||
node.AppendNode(v.Provider.toLinesNode())
|
node.AppendNode(v.Provider.toLinesNode())
|
||||||
|
|
||||||
if v.Type == constants.OpenVPN {
|
if v.Type == vpn.OpenVPN {
|
||||||
node.AppendNode(v.OpenVPN.toLinesNode())
|
node.AppendNode(v.OpenVPN.toLinesNode())
|
||||||
} else {
|
} else {
|
||||||
node.AppendNode(v.Wireguard.toLinesNode())
|
node.AppendNode(v.Wireguard.toLinesNode())
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"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/providers"
|
||||||
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *Reader) readProvider(vpnType string) (provider settings.Provider, err error) {
|
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 := r.getEnvWithRetro("VPN_SERVICE_PROVIDER", "VPNSP")
|
||||||
s = strings.ToLower(s)
|
s = strings.ToLower(s)
|
||||||
switch {
|
switch {
|
||||||
case vpnType != constants.Wireguard &&
|
case vpnType != vpn.Wireguard &&
|
||||||
os.Getenv("OPENVPN_CUSTOM_CONFIG") != "": // retro compatibility
|
os.Getenv("OPENVPN_CUSTOM_CONFIG") != "": // retro compatibility
|
||||||
return stringPtr(providers.Custom)
|
return stringPtr(providers.Custom)
|
||||||
case s == "":
|
case s == "":
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
package constants
|
package constants
|
||||||
|
|
||||||
const (
|
|
||||||
OpenVPN = "openvpn"
|
|
||||||
Wireguard = "wireguard"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// TCP is a network protocol (reliable and slower than UDP).
|
// TCP is a network protocol (reliable and slower than UDP).
|
||||||
TCP string = "tcp"
|
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/configuration/settings"
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/constants"
|
||||||
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
"github.com/qdm12/gluetun/internal/openvpn/extract"
|
"github.com/qdm12/gluetun/internal/openvpn/extract"
|
||||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
@@ -19,9 +20,9 @@ var (
|
|||||||
func (p *Provider) GetConnection(selection settings.ServerSelection) (
|
func (p *Provider) GetConnection(selection settings.ServerSelection) (
|
||||||
connection models.Connection, err error) {
|
connection models.Connection, err error) {
|
||||||
switch selection.VPN {
|
switch selection.VPN {
|
||||||
case constants.OpenVPN:
|
case vpn.OpenVPN:
|
||||||
return getOpenVPNConnection(p.extractor, selection)
|
return getOpenVPNConnection(p.extractor, selection)
|
||||||
case constants.Wireguard:
|
case vpn.Wireguard:
|
||||||
return getWireguardConnection(selection), nil
|
return getWireguardConnection(selection), nil
|
||||||
default:
|
default:
|
||||||
return connection, fmt.Errorf("%w: %s", ErrVPNTypeNotSupported, selection.VPN)
|
return connection, fmt.Errorf("%w: %s", ErrVPNTypeNotSupported, selection.VPN)
|
||||||
@@ -44,7 +45,7 @@ func getWireguardConnection(selection settings.ServerSelection) (
|
|||||||
connection models.Connection) {
|
connection models.Connection) {
|
||||||
port := getPort(*selection.Wireguard.EndpointPort, selection)
|
port := getPort(*selection.Wireguard.EndpointPort, selection)
|
||||||
return models.Connection{
|
return models.Connection{
|
||||||
Type: constants.Wireguard,
|
Type: vpn.Wireguard,
|
||||||
IP: selection.Wireguard.EndpointIP,
|
IP: selection.Wireguard.EndpointIP,
|
||||||
Port: port,
|
Port: port,
|
||||||
Protocol: constants.UDP,
|
Protocol: constants.UDP,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/constants"
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -35,7 +36,7 @@ func Test_Provider_GetConnection(t *testing.T) {
|
|||||||
},
|
},
|
||||||
selection: settings.ServerSelection{}.WithDefaults(providers.Expressvpn),
|
selection: settings.ServerSelection{}.WithDefaults(providers.Expressvpn),
|
||||||
connection: models.Connection{
|
connection: models.Connection{
|
||||||
Type: constants.OpenVPN,
|
Type: vpn.OpenVPN,
|
||||||
IP: net.IPv4(1, 1, 1, 1),
|
IP: net.IPv4(1, 1, 1, 1),
|
||||||
Port: 1195,
|
Port: 1195,
|
||||||
Protocol: constants.UDP,
|
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},
|
{IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
|
||||||
},
|
},
|
||||||
connection: models.Connection{
|
connection: models.Connection{
|
||||||
Type: constants.OpenVPN,
|
Type: vpn.OpenVPN,
|
||||||
IP: net.IPv4(2, 2, 2, 2),
|
IP: net.IPv4(2, 2, 2, 2),
|
||||||
Port: 1195,
|
Port: 1195,
|
||||||
Protocol: constants.UDP,
|
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},
|
{Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
|
||||||
},
|
},
|
||||||
connection: models.Connection{
|
connection: models.Connection{
|
||||||
Type: constants.OpenVPN,
|
Type: vpn.OpenVPN,
|
||||||
IP: net.IPv4(2, 2, 2, 2),
|
IP: net.IPv4(2, 2, 2, 2),
|
||||||
Port: 1195,
|
Port: 1195,
|
||||||
Protocol: constants.UDP,
|
Protocol: constants.UDP,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/constants"
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -29,13 +30,13 @@ func Test_Ivpn_GetConnection(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"no filter": {
|
"no filter": {
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true},
|
{VPN: vpn.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: vpn.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(3, 3, 3, 3)}, UDP: true},
|
||||||
},
|
},
|
||||||
selection: settings.ServerSelection{}.WithDefaults(providers.Ivpn),
|
selection: settings.ServerSelection{}.WithDefaults(providers.Ivpn),
|
||||||
connection: models.Connection{
|
connection: models.Connection{
|
||||||
Type: constants.OpenVPN,
|
Type: vpn.OpenVPN,
|
||||||
IP: net.IPv4(1, 1, 1, 1),
|
IP: net.IPv4(1, 1, 1, 1),
|
||||||
Port: 1194,
|
Port: 1194,
|
||||||
Protocol: constants.UDP,
|
Protocol: constants.UDP,
|
||||||
@@ -46,12 +47,12 @@ func Test_Ivpn_GetConnection(t *testing.T) {
|
|||||||
TargetIP: net.IPv4(2, 2, 2, 2),
|
TargetIP: net.IPv4(2, 2, 2, 2),
|
||||||
}.WithDefaults(providers.Ivpn),
|
}.WithDefaults(providers.Ivpn),
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true},
|
{VPN: vpn.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: vpn.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(3, 3, 3, 3)}, UDP: true},
|
||||||
},
|
},
|
||||||
connection: models.Connection{
|
connection: models.Connection{
|
||||||
Type: constants.OpenVPN,
|
Type: vpn.OpenVPN,
|
||||||
IP: net.IPv4(2, 2, 2, 2),
|
IP: net.IPv4(2, 2, 2, 2),
|
||||||
Port: 1194,
|
Port: 1194,
|
||||||
Protocol: constants.UDP,
|
Protocol: constants.UDP,
|
||||||
@@ -62,12 +63,12 @@ func Test_Ivpn_GetConnection(t *testing.T) {
|
|||||||
Hostnames: []string{"b"},
|
Hostnames: []string{"b"},
|
||||||
}.WithDefaults(providers.Ivpn),
|
}.WithDefaults(providers.Ivpn),
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true},
|
{VPN: vpn.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: vpn.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(3, 3, 3, 3)}, UDP: true},
|
||||||
},
|
},
|
||||||
connection: models.Connection{
|
connection: models.Connection{
|
||||||
Type: constants.OpenVPN,
|
Type: vpn.OpenVPN,
|
||||||
IP: net.IPv4(2, 2, 2, 2),
|
IP: net.IPv4(2, 2, 2, 2),
|
||||||
Port: 1194,
|
Port: 1194,
|
||||||
Protocol: constants.UDP,
|
Protocol: constants.UDP,
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"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/providers"
|
||||||
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -30,15 +30,15 @@ func Test_Ivpn_filterServers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"no filter": {
|
"no filter": {
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Hostname: "a", UDP: true},
|
{VPN: vpn.OpenVPN, Hostname: "a", UDP: true},
|
||||||
{VPN: constants.OpenVPN, Hostname: "b", UDP: true},
|
{VPN: vpn.OpenVPN, Hostname: "b", UDP: true},
|
||||||
{VPN: constants.OpenVPN, Hostname: "c", UDP: true},
|
{VPN: vpn.OpenVPN, Hostname: "c", UDP: true},
|
||||||
},
|
},
|
||||||
selection: settings.ServerSelection{}.WithDefaults(providers.Ivpn),
|
selection: settings.ServerSelection{}.WithDefaults(providers.Ivpn),
|
||||||
filtered: []models.Server{
|
filtered: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Hostname: "a", UDP: true},
|
{VPN: vpn.OpenVPN, Hostname: "a", UDP: true},
|
||||||
{VPN: constants.OpenVPN, Hostname: "b", UDP: true},
|
{VPN: vpn.OpenVPN, Hostname: "b", UDP: true},
|
||||||
{VPN: constants.OpenVPN, Hostname: "c", UDP: true},
|
{VPN: vpn.OpenVPN, Hostname: "c", UDP: true},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"filter by country": {
|
"filter by country": {
|
||||||
@@ -46,12 +46,12 @@ func Test_Ivpn_filterServers(t *testing.T) {
|
|||||||
Countries: []string{"b"},
|
Countries: []string{"b"},
|
||||||
}.WithDefaults(providers.Ivpn),
|
}.WithDefaults(providers.Ivpn),
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Country: "a", UDP: true},
|
{VPN: vpn.OpenVPN, Country: "a", UDP: true},
|
||||||
{VPN: constants.OpenVPN, Country: "b", UDP: true},
|
{VPN: vpn.OpenVPN, Country: "b", UDP: true},
|
||||||
{VPN: constants.OpenVPN, Country: "c", UDP: true},
|
{VPN: vpn.OpenVPN, Country: "c", UDP: true},
|
||||||
},
|
},
|
||||||
filtered: []models.Server{
|
filtered: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Country: "b", UDP: true},
|
{VPN: vpn.OpenVPN, Country: "b", UDP: true},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"filter by city": {
|
"filter by city": {
|
||||||
@@ -59,12 +59,12 @@ func Test_Ivpn_filterServers(t *testing.T) {
|
|||||||
Cities: []string{"b"},
|
Cities: []string{"b"},
|
||||||
}.WithDefaults(providers.Ivpn),
|
}.WithDefaults(providers.Ivpn),
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, City: "a", UDP: true},
|
{VPN: vpn.OpenVPN, City: "a", UDP: true},
|
||||||
{VPN: constants.OpenVPN, City: "b", UDP: true},
|
{VPN: vpn.OpenVPN, City: "b", UDP: true},
|
||||||
{VPN: constants.OpenVPN, City: "c", UDP: true},
|
{VPN: vpn.OpenVPN, City: "c", UDP: true},
|
||||||
},
|
},
|
||||||
filtered: []models.Server{
|
filtered: []models.Server{
|
||||||
{VPN: constants.OpenVPN, City: "b", UDP: true},
|
{VPN: vpn.OpenVPN, City: "b", UDP: true},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"filter by ISP": {
|
"filter by ISP": {
|
||||||
@@ -72,12 +72,12 @@ func Test_Ivpn_filterServers(t *testing.T) {
|
|||||||
ISPs: []string{"b"},
|
ISPs: []string{"b"},
|
||||||
}.WithDefaults(providers.Ivpn),
|
}.WithDefaults(providers.Ivpn),
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, ISP: "a", UDP: true},
|
{VPN: vpn.OpenVPN, ISP: "a", UDP: true},
|
||||||
{VPN: constants.OpenVPN, ISP: "b", UDP: true},
|
{VPN: vpn.OpenVPN, ISP: "b", UDP: true},
|
||||||
{VPN: constants.OpenVPN, ISP: "c", UDP: true},
|
{VPN: vpn.OpenVPN, ISP: "c", UDP: true},
|
||||||
},
|
},
|
||||||
filtered: []models.Server{
|
filtered: []models.Server{
|
||||||
{VPN: constants.OpenVPN, ISP: "b", UDP: true},
|
{VPN: vpn.OpenVPN, ISP: "b", UDP: true},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"filter by hostname": {
|
"filter by hostname": {
|
||||||
@@ -85,12 +85,12 @@ func Test_Ivpn_filterServers(t *testing.T) {
|
|||||||
Hostnames: []string{"b"},
|
Hostnames: []string{"b"},
|
||||||
}.WithDefaults(providers.Ivpn),
|
}.WithDefaults(providers.Ivpn),
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Hostname: "a", UDP: true},
|
{VPN: vpn.OpenVPN, Hostname: "a", UDP: true},
|
||||||
{VPN: constants.OpenVPN, Hostname: "b", UDP: true},
|
{VPN: vpn.OpenVPN, Hostname: "b", UDP: true},
|
||||||
{VPN: constants.OpenVPN, Hostname: "c", UDP: true},
|
{VPN: vpn.OpenVPN, Hostname: "c", UDP: true},
|
||||||
},
|
},
|
||||||
filtered: []models.Server{
|
filtered: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Hostname: "b", UDP: true},
|
{VPN: vpn.OpenVPN, Hostname: "b", UDP: true},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"filter by protocol": {
|
"filter by protocol": {
|
||||||
@@ -100,12 +100,12 @@ func Test_Ivpn_filterServers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}.WithDefaults(providers.Ivpn),
|
}.WithDefaults(providers.Ivpn),
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Hostname: "a", UDP: true},
|
{VPN: vpn.OpenVPN, Hostname: "a", UDP: true},
|
||||||
{VPN: constants.OpenVPN, Hostname: "b", UDP: true, TCP: true},
|
{VPN: vpn.OpenVPN, Hostname: "b", UDP: true, TCP: true},
|
||||||
{VPN: constants.OpenVPN, Hostname: "c", UDP: true},
|
{VPN: vpn.OpenVPN, Hostname: "c", UDP: true},
|
||||||
},
|
},
|
||||||
filtered: []models.Server{
|
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/configuration/settings"
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/constants"
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -29,13 +30,13 @@ func Test_Mullvad_GetConnection(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"no filter": {
|
"no filter": {
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
||||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
|
{VPN: vpn.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(3, 3, 3, 3)}},
|
||||||
},
|
},
|
||||||
selection: settings.ServerSelection{}.WithDefaults(providers.Mullvad),
|
selection: settings.ServerSelection{}.WithDefaults(providers.Mullvad),
|
||||||
connection: models.Connection{
|
connection: models.Connection{
|
||||||
Type: constants.OpenVPN,
|
Type: vpn.OpenVPN,
|
||||||
IP: net.IPv4(1, 1, 1, 1),
|
IP: net.IPv4(1, 1, 1, 1),
|
||||||
Port: 1194,
|
Port: 1194,
|
||||||
Protocol: constants.UDP,
|
Protocol: constants.UDP,
|
||||||
@@ -46,12 +47,12 @@ func Test_Mullvad_GetConnection(t *testing.T) {
|
|||||||
TargetIP: net.IPv4(2, 2, 2, 2),
|
TargetIP: net.IPv4(2, 2, 2, 2),
|
||||||
}.WithDefaults(providers.Mullvad),
|
}.WithDefaults(providers.Mullvad),
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
||||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
|
{VPN: vpn.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(3, 3, 3, 3)}},
|
||||||
},
|
},
|
||||||
connection: models.Connection{
|
connection: models.Connection{
|
||||||
Type: constants.OpenVPN,
|
Type: vpn.OpenVPN,
|
||||||
IP: net.IPv4(2, 2, 2, 2),
|
IP: net.IPv4(2, 2, 2, 2),
|
||||||
Port: 1194,
|
Port: 1194,
|
||||||
Protocol: constants.UDP,
|
Protocol: constants.UDP,
|
||||||
@@ -62,12 +63,12 @@ func Test_Mullvad_GetConnection(t *testing.T) {
|
|||||||
Hostnames: []string{"b"},
|
Hostnames: []string{"b"},
|
||||||
}.WithDefaults(providers.Mullvad),
|
}.WithDefaults(providers.Mullvad),
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
{VPN: vpn.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: vpn.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(3, 3, 3, 3)}},
|
||||||
},
|
},
|
||||||
connection: models.Connection{
|
connection: models.Connection{
|
||||||
Type: constants.OpenVPN,
|
Type: vpn.OpenVPN,
|
||||||
IP: net.IPv4(2, 2, 2, 2),
|
IP: net.IPv4(2, 2, 2, 2),
|
||||||
Port: 1194,
|
Port: 1194,
|
||||||
Protocol: constants.UDP,
|
Protocol: constants.UDP,
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"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/providers"
|
||||||
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -30,28 +30,28 @@ func Test_Mullvad_filterServers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"no filter": {
|
"no filter": {
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Hostname: "a"},
|
{VPN: vpn.OpenVPN, Hostname: "a"},
|
||||||
{VPN: constants.OpenVPN, Hostname: "b"},
|
{VPN: vpn.OpenVPN, Hostname: "b"},
|
||||||
{VPN: constants.OpenVPN, Hostname: "c"},
|
{VPN: vpn.OpenVPN, Hostname: "c"},
|
||||||
},
|
},
|
||||||
selection: settings.ServerSelection{}.WithDefaults(providers.Mullvad),
|
selection: settings.ServerSelection{}.WithDefaults(providers.Mullvad),
|
||||||
filtered: []models.Server{
|
filtered: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Hostname: "a"},
|
{VPN: vpn.OpenVPN, Hostname: "a"},
|
||||||
{VPN: constants.OpenVPN, Hostname: "b"},
|
{VPN: vpn.OpenVPN, Hostname: "b"},
|
||||||
{VPN: constants.OpenVPN, Hostname: "c"},
|
{VPN: vpn.OpenVPN, Hostname: "c"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"filter OpenVPN out": {
|
"filter OpenVPN out": {
|
||||||
selection: settings.ServerSelection{
|
selection: settings.ServerSelection{
|
||||||
VPN: constants.Wireguard,
|
VPN: vpn.Wireguard,
|
||||||
}.WithDefaults(providers.Mullvad),
|
}.WithDefaults(providers.Mullvad),
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Hostname: "a"},
|
{VPN: vpn.OpenVPN, Hostname: "a"},
|
||||||
{VPN: constants.Wireguard, Hostname: "b"},
|
{VPN: vpn.Wireguard, Hostname: "b"},
|
||||||
{VPN: constants.OpenVPN, Hostname: "c"},
|
{VPN: vpn.OpenVPN, Hostname: "c"},
|
||||||
},
|
},
|
||||||
filtered: []models.Server{
|
filtered: []models.Server{
|
||||||
{VPN: constants.Wireguard, Hostname: "b"},
|
{VPN: vpn.Wireguard, Hostname: "b"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"filter by country": {
|
"filter by country": {
|
||||||
@@ -59,12 +59,12 @@ func Test_Mullvad_filterServers(t *testing.T) {
|
|||||||
Countries: []string{"b"},
|
Countries: []string{"b"},
|
||||||
}.WithDefaults(providers.Mullvad),
|
}.WithDefaults(providers.Mullvad),
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Country: "a"},
|
{VPN: vpn.OpenVPN, Country: "a"},
|
||||||
{VPN: constants.OpenVPN, Country: "b"},
|
{VPN: vpn.OpenVPN, Country: "b"},
|
||||||
{VPN: constants.OpenVPN, Country: "c"},
|
{VPN: vpn.OpenVPN, Country: "c"},
|
||||||
},
|
},
|
||||||
filtered: []models.Server{
|
filtered: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Country: "b"},
|
{VPN: vpn.OpenVPN, Country: "b"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"filter by city": {
|
"filter by city": {
|
||||||
@@ -72,12 +72,12 @@ func Test_Mullvad_filterServers(t *testing.T) {
|
|||||||
Cities: []string{"b"},
|
Cities: []string{"b"},
|
||||||
}.WithDefaults(providers.Mullvad),
|
}.WithDefaults(providers.Mullvad),
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, City: "a"},
|
{VPN: vpn.OpenVPN, City: "a"},
|
||||||
{VPN: constants.OpenVPN, City: "b"},
|
{VPN: vpn.OpenVPN, City: "b"},
|
||||||
{VPN: constants.OpenVPN, City: "c"},
|
{VPN: vpn.OpenVPN, City: "c"},
|
||||||
},
|
},
|
||||||
filtered: []models.Server{
|
filtered: []models.Server{
|
||||||
{VPN: constants.OpenVPN, City: "b"},
|
{VPN: vpn.OpenVPN, City: "b"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"filter by ISP": {
|
"filter by ISP": {
|
||||||
@@ -85,12 +85,12 @@ func Test_Mullvad_filterServers(t *testing.T) {
|
|||||||
ISPs: []string{"b"},
|
ISPs: []string{"b"},
|
||||||
}.WithDefaults(providers.Mullvad),
|
}.WithDefaults(providers.Mullvad),
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, ISP: "a"},
|
{VPN: vpn.OpenVPN, ISP: "a"},
|
||||||
{VPN: constants.OpenVPN, ISP: "b"},
|
{VPN: vpn.OpenVPN, ISP: "b"},
|
||||||
{VPN: constants.OpenVPN, ISP: "c"},
|
{VPN: vpn.OpenVPN, ISP: "c"},
|
||||||
},
|
},
|
||||||
filtered: []models.Server{
|
filtered: []models.Server{
|
||||||
{VPN: constants.OpenVPN, ISP: "b"},
|
{VPN: vpn.OpenVPN, ISP: "b"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"filter by hostname": {
|
"filter by hostname": {
|
||||||
@@ -98,12 +98,12 @@ func Test_Mullvad_filterServers(t *testing.T) {
|
|||||||
Hostnames: []string{"b"},
|
Hostnames: []string{"b"},
|
||||||
}.WithDefaults(providers.Mullvad),
|
}.WithDefaults(providers.Mullvad),
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Hostname: "a"},
|
{VPN: vpn.OpenVPN, Hostname: "a"},
|
||||||
{VPN: constants.OpenVPN, Hostname: "b"},
|
{VPN: vpn.OpenVPN, Hostname: "b"},
|
||||||
{VPN: constants.OpenVPN, Hostname: "c"},
|
{VPN: vpn.OpenVPN, Hostname: "c"},
|
||||||
},
|
},
|
||||||
filtered: []models.Server{
|
filtered: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Hostname: "b"},
|
{VPN: vpn.OpenVPN, Hostname: "b"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"filter by owned": {
|
"filter by owned": {
|
||||||
@@ -111,12 +111,12 @@ func Test_Mullvad_filterServers(t *testing.T) {
|
|||||||
OwnedOnly: boolPtr(true),
|
OwnedOnly: boolPtr(true),
|
||||||
}.WithDefaults(providers.Mullvad),
|
}.WithDefaults(providers.Mullvad),
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Hostname: "a"},
|
{VPN: vpn.OpenVPN, Hostname: "a"},
|
||||||
{VPN: constants.OpenVPN, Hostname: "b", Owned: true},
|
{VPN: vpn.OpenVPN, Hostname: "b", Owned: true},
|
||||||
{VPN: constants.OpenVPN, Hostname: "c"},
|
{VPN: vpn.OpenVPN, Hostname: "c"},
|
||||||
},
|
},
|
||||||
filtered: []models.Server{
|
filtered: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Hostname: "b", Owned: true},
|
{VPN: vpn.OpenVPN, Hostname: "b", Owned: true},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"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/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ func PickConnection(connections []models.Connection,
|
|||||||
return connection, ErrNoConnectionToPickFrom
|
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
|
// we need the right public key
|
||||||
return getTargetIPConnection(connections, selection.TargetIP)
|
return getTargetIPConnection(connections, selection.TargetIP)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"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,
|
func GetPort(selection settings.ServerSelection,
|
||||||
defaultOpenVPNTCP, defaultOpenVPNUDP, defaultWireguard uint16) (port uint16) {
|
defaultOpenVPNTCP, defaultOpenVPNUDP, defaultWireguard uint16) (port uint16) {
|
||||||
switch selection.VPN {
|
switch selection.VPN {
|
||||||
case constants.Wireguard:
|
case vpn.Wireguard:
|
||||||
customPort := *selection.Wireguard.EndpointPort
|
customPort := *selection.Wireguard.EndpointPort
|
||||||
if customPort > 0 {
|
if customPort > 0 {
|
||||||
return customPort
|
return customPort
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"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"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ func Test_GetPort(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"OpenVPN UDP": {
|
"OpenVPN UDP": {
|
||||||
selection: settings.ServerSelection{
|
selection: settings.ServerSelection{
|
||||||
VPN: constants.OpenVPN,
|
VPN: vpn.OpenVPN,
|
||||||
OpenVPN: settings.OpenVPNSelection{
|
OpenVPN: settings.OpenVPNSelection{
|
||||||
CustomPort: uint16Ptr(0),
|
CustomPort: uint16Ptr(0),
|
||||||
TCP: boolPtr(false),
|
TCP: boolPtr(false),
|
||||||
@@ -40,7 +40,7 @@ func Test_GetPort(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"OpenVPN TCP": {
|
"OpenVPN TCP": {
|
||||||
selection: settings.ServerSelection{
|
selection: settings.ServerSelection{
|
||||||
VPN: constants.OpenVPN,
|
VPN: vpn.OpenVPN,
|
||||||
OpenVPN: settings.OpenVPNSelection{
|
OpenVPN: settings.OpenVPNSelection{
|
||||||
CustomPort: uint16Ptr(0),
|
CustomPort: uint16Ptr(0),
|
||||||
TCP: boolPtr(true),
|
TCP: boolPtr(true),
|
||||||
@@ -50,7 +50,7 @@ func Test_GetPort(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"OpenVPN custom port": {
|
"OpenVPN custom port": {
|
||||||
selection: settings.ServerSelection{
|
selection: settings.ServerSelection{
|
||||||
VPN: constants.OpenVPN,
|
VPN: vpn.OpenVPN,
|
||||||
OpenVPN: settings.OpenVPNSelection{
|
OpenVPN: settings.OpenVPNSelection{
|
||||||
CustomPort: uint16Ptr(1234),
|
CustomPort: uint16Ptr(1234),
|
||||||
},
|
},
|
||||||
@@ -59,13 +59,13 @@ func Test_GetPort(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"Wireguard": {
|
"Wireguard": {
|
||||||
selection: settings.ServerSelection{
|
selection: settings.ServerSelection{
|
||||||
VPN: constants.Wireguard,
|
VPN: vpn.Wireguard,
|
||||||
}.WithDefaults(""),
|
}.WithDefaults(""),
|
||||||
port: defaultWireguard,
|
port: defaultWireguard,
|
||||||
},
|
},
|
||||||
"Wireguard custom port": {
|
"Wireguard custom port": {
|
||||||
selection: settings.ServerSelection{
|
selection: settings.ServerSelection{
|
||||||
VPN: constants.Wireguard,
|
VPN: vpn.Wireguard,
|
||||||
Wireguard: settings.WireguardSelection{
|
Wireguard: settings.WireguardSelection{
|
||||||
EndpointPort: uint16Ptr(1234),
|
EndpointPort: uint16Ptr(1234),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ package utils
|
|||||||
import (
|
import (
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/constants"
|
||||||
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetProtocol(selection settings.ServerSelection) (protocol string) {
|
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.TCP
|
||||||
}
|
}
|
||||||
return constants.UDP
|
return constants.UDP
|
||||||
@@ -15,7 +16,7 @@ func GetProtocol(selection settings.ServerSelection) (protocol string) {
|
|||||||
func FilterByProtocol(selection settings.ServerSelection,
|
func FilterByProtocol(selection settings.ServerSelection,
|
||||||
serverTCP, serverUDP bool) (filtered bool) {
|
serverTCP, serverUDP bool) (filtered bool) {
|
||||||
switch selection.VPN {
|
switch selection.VPN {
|
||||||
case constants.Wireguard:
|
case vpn.Wireguard:
|
||||||
return !serverUDP
|
return !serverUDP
|
||||||
default: // OpenVPN
|
default: // OpenVPN
|
||||||
wantTCP := *selection.OpenVPN.TCP
|
wantTCP := *selection.OpenVPN.TCP
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/constants"
|
||||||
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,7 +21,7 @@ func Test_GetProtocol(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"OpenVPN UDP": {
|
"OpenVPN UDP": {
|
||||||
selection: settings.ServerSelection{
|
selection: settings.ServerSelection{
|
||||||
VPN: constants.OpenVPN,
|
VPN: vpn.OpenVPN,
|
||||||
OpenVPN: settings.OpenVPNSelection{
|
OpenVPN: settings.OpenVPNSelection{
|
||||||
TCP: boolPtr(false),
|
TCP: boolPtr(false),
|
||||||
},
|
},
|
||||||
@@ -29,7 +30,7 @@ func Test_GetProtocol(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"OpenVPN TCP": {
|
"OpenVPN TCP": {
|
||||||
selection: settings.ServerSelection{
|
selection: settings.ServerSelection{
|
||||||
VPN: constants.OpenVPN,
|
VPN: vpn.OpenVPN,
|
||||||
OpenVPN: settings.OpenVPNSelection{
|
OpenVPN: settings.OpenVPNSelection{
|
||||||
TCP: boolPtr(true),
|
TCP: boolPtr(true),
|
||||||
},
|
},
|
||||||
@@ -38,7 +39,7 @@ func Test_GetProtocol(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"Wireguard": {
|
"Wireguard": {
|
||||||
selection: settings.ServerSelection{
|
selection: settings.ServerSelection{
|
||||||
VPN: constants.Wireguard,
|
VPN: vpn.Wireguard,
|
||||||
},
|
},
|
||||||
protocol: constants.UDP,
|
protocol: constants.UDP,
|
||||||
},
|
},
|
||||||
@@ -67,21 +68,21 @@ func Test_FilterByProtocol(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
"Wireguard and server has UDP": {
|
"Wireguard and server has UDP": {
|
||||||
selection: settings.ServerSelection{
|
selection: settings.ServerSelection{
|
||||||
VPN: constants.Wireguard,
|
VPN: vpn.Wireguard,
|
||||||
},
|
},
|
||||||
serverUDP: true,
|
serverUDP: true,
|
||||||
filtered: false,
|
filtered: false,
|
||||||
},
|
},
|
||||||
"Wireguard and server has not UDP": {
|
"Wireguard and server has not UDP": {
|
||||||
selection: settings.ServerSelection{
|
selection: settings.ServerSelection{
|
||||||
VPN: constants.Wireguard,
|
VPN: vpn.Wireguard,
|
||||||
},
|
},
|
||||||
serverUDP: false,
|
serverUDP: false,
|
||||||
filtered: true,
|
filtered: true,
|
||||||
},
|
},
|
||||||
"OpenVPN UDP and server has UDP": {
|
"OpenVPN UDP and server has UDP": {
|
||||||
selection: settings.ServerSelection{
|
selection: settings.ServerSelection{
|
||||||
VPN: constants.OpenVPN,
|
VPN: vpn.OpenVPN,
|
||||||
OpenVPN: settings.OpenVPNSelection{
|
OpenVPN: settings.OpenVPNSelection{
|
||||||
TCP: boolPtr(false),
|
TCP: boolPtr(false),
|
||||||
},
|
},
|
||||||
@@ -91,7 +92,7 @@ func Test_FilterByProtocol(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"OpenVPN UDP and server has not UDP": {
|
"OpenVPN UDP and server has not UDP": {
|
||||||
selection: settings.ServerSelection{
|
selection: settings.ServerSelection{
|
||||||
VPN: constants.OpenVPN,
|
VPN: vpn.OpenVPN,
|
||||||
OpenVPN: settings.OpenVPNSelection{
|
OpenVPN: settings.OpenVPNSelection{
|
||||||
TCP: boolPtr(false),
|
TCP: boolPtr(false),
|
||||||
},
|
},
|
||||||
@@ -101,7 +102,7 @@ func Test_FilterByProtocol(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"OpenVPN TCP and server has TCP": {
|
"OpenVPN TCP and server has TCP": {
|
||||||
selection: settings.ServerSelection{
|
selection: settings.ServerSelection{
|
||||||
VPN: constants.OpenVPN,
|
VPN: vpn.OpenVPN,
|
||||||
OpenVPN: settings.OpenVPNSelection{
|
OpenVPN: settings.OpenVPNSelection{
|
||||||
TCP: boolPtr(true),
|
TCP: boolPtr(true),
|
||||||
},
|
},
|
||||||
@@ -111,7 +112,7 @@ func Test_FilterByProtocol(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"OpenVPN TCP and server has not TCP": {
|
"OpenVPN TCP and server has not TCP": {
|
||||||
selection: settings.ServerSelection{
|
selection: settings.ServerSelection{
|
||||||
VPN: constants.OpenVPN,
|
VPN: vpn.OpenVPN,
|
||||||
OpenVPN: settings.OpenVPNSelection{
|
OpenVPN: settings.OpenVPNSelection{
|
||||||
TCP: boolPtr(true),
|
TCP: boolPtr(true),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/constants"
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -25,7 +26,7 @@ func Test_Wevpn_GetConnection(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
"no server available": {
|
"no server available": {
|
||||||
selection: settings.ServerSelection{
|
selection: settings.ServerSelection{
|
||||||
VPN: constants.OpenVPN,
|
VPN: vpn.OpenVPN,
|
||||||
}.WithDefaults(providers.Wevpn),
|
}.WithDefaults(providers.Wevpn),
|
||||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
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),
|
selection: settings.ServerSelection{}.WithDefaults(providers.Wevpn),
|
||||||
connection: models.Connection{
|
connection: models.Connection{
|
||||||
Type: constants.OpenVPN,
|
Type: vpn.OpenVPN,
|
||||||
IP: net.IPv4(1, 1, 1, 1),
|
IP: net.IPv4(1, 1, 1, 1),
|
||||||
Port: 1194,
|
Port: 1194,
|
||||||
Protocol: constants.UDP,
|
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)}},
|
{UDP: true, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
|
||||||
},
|
},
|
||||||
connection: models.Connection{
|
connection: models.Connection{
|
||||||
Type: constants.OpenVPN,
|
Type: vpn.OpenVPN,
|
||||||
IP: net.IPv4(2, 2, 2, 2),
|
IP: net.IPv4(2, 2, 2, 2),
|
||||||
Port: 1194,
|
Port: 1194,
|
||||||
Protocol: constants.UDP,
|
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)}},
|
{UDP: true, Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
|
||||||
},
|
},
|
||||||
connection: models.Connection{
|
connection: models.Connection{
|
||||||
Type: constants.OpenVPN,
|
Type: vpn.OpenVPN,
|
||||||
IP: net.IPv4(2, 2, 2, 2),
|
IP: net.IPv4(2, 2, 2, 2),
|
||||||
Port: 1194,
|
Port: 1194,
|
||||||
Protocol: constants.UDP,
|
Protocol: constants.UDP,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/constants"
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -29,13 +30,13 @@ func Test_Windscribe_GetConnection(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"no filter": {
|
"no filter": {
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
||||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
|
{VPN: vpn.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(3, 3, 3, 3)}},
|
||||||
},
|
},
|
||||||
selection: settings.ServerSelection{}.WithDefaults(providers.Windscribe),
|
selection: settings.ServerSelection{}.WithDefaults(providers.Windscribe),
|
||||||
connection: models.Connection{
|
connection: models.Connection{
|
||||||
Type: constants.OpenVPN,
|
Type: vpn.OpenVPN,
|
||||||
IP: net.IPv4(1, 1, 1, 1),
|
IP: net.IPv4(1, 1, 1, 1),
|
||||||
Port: 1194,
|
Port: 1194,
|
||||||
Protocol: constants.UDP,
|
Protocol: constants.UDP,
|
||||||
@@ -46,12 +47,12 @@ func Test_Windscribe_GetConnection(t *testing.T) {
|
|||||||
TargetIP: net.IPv4(2, 2, 2, 2),
|
TargetIP: net.IPv4(2, 2, 2, 2),
|
||||||
}.WithDefaults(providers.Windscribe),
|
}.WithDefaults(providers.Windscribe),
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
||||||
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
|
{VPN: vpn.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(3, 3, 3, 3)}},
|
||||||
},
|
},
|
||||||
connection: models.Connection{
|
connection: models.Connection{
|
||||||
Type: constants.OpenVPN,
|
Type: vpn.OpenVPN,
|
||||||
IP: net.IPv4(2, 2, 2, 2),
|
IP: net.IPv4(2, 2, 2, 2),
|
||||||
Port: 1194,
|
Port: 1194,
|
||||||
Protocol: constants.UDP,
|
Protocol: constants.UDP,
|
||||||
@@ -62,12 +63,12 @@ func Test_Windscribe_GetConnection(t *testing.T) {
|
|||||||
Hostnames: []string{"b"},
|
Hostnames: []string{"b"},
|
||||||
}.WithDefaults(providers.Windscribe),
|
}.WithDefaults(providers.Windscribe),
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
|
{VPN: vpn.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: vpn.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(3, 3, 3, 3)}},
|
||||||
},
|
},
|
||||||
connection: models.Connection{
|
connection: models.Connection{
|
||||||
Type: constants.OpenVPN,
|
Type: vpn.OpenVPN,
|
||||||
IP: net.IPv4(2, 2, 2, 2),
|
IP: net.IPv4(2, 2, 2, 2),
|
||||||
Port: 1194,
|
Port: 1194,
|
||||||
Protocol: constants.UDP,
|
Protocol: constants.UDP,
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"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/providers"
|
||||||
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -28,28 +28,28 @@ func Test_Windscribe_filterServers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"no filter": {
|
"no filter": {
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Hostname: "a"},
|
{VPN: vpn.OpenVPN, Hostname: "a"},
|
||||||
{VPN: constants.OpenVPN, Hostname: "b"},
|
{VPN: vpn.OpenVPN, Hostname: "b"},
|
||||||
{VPN: constants.OpenVPN, Hostname: "c"},
|
{VPN: vpn.OpenVPN, Hostname: "c"},
|
||||||
},
|
},
|
||||||
selection: settings.ServerSelection{}.WithDefaults(providers.Windscribe),
|
selection: settings.ServerSelection{}.WithDefaults(providers.Windscribe),
|
||||||
filtered: []models.Server{
|
filtered: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Hostname: "a"},
|
{VPN: vpn.OpenVPN, Hostname: "a"},
|
||||||
{VPN: constants.OpenVPN, Hostname: "b"},
|
{VPN: vpn.OpenVPN, Hostname: "b"},
|
||||||
{VPN: constants.OpenVPN, Hostname: "c"},
|
{VPN: vpn.OpenVPN, Hostname: "c"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"filter OpenVPN out": {
|
"filter OpenVPN out": {
|
||||||
selection: settings.ServerSelection{
|
selection: settings.ServerSelection{
|
||||||
VPN: constants.Wireguard,
|
VPN: vpn.Wireguard,
|
||||||
}.WithDefaults(providers.Windscribe),
|
}.WithDefaults(providers.Windscribe),
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Hostname: "a"},
|
{VPN: vpn.OpenVPN, Hostname: "a"},
|
||||||
{VPN: constants.Wireguard, Hostname: "b"},
|
{VPN: vpn.Wireguard, Hostname: "b"},
|
||||||
{VPN: constants.OpenVPN, Hostname: "c"},
|
{VPN: vpn.OpenVPN, Hostname: "c"},
|
||||||
},
|
},
|
||||||
filtered: []models.Server{
|
filtered: []models.Server{
|
||||||
{VPN: constants.Wireguard, Hostname: "b"},
|
{VPN: vpn.Wireguard, Hostname: "b"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"filter by region": {
|
"filter by region": {
|
||||||
@@ -57,12 +57,12 @@ func Test_Windscribe_filterServers(t *testing.T) {
|
|||||||
Regions: []string{"b"},
|
Regions: []string{"b"},
|
||||||
}.WithDefaults(providers.Windscribe),
|
}.WithDefaults(providers.Windscribe),
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Region: "a"},
|
{VPN: vpn.OpenVPN, Region: "a"},
|
||||||
{VPN: constants.OpenVPN, Region: "b"},
|
{VPN: vpn.OpenVPN, Region: "b"},
|
||||||
{VPN: constants.OpenVPN, Region: "c"},
|
{VPN: vpn.OpenVPN, Region: "c"},
|
||||||
},
|
},
|
||||||
filtered: []models.Server{
|
filtered: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Region: "b"},
|
{VPN: vpn.OpenVPN, Region: "b"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"filter by city": {
|
"filter by city": {
|
||||||
@@ -70,12 +70,12 @@ func Test_Windscribe_filterServers(t *testing.T) {
|
|||||||
Cities: []string{"b"},
|
Cities: []string{"b"},
|
||||||
}.WithDefaults(providers.Windscribe),
|
}.WithDefaults(providers.Windscribe),
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, City: "a"},
|
{VPN: vpn.OpenVPN, City: "a"},
|
||||||
{VPN: constants.OpenVPN, City: "b"},
|
{VPN: vpn.OpenVPN, City: "b"},
|
||||||
{VPN: constants.OpenVPN, City: "c"},
|
{VPN: vpn.OpenVPN, City: "c"},
|
||||||
},
|
},
|
||||||
filtered: []models.Server{
|
filtered: []models.Server{
|
||||||
{VPN: constants.OpenVPN, City: "b"},
|
{VPN: vpn.OpenVPN, City: "b"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"filter by hostname": {
|
"filter by hostname": {
|
||||||
@@ -83,12 +83,12 @@ func Test_Windscribe_filterServers(t *testing.T) {
|
|||||||
Hostnames: []string{"b"},
|
Hostnames: []string{"b"},
|
||||||
}.WithDefaults(providers.Windscribe),
|
}.WithDefaults(providers.Windscribe),
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Hostname: "a"},
|
{VPN: vpn.OpenVPN, Hostname: "a"},
|
||||||
{VPN: constants.OpenVPN, Hostname: "b"},
|
{VPN: vpn.OpenVPN, Hostname: "b"},
|
||||||
{VPN: constants.OpenVPN, Hostname: "c"},
|
{VPN: vpn.OpenVPN, Hostname: "c"},
|
||||||
},
|
},
|
||||||
filtered: []models.Server{
|
filtered: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Hostname: "b"},
|
{VPN: vpn.OpenVPN, Hostname: "b"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"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/models"
|
||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"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))
|
servers = make([]models.Server, 0, len(hosts))
|
||||||
for _, serverData := range data.Servers {
|
for _, serverData := range data.Servers {
|
||||||
vpnType := constants.OpenVPN
|
vpnType := vpn.OpenVPN
|
||||||
hostname := serverData.Hostnames.OpenVPN
|
hostname := serverData.Hostnames.OpenVPN
|
||||||
tcp := true
|
tcp := true
|
||||||
wgPubKey := ""
|
wgPubKey := ""
|
||||||
if hostname == "" {
|
if hostname == "" {
|
||||||
vpnType = constants.Wireguard
|
vpnType = vpn.Wireguard
|
||||||
hostname = serverData.Hostnames.Wireguard
|
hostname = serverData.Hostnames.Wireguard
|
||||||
tcp = false
|
tcp = false
|
||||||
wgPubKey = serverData.WgPubKey
|
wgPubKey = serverData.WgPubKey
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/golang/mock/gomock"
|
"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/models"
|
||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/updater/resolver"
|
||||||
"github.com/qdm12/gluetun/internal/updater/resolver/mock_resolver"
|
"github.com/qdm12/gluetun/internal/updater/resolver/mock_resolver"
|
||||||
@@ -85,13 +85,13 @@ func Test_GetServers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
resolveWarnings: []string{"resolve warning"},
|
resolveWarnings: []string{"resolve warning"},
|
||||||
servers: []models.Server{
|
servers: []models.Server{
|
||||||
{VPN: constants.OpenVPN, Country: "Country1",
|
{VPN: vpn.OpenVPN, Country: "Country1",
|
||||||
City: "City A", Hostname: "hosta", TCP: true, UDP: true,
|
City: "City A", Hostname: "hosta", TCP: true, UDP: true,
|
||||||
IPs: []net.IP{{1, 1, 1, 1}, {2, 2, 2, 2}}},
|
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,
|
City: "City B", Hostname: "hostb", TCP: true, UDP: true,
|
||||||
IPs: []net.IP{{3, 3, 3, 3}, {4, 4, 4, 4}}},
|
IPs: []net.IP{{3, 3, 3, 3}, {4, 4, 4, 4}}},
|
||||||
{VPN: constants.Wireguard,
|
{VPN: vpn.Wireguard,
|
||||||
Country: "Country3", City: "City C",
|
Country: "Country3", City: "City C",
|
||||||
Hostname: "hostc", UDP: true,
|
Hostname: "hostc", UDP: true,
|
||||||
WgPubKey: "xyz",
|
WgPubKey: "xyz",
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,9 +35,9 @@ func (hts hostToServer) add(data serverData) (err error) {
|
|||||||
|
|
||||||
switch data.Type {
|
switch data.Type {
|
||||||
case "openvpn":
|
case "openvpn":
|
||||||
server.VPN = constants.OpenVPN
|
server.VPN = vpn.OpenVPN
|
||||||
case "wireguard":
|
case "wireguard":
|
||||||
server.VPN = constants.Wireguard
|
server.VPN = vpn.Wireguard
|
||||||
case "bridge":
|
case "bridge":
|
||||||
// ignore bridge servers
|
// ignore bridge servers
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"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/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ func GetServers(ctx context.Context, client *http.Client, minServers int) (
|
|||||||
ips = append(ips, node.IP2)
|
ips = append(ips, node.IP2)
|
||||||
}
|
}
|
||||||
server := models.Server{
|
server := models.Server{
|
||||||
VPN: constants.OpenVPN,
|
VPN: vpn.OpenVPN,
|
||||||
Region: region,
|
Region: region,
|
||||||
City: city,
|
City: city,
|
||||||
Hostname: node.Hostname,
|
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)
|
return nil, fmt.Errorf("%w: for node %s", ErrNoWireguardKey, node.Hostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
server.VPN = constants.Wireguard
|
server.VPN = vpn.Wireguard
|
||||||
server.OvpnX509 = ""
|
server.OvpnX509 = ""
|
||||||
server.WgPubKey = wgPubKey
|
server.WgPubKey = wgPubKey
|
||||||
server.IPs = []net.IP{node.IP3}
|
server.IPs = []net.IP{node.IP3}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/constants"
|
||||||
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
"github.com/qdm12/gluetun/internal/provider"
|
"github.com/qdm12/gluetun/internal/provider"
|
||||||
"github.com/qdm12/log"
|
"github.com/qdm12/log"
|
||||||
)
|
)
|
||||||
@@ -36,7 +37,7 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
|
|||||||
var serverName, vpnInterface string
|
var serverName, vpnInterface string
|
||||||
var err error
|
var err error
|
||||||
subLogger := l.logger.New(log.SetComponent(settings.Type))
|
subLogger := l.logger.New(log.SetComponent(settings.Type))
|
||||||
if settings.Type == constants.OpenVPN {
|
if settings.Type == vpn.OpenVPN {
|
||||||
vpnInterface = settings.OpenVPN.Interface
|
vpnInterface = settings.OpenVPN.Interface
|
||||||
vpnRunner, serverName, err = setupOpenVPN(ctx, l.fw,
|
vpnRunner, serverName, err = setupOpenVPN(ctx, l.fw,
|
||||||
l.openvpnConf, providerConf, settings, l.starter, subLogger)
|
l.openvpnConf, providerConf, settings, l.starter, subLogger)
|
||||||
|
|||||||
Reference in New Issue
Block a user