chore(updater): move updater packages to pkg/updaters/<name>

This commit is contained in:
Quentin McGaw
2026-04-23 03:47:57 +00:00
parent 5b01324d5f
commit 13503b0ae0
268 changed files with 1602 additions and 1026 deletions
+2 -2
View File
@@ -45,9 +45,9 @@ import (
"github.com/qdm12/gluetun/internal/storage"
"github.com/qdm12/gluetun/internal/tun"
updater "github.com/qdm12/gluetun/internal/updater/loop"
"github.com/qdm12/gluetun/internal/updater/resolver"
"github.com/qdm12/gluetun/internal/updater/unzip"
"github.com/qdm12/gluetun/internal/vpn"
"github.com/qdm12/gluetun/pkg/updaters/resolver"
"github.com/qdm12/gluetun/pkg/updaters/unzip"
"github.com/qdm12/gosettings/reader"
"github.com/qdm12/gosettings/reader/sources/env"
"github.com/qdm12/goshutdown"
+2 -2
View File
@@ -10,12 +10,12 @@ import (
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/netlink"
"github.com/qdm12/gluetun/internal/openvpn/extract"
"github.com/qdm12/gluetun/internal/provider"
"github.com/qdm12/gluetun/internal/storage"
"github.com/qdm12/gluetun/internal/updater/resolver"
"github.com/qdm12/gluetun/pkg/publicip/models"
"github.com/qdm12/gluetun/pkg/updaters/resolver"
"github.com/qdm12/gosettings/reader"
)
+3 -3
View File
@@ -17,11 +17,11 @@ import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/openvpn/extract"
"github.com/qdm12/gluetun/internal/provider"
"github.com/qdm12/gluetun/internal/publicip/api"
"github.com/qdm12/gluetun/internal/storage"
"github.com/qdm12/gluetun/internal/updater"
"github.com/qdm12/gluetun/internal/updater/resolver"
"github.com/qdm12/gluetun/internal/updater/unzip"
"github.com/qdm12/gluetun/pkg/publicip/api"
"github.com/qdm12/gluetun/pkg/updaters/resolver"
"github.com/qdm12/gluetun/pkg/updaters/unzip"
)
type UpdaterLogger interface {
@@ -6,9 +6,9 @@ import (
"strings"
"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/provider/privateinternetaccess/presets"
"github.com/qdm12/gluetun/pkg/updaters/constants"
"github.com/qdm12/gosettings"
"github.com/qdm12/gosettings/reader"
"github.com/qdm12/gosettings/validate"
+5 -5
View File
@@ -7,7 +7,7 @@ import (
"strings"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/pkg/updaters/constants"
"github.com/qdm12/gosettings"
"github.com/qdm12/gosettings/reader"
"github.com/qdm12/gosettings/validate"
@@ -31,9 +31,9 @@ func (p *Provider) validate(vpnType string, filterChoicesGetter FilterChoicesGet
// Validate Name
var validNames []string
switch vpnType {
case vpn.AmneziaWg:
case constants.AmneziaWg:
validNames = []string{providers.Custom}
case vpn.OpenVPN:
case constants.OpenVPN:
validNames = providers.AllWithCustom()
validNames = append(validNames, "pia") // Retro-compatibility
// Remove Mullvad since it no longer supports OpenVPN as of January 15th, 2026
@@ -41,7 +41,7 @@ func (p *Provider) validate(vpnType string, filterChoicesGetter FilterChoicesGet
validNames[mullvadIndex], validNames[len(validNames)-1] = validNames[len(validNames)-1], validNames[mullvadIndex]
validNames = validNames[:len(validNames)-1]
sort.Strings(validNames)
case vpn.Wireguard:
case constants.Wireguard:
validNames = []string{
providers.Airvpn,
providers.Custom,
@@ -122,7 +122,7 @@ func (p *Provider) read(r *reader.Reader, vpnType string) (err error) {
func readVPNServiceProvider(r *reader.Reader, vpnType string) (vpnProvider string) {
vpnProvider = r.String("VPN_SERVICE_PROVIDER", reader.RetroKeys("VPNSP"))
if vpnProvider == "" {
if vpnType != vpn.Wireguard && r.Get("OPENVPN_CUSTOM_CONFIG") != nil {
if vpnType != constants.Wireguard && r.Get("OPENVPN_CUSTOM_CONFIG") != nil {
// retro compatibility
return providers.Custom
}
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"fmt"
"path/filepath"
"github.com/qdm12/gluetun/internal/publicip/api"
"github.com/qdm12/gluetun/pkg/publicip/api"
"github.com/qdm12/gosettings"
"github.com/qdm12/gosettings/reader"
"github.com/qdm12/gotree"
@@ -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/providers"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/pkg/updaters/constants"
"github.com/qdm12/gosettings"
"github.com/qdm12/gosettings/reader"
"github.com/qdm12/gosettings/validate"
@@ -75,7 +75,7 @@ func (ss *ServerSelection) validate(vpnServiceProvider string,
filterChoicesGetter FilterChoicesGetter, warner Warner,
) (err error) {
switch ss.VPN {
case vpn.AmneziaWg, vpn.OpenVPN, vpn.Wireguard:
case constants.AmneziaWg, constants.OpenVPN, constants.Wireguard:
default:
return fmt.Errorf("VPN type is not valid: %s", ss.VPN)
}
@@ -108,7 +108,7 @@ func (ss *ServerSelection) validate(vpnServiceProvider string,
return fmt.Errorf("for VPN service provider %s: %w", vpnServiceProvider, err)
}
if ss.VPN == vpn.OpenVPN {
if ss.VPN == constants.OpenVPN {
err = ss.OpenVPN.validate(vpnServiceProvider)
if err != nil {
return fmt.Errorf("OpenVPN server selection settings: %w", err)
@@ -324,7 +324,7 @@ func (ss *ServerSelection) overrideWith(other ServerSelection) {
}
func (ss *ServerSelection) setDefaults(vpnProvider string, portForwardingEnabled bool) {
ss.VPN = gosettings.DefaultComparable(ss.VPN, vpn.OpenVPN)
ss.VPN = gosettings.DefaultComparable(ss.VPN, constants.OpenVPN)
ss.OwnedOnly = gosettings.DefaultPointer(ss.OwnedOnly, false)
ss.FreeOnly = gosettings.DefaultPointer(ss.FreeOnly, false)
ss.PremiumOnly = gosettings.DefaultPointer(ss.PremiumOnly, false)
@@ -414,7 +414,7 @@ func (ss ServerSelection) toLinesNode() (node *gotree.Node) {
node.Appendf("Port forwarding only servers: yes")
}
if ss.VPN == vpn.OpenVPN {
if ss.VPN == constants.OpenVPN {
node.AppendNode(ss.OpenVPN.toLinesNode())
} else {
node.AppendNode(ss.Wireguard.toLinesNode())
@@ -506,7 +506,7 @@ func (ss *ServerSelection) read(r *reader.Reader,
return err
}
amneziawg := ss.VPN == vpn.AmneziaWg
amneziawg := ss.VPN == constants.AmneziaWg
err = ss.Wireguard.read(r, amneziawg)
if err != nil {
return err
+2 -2
View File
@@ -5,9 +5,9 @@ import (
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
"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/pprof"
"github.com/qdm12/gluetun/pkg/updaters/constants"
"github.com/qdm12/gosettings/reader"
"github.com/qdm12/gotree"
)
@@ -175,7 +175,7 @@ func (s Settings) Warnings() (warnings []string) {
}
if helpers.IsOneOf(s.VPN.Provider.Name, providers.SlickVPN) &&
s.VPN.Type == vpn.OpenVPN {
s.VPN.Type == constants.OpenVPN {
warnings = append(warnings, "OpenVPN 2.5 and 2.6 use OpenSSL 3 "+
"which prohibits the usage of weak security in today's standards. "+
s.VPN.Provider.Name+" uses weak security which is out "+
@@ -3,7 +3,7 @@ package settings
import (
"strings"
"github.com/qdm12/gluetun/internal/provider/surfshark/servers"
"github.com/qdm12/gluetun/pkg/updaters/providers/surfshark/servers"
)
func surfsharkRetroRegion(selection ServerSelection) (
@@ -3,7 +3,7 @@ package validation
import (
"sort"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/pkg/updaters/models"
)
func sortedInsert(ss []string, s string) []string {
@@ -1,7 +1,7 @@
package validation
import (
"github.com/qdm12/gluetun/internal/provider/surfshark/servers"
"github.com/qdm12/gluetun/pkg/updaters/providers/surfshark/servers"
)
// TODO remove in v4.
+9 -9
View File
@@ -3,7 +3,7 @@ package settings
import (
"fmt"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/pkg/updaters/constants"
"github.com/qdm12/gosettings"
"github.com/qdm12/gosettings/reader"
"github.com/qdm12/gosettings/validate"
@@ -35,7 +35,7 @@ type VPN struct {
// TODO v4 remove pointer for receiver (because of Surfshark).
func (v *VPN) Validate(filterChoicesGetter FilterChoicesGetter, ipv6Supported bool, warner Warner) (err error) {
// Validate Type
validVPNTypes := []string{vpn.AmneziaWg, vpn.OpenVPN, vpn.Wireguard}
validVPNTypes := []string{constants.AmneziaWg, constants.OpenVPN, constants.Wireguard}
if err = validate.IsOneOf(v.Type, validVPNTypes...); err != nil {
return fmt.Errorf("VPN type is not valid: %w", err)
}
@@ -46,17 +46,17 @@ func (v *VPN) Validate(filterChoicesGetter FilterChoicesGetter, ipv6Supported bo
}
switch v.Type {
case vpn.AmneziaWg:
case constants.AmneziaWg:
err = v.AmneziaWg.validate(v.Provider.Name, ipv6Supported)
if err != nil {
return fmt.Errorf("AmneziaWG settings: %w", err)
}
case vpn.OpenVPN:
case constants.OpenVPN:
err := v.OpenVPN.validate(v.Provider.Name)
if err != nil {
return fmt.Errorf("OpenVPN settings: %w", err)
}
case vpn.Wireguard:
case constants.Wireguard:
const amneziawg = false
err := v.Wireguard.validate(v.Provider.Name, ipv6Supported, amneziawg)
if err != nil {
@@ -97,7 +97,7 @@ func (v *VPN) OverrideWith(other VPN) {
}
func (v *VPN) setDefaults() {
v.Type = gosettings.DefaultComparable(v.Type, vpn.OpenVPN)
v.Type = gosettings.DefaultComparable(v.Type, constants.OpenVPN)
v.Provider.setDefaults()
v.AmneziaWg.setDefaults(v.Provider.Name)
v.OpenVPN.setDefaults(v.Provider.Name)
@@ -117,11 +117,11 @@ func (v VPN) toLinesNode() (node *gotree.Node) {
node.AppendNode(v.Provider.toLinesNode())
switch v.Type {
case vpn.AmneziaWg:
case constants.AmneziaWg:
node.AppendNode(v.AmneziaWg.toLinesNode())
case vpn.OpenVPN:
case constants.OpenVPN:
node.AppendNode(v.OpenVPN.toLinesNode())
case vpn.Wireguard:
case constants.Wireguard:
node.AppendNode(v.Wireguard.toLinesNode())
}
node.AppendNode(v.PMTUD.toLinesNode())
@@ -3,7 +3,9 @@ package providers
import (
"testing"
"github.com/qdm12/gluetun/pkg/updaters"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_All(t *testing.T) {
@@ -21,3 +23,27 @@ func Test_AllWithCustom(t *testing.T) {
assert.Contains(t, all, Custom)
assert.Len(t, all, len(All())+1)
}
func Test_MatchUpdaters(t *testing.T) {
t.Parallel()
fetcherNames := updaters.ListAllNames()
allProviders := All()
require.Equal(t, len(allProviders), len(fetcherNames), "number of providers in All() should match number of fetchers")
nameToFound := make(map[string]bool, len(allProviders))
for _, provider := range allProviders {
nameToFound[provider] = false
}
for _, fetcherName := range fetcherNames {
found, ok := nameToFound[fetcherName]
require.True(t, ok, "fetcher name %q not found in %v", fetcherName, allProviders)
require.False(t, found, "fetcher name %q is duplicated in %v", fetcherName, allProviders)
nameToFound[fetcherName] = true
}
for provider, found := range nameToFound {
assert.True(t, found, "provider %q from All() does not have a matching fetcher", provider)
}
}
+6 -5
View File
@@ -5,7 +5,8 @@ import (
"strings"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/pkg/updaters/constants"
"github.com/qdm12/gluetun/pkg/updaters/models"
)
func boolToMarkdown(b bool) string {
@@ -42,7 +43,7 @@ const (
vpnHeader = "VPN"
)
func (s *Server) ToMarkdown(headers ...string) (markdown string) {
func serverToMarkdown(s models.Server, headers ...string) (markdown string) {
if len(headers) == 0 {
return ""
}
@@ -81,7 +82,7 @@ func (s *Server) ToMarkdown(headers ...string) (markdown string) {
case tcpHeader:
fields[i] = boolToMarkdown(s.TCP)
case udpHeader:
fields[i] = boolToMarkdown(s.UDP || s.VPN == vpn.Wireguard)
fields[i] = boolToMarkdown(s.UDP || s.VPN == constants.Wireguard)
case vpnHeader:
fields[i] = s.VPN
}
@@ -90,7 +91,7 @@ func (s *Server) ToMarkdown(headers ...string) (markdown string) {
return "| " + strings.Join(fields, " | ") + " |"
}
func (s *Servers) toMarkdown(vpnProvider string) (formatted string, err error) {
func serversToMarkdown(s models.Servers, vpnProvider string) (formatted string, err error) {
headers, err := getMarkdownHeaders(vpnProvider)
if err != nil {
return "", fmt.Errorf("getting markdown headers: %w", err)
@@ -100,7 +101,7 @@ func (s *Servers) toMarkdown(vpnProvider string) (formatted string, err error) {
entries := make([]string, len(s.Servers))
for i, server := range s.Servers {
entries[i] = server.ToMarkdown(headers...)
entries[i] = serverToMarkdown(server, headers...)
}
formatted = legend + "\n" +
+11 -10
View File
@@ -4,16 +4,17 @@ import (
"testing"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/pkg/updaters/constants"
"github.com/qdm12/gluetun/pkg/updaters/models"
"github.com/stretchr/testify/assert"
)
func Test_Servers_ToMarkdown(t *testing.T) {
func Test_serversToMarkdown(t *testing.T) {
t.Parallel()
testCases := map[string]struct {
provider string
servers Servers
servers models.Servers
formatted string
errMessage string
}{
@@ -23,8 +24,8 @@ func Test_Servers_ToMarkdown(t *testing.T) {
},
providers.Cyberghost: {
provider: providers.Cyberghost,
servers: Servers{
Servers: []Server{
servers: models.Servers{
Servers: []models.Server{
{Country: "a", UDP: true, Hostname: "xa"},
{Country: "b", TCP: true, Hostname: "xb"},
},
@@ -36,10 +37,10 @@ func Test_Servers_ToMarkdown(t *testing.T) {
},
providers.Fastestvpn: {
provider: providers.Fastestvpn,
servers: Servers{
Servers: []Server{
{Country: "a", Hostname: "xa", VPN: vpn.OpenVPN, TCP: true},
{Country: "b", Hostname: "xb", VPN: vpn.OpenVPN, UDP: true},
servers: models.Servers{
Servers: []models.Server{
{Country: "a", Hostname: "xa", VPN: constants.OpenVPN, TCP: true},
{Country: "b", Hostname: "xb", VPN: constants.OpenVPN, UDP: true},
},
},
formatted: "| Country | Hostname | VPN | TCP | UDP |\n" +
@@ -53,7 +54,7 @@ func Test_Servers_ToMarkdown(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()
markdown, err := testCase.servers.toMarkdown(testCase.provider)
markdown, err := serversToMarkdown(testCase.servers, testCase.provider)
assert.Equal(t, testCase.formatted, markdown)
if testCase.errMessage != "" {
+8 -13
View File
@@ -9,11 +9,12 @@ import (
"sort"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/pkg/updaters/models"
)
type AllServers struct {
Version uint16 // used for migration of the top level scheme
ProviderToServers map[string]Servers
ProviderToServers map[string]models.Servers
}
var _ json.Marshaler = (*AllServers)(nil)
@@ -110,7 +111,7 @@ func (a *AllServers) UnmarshalJSON(data []byte) (err error) {
return nil
}
a.ProviderToServers = make(map[string]Servers, len(keyValues))
a.ProviderToServers = make(map[string]models.Servers, len(keyValues))
allProviders := providers.All()
allProvidersSet := make(map[string]struct{}, len(allProviders))
@@ -131,7 +132,7 @@ func (a *AllServers) UnmarshalJSON(data []byte) (err error) {
key, err)
}
var servers Servers
var servers models.Servers
err = json.Unmarshal(jsonValue, &servers)
if err != nil {
return fmt.Errorf("decoding %s servers: %w",
@@ -151,24 +152,18 @@ func (a *AllServers) Count() (count int) {
return count
}
type Servers struct {
Version uint16 `json:"version"`
Timestamp int64 `json:"timestamp"`
Servers []Server `json:"servers,omitempty"`
}
func (s *Servers) Format(vpnProvider, format string) (formatted string, err error) {
func FormatServers(s models.Servers, vpnProvider, format string) (formatted string, err error) {
switch format {
case "markdown":
return s.toMarkdown(vpnProvider)
return serversToMarkdown(s, vpnProvider)
case "json":
return s.toJSON()
return serversToJSON(s)
default:
return "", fmt.Errorf("servers format not supported: %s", format)
}
}
func (s *Servers) toJSON() (formatted string, err error) {
func serversToJSON(s models.Servers) (formatted string, err error) {
buffer := bytes.NewBuffer(nil)
encoder := json.NewEncoder(buffer)
encoder.SetIndent("", " ")
+11 -10
View File
@@ -6,6 +6,7 @@ import (
"testing"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/pkg/updaters/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -20,18 +21,18 @@ func Test_AllServers_MarshalJSON(t *testing.T) {
}{
"no provider": {
allServers: &AllServers{
ProviderToServers: map[string]Servers{},
ProviderToServers: map[string]models.Servers{},
},
dataString: `{"version":0}`,
},
"two providers": {
allServers: &AllServers{
Version: 1,
ProviderToServers: map[string]Servers{
ProviderToServers: map[string]models.Servers{
providers.Cyberghost: {
Version: 1,
Timestamp: 1000,
Servers: []Server{
Servers: []models.Server{
{Country: "A"},
{Country: "B"},
},
@@ -39,7 +40,7 @@ func Test_AllServers_MarshalJSON(t *testing.T) {
providers.Privado: {
Version: 2,
Timestamp: 2000,
Servers: []Server{
Servers: []models.Server{
{City: "C"},
{City: "D"},
},
@@ -100,11 +101,11 @@ func Test_AllServers_UnmarshalJSON(t *testing.T) {
`"privado":{"version":2,"timestamp":2000,"servers":[{"city":"C"},{"city":"D"}]}}`,
allServers: AllServers{
Version: 1,
ProviderToServers: map[string]Servers{
ProviderToServers: map[string]models.Servers{
providers.Cyberghost: {
Version: 1,
Timestamp: 1000,
Servers: []Server{
Servers: []models.Server{
{Country: "A"},
{Country: "B"},
},
@@ -112,7 +113,7 @@ func Test_AllServers_UnmarshalJSON(t *testing.T) {
providers.Privado: {
Version: 2,
Timestamp: 2000,
Servers: []Server{
Servers: []models.Server{
{City: "C"},
{City: "D"},
},
@@ -146,11 +147,11 @@ func Test_AllServers_JSON_Marshal_Unmarshal(t *testing.T) {
allServers := &AllServers{
Version: 1,
ProviderToServers: map[string]Servers{
ProviderToServers: map[string]models.Servers{
providers.Cyberghost: {
Version: 1,
Timestamp: 1000,
Servers: []Server{
Servers: []models.Server{
{Country: "A"},
{Country: "B"},
},
@@ -158,7 +159,7 @@ func Test_AllServers_JSON_Marshal_Unmarshal(t *testing.T) {
providers.Privado: {
Version: 2,
Timestamp: 2000,
Servers: []Server{
Servers: []models.Server{
{City: "C"},
{City: "D"},
},
+1 -1
View File
@@ -7,8 +7,8 @@ import (
"strconv"
"strings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/pkg/updaters/constants"
)
func extractDataFromLines(lines []string) (
+1 -1
View File
@@ -5,8 +5,8 @@ import (
"net/netip"
"testing"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/pkg/updaters/constants"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
+3 -4
View File
@@ -1,9 +1,8 @@
package pmtud
import (
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/vpn"
pconstants "github.com/qdm12/gluetun/internal/pmtud/constants"
"github.com/qdm12/gluetun/pkg/updaters/constants"
)
// MaxTheoreticalVPNMTU returns the theoretical maximum MTU for a VPN tunnel
@@ -27,9 +26,9 @@ func MaxTheoreticalVPNMTU(vpnType, network string, ipv6 bool) uint32 {
panic("unknown network protocol: " + network)
}
switch vpnType {
case vpn.Wireguard, vpn.AmneziaWg:
case constants.Wireguard, constants.AmneziaWg:
vpnLinkMTU -= pconstants.WireguardHeaderLength
case vpn.OpenVPN:
case constants.OpenVPN:
vpnLinkMTU -= pconstants.OpenVPNHeaderMaxLength
default:
panic("unknown VPN type: " + vpnType)
+4 -3
View File
@@ -4,22 +4,23 @@ import (
"net/http"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/airvpn/updater"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/utils"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/airvpn"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
func New(storage common.Storage, client *http.Client) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(client),
Fetcher: airvpn.New(client),
}
}
+2 -117
View File
@@ -1,59 +1,17 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: github.com/qdm12/gluetun/internal/provider/common (interfaces: ParallelResolver,Storage,Unzipper,Warner)
// Source: github.com/qdm12/gluetun/internal/provider/common (interfaces: Storage)
// Package common is a generated GoMock package.
package common
import (
context "context"
netip "net/netip"
reflect "reflect"
gomock "github.com/golang/mock/gomock"
settings "github.com/qdm12/gluetun/internal/configuration/settings"
models "github.com/qdm12/gluetun/internal/models"
resolver "github.com/qdm12/gluetun/internal/updater/resolver"
models "github.com/qdm12/gluetun/pkg/updaters/models"
)
// MockParallelResolver is a mock of ParallelResolver interface.
type MockParallelResolver struct {
ctrl *gomock.Controller
recorder *MockParallelResolverMockRecorder
}
// MockParallelResolverMockRecorder is the mock recorder for MockParallelResolver.
type MockParallelResolverMockRecorder struct {
mock *MockParallelResolver
}
// NewMockParallelResolver creates a new mock instance.
func NewMockParallelResolver(ctrl *gomock.Controller) *MockParallelResolver {
mock := &MockParallelResolver{ctrl: ctrl}
mock.recorder = &MockParallelResolverMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockParallelResolver) EXPECT() *MockParallelResolverMockRecorder {
return m.recorder
}
// Resolve mocks base method.
func (m *MockParallelResolver) Resolve(arg0 context.Context, arg1 resolver.ParallelSettings) (map[string][]netip.Addr, []string, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Resolve", arg0, arg1)
ret0, _ := ret[0].(map[string][]netip.Addr)
ret1, _ := ret[1].([]string)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
}
// Resolve indicates an expected call of Resolve.
func (mr *MockParallelResolverMockRecorder) Resolve(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Resolve", reflect.TypeOf((*MockParallelResolver)(nil).Resolve), arg0, arg1)
}
// MockStorage is a mock of Storage interface.
type MockStorage struct {
ctrl *gomock.Controller
@@ -91,76 +49,3 @@ func (mr *MockStorageMockRecorder) FilterServers(arg0, arg1 interface{}) *gomock
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FilterServers", reflect.TypeOf((*MockStorage)(nil).FilterServers), arg0, arg1)
}
// MockUnzipper is a mock of Unzipper interface.
type MockUnzipper struct {
ctrl *gomock.Controller
recorder *MockUnzipperMockRecorder
}
// MockUnzipperMockRecorder is the mock recorder for MockUnzipper.
type MockUnzipperMockRecorder struct {
mock *MockUnzipper
}
// NewMockUnzipper creates a new mock instance.
func NewMockUnzipper(ctrl *gomock.Controller) *MockUnzipper {
mock := &MockUnzipper{ctrl: ctrl}
mock.recorder = &MockUnzipperMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockUnzipper) EXPECT() *MockUnzipperMockRecorder {
return m.recorder
}
// FetchAndExtract mocks base method.
func (m *MockUnzipper) FetchAndExtract(arg0 context.Context, arg1 string) (map[string][]byte, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FetchAndExtract", arg0, arg1)
ret0, _ := ret[0].(map[string][]byte)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// FetchAndExtract indicates an expected call of FetchAndExtract.
func (mr *MockUnzipperMockRecorder) FetchAndExtract(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FetchAndExtract", reflect.TypeOf((*MockUnzipper)(nil).FetchAndExtract), arg0, arg1)
}
// MockWarner is a mock of Warner interface.
type MockWarner struct {
ctrl *gomock.Controller
recorder *MockWarnerMockRecorder
}
// MockWarnerMockRecorder is the mock recorder for MockWarner.
type MockWarnerMockRecorder struct {
mock *MockWarner
}
// NewMockWarner creates a new mock instance.
func NewMockWarner(ctrl *gomock.Controller) *MockWarner {
mock := &MockWarner{ctrl: ctrl}
mock.recorder = &MockWarnerMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockWarner) EXPECT() *MockWarnerMockRecorder {
return m.recorder
}
// Warn mocks base method.
func (m *MockWarner) Warn(arg0 string) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Warn", arg0)
}
// Warn indicates an expected call of Warn.
func (mr *MockWarnerMockRecorder) Warn(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Warn", reflect.TypeOf((*MockWarner)(nil).Warn), arg0)
}
@@ -3,4 +3,4 @@ package common
// Exceptionally, these mocks are exported since they are used by all
// provider subpackages tests, and it reduces test code duplication a lot.
// Note mocks.go might need to be removed before re-generating it.
//go:generate mockgen -destination=mocks.go -package $GOPACKAGE . ParallelResolver,Storage,Unzipper,Warner
//go:generate mockgen -destination=mocks.go -package $GOPACKAGE . Storage
+1 -1
View File
@@ -2,7 +2,7 @@ package common
import (
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/pkg/updaters/models"
)
type Storage interface {
+4 -5
View File
@@ -4,9 +4,8 @@ import (
"fmt"
"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/pkg/updaters/constants"
)
// GetConnection gets the connection from the OpenVPN configuration file.
@@ -14,9 +13,9 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, _ bool) (
connection models.Connection, err error,
) {
switch selection.VPN {
case vpn.OpenVPN:
case constants.OpenVPN:
return getOpenVPNConnection(p.extractor, selection)
case vpn.Wireguard, vpn.AmneziaWg:
case constants.Wireguard, constants.AmneziaWg:
return getWireguardConnection(selection), nil
default:
return connection, fmt.Errorf("VPN type not supported for custom provider: %s", selection.VPN)
@@ -52,7 +51,7 @@ func getWireguardConnection(selection settings.ServerSelection) (
connection models.Connection,
) {
connection = models.Connection{
Type: vpn.Wireguard,
Type: constants.Wireguard,
IP: selection.Wireguard.EndpointIP,
Port: *selection.Wireguard.EndpointPort,
Protocol: constants.UDP,
+1 -1
View File
@@ -5,9 +5,9 @@ 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/models"
"github.com/qdm12/gluetun/pkg/updaters/constants"
"github.com/stretchr/testify/assert"
)
+1 -1
View File
@@ -2,8 +2,8 @@ package custom
import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/utils"
"github.com/qdm12/gluetun/pkg/updaters/common"
)
type Provider struct {
+6 -5
View File
@@ -3,23 +3,24 @@ package cyberghost
import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/cyberghost/updater"
"github.com/qdm12/gluetun/internal/provider/utils"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/cyberghost"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
func New(storage common.Storage, updaterWarner common.Warner,
parallelResolver common.ParallelResolver,
func New(storage common.Storage, updaterWarner updaters.Warner,
parallelResolver updaters.ParallelResolver,
) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(parallelResolver, updaterWarner),
Fetcher: cyberghost.New(parallelResolver, updaterWarner),
}
}
+6 -5
View File
@@ -5,24 +5,25 @@ import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/example/updater"
"github.com/qdm12/gluetun/internal/provider/utils"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/example"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
// TODO: remove unneeded arguments once the updater is implemented.
func New(storage common.Storage, updaterWarner common.Warner, client *http.Client,
unzipper common.Unzipper, parallelResolver common.ParallelResolver,
func New(storage common.Storage, updaterWarner updaters.Warner, client *http.Client,
unzipper updaters.Unzipper, parallelResolver updaters.ParallelResolver,
) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(updaterWarner, unzipper, client, parallelResolver),
Fetcher: example.New(updaterWarner, unzipper, client, parallelResolver),
}
}
+12 -11
View File
@@ -7,11 +7,12 @@ import (
"github.com/golang/mock/gomock"
"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/qdm12/gluetun/internal/provider/common"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/constants"
umodels "github.com/qdm12/gluetun/pkg/updaters/models"
"github.com/stretchr/testify/assert"
)
@@ -21,7 +22,7 @@ func Test_Provider_GetConnection(t *testing.T) {
const provider = providers.Expressvpn
testCases := map[string]struct {
filteredServers []models.Server
filteredServers []umodels.Server
storageErr error
selection settings.ServerSelection
ipv6Supported bool
@@ -34,7 +35,7 @@ func Test_Provider_GetConnection(t *testing.T) {
errMessage: "filtering servers: test error",
},
"default OpenVPN TCP port": {
filteredServers: []models.Server{
filteredServers: []umodels.Server{
{IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})}},
},
selection: settings.ServerSelection{
@@ -45,7 +46,7 @@ func Test_Provider_GetConnection(t *testing.T) {
panicMessage: "no default OpenVPN TCP port is defined!",
},
"default OpenVPN UDP port": {
filteredServers: []models.Server{
filteredServers: []umodels.Server{
{IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})}},
},
selection: settings.ServerSelection{
@@ -54,18 +55,18 @@ func Test_Provider_GetConnection(t *testing.T) {
},
}.WithDefaults(provider),
connection: models.Connection{
Type: vpn.OpenVPN,
Type: constants.OpenVPN,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Port: 1195,
Protocol: constants.UDP,
},
},
"default Wireguard port": {
filteredServers: []models.Server{
filteredServers: []umodels.Server{
{IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})}},
},
selection: settings.ServerSelection{
VPN: vpn.Wireguard,
VPN: constants.Wireguard,
}.WithDefaults(provider),
panicMessage: "no default Wireguard port is defined!",
},
@@ -80,9 +81,9 @@ func Test_Provider_GetConnection(t *testing.T) {
storage.EXPECT().FilterServers(provider, testCase.selection).
Return(testCase.filteredServers, testCase.storageErr)
unzipper := (common.Unzipper)(nil)
warner := (common.Warner)(nil)
parallelResolver := (common.ParallelResolver)(nil)
unzipper := (updaters.Unzipper)(nil)
warner := (updaters.Warner)(nil)
parallelResolver := (updaters.ParallelResolver)(nil)
provider := New(storage, unzipper, warner, parallelResolver)
if testCase.panicMessage != "" {
+6 -5
View File
@@ -3,23 +3,24 @@ package expressvpn
import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/expressvpn/updater"
"github.com/qdm12/gluetun/internal/provider/utils"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/expressvpn"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
func New(storage common.Storage, unzipper common.Unzipper, updaterWarner common.Warner,
parallelResolver common.ParallelResolver,
func New(storage common.Storage, unzipper updaters.Unzipper, updaterWarner updaters.Warner,
parallelResolver updaters.ParallelResolver,
) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
Fetcher: expressvpn.New(unzipper, updaterWarner, parallelResolver),
}
}
+6 -5
View File
@@ -5,23 +5,24 @@ import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/fastestvpn/updater"
"github.com/qdm12/gluetun/internal/provider/utils"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/fastestvpn"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
func New(storage common.Storage, client *http.Client, updaterWarner common.Warner,
parallelResolver common.ParallelResolver,
func New(storage common.Storage, client *http.Client, updaterWarner updaters.Warner,
parallelResolver updaters.ParallelResolver,
) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(client, updaterWarner, parallelResolver),
Fetcher: fastestvpn.New(client, updaterWarner, parallelResolver),
}
}
+6 -5
View File
@@ -3,23 +3,24 @@ package giganews
import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/giganews/updater"
"github.com/qdm12/gluetun/internal/provider/utils"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/giganews"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
func New(storage common.Storage, unzipper common.Unzipper, updaterWarner common.Warner,
parallelResolver common.ParallelResolver,
func New(storage common.Storage, unzipper updaters.Unzipper, updaterWarner updaters.Warner,
parallelResolver updaters.ParallelResolver,
) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
Fetcher: giganews.New(unzipper, updaterWarner, parallelResolver),
}
}
+6 -5
View File
@@ -5,23 +5,24 @@ import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/hidemyass/updater"
"github.com/qdm12/gluetun/internal/provider/utils"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/hidemyass"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
func New(storage common.Storage, client *http.Client, updaterWarner common.Warner,
parallelResolver common.ParallelResolver,
func New(storage common.Storage, client *http.Client, updaterWarner updaters.Warner,
parallelResolver updaters.ParallelResolver,
) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(client, updaterWarner, parallelResolver),
Fetcher: hidemyass.New(client, updaterWarner, parallelResolver),
}
}
+6 -5
View File
@@ -3,23 +3,24 @@ package ipvanish
import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/ipvanish/updater"
"github.com/qdm12/gluetun/internal/provider/utils"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/ipvanish"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
func New(storage common.Storage, unzipper common.Unzipper, updaterWarner common.Warner,
parallelResolver common.ParallelResolver,
func New(storage common.Storage, unzipper updaters.Unzipper, updaterWarner updaters.Warner,
parallelResolver updaters.ParallelResolver,
) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
Fetcher: ipvanish.New(unzipper, updaterWarner, parallelResolver),
}
}
+13 -12
View File
@@ -8,11 +8,12 @@ import (
"github.com/golang/mock/gomock"
"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/qdm12/gluetun/internal/provider/common"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/constants"
umodels "github.com/qdm12/gluetun/pkg/updaters/models"
"github.com/stretchr/testify/assert"
)
@@ -22,7 +23,7 @@ func Test_Provider_GetConnection(t *testing.T) {
const provider = providers.Ivpn
testCases := map[string]struct {
filteredServers []models.Server
filteredServers []umodels.Server
storageErr error
selection settings.ServerSelection
ipv6Supported bool
@@ -34,7 +35,7 @@ func Test_Provider_GetConnection(t *testing.T) {
errMessage: "filtering servers: test error",
},
"default OpenVPN TCP port": {
filteredServers: []models.Server{
filteredServers: []umodels.Server{
{IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})}},
},
selection: settings.ServerSelection{
@@ -43,14 +44,14 @@ func Test_Provider_GetConnection(t *testing.T) {
},
}.WithDefaults(provider),
connection: models.Connection{
Type: vpn.OpenVPN,
Type: constants.OpenVPN,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Port: 443,
Protocol: constants.TCP,
},
},
"default OpenVPN UDP port": {
filteredServers: []models.Server{
filteredServers: []umodels.Server{
{IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})}},
},
selection: settings.ServerSelection{
@@ -59,21 +60,21 @@ func Test_Provider_GetConnection(t *testing.T) {
},
}.WithDefaults(provider),
connection: models.Connection{
Type: vpn.OpenVPN,
Type: constants.OpenVPN,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Port: 1194,
Protocol: constants.UDP,
},
},
"default Wireguard port": {
filteredServers: []models.Server{
filteredServers: []umodels.Server{
{IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})}, WgPubKey: "x"},
},
selection: settings.ServerSelection{
VPN: vpn.Wireguard,
VPN: constants.Wireguard,
}.WithDefaults(provider),
connection: models.Connection{
Type: vpn.Wireguard,
Type: constants.Wireguard,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Port: 58237,
Protocol: constants.UDP,
@@ -92,8 +93,8 @@ func Test_Provider_GetConnection(t *testing.T) {
Return(testCase.filteredServers, testCase.storageErr)
client := (*http.Client)(nil)
warner := (common.Warner)(nil)
parallelResolver := (common.ParallelResolver)(nil)
warner := (updaters.Warner)(nil)
parallelResolver := (updaters.ParallelResolver)(nil)
provider := New(storage, client, warner, parallelResolver)
connection, err := provider.GetConnection(testCase.selection, testCase.ipv6Supported)
+6 -5
View File
@@ -5,23 +5,24 @@ import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/ivpn/updater"
"github.com/qdm12/gluetun/internal/provider/utils"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/ivpn"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
func New(storage common.Storage, client *http.Client, updaterWarner common.Warner,
parallelResolver common.ParallelResolver,
func New(storage common.Storage, client *http.Client, updaterWarner updaters.Warner,
parallelResolver updaters.ParallelResolver,
) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(client, updaterWarner, parallelResolver),
Fetcher: ivpn.New(client, updaterWarner, parallelResolver),
}
}
+6 -6
View File
@@ -8,11 +8,11 @@ import (
"github.com/golang/mock/gomock"
"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/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/pkg/updaters/constants"
umodels "github.com/qdm12/gluetun/pkg/updaters/models"
"github.com/stretchr/testify/assert"
)
@@ -22,7 +22,7 @@ func Test_Provider_GetConnection(t *testing.T) {
const provider = providers.Mullvad
testCases := map[string]struct {
filteredServers []models.Server
filteredServers []umodels.Server
storageErr error
selection settings.ServerSelection
ipv6Supported bool
@@ -34,14 +34,14 @@ func Test_Provider_GetConnection(t *testing.T) {
errMessage: "filtering servers: test error",
},
"default Wireguard port": {
filteredServers: []models.Server{
filteredServers: []umodels.Server{
{IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})}, WgPubKey: "x"},
},
selection: settings.ServerSelection{
VPN: vpn.Wireguard,
VPN: constants.Wireguard,
}.WithDefaults(provider),
connection: models.Connection{
Type: vpn.Wireguard,
Type: constants.Wireguard,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Port: 51820,
Protocol: constants.UDP,
+4 -3
View File
@@ -5,14 +5,15 @@ import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/mullvad/updater"
"github.com/qdm12/gluetun/internal/provider/utils"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/mullvad"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
func New(storage common.Storage, client *http.Client,
@@ -20,7 +21,7 @@ func New(storage common.Storage, client *http.Client,
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(client),
Fetcher: mullvad.New(client),
}
}
+5 -4
View File
@@ -5,22 +5,23 @@ import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/nordvpn/updater"
"github.com/qdm12/gluetun/internal/provider/utils"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/nordvpn"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
func New(storage common.Storage, client *http.Client, updaterWarner common.Warner,
func New(storage common.Storage, client *http.Client, updaterWarner updaters.Warner,
) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(client, updaterWarner),
Fetcher: nordvpn.New(client, updaterWarner),
}
}
+5 -4
View File
@@ -3,22 +3,23 @@ package perfectprivacy
import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/perfectprivacy/updater"
"github.com/qdm12/gluetun/internal/provider/utils"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/perfectprivacy"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
func New(storage common.Storage, unzipper common.Unzipper, updaterWarner common.Warner,
func New(storage common.Storage, unzipper updaters.Unzipper, updaterWarner updaters.Warner,
) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(unzipper, updaterWarner),
Fetcher: perfectprivacy.New(unzipper, updaterWarner),
}
}
+5 -4
View File
@@ -5,22 +5,23 @@ import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/privado/updater"
"github.com/qdm12/gluetun/internal/provider/utils"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/privado"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
func New(storage common.Storage, client *http.Client, updaterWarner common.Warner,
func New(storage common.Storage, client *http.Client, updaterWarner updaters.Warner,
) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(client, updaterWarner),
Fetcher: privado.New(client, updaterWarner),
}
}
@@ -7,15 +7,16 @@ import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/privateinternetaccess/updater"
"github.com/qdm12/gluetun/internal/provider/utils"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/privateinternetaccess"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
timeNow func() time.Time
common.Fetcher
updaters.Fetcher
// Port forwarding
portForwardPath string
apiIP netip.Addr
@@ -30,7 +31,7 @@ func New(storage common.Storage, timeNow func() time.Time,
timeNow: timeNow,
connPicker: utils.NewConnectionPicker(),
portForwardPath: jsonPortForwardPath,
Fetcher: updater.New(client),
Fetcher: privateinternetaccess.New(client),
}
}
+6 -5
View File
@@ -3,23 +3,24 @@ package privatevpn
import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/privatevpn/updater"
"github.com/qdm12/gluetun/internal/provider/utils"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/privatevpn"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
func New(storage common.Storage, unzipper common.Unzipper, updaterWarner common.Warner,
parallelResolver common.ParallelResolver,
func New(storage common.Storage, unzipper updaters.Unzipper, updaterWarner updaters.Warner,
parallelResolver updaters.ParallelResolver,
) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
Fetcher: privatevpn.New(unzipper, updaterWarner, parallelResolver),
}
}
+5 -4
View File
@@ -5,24 +5,25 @@ import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/protonvpn/updater"
"github.com/qdm12/gluetun/internal/provider/utils"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/protonvpn"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
internalToExternalPorts map[uint16]uint16
}
func New(storage common.Storage, client *http.Client, updaterWarner common.Warner,
func New(storage common.Storage, client *http.Client, updaterWarner updaters.Warner,
email, password string,
) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(client, updaterWarner, email, password),
Fetcher: protonvpn.New(client, updaterWarner, email, password),
}
}
+2 -1
View File
@@ -5,6 +5,7 @@ import (
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/models"
umodels "github.com/qdm12/gluetun/pkg/updaters/models"
)
// Provider contains methods to read and modify the openvpn configuration to connect as a client.
@@ -13,5 +14,5 @@ type Provider interface {
OpenVPNConfig(connection models.Connection, settings settings.OpenVPN, ipv6Supported bool) (lines []string)
Name() string
FetchServers(ctx context.Context, minServers int) (
servers []models.Server, err error)
servers []umodels.Server, err error)
}
+5 -4
View File
@@ -9,7 +9,6 @@ import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/airvpn"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/custom"
"github.com/qdm12/gluetun/internal/provider/cyberghost"
"github.com/qdm12/gluetun/internal/provider/expressvpn"
@@ -33,6 +32,8 @@ import (
"github.com/qdm12/gluetun/internal/provider/vpnunlimited"
"github.com/qdm12/gluetun/internal/provider/vyprvpn"
"github.com/qdm12/gluetun/internal/provider/windscribe"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
umodels "github.com/qdm12/gluetun/pkg/updaters/models"
)
type Providers struct {
@@ -41,7 +42,7 @@ type Providers struct {
type Storage interface {
FilterServers(provider string, selection settings.ServerSelection) (
servers []models.Server, err error)
servers []umodels.Server, err error)
}
type Extractor interface {
@@ -50,8 +51,8 @@ type Extractor interface {
}
func NewProviders(storage Storage, timeNow func() time.Time,
updaterWarner common.Warner, client *http.Client, unzipper common.Unzipper,
parallelResolver common.ParallelResolver, ipFetcher common.IPFetcher,
updaterWarner updaters.Warner, client *http.Client, unzipper updaters.Unzipper,
parallelResolver updaters.ParallelResolver, ipFetcher updaters.IPFetcher,
extractor custom.Extractor, credentials settings.Updater,
) *Providers {
//nolint:lll
+6 -5
View File
@@ -3,23 +3,24 @@ package purevpn
import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/purevpn/updater"
"github.com/qdm12/gluetun/internal/provider/utils"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/purevpn"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
func New(storage common.Storage, ipFetcher common.IPFetcher, unzipper common.Unzipper,
updaterWarner common.Warner, parallelResolver common.ParallelResolver,
func New(storage common.Storage, ipFetcher updaters.IPFetcher, unzipper updaters.Unzipper,
updaterWarner updaters.Warner, parallelResolver updaters.ParallelResolver,
) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(ipFetcher, unzipper, updaterWarner, parallelResolver),
Fetcher: purevpn.New(ipFetcher, unzipper, updaterWarner, parallelResolver),
}
}
+6 -5
View File
@@ -5,23 +5,24 @@ import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/slickvpn/updater"
"github.com/qdm12/gluetun/internal/provider/utils"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/slickvpn"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
func New(storage common.Storage, client *http.Client, updaterWarner common.Warner,
parallelResolver common.ParallelResolver,
func New(storage common.Storage, client *http.Client, updaterWarner updaters.Warner,
parallelResolver updaters.ParallelResolver,
) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(client, updaterWarner, parallelResolver),
Fetcher: slickvpn.New(client, updaterWarner, parallelResolver),
}
}
+6 -5
View File
@@ -5,23 +5,24 @@ import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/surfshark/updater"
"github.com/qdm12/gluetun/internal/provider/utils"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/surfshark"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
func New(storage common.Storage, client *http.Client, unzipper common.Unzipper,
updaterWarner common.Warner, parallelResolver common.ParallelResolver,
func New(storage common.Storage, client *http.Client, unzipper updaters.Unzipper,
updaterWarner updaters.Warner, parallelResolver updaters.ParallelResolver,
) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(client, unzipper, updaterWarner, parallelResolver),
Fetcher: surfshark.New(client, unzipper, updaterWarner, parallelResolver),
}
}
@@ -1,28 +0,0 @@
package updater
import (
"time"
"github.com/qdm12/gluetun/internal/updater/resolver"
)
func parallelResolverSettings(hosts []string) (settings resolver.ParallelSettings) {
const (
maxFailRatio = 0.1
maxDuration = 20 * time.Second
betweenDuration = time.Second
maxNoNew = 2
maxFails = 2
)
return resolver.ParallelSettings{
Hosts: hosts,
MaxFailRatio: maxFailRatio,
Repeat: resolver.RepeatSettings{
MaxDuration: maxDuration,
BetweenDuration: betweenDuration,
MaxNoNew: maxNoNew,
MaxFails: maxFails,
SortIPs: true,
},
}
}
+6 -5
View File
@@ -3,23 +3,24 @@ package torguard
import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/torguard/updater"
"github.com/qdm12/gluetun/internal/provider/utils"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/torguard"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
func New(storage common.Storage, unzipper common.Unzipper, updaterWarner common.Warner,
parallelResolver common.ParallelResolver,
func New(storage common.Storage, unzipper updaters.Unzipper, updaterWarner updaters.Warner,
parallelResolver updaters.ParallelResolver,
) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
Fetcher: torguard.New(unzipper, updaterWarner, parallelResolver),
}
}
@@ -1,28 +0,0 @@
package updater
import (
"time"
"github.com/qdm12/gluetun/internal/updater/resolver"
)
func parallelResolverSettings(hosts []string) (settings resolver.ParallelSettings) {
const (
maxFailRatio = 0.1
maxDuration = 20 * time.Second
betweenDuration = time.Second
maxNoNew = 2
maxFails = 2
)
return resolver.ParallelSettings{
Hosts: hosts,
MaxFailRatio: maxFailRatio,
Repeat: resolver.RepeatSettings{
MaxDuration: maxDuration,
BetweenDuration: betweenDuration,
MaxNoNew: maxNoNew,
MaxFails: maxFails,
SortIPs: true,
},
}
}
@@ -1,21 +0,0 @@
package updater
import (
"github.com/qdm12/gluetun/internal/provider/common"
)
type Updater struct {
unzipper common.Unzipper
parallelResolver common.ParallelResolver
warner common.Warner
}
func New(unzipper common.Unzipper, warner common.Warner,
parallelResolver common.ParallelResolver,
) *Updater {
return &Updater{
unzipper: unzipper,
parallelResolver: parallelResolver,
warner: warner,
}
}
+4 -3
View File
@@ -5,8 +5,9 @@ import (
"slices"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/pkg/updaters/constants"
umodels "github.com/qdm12/gluetun/pkg/updaters/models"
)
type ConnectionDefaults struct {
@@ -27,7 +28,7 @@ func NewConnectionDefaults(openvpnTCPPort, openvpnUDPPort,
type Storage interface {
FilterServers(provider string, selection settings.ServerSelection) (
servers []models.Server, err error)
servers []umodels.Server, err error)
}
func GetConnection(provider string,
@@ -56,7 +57,7 @@ func GetConnection(provider string,
}
hostname := server.Hostname
if selection.VPN == vpn.OpenVPN && server.OvpnX509 != "" {
if selection.VPN == constants.OpenVPN && server.OvpnX509 != "" {
// For Windscribe where hostname and
// OpenVPN x509 are not the same.
hostname = server.OvpnX509
+23 -23
View File
@@ -8,11 +8,11 @@ import (
"github.com/golang/mock/gomock"
"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/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/pkg/updaters/constants"
umodels "github.com/qdm12/gluetun/pkg/updaters/models"
"github.com/stretchr/testify/assert"
)
@@ -21,7 +21,7 @@ func Test_GetConnection(t *testing.T) {
testCases := map[string]struct {
provider string
filteredServers []models.Server
filteredServers []umodels.Server
filterError error
serverSelection settings.ServerSelection
defaults ConnectionDefaults
@@ -35,9 +35,9 @@ func Test_GetConnection(t *testing.T) {
errMessage: "filtering servers: test error",
},
"server without IPs": {
filteredServers: []models.Server{
{VPN: vpn.OpenVPN, UDP: true},
{VPN: vpn.OpenVPN, UDP: true},
filteredServers: []umodels.Server{
{VPN: constants.OpenVPN, UDP: true},
{VPN: constants.OpenVPN, UDP: true},
},
serverSelection: settings.ServerSelection{}.
WithDefaults(providers.Mullvad),
@@ -49,9 +49,9 @@ func Test_GetConnection(t *testing.T) {
errMessage: "no connection to pick from",
},
"OpenVPN server with hostname": {
filteredServers: []models.Server{
filteredServers: []umodels.Server{
{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
UDP: true,
IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})},
Hostname: "name",
@@ -62,7 +62,7 @@ func Test_GetConnection(t *testing.T) {
defaults: NewConnectionDefaults(443, 1194, 58820),
randSource: rand.NewSource(0),
connection: models.Connection{
Type: vpn.OpenVPN,
Type: constants.OpenVPN,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Protocol: constants.UDP,
Port: 1194,
@@ -70,9 +70,9 @@ func Test_GetConnection(t *testing.T) {
},
},
"OpenVPN server with x509": {
filteredServers: []models.Server{
filteredServers: []umodels.Server{
{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
UDP: true,
IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})},
Hostname: "hostname",
@@ -84,7 +84,7 @@ func Test_GetConnection(t *testing.T) {
defaults: NewConnectionDefaults(443, 1194, 58820),
randSource: rand.NewSource(0),
connection: models.Connection{
Type: vpn.OpenVPN,
Type: constants.OpenVPN,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Protocol: constants.UDP,
Port: 1194,
@@ -92,9 +92,9 @@ func Test_GetConnection(t *testing.T) {
},
},
"server with IPv4 and IPv6": {
filteredServers: []models.Server{
filteredServers: []umodels.Server{
{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
UDP: true,
IPs: []netip.Addr{
netip.AddrFrom4([4]byte{1, 1, 1, 1}),
@@ -112,16 +112,16 @@ func Test_GetConnection(t *testing.T) {
defaults: NewConnectionDefaults(443, 1194, 58820),
randSource: rand.NewSource(0),
connection: models.Connection{
Type: vpn.OpenVPN,
Type: constants.OpenVPN,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Protocol: constants.UDP,
Port: 1194,
},
},
"server with IPv4 and IPv6 and ipv6 supported": {
filteredServers: []models.Server{
filteredServers: []umodels.Server{
{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
UDP: true,
IPs: []netip.Addr{
netip.AddrFrom4([4]byte{1, 1, 1, 1}),
@@ -135,28 +135,28 @@ func Test_GetConnection(t *testing.T) {
ipv6Supported: true,
randSource: rand.NewSource(0),
connection: models.Connection{
Type: vpn.OpenVPN,
Type: constants.OpenVPN,
IP: netip.IPv6Unspecified(),
Protocol: constants.UDP,
Port: 1194,
},
},
"mixed servers": {
filteredServers: []models.Server{
filteredServers: []umodels.Server{
{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
UDP: true,
IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})},
OvpnX509: "ovpnx509",
},
{
VPN: vpn.Wireguard,
VPN: constants.Wireguard,
UDP: true,
IPs: []netip.Addr{netip.AddrFrom4([4]byte{2, 2, 2, 2})},
OvpnX509: "ovpnx509",
},
{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
UDP: true,
IPs: []netip.Addr{
netip.AddrFrom4([4]byte{3, 3, 3, 3}),
@@ -170,7 +170,7 @@ func Test_GetConnection(t *testing.T) {
defaults: NewConnectionDefaults(443, 1194, 58820),
randSource: rand.NewSource(0),
connection: models.Connection{
Type: vpn.OpenVPN,
Type: constants.OpenVPN,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Protocol: constants.UDP,
Port: 1194,
+9 -1
View File
@@ -4,7 +4,7 @@ import (
"context"
"fmt"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/pkg/updaters/models"
)
type NoFetcher struct {
@@ -22,3 +22,11 @@ func (n *NoFetcher) FetchServers(context.Context, int) (
) {
return nil, fmt.Errorf("fetching of servers is not supported for %s", n.providerName)
}
func (n *NoFetcher) Version() uint16 {
return 1
}
func (n *NoFetcher) Name() string {
return n.providerName
}
+1 -1
View File
@@ -5,10 +5,10 @@ import (
"strings"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/openvpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/openvpn/pkcs8"
"github.com/qdm12/gluetun/pkg/updaters/constants"
)
type OpenVPNProviderSettings struct {
+4 -4
View File
@@ -9,8 +9,8 @@ import (
"sync"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/pkg/updaters/constants"
)
// ConnectionPicker is a struct that holds the state of the connection pool cycler.
@@ -89,16 +89,16 @@ func pickConnection(connections []models.Connection,
var targetIP netip.Addr
switch selection.VPN {
case vpn.OpenVPN:
case constants.OpenVPN:
targetIP = selection.OpenVPN.EndpointIP
case vpn.Wireguard, vpn.AmneziaWg:
case constants.Wireguard, constants.AmneziaWg:
targetIP = selection.Wireguard.EndpointIP
default:
panic("unknown VPN type: " + selection.VPN)
}
targetIPSet := targetIP.IsValid() && !targetIP.IsUnspecified()
if targetIPSet && selection.VPN == vpn.Wireguard {
if targetIPSet && selection.VPN == constants.Wireguard {
// we need the right public key
return getTargetIPConnection(connections, targetIP)
}
+16 -16
View File
@@ -5,8 +5,8 @@ import (
"testing"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/pkg/updaters/constants"
"github.com/stretchr/testify/assert"
)
@@ -58,56 +58,56 @@ func Test_pickConnection(t *testing.T) {
},
"openvpn_cycles": {
connections: []models.Connection{
{Type: vpn.OpenVPN, Port: 1, Hostname: "one"},
{Type: vpn.OpenVPN, Port: 2, Hostname: "two"},
{Type: constants.OpenVPN, Port: 1, Hostname: "one"},
{Type: constants.OpenVPN, Port: 2, Hostname: "two"},
},
selection: settings.ServerSelection{VPN: vpn.OpenVPN},
selection: settings.ServerSelection{VPN: constants.OpenVPN},
connection1: models.Connection{
Type: vpn.OpenVPN, Port: 1,
Type: constants.OpenVPN, Port: 1,
Hostname: "one",
},
connection2: models.Connection{
Type: vpn.OpenVPN, Port: 2,
Type: constants.OpenVPN, Port: 2,
Hostname: "two",
},
},
"openvpn_endpoint_ip_overrides_cycle_pick": {
connections: []models.Connection{
{Type: vpn.OpenVPN, Hostname: "one", IP: netip.AddrFrom4([4]byte{1, 1, 1, 1})},
{Type: vpn.OpenVPN, Hostname: "two", IP: netip.AddrFrom4([4]byte{2, 2, 2, 2})},
{Type: constants.OpenVPN, Hostname: "one", IP: netip.AddrFrom4([4]byte{1, 1, 1, 1})},
{Type: constants.OpenVPN, Hostname: "two", IP: netip.AddrFrom4([4]byte{2, 2, 2, 2})},
},
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
EndpointIP: netip.AddrFrom4([4]byte{9, 9, 9, 9}),
},
},
connection1: models.Connection{
Type: vpn.OpenVPN, Hostname: "one",
Type: constants.OpenVPN, Hostname: "one",
IP: netip.AddrFrom4([4]byte{9, 9, 9, 9}),
},
connection2: models.Connection{
Type: vpn.OpenVPN, Hostname: "two",
Type: constants.OpenVPN, Hostname: "two",
IP: netip.AddrFrom4([4]byte{9, 9, 9, 9}),
},
},
"wireguard_endpoint_ip_picks_target": {
connections: []models.Connection{
{Type: vpn.Wireguard, Hostname: "one", IP: netip.AddrFrom4([4]byte{1, 1, 1, 1})},
{Type: vpn.Wireguard, Hostname: "two", IP: netip.AddrFrom4([4]byte{2, 2, 2, 2})},
{Type: constants.Wireguard, Hostname: "one", IP: netip.AddrFrom4([4]byte{1, 1, 1, 1})},
{Type: constants.Wireguard, Hostname: "two", IP: netip.AddrFrom4([4]byte{2, 2, 2, 2})},
},
selection: settings.ServerSelection{
VPN: vpn.Wireguard,
VPN: constants.Wireguard,
Wireguard: settings.WireguardSelection{
EndpointIP: netip.AddrFrom4([4]byte{2, 2, 2, 2}),
},
},
connection1: models.Connection{
Type: vpn.Wireguard, Hostname: "two",
Type: constants.Wireguard, Hostname: "two",
IP: netip.AddrFrom4([4]byte{2, 2, 2, 2}),
},
connection2: models.Connection{
Type: vpn.Wireguard, Hostname: "two",
Type: constants.Wireguard, Hostname: "two",
IP: netip.AddrFrom4([4]byte{2, 2, 2, 2}),
},
},
+2 -3
View File
@@ -4,15 +4,14 @@ import (
"fmt"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/pkg/updaters/constants"
)
func getPort(selection settings.ServerSelection,
defaultOpenVPNTCP, defaultOpenVPNUDP, defaultWireguard uint16,
) (port uint16) {
switch selection.VPN {
case vpn.Wireguard:
case constants.Wireguard:
customPort := *selection.Wireguard.EndpointPort
if customPort > 0 {
return customPort
+9 -10
View File
@@ -4,8 +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/qdm12/gluetun/pkg/updaters/constants"
"github.com/stretchr/testify/assert"
)
@@ -37,7 +36,7 @@ func Test_GetPort(t *testing.T) {
},
"OpenVPN UDP": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
CustomPort: uint16Ptr(0),
Protocol: constants.UDP,
@@ -50,7 +49,7 @@ func Test_GetPort(t *testing.T) {
},
"OpenVPN UDP no default port defined": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
CustomPort: uint16Ptr(0),
Protocol: constants.UDP,
@@ -60,7 +59,7 @@ func Test_GetPort(t *testing.T) {
},
"OpenVPN TCP": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
CustomPort: uint16Ptr(0),
Protocol: constants.TCP,
@@ -71,7 +70,7 @@ func Test_GetPort(t *testing.T) {
},
"OpenVPN TCP no default port defined": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
CustomPort: uint16Ptr(0),
Protocol: constants.TCP,
@@ -81,7 +80,7 @@ func Test_GetPort(t *testing.T) {
},
"OpenVPN custom port": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
CustomPort: uint16Ptr(1234),
},
@@ -90,14 +89,14 @@ func Test_GetPort(t *testing.T) {
},
"Wireguard": {
selection: settings.ServerSelection{
VPN: vpn.Wireguard,
VPN: constants.Wireguard,
}.WithDefaults(""),
defaultWireguard: defaultWireguard,
port: defaultWireguard,
},
"Wireguard custom port": {
selection: settings.ServerSelection{
VPN: vpn.Wireguard,
VPN: constants.Wireguard,
Wireguard: settings.WireguardSelection{
EndpointPort: uint16Ptr(1234),
},
@@ -107,7 +106,7 @@ func Test_GetPort(t *testing.T) {
},
"Wireguard no default port defined": {
selection: settings.ServerSelection{
VPN: vpn.Wireguard,
VPN: constants.Wireguard,
}.WithDefaults(""),
panics: "no default Wireguard port is defined!",
},
+3 -4
View File
@@ -2,12 +2,11 @@ package utils
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/pkg/updaters/constants"
)
func getProtocol(selection settings.ServerSelection) (protocol string) {
if selection.VPN == vpn.OpenVPN && selection.OpenVPN.Protocol == constants.TCP {
if selection.VPN == constants.OpenVPN && selection.OpenVPN.Protocol == constants.TCP {
return constants.TCP
}
return constants.UDP
@@ -17,7 +16,7 @@ func filterByProtocol(selection settings.ServerSelection,
serverTCP, serverUDP bool,
) (filtered bool) {
switch selection.VPN {
case vpn.Wireguard:
case constants.Wireguard:
return !serverUDP
default: // OpenVPN
wantTCP := selection.OpenVPN.Protocol == constants.TCP
+10 -11
View File
@@ -4,8 +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/qdm12/gluetun/pkg/updaters/constants"
"github.com/stretchr/testify/assert"
)
@@ -21,7 +20,7 @@ func Test_getProtocol(t *testing.T) {
},
"OpenVPN UDP": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
Protocol: constants.UDP,
},
@@ -30,7 +29,7 @@ func Test_getProtocol(t *testing.T) {
},
"OpenVPN TCP": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
Protocol: constants.TCP,
},
@@ -39,7 +38,7 @@ func Test_getProtocol(t *testing.T) {
},
"Wireguard": {
selection: settings.ServerSelection{
VPN: vpn.Wireguard,
VPN: constants.Wireguard,
},
protocol: constants.UDP,
},
@@ -67,21 +66,21 @@ func Test_filterByProtocol(t *testing.T) {
}{
"Wireguard and server has UDP": {
selection: settings.ServerSelection{
VPN: vpn.Wireguard,
VPN: constants.Wireguard,
},
serverUDP: true,
filtered: false,
},
"Wireguard and server has not UDP": {
selection: settings.ServerSelection{
VPN: vpn.Wireguard,
VPN: constants.Wireguard,
},
serverUDP: false,
filtered: true,
},
"OpenVPN UDP and server has UDP": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
Protocol: constants.UDP,
},
@@ -91,7 +90,7 @@ func Test_filterByProtocol(t *testing.T) {
},
"OpenVPN UDP and server has not UDP": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
Protocol: constants.UDP,
},
@@ -101,7 +100,7 @@ func Test_filterByProtocol(t *testing.T) {
},
"OpenVPN TCP and server has TCP": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
Protocol: constants.TCP,
},
@@ -111,7 +110,7 @@ func Test_filterByProtocol(t *testing.T) {
},
"OpenVPN TCP and server has not TCP": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
Protocol: constants.TCP,
},
+6 -5
View File
@@ -6,22 +6,23 @@ import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/utils"
"github.com/qdm12/gluetun/internal/provider/vpnsecure/updater"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/vpnsecure"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
func New(storage common.Storage, client *http.Client, updaterWarner common.Warner,
parallelResolver common.ParallelResolver,
func New(storage common.Storage, client *http.Client, updaterWarner updaters.Warner,
parallelResolver updaters.ParallelResolver,
) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(client, updaterWarner, parallelResolver),
Fetcher: vpnsecure.New(client, updaterWarner, parallelResolver),
}
}
@@ -1,23 +0,0 @@
package updater
import (
"net/http"
"github.com/qdm12/gluetun/internal/provider/common"
)
type Updater struct {
client *http.Client
parallelResolver common.ParallelResolver
warner common.Warner
}
func New(client *http.Client, warner common.Warner,
parallelResolver common.ParallelResolver,
) *Updater {
return &Updater{
client: client,
parallelResolver: parallelResolver,
warner: warner,
}
}
+6 -5
View File
@@ -4,22 +4,23 @@ import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/utils"
"github.com/qdm12/gluetun/internal/provider/vpnunlimited/updater"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/vpnunlimited"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
func New(storage common.Storage, unzipper common.Unzipper, updaterWarner common.Warner,
parallelResolver common.ParallelResolver,
func New(storage common.Storage, unzipper updaters.Unzipper, updaterWarner updaters.Warner,
parallelResolver updaters.ParallelResolver,
) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
Fetcher: vpnunlimited.New(unzipper, updaterWarner, parallelResolver),
}
}
@@ -1,28 +0,0 @@
package updater
import (
"time"
"github.com/qdm12/gluetun/internal/updater/resolver"
)
func parallelResolverSettings(hosts []string) (settings resolver.ParallelSettings) {
const (
maxFailRatio = 0.1
maxDuration = 20 * time.Second
betweenDuration = time.Second
maxNoNew = 2
maxFails = 2
)
return resolver.ParallelSettings{
Hosts: hosts,
MaxFailRatio: maxFailRatio,
Repeat: resolver.RepeatSettings{
MaxDuration: maxDuration,
BetweenDuration: betweenDuration,
MaxNoNew: maxNoNew,
MaxFails: maxFails,
SortIPs: true,
},
}
}
@@ -1,21 +0,0 @@
package updater
import (
"github.com/qdm12/gluetun/internal/provider/common"
)
type Updater struct {
unzipper common.Unzipper
parallelResolver common.ParallelResolver
warner common.Warner
}
func New(unzipper common.Unzipper, warner common.Warner,
parallelResolver common.ParallelResolver,
) *Updater {
return &Updater{
unzipper: unzipper,
parallelResolver: parallelResolver,
warner: warner,
}
}
+6 -5
View File
@@ -4,22 +4,23 @@ import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/utils"
"github.com/qdm12/gluetun/internal/provider/vyprvpn/updater"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/vyprvpn"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
func New(storage common.Storage, unzipper common.Unzipper, updaterWarner common.Warner,
parallelResolver common.ParallelResolver,
func New(storage common.Storage, unzipper updaters.Unzipper, updaterWarner updaters.Warner,
parallelResolver updaters.ParallelResolver,
) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
Fetcher: vyprvpn.New(unzipper, updaterWarner, parallelResolver),
}
}
@@ -1,21 +0,0 @@
package updater
import (
"github.com/qdm12/gluetun/internal/provider/common"
)
type Updater struct {
unzipper common.Unzipper
parallelResolver common.ParallelResolver
warner common.Warner
}
func New(unzipper common.Unzipper, warner common.Warner,
parallelResolver common.ParallelResolver,
) *Updater {
return &Updater{
unzipper: unzipper,
parallelResolver: parallelResolver,
warner: warner,
}
}
+12 -11
View File
@@ -8,11 +8,12 @@ import (
"github.com/golang/mock/gomock"
"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/qdm12/gluetun/internal/provider/common"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/constants"
umodels "github.com/qdm12/gluetun/pkg/updaters/models"
"github.com/stretchr/testify/assert"
)
@@ -22,7 +23,7 @@ func Test_Provider_GetConnection(t *testing.T) {
const provider = providers.Windscribe
testCases := map[string]struct {
filteredServers []models.Server
filteredServers []umodels.Server
storageErr error
selection settings.ServerSelection
ipv6Supported bool
@@ -35,7 +36,7 @@ func Test_Provider_GetConnection(t *testing.T) {
errMessage: "filtering servers: test error",
},
"default OpenVPN TCP port": {
filteredServers: []models.Server{
filteredServers: []umodels.Server{
{IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})}},
},
selection: settings.ServerSelection{
@@ -44,14 +45,14 @@ func Test_Provider_GetConnection(t *testing.T) {
},
}.WithDefaults(provider),
connection: models.Connection{
Type: vpn.OpenVPN,
Type: constants.OpenVPN,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Port: 443,
Protocol: constants.TCP,
},
},
"default OpenVPN UDP port": {
filteredServers: []models.Server{
filteredServers: []umodels.Server{
{IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})}},
},
selection: settings.ServerSelection{
@@ -60,21 +61,21 @@ func Test_Provider_GetConnection(t *testing.T) {
},
}.WithDefaults(provider),
connection: models.Connection{
Type: vpn.OpenVPN,
Type: constants.OpenVPN,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Port: 1194,
Protocol: constants.UDP,
},
},
"default Wireguard port": {
filteredServers: []models.Server{
filteredServers: []umodels.Server{
{IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})}, WgPubKey: "x"},
},
selection: settings.ServerSelection{
VPN: vpn.Wireguard,
VPN: constants.Wireguard,
}.WithDefaults(provider),
connection: models.Connection{
Type: vpn.Wireguard,
Type: constants.Wireguard,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Port: 1194,
Protocol: constants.UDP,
@@ -93,7 +94,7 @@ func Test_Provider_GetConnection(t *testing.T) {
Return(testCase.filteredServers, testCase.storageErr)
client := (*http.Client)(nil)
warner := (common.Warner)(nil)
warner := (updaters.Warner)(nil)
provider := New(storage, client, warner)
if testCase.panicMessage != "" {
+5 -4
View File
@@ -6,21 +6,22 @@ import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/utils"
"github.com/qdm12/gluetun/internal/provider/windscribe/updater"
updaters "github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/providers/windscribe"
)
type Provider struct {
storage common.Storage
connPicker *utils.ConnectionPicker
common.Fetcher
updaters.Fetcher
}
func New(storage common.Storage, client *http.Client, updaterWarner common.Warner,
func New(storage common.Storage, client *http.Client, updaterWarner updaters.Warner,
) *Provider {
return &Provider{
storage: storage,
connPicker: utils.NewConnectionPicker(),
Fetcher: updater.New(client, updaterWarner),
Fetcher: windscribe.New(client, updaterWarner),
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
package publicip
import "github.com/qdm12/gluetun/internal/models"
import "github.com/qdm12/gluetun/pkg/publicip/models"
// GetData returns the public IP data obtained from the last
// fetch. It is notably used by the HTTP control server.
+2 -2
View File
@@ -9,8 +9,8 @@ import (
"time"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/publicip/api"
"github.com/qdm12/gluetun/pkg/publicip/api"
"github.com/qdm12/gluetun/pkg/publicip/models"
)
type Loop struct {
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"reflect"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/publicip/api"
"github.com/qdm12/gluetun/pkg/publicip/api"
)
func (l *Loop) update(partialUpdate settings.PublicIP) (err error) {
+2 -1
View File
@@ -5,6 +5,7 @@ import (
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/models"
publicipmodels "github.com/qdm12/gluetun/pkg/publicip/models"
)
type VPNLooper interface {
@@ -27,7 +28,7 @@ type PortForwarding interface {
}
type PublicIPLoop interface {
GetData() (data models.PublicIP)
GetData() (data publicipmodels.PublicIP)
}
type Storage interface {
+4 -4
View File
@@ -7,7 +7,7 @@ import (
"strings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/vpn"
uconstants "github.com/qdm12/gluetun/pkg/updaters/constants"
)
func newOpenvpnHandler(ctx context.Context, looper VPNLooper, w warner) http.Handler {
@@ -60,7 +60,7 @@ func (h *openvpnHandler) getStatus(w http.ResponseWriter) {
openVPNStatus := vpnStatus
if vpnStatus != constants.Stopped {
vpnSettings := h.looper.GetSettings()
if vpnSettings.Type != vpn.OpenVPN {
if vpnSettings.Type != uconstants.OpenVPN {
openVPNStatus = constants.Stopped
}
}
@@ -88,9 +88,9 @@ func (h *openvpnHandler) setStatus(w http.ResponseWriter, r *http.Request) {
var outcome string
loopSettings := h.looper.GetSettings()
if status == constants.Running && loopSettings.Type != vpn.OpenVPN {
if status == constants.Running && loopSettings.Type != uconstants.OpenVPN {
// Stop Wireguard if it was the selected type and we want to start OpenVPN
loopSettings.Type = vpn.OpenVPN
loopSettings.Type = uconstants.OpenVPN
outcome = h.looper.SetSettings(h.ctx, loopSettings)
} else {
// Only update status of OpenVPN
+1 -1
View File
@@ -3,7 +3,7 @@ package storage
import (
"net/netip"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/pkg/updaters/models"
)
func copyServer(server models.Server) (serverCopy models.Server) {
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"net/netip"
"testing"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/pkg/updaters/models"
"github.com/stretchr/testify/assert"
)
+4 -5
View File
@@ -6,10 +6,9 @@ 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"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/pkg/updaters/constants"
"github.com/qdm12/gluetun/pkg/updaters/models"
)
// FilterServers filter servers for the given provider and according
@@ -57,7 +56,7 @@ func filterServer(server models.Server,
return true
}
if server.VPN != vpn.Wireguard &&
if server.VPN != constants.Wireguard &&
filterByProtocol(selection, server.TCP, server.UDP) {
return true
}
@@ -157,7 +156,7 @@ func filterByProtocol(selection settings.ServerSelection,
serverTCP, serverUDP bool,
) (filtered bool) {
switch selection.VPN {
case vpn.Wireguard:
case constants.Wireguard:
return !serverUDP
default: // OpenVPN
wantTCP := selection.OpenVPN.Protocol == constants.TCP
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"path/filepath"
"sort"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/pkg/updaters/models"
)
// FlushToFile flushes the merged servers data to the file
+2 -3
View File
@@ -6,8 +6,7 @@ import (
"strings"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/pkg/updaters/constants"
)
func commaJoin(slice []string) string {
@@ -147,7 +146,7 @@ func noServerFoundError(selection settings.ServerSelection) (err error) {
}
targetIP := selection.OpenVPN.EndpointIP
if selection.VPN == vpn.Wireguard {
if selection.VPN == constants.Wireguard {
targetIP = selection.Wireguard.EndpointIP
}
if targetIP.IsValid() {
+7 -6
View File
@@ -8,13 +8,14 @@ import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/format"
"github.com/qdm12/gluetun/internal/models"
umodels "github.com/qdm12/gluetun/pkg/updaters/models"
)
func (s *Storage) mergeServers(hardcoded, persisted models.AllServers) models.AllServers {
allProviders := providers.All()
merged := models.AllServers{
Version: hardcoded.Version,
ProviderToServers: make(map[string]models.Servers, len(allProviders)),
ProviderToServers: make(map[string]umodels.Servers, len(allProviders)),
}
for _, provider := range allProviders {
@@ -28,8 +29,8 @@ func (s *Storage) mergeServers(hardcoded, persisted models.AllServers) models.Al
}
func (s *Storage) mergeProviderServers(provider string,
hardcoded, persisted models.Servers,
) (merged models.Servers) {
hardcoded, persisted umodels.Servers,
) (merged umodels.Servers) {
nowTimestamp := time.Now().Unix()
if persisted.Timestamp > nowTimestamp {
s.logger.Warn(fmt.Sprintf(
@@ -48,7 +49,7 @@ func (s *Storage) mergeProviderServers(provider string,
return persisted
}
persistedServerKeyToServer := make(map[string]models.Server)
persistedServerKeyToServer := make(map[string]umodels.Server)
for _, persistedServer := range persisted.Servers {
if persistedServer.Keep {
persistedServerKeyToServer[persistedServer.Key()] = persistedServer
@@ -56,7 +57,7 @@ func (s *Storage) mergeProviderServers(provider string,
}
merged = hardcoded // use all fields from hardcoded
merged.Servers = make([]models.Server, 0, len(hardcoded.Servers)+len(persistedServerKeyToServer))
merged.Servers = make([]umodels.Server, 0, len(hardcoded.Servers)+len(persistedServerKeyToServer))
for _, hardcodedServer := range hardcoded.Servers {
hardcodedServerKey := hardcodedServer.Key()
@@ -75,7 +76,7 @@ func (s *Storage) mergeProviderServers(provider string,
merged.Servers = append(merged.Servers, persistedServer)
}
sort.Sort(models.SortableServers(merged.Servers))
sort.Sort(umodels.SortableServers(merged.Servers))
return merged
}
+3 -2
View File
@@ -8,6 +8,7 @@ import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/models"
umodels "github.com/qdm12/gluetun/pkg/updaters/models"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
@@ -48,7 +49,7 @@ func (s *Storage) extractServersFromBytes(b []byte, hardcodedVersions map[string
// Note schema version is at map key "version" as number
allProviders := providers.All()
servers.ProviderToServers = make(map[string]models.Servers, len(allProviders))
servers.ProviderToServers = make(map[string]umodels.Servers, len(allProviders))
titleCaser := cases.Title(language.English)
for _, provider := range allProviders {
hardcodedVersion, ok := hardcodedVersions[provider]
@@ -81,7 +82,7 @@ func (s *Storage) extractServersFromBytes(b []byte, hardcodedVersions map[string
}
func (s *Storage) readServers(provider string, hardcodedVersion uint16,
rawMessage json.RawMessage, titleCaser cases.Caser) (servers models.Servers,
rawMessage json.RawMessage, titleCaser cases.Caser) (servers umodels.Servers,
versionsMatch bool, err error,
) {
provider = titleCaser.String(provider)
+4 -3
View File
@@ -7,6 +7,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/models"
umodels "github.com/qdm12/gluetun/pkg/updaters/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -58,7 +59,7 @@ func Test_extractServersFromBytes(t *testing.T) {
providers.Cyberghost: 1,
}),
persisted: models.AllServers{
ProviderToServers: map[string]models.Servers{},
ProviderToServers: map[string]umodels.Servers{},
},
},
"same versions": {
@@ -69,7 +70,7 @@ func Test_extractServersFromBytes(t *testing.T) {
providers.Cyberghost: 1,
}),
persisted: models.AllServers{
ProviderToServers: map[string]models.Servers{
ProviderToServers: map[string]umodels.Servers{
providers.Cyberghost: {Version: 1},
},
},
@@ -85,7 +86,7 @@ func Test_extractServersFromBytes(t *testing.T) {
"Cyberghost servers from file discarded because they have version 1 and hardcoded servers have version 2",
},
persisted: models.AllServers{
ProviderToServers: map[string]models.Servers{},
ProviderToServers: map[string]umodels.Servers{},
},
},
}
+5 -4
View File
@@ -6,6 +6,7 @@ import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/models"
umodels "github.com/qdm12/gluetun/pkg/updaters/models"
)
// SetServers sets the given servers for the given provider
@@ -13,7 +14,7 @@ import (
// to file.
// Note the servers given are not copied so the caller must
// NOT MUTATE them after calling this method.
func (s *Storage) SetServers(provider string, servers []models.Server) (err error) {
func (s *Storage) SetServers(provider string, servers []umodels.Server) (err error) {
if provider == providers.Custom {
return
}
@@ -57,12 +58,12 @@ func (s *Storage) Format(provider, format string) (formatted string, err error)
defer s.mergedMutex.RUnlock()
serversObject := s.getMergedServersObject(provider)
return serversObject.Format(provider, format)
return models.FormatServers(serversObject, provider, format)
}
// ServersAreEqual returns whether the servers for the provider
// in storage are equal to the servers slice given.
func (s *Storage) ServersAreEqual(provider string, servers []models.Server) (equal bool) {
func (s *Storage) ServersAreEqual(provider string, servers []umodels.Server) (equal bool) {
if provider == providers.Custom {
return true
}
@@ -86,7 +87,7 @@ func (s *Storage) ServersAreEqual(provider string, servers []models.Server) (equ
return true
}
func (s *Storage) getMergedServersObject(provider string) (serversObject models.Servers) {
func (s *Storage) getMergedServersObject(provider string) (serversObject umodels.Servers) {
serversObject, ok := s.mergedServers.ProviderToServers[provider]
if !ok {
panicOnProviderMissingHardcoded(provider)
+1 -1
View File
@@ -4,8 +4,8 @@ import (
"context"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider"
"github.com/qdm12/gluetun/pkg/updaters/models"
)
type Providers interface {
+2 -2
View File
@@ -6,8 +6,8 @@ import (
"errors"
"fmt"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/models"
)
type Provider interface {
+2 -2
View File
@@ -6,8 +6,8 @@ import (
"net/http"
"time"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/updater/unzip"
"github.com/qdm12/gluetun/pkg/updaters/common"
"github.com/qdm12/gluetun/pkg/updaters/unzip"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
+3 -3
View File
@@ -6,7 +6,7 @@ import (
"strings"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/pkg/updaters/constants"
)
func (l *Loop) cleanup() {
@@ -49,9 +49,9 @@ func (l *Loop) cleanup() {
func getVPNInterface(settings settings.VPN) string {
switch settings.Type {
case vpn.OpenVPN:
case constants.OpenVPN:
return settings.OpenVPN.Interface
case vpn.Wireguard:
case constants.Wireguard:
return settings.Wireguard.Interface
default:
panic("invalid VPN type: " + settings.Type)
+3 -2
View File
@@ -13,6 +13,7 @@ import (
portforward "github.com/qdm12/gluetun/internal/portforward"
"github.com/qdm12/gluetun/internal/provider"
"github.com/qdm12/gluetun/internal/provider/utils"
umodels "github.com/qdm12/gluetun/pkg/updaters/models"
)
type Firewall interface {
@@ -46,7 +47,7 @@ type Provider interface {
OpenVPNConfig(connection models.Connection, settings settings.OpenVPN, ipv6Supported bool) (lines []string)
Name() string
FetchServers(ctx context.Context, minServers int) (
servers []models.Server, err error)
servers []umodels.Server, err error)
}
type PortForwarder interface {
@@ -57,7 +58,7 @@ type PortForwarder interface {
}
type Storage interface {
FilterServers(provider string, selection settings.ServerSelection) (servers []models.Server, err error)
FilterServers(provider string, selection settings.ServerSelection) (servers []umodels.Server, err error)
}
type NetLinker interface {
+4 -4
View File
@@ -2,8 +2,8 @@ package vpn
import (
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/netlink"
"github.com/qdm12/gluetun/pkg/updaters/constants"
)
func (l *Loop) isIPv6Used(settings settings.VPN) bool {
@@ -11,14 +11,14 @@ func (l *Loop) isIPv6Used(settings settings.VPN) bool {
return false
}
switch settings.Type {
case vpn.AmneziaWg:
case constants.AmneziaWg:
for _, prefix := range settings.AmneziaWg.Wireguard.Addresses {
if prefix.Addr().Is6() {
return true
}
}
return false
case vpn.OpenVPN:
case constants.OpenVPN:
link, err := l.netLinker.LinkByName(settings.OpenVPN.Interface)
if err != nil {
l.logger.Warnf("assuming IPv6 is not supported, cannot get OpenVPN link by name: %v", err)
@@ -35,7 +35,7 @@ func (l *Loop) isIPv6Used(settings settings.VPN) bool {
}
}
return false
case vpn.Wireguard:
case constants.Wireguard:
for _, prefix := range settings.Wireguard.Addresses {
if prefix.Addr().Is6() {
return true
+5 -5
View File
@@ -4,8 +4,8 @@ import (
"context"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
uconstants "github.com/qdm12/gluetun/pkg/updaters/constants"
"github.com/qdm12/log"
)
@@ -34,15 +34,15 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
var err error
subLogger := l.logger.New(log.SetComponent(settings.Type))
switch settings.Type {
case vpn.AmneziaWg:
case uconstants.AmneziaWg:
vpnInterface = settings.AmneziaWg.Wireguard.Interface
vpnRunner, connection, err = setupAmneziaWg(ctx, l.netLinker, l.fw,
providerConf, settings, l.ipv6SupportLevel, subLogger)
case vpn.OpenVPN:
case uconstants.OpenVPN:
vpnInterface = settings.OpenVPN.Interface
vpnRunner, connection, err = setupOpenVPN(ctx, l.fw,
l.openvpnConf, providerConf, settings, l.ipv6SupportLevel, l.cmder, subLogger)
case vpn.Wireguard:
case uconstants.Wireguard:
vpnInterface = settings.Wireguard.Interface
vpnRunner, connection, err = setupWireguard(ctx, l.netLinker, l.fw,
providerConf, settings, l.ipv6SupportLevel, subLogger)
@@ -56,7 +56,7 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
tunnelUpData := tunnelUpData{
upCommand: *settings.UpCommand,
pmtud: tunnelUpPMTUDData{
enabled: settings.Type != vpn.Wireguard || *settings.Wireguard.MTU == 0,
enabled: settings.Type != uconstants.Wireguard || *settings.Wireguard.MTU == 0,
vpnType: settings.Type,
network: connection.Protocol,
ipv6: l.isIPv6Used(settings),
+3 -3
View File
@@ -9,12 +9,12 @@ import (
"time"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/netlink"
"github.com/qdm12/gluetun/internal/pmtud"
pconstants "github.com/qdm12/gluetun/internal/pmtud/constants"
"github.com/qdm12/gluetun/internal/pmtud/tcp"
"github.com/qdm12/gluetun/internal/version"
uconstants "github.com/qdm12/gluetun/pkg/updaters/constants"
"github.com/qdm12/log"
)
@@ -36,7 +36,7 @@ type tunnelUpPMTUDData struct {
// enabled is notably false if the user specifies a custom MTU.
enabled bool
// vpnType is used to find the maximum VPN header overhead.
// It can be [vpn.Wireguard] or [vpn.OpenVPN].
// It can be [constants.Wireguard] or [constants.OpenVPN].
vpnType string
// network is used to find the network level header overhead.
// It can be [constants.UDP] or [constants.TCP].
@@ -53,7 +53,7 @@ type tunnelUpPMTUDData struct {
func (l *Loop) onTunnelUp(ctx, loopCtx context.Context, data tunnelUpData) {
switch vpnType := l.GetSettings().Type; vpnType {
case vpn.Wireguard, vpn.AmneziaWg:
case uconstants.Wireguard, uconstants.AmneziaWg:
l.logger.Infof("%s setup is complete. "+
"Note %s is a silent protocol and it may or may not work, without giving any error message. "+
"Typically i/o timeout errors indicate the %s connection is not working.",
@@ -9,8 +9,8 @@ import (
"strings"
"time"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/pkg/publicip/models"
"github.com/qdm12/gluetun/pkg/updaters/constants"
)
type cloudflare struct {
@@ -9,7 +9,7 @@ import (
"strings"
"time"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/pkg/publicip/models"
)
type echoip struct {

Some files were not shown because too many files have changed in this diff Show More