diff --git a/cmd/gluetun/main.go b/cmd/gluetun/main.go index 21f0c1dc..9ebca102 100644 --- a/cmd/gluetun/main.go +++ b/cmd/gluetun/main.go @@ -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" diff --git a/internal/cli/openvpnconfig.go b/internal/cli/openvpnconfig.go index 2a7bc62c..6f433456 100644 --- a/internal/cli/openvpnconfig.go +++ b/internal/cli/openvpnconfig.go @@ -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" ) diff --git a/internal/cli/update.go b/internal/cli/update.go index 3a065d68..6310b7e8 100644 --- a/internal/cli/update.go +++ b/internal/cli/update.go @@ -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 { diff --git a/internal/configuration/settings/openvpnselection.go b/internal/configuration/settings/openvpnselection.go index 268e2032..342b53c6 100644 --- a/internal/configuration/settings/openvpnselection.go +++ b/internal/configuration/settings/openvpnselection.go @@ -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" diff --git a/internal/configuration/settings/provider.go b/internal/configuration/settings/provider.go index ccc3acac..eff32c29 100644 --- a/internal/configuration/settings/provider.go +++ b/internal/configuration/settings/provider.go @@ -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 } diff --git a/internal/configuration/settings/publicip.go b/internal/configuration/settings/publicip.go index 7953bc57..6a3d7507 100644 --- a/internal/configuration/settings/publicip.go +++ b/internal/configuration/settings/publicip.go @@ -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" diff --git a/internal/configuration/settings/serverselection.go b/internal/configuration/settings/serverselection.go index c3e6a6d6..55681fea 100644 --- a/internal/configuration/settings/serverselection.go +++ b/internal/configuration/settings/serverselection.go @@ -8,8 +8,8 @@ import ( "github.com/qdm12/gluetun/internal/configuration/settings/helpers" "github.com/qdm12/gluetun/internal/configuration/settings/validation" "github.com/qdm12/gluetun/internal/constants/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 diff --git a/internal/configuration/settings/settings.go b/internal/configuration/settings/settings.go index 08e8644a..850c7d25 100644 --- a/internal/configuration/settings/settings.go +++ b/internal/configuration/settings/settings.go @@ -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 "+ diff --git a/internal/configuration/settings/surfshark_retro.go b/internal/configuration/settings/surfshark_retro.go index 96ff3119..4334bd2a 100644 --- a/internal/configuration/settings/surfshark_retro.go +++ b/internal/configuration/settings/surfshark_retro.go @@ -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) ( diff --git a/internal/configuration/settings/validation/servers.go b/internal/configuration/settings/validation/servers.go index c659ff32..1018900c 100644 --- a/internal/configuration/settings/validation/servers.go +++ b/internal/configuration/settings/validation/servers.go @@ -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 { diff --git a/internal/configuration/settings/validation/surfshark.go b/internal/configuration/settings/validation/surfshark.go index 5cec3ed7..d0c2783a 100644 --- a/internal/configuration/settings/validation/surfshark.go +++ b/internal/configuration/settings/validation/surfshark.go @@ -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. diff --git a/internal/configuration/settings/vpn.go b/internal/configuration/settings/vpn.go index 26fcdf20..94136cca 100644 --- a/internal/configuration/settings/vpn.go +++ b/internal/configuration/settings/vpn.go @@ -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()) diff --git a/internal/constants/providers/providers_test.go b/internal/constants/providers/providers_test.go index 88491dd9..7c4c4feb 100644 --- a/internal/constants/providers/providers_test.go +++ b/internal/constants/providers/providers_test.go @@ -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) + } +} diff --git a/internal/models/markdown.go b/internal/models/markdown.go index 27d6b274..685c0ca9 100644 --- a/internal/models/markdown.go +++ b/internal/models/markdown.go @@ -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" + diff --git a/internal/models/markdown_test.go b/internal/models/markdown_test.go index 4b0dbfd7..b3058a23 100644 --- a/internal/models/markdown_test.go +++ b/internal/models/markdown_test.go @@ -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 != "" { diff --git a/internal/models/servers.go b/internal/models/servers.go index 6ae47c48..8cc18c0a 100644 --- a/internal/models/servers.go +++ b/internal/models/servers.go @@ -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("", " ") diff --git a/internal/models/servers_test.go b/internal/models/servers_test.go index dc96592a..ae133227 100644 --- a/internal/models/servers_test.go +++ b/internal/models/servers_test.go @@ -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"}, }, diff --git a/internal/openvpn/extract/extract.go b/internal/openvpn/extract/extract.go index b5557e46..b9e76d10 100644 --- a/internal/openvpn/extract/extract.go +++ b/internal/openvpn/extract/extract.go @@ -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) ( diff --git a/internal/openvpn/extract/extract_test.go b/internal/openvpn/extract/extract_test.go index 200bfdb8..b5bf1ebc 100644 --- a/internal/openvpn/extract/extract_test.go +++ b/internal/openvpn/extract/extract_test.go @@ -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" ) diff --git a/internal/pmtud/vpn.go b/internal/pmtud/vpn.go index b3fe1a5d..669aba1a 100644 --- a/internal/pmtud/vpn.go +++ b/internal/pmtud/vpn.go @@ -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) diff --git a/internal/provider/airvpn/provider.go b/internal/provider/airvpn/provider.go index 9a7dc7ed..5b2fb626 100644 --- a/internal/provider/airvpn/provider.go +++ b/internal/provider/airvpn/provider.go @@ -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), } } diff --git a/internal/provider/common/mocks.go b/internal/provider/common/mocks.go index d7ddaa1a..dcac43e9 100644 --- a/internal/provider/common/mocks.go +++ b/internal/provider/common/mocks.go @@ -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) -} diff --git a/internal/provider/common/mocks_generate_test.go b/internal/provider/common/mocks_generate_test.go index 4732dd7f..b17ce2ad 100644 --- a/internal/provider/common/mocks_generate_test.go +++ b/internal/provider/common/mocks_generate_test.go @@ -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 diff --git a/internal/provider/common/storage.go b/internal/provider/common/storage.go index eb720a12..f2a94637 100644 --- a/internal/provider/common/storage.go +++ b/internal/provider/common/storage.go @@ -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 { diff --git a/internal/provider/custom/connection.go b/internal/provider/custom/connection.go index 820a8bab..25ee8746 100644 --- a/internal/provider/custom/connection.go +++ b/internal/provider/custom/connection.go @@ -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, diff --git a/internal/provider/custom/openvpnconf_test.go b/internal/provider/custom/openvpnconf_test.go index f23d681a..98345db5 100644 --- a/internal/provider/custom/openvpnconf_test.go +++ b/internal/provider/custom/openvpnconf_test.go @@ -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" ) diff --git a/internal/provider/custom/provider.go b/internal/provider/custom/provider.go index 4c923e78..935c0190 100644 --- a/internal/provider/custom/provider.go +++ b/internal/provider/custom/provider.go @@ -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 { diff --git a/internal/provider/cyberghost/provider.go b/internal/provider/cyberghost/provider.go index d4222035..ba0f9ca4 100644 --- a/internal/provider/cyberghost/provider.go +++ b/internal/provider/cyberghost/provider.go @@ -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), } } diff --git a/internal/provider/example/provider.go b/internal/provider/example/provider.go index 44672ca6..877d4205 100644 --- a/internal/provider/example/provider.go +++ b/internal/provider/example/provider.go @@ -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), } } diff --git a/internal/provider/expressvpn/connection_test.go b/internal/provider/expressvpn/connection_test.go index 95287663..8084eb92 100644 --- a/internal/provider/expressvpn/connection_test.go +++ b/internal/provider/expressvpn/connection_test.go @@ -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 != "" { diff --git a/internal/provider/expressvpn/provider.go b/internal/provider/expressvpn/provider.go index 00a4a6e4..dc798c9e 100644 --- a/internal/provider/expressvpn/provider.go +++ b/internal/provider/expressvpn/provider.go @@ -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), } } diff --git a/internal/provider/fastestvpn/provider.go b/internal/provider/fastestvpn/provider.go index 87fff14d..25e4b40b 100644 --- a/internal/provider/fastestvpn/provider.go +++ b/internal/provider/fastestvpn/provider.go @@ -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), } } diff --git a/internal/provider/giganews/provider.go b/internal/provider/giganews/provider.go index 4fbb350b..51d4c30f 100644 --- a/internal/provider/giganews/provider.go +++ b/internal/provider/giganews/provider.go @@ -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), } } diff --git a/internal/provider/hidemyass/provider.go b/internal/provider/hidemyass/provider.go index e4bef0c1..75aed464 100644 --- a/internal/provider/hidemyass/provider.go +++ b/internal/provider/hidemyass/provider.go @@ -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), } } diff --git a/internal/provider/ipvanish/provider.go b/internal/provider/ipvanish/provider.go index d32a6677..272d11fb 100644 --- a/internal/provider/ipvanish/provider.go +++ b/internal/provider/ipvanish/provider.go @@ -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), } } diff --git a/internal/provider/ivpn/connection_test.go b/internal/provider/ivpn/connection_test.go index 10f251b7..58a35b56 100644 --- a/internal/provider/ivpn/connection_test.go +++ b/internal/provider/ivpn/connection_test.go @@ -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) diff --git a/internal/provider/ivpn/provider.go b/internal/provider/ivpn/provider.go index ebf2759b..bf53add8 100644 --- a/internal/provider/ivpn/provider.go +++ b/internal/provider/ivpn/provider.go @@ -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), } } diff --git a/internal/provider/mullvad/connection_test.go b/internal/provider/mullvad/connection_test.go index ccdf4a0d..6f20c607 100644 --- a/internal/provider/mullvad/connection_test.go +++ b/internal/provider/mullvad/connection_test.go @@ -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, diff --git a/internal/provider/mullvad/provider.go b/internal/provider/mullvad/provider.go index 491c55be..0874e61f 100644 --- a/internal/provider/mullvad/provider.go +++ b/internal/provider/mullvad/provider.go @@ -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), } } diff --git a/internal/provider/nordvpn/provider.go b/internal/provider/nordvpn/provider.go index 356c1e19..f8ef441b 100644 --- a/internal/provider/nordvpn/provider.go +++ b/internal/provider/nordvpn/provider.go @@ -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), } } diff --git a/internal/provider/perfectprivacy/provider.go b/internal/provider/perfectprivacy/provider.go index e4488396..530cdaf3 100644 --- a/internal/provider/perfectprivacy/provider.go +++ b/internal/provider/perfectprivacy/provider.go @@ -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), } } diff --git a/internal/provider/privado/provider.go b/internal/provider/privado/provider.go index 7868cdd2..23177fa3 100644 --- a/internal/provider/privado/provider.go +++ b/internal/provider/privado/provider.go @@ -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), } } diff --git a/internal/provider/privateinternetaccess/provider.go b/internal/provider/privateinternetaccess/provider.go index da5ecf78..644ee3e7 100644 --- a/internal/provider/privateinternetaccess/provider.go +++ b/internal/provider/privateinternetaccess/provider.go @@ -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), } } diff --git a/internal/provider/privatevpn/provider.go b/internal/provider/privatevpn/provider.go index 0678b01e..5f1af236 100644 --- a/internal/provider/privatevpn/provider.go +++ b/internal/provider/privatevpn/provider.go @@ -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), } } diff --git a/internal/provider/protonvpn/provider.go b/internal/provider/protonvpn/provider.go index ea330365..1302c2a9 100644 --- a/internal/provider/protonvpn/provider.go +++ b/internal/provider/protonvpn/provider.go @@ -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), } } diff --git a/internal/provider/provider.go b/internal/provider/provider.go index d9b0bebb..9da86818 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -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) } diff --git a/internal/provider/providers.go b/internal/provider/providers.go index 07402096..375c781b 100644 --- a/internal/provider/providers.go +++ b/internal/provider/providers.go @@ -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 diff --git a/internal/provider/purevpn/provider.go b/internal/provider/purevpn/provider.go index 40d3f884..a8b00156 100644 --- a/internal/provider/purevpn/provider.go +++ b/internal/provider/purevpn/provider.go @@ -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), } } diff --git a/internal/provider/slickvpn/provider.go b/internal/provider/slickvpn/provider.go index 3f77a758..1a3cd05a 100644 --- a/internal/provider/slickvpn/provider.go +++ b/internal/provider/slickvpn/provider.go @@ -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), } } diff --git a/internal/provider/surfshark/provider.go b/internal/provider/surfshark/provider.go index f3bb1773..e3d31344 100644 --- a/internal/provider/surfshark/provider.go +++ b/internal/provider/surfshark/provider.go @@ -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), } } diff --git a/internal/provider/surfshark/updater/resolve.go b/internal/provider/surfshark/updater/resolve.go deleted file mode 100644 index d0b3fa0c..00000000 --- a/internal/provider/surfshark/updater/resolve.go +++ /dev/null @@ -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, - }, - } -} diff --git a/internal/provider/torguard/provider.go b/internal/provider/torguard/provider.go index 573e1d9d..4f01f612 100644 --- a/internal/provider/torguard/provider.go +++ b/internal/provider/torguard/provider.go @@ -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), } } diff --git a/internal/provider/torguard/updater/resolve.go b/internal/provider/torguard/updater/resolve.go deleted file mode 100644 index d0b3fa0c..00000000 --- a/internal/provider/torguard/updater/resolve.go +++ /dev/null @@ -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, - }, - } -} diff --git a/internal/provider/torguard/updater/updater.go b/internal/provider/torguard/updater/updater.go deleted file mode 100644 index d61e235d..00000000 --- a/internal/provider/torguard/updater/updater.go +++ /dev/null @@ -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, - } -} diff --git a/internal/provider/utils/connection.go b/internal/provider/utils/connection.go index 5761208c..f27e7a2b 100644 --- a/internal/provider/utils/connection.go +++ b/internal/provider/utils/connection.go @@ -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 diff --git a/internal/provider/utils/connection_test.go b/internal/provider/utils/connection_test.go index 144f1325..259d6743 100644 --- a/internal/provider/utils/connection_test.go +++ b/internal/provider/utils/connection_test.go @@ -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, diff --git a/internal/provider/utils/nofetcher.go b/internal/provider/utils/nofetcher.go index f4ba3ecf..8bd50920 100644 --- a/internal/provider/utils/nofetcher.go +++ b/internal/provider/utils/nofetcher.go @@ -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 +} diff --git a/internal/provider/utils/openvpn.go b/internal/provider/utils/openvpn.go index 2331fd06..270b8950 100644 --- a/internal/provider/utils/openvpn.go +++ b/internal/provider/utils/openvpn.go @@ -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 { diff --git a/internal/provider/utils/pick.go b/internal/provider/utils/pick.go index e6ae0415..c5fbbdf1 100644 --- a/internal/provider/utils/pick.go +++ b/internal/provider/utils/pick.go @@ -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) } diff --git a/internal/provider/utils/pick_test.go b/internal/provider/utils/pick_test.go index 563c2d33..95f7403f 100644 --- a/internal/provider/utils/pick_test.go +++ b/internal/provider/utils/pick_test.go @@ -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}), }, }, diff --git a/internal/provider/utils/port.go b/internal/provider/utils/port.go index 1f32ef4a..24f2bd0f 100644 --- a/internal/provider/utils/port.go +++ b/internal/provider/utils/port.go @@ -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 diff --git a/internal/provider/utils/port_test.go b/internal/provider/utils/port_test.go index 1967b47b..84ba3537 100644 --- a/internal/provider/utils/port_test.go +++ b/internal/provider/utils/port_test.go @@ -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!", }, diff --git a/internal/provider/utils/protocol.go b/internal/provider/utils/protocol.go index 143d7227..e35ce11b 100644 --- a/internal/provider/utils/protocol.go +++ b/internal/provider/utils/protocol.go @@ -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 diff --git a/internal/provider/utils/protocol_test.go b/internal/provider/utils/protocol_test.go index 178b033b..55322c27 100644 --- a/internal/provider/utils/protocol_test.go +++ b/internal/provider/utils/protocol_test.go @@ -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, }, diff --git a/internal/provider/vpnsecure/provider.go b/internal/provider/vpnsecure/provider.go index ea203e95..af07fbbc 100644 --- a/internal/provider/vpnsecure/provider.go +++ b/internal/provider/vpnsecure/provider.go @@ -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), } } diff --git a/internal/provider/vpnsecure/updater/updater.go b/internal/provider/vpnsecure/updater/updater.go deleted file mode 100644 index df4427cc..00000000 --- a/internal/provider/vpnsecure/updater/updater.go +++ /dev/null @@ -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, - } -} diff --git a/internal/provider/vpnunlimited/provider.go b/internal/provider/vpnunlimited/provider.go index 372cd918..2605f4ca 100644 --- a/internal/provider/vpnunlimited/provider.go +++ b/internal/provider/vpnunlimited/provider.go @@ -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), } } diff --git a/internal/provider/vpnunlimited/updater/resolve.go b/internal/provider/vpnunlimited/updater/resolve.go deleted file mode 100644 index d0b3fa0c..00000000 --- a/internal/provider/vpnunlimited/updater/resolve.go +++ /dev/null @@ -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, - }, - } -} diff --git a/internal/provider/vpnunlimited/updater/updater.go b/internal/provider/vpnunlimited/updater/updater.go deleted file mode 100644 index d61e235d..00000000 --- a/internal/provider/vpnunlimited/updater/updater.go +++ /dev/null @@ -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, - } -} diff --git a/internal/provider/vyprvpn/provider.go b/internal/provider/vyprvpn/provider.go index e6055e8b..ba352c23 100644 --- a/internal/provider/vyprvpn/provider.go +++ b/internal/provider/vyprvpn/provider.go @@ -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), } } diff --git a/internal/provider/vyprvpn/updater/updater.go b/internal/provider/vyprvpn/updater/updater.go deleted file mode 100644 index d61e235d..00000000 --- a/internal/provider/vyprvpn/updater/updater.go +++ /dev/null @@ -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, - } -} diff --git a/internal/provider/windscribe/connection_test.go b/internal/provider/windscribe/connection_test.go index ce4f8cc4..a24562fe 100644 --- a/internal/provider/windscribe/connection_test.go +++ b/internal/provider/windscribe/connection_test.go @@ -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 != "" { diff --git a/internal/provider/windscribe/provider.go b/internal/provider/windscribe/provider.go index df4d1441..6b3694b7 100644 --- a/internal/provider/windscribe/provider.go +++ b/internal/provider/windscribe/provider.go @@ -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), } } diff --git a/internal/publicip/data.go b/internal/publicip/data.go index 76c45d6f..0e823b8b 100644 --- a/internal/publicip/data.go +++ b/internal/publicip/data.go @@ -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. diff --git a/internal/publicip/loop.go b/internal/publicip/loop.go index 6533aa25..44a2f26f 100644 --- a/internal/publicip/loop.go +++ b/internal/publicip/loop.go @@ -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 { diff --git a/internal/publicip/update.go b/internal/publicip/update.go index 71dbdb13..40a787c1 100644 --- a/internal/publicip/update.go +++ b/internal/publicip/update.go @@ -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) { diff --git a/internal/server/interfaces.go b/internal/server/interfaces.go index b49d2837..05cc4133 100644 --- a/internal/server/interfaces.go +++ b/internal/server/interfaces.go @@ -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 { diff --git a/internal/server/openvpn.go b/internal/server/openvpn.go index 66a9a620..fa798dee 100644 --- a/internal/server/openvpn.go +++ b/internal/server/openvpn.go @@ -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 diff --git a/internal/storage/copy.go b/internal/storage/copy.go index 113478f9..9f93a591 100644 --- a/internal/storage/copy.go +++ b/internal/storage/copy.go @@ -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) { diff --git a/internal/storage/copy_test.go b/internal/storage/copy_test.go index bea568d2..490d5ba4 100644 --- a/internal/storage/copy_test.go +++ b/internal/storage/copy_test.go @@ -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" ) diff --git a/internal/storage/filter.go b/internal/storage/filter.go index 81d6cdbc..ae69caea 100644 --- a/internal/storage/filter.go +++ b/internal/storage/filter.go @@ -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 diff --git a/internal/storage/flush.go b/internal/storage/flush.go index 3cb3b259..dece1494 100644 --- a/internal/storage/flush.go +++ b/internal/storage/flush.go @@ -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 diff --git a/internal/storage/formatting.go b/internal/storage/formatting.go index 44865a5b..09c412d3 100644 --- a/internal/storage/formatting.go +++ b/internal/storage/formatting.go @@ -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() { diff --git a/internal/storage/merge.go b/internal/storage/merge.go index b8cece57..ac7e7ce3 100644 --- a/internal/storage/merge.go +++ b/internal/storage/merge.go @@ -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 } diff --git a/internal/storage/read.go b/internal/storage/read.go index cc37a998..da1d9b8b 100644 --- a/internal/storage/read.go +++ b/internal/storage/read.go @@ -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) diff --git a/internal/storage/read_test.go b/internal/storage/read_test.go index 20bbe17a..910a868f 100644 --- a/internal/storage/read_test.go +++ b/internal/storage/read_test.go @@ -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{}, }, }, } diff --git a/internal/storage/servers.go b/internal/storage/servers.go index d02eeebb..91c6a1c2 100644 --- a/internal/storage/servers.go +++ b/internal/storage/servers.go @@ -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) diff --git a/internal/updater/interfaces.go b/internal/updater/interfaces.go index 0f80613c..7afcf50f 100644 --- a/internal/updater/interfaces.go +++ b/internal/updater/interfaces.go @@ -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 { diff --git a/internal/updater/providers.go b/internal/updater/providers.go index 237e843c..fa8e6976 100644 --- a/internal/updater/providers.go +++ b/internal/updater/providers.go @@ -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 { diff --git a/internal/updater/updater.go b/internal/updater/updater.go index 986d22d4..5fdd14a5 100644 --- a/internal/updater/updater.go +++ b/internal/updater/updater.go @@ -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" ) diff --git a/internal/vpn/cleanup.go b/internal/vpn/cleanup.go index fbc58f0d..c7d545a0 100644 --- a/internal/vpn/cleanup.go +++ b/internal/vpn/cleanup.go @@ -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) diff --git a/internal/vpn/interfaces.go b/internal/vpn/interfaces.go index 5d585ace..c3ba5ad3 100644 --- a/internal/vpn/interfaces.go +++ b/internal/vpn/interfaces.go @@ -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 { diff --git a/internal/vpn/ipv6.go b/internal/vpn/ipv6.go index 4a7d62f5..a2062067 100644 --- a/internal/vpn/ipv6.go +++ b/internal/vpn/ipv6.go @@ -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 diff --git a/internal/vpn/run.go b/internal/vpn/run.go index 1e49bbe4..39b072a0 100644 --- a/internal/vpn/run.go +++ b/internal/vpn/run.go @@ -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), diff --git a/internal/vpn/tunnelup.go b/internal/vpn/tunnelup.go index 4843812a..0f1e7b5b 100644 --- a/internal/vpn/tunnelup.go +++ b/internal/vpn/tunnelup.go @@ -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.", diff --git a/internal/publicip/api/api.go b/pkg/publicip/api/api.go similarity index 100% rename from internal/publicip/api/api.go rename to pkg/publicip/api/api.go diff --git a/internal/publicip/api/api_test.go b/pkg/publicip/api/api_test.go similarity index 100% rename from internal/publicip/api/api_test.go rename to pkg/publicip/api/api_test.go diff --git a/internal/publicip/api/cloudflare.go b/pkg/publicip/api/cloudflare.go similarity index 96% rename from internal/publicip/api/cloudflare.go rename to pkg/publicip/api/cloudflare.go index 26439f28..2f45386b 100644 --- a/internal/publicip/api/cloudflare.go +++ b/pkg/publicip/api/cloudflare.go @@ -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 { diff --git a/internal/publicip/api/echoip.go b/pkg/publicip/api/echoip.go similarity index 98% rename from internal/publicip/api/echoip.go rename to pkg/publicip/api/echoip.go index a52f40e6..4a413eba 100644 --- a/internal/publicip/api/echoip.go +++ b/pkg/publicip/api/echoip.go @@ -9,7 +9,7 @@ import ( "strings" "time" - "github.com/qdm12/gluetun/internal/models" + "github.com/qdm12/gluetun/pkg/publicip/models" ) type echoip struct { diff --git a/internal/publicip/api/errors.go b/pkg/publicip/api/errors.go similarity index 100% rename from internal/publicip/api/errors.go rename to pkg/publicip/api/errors.go diff --git a/internal/publicip/api/interfaces.go b/pkg/publicip/api/interfaces.go similarity index 86% rename from internal/publicip/api/interfaces.go rename to pkg/publicip/api/interfaces.go index 056a026c..12922ebb 100644 --- a/internal/publicip/api/interfaces.go +++ b/pkg/publicip/api/interfaces.go @@ -4,7 +4,7 @@ import ( "context" "net/netip" - "github.com/qdm12/gluetun/internal/models" + "github.com/qdm12/gluetun/pkg/publicip/models" ) type Fetcher interface { diff --git a/internal/publicip/api/ip2location.go b/pkg/publicip/api/ip2location.go similarity index 97% rename from internal/publicip/api/ip2location.go rename to pkg/publicip/api/ip2location.go index d1e8290f..73eb276a 100644 --- a/internal/publicip/api/ip2location.go +++ b/pkg/publicip/api/ip2location.go @@ -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 ip2Location struct { diff --git a/internal/publicip/api/ipinfo.go b/pkg/publicip/api/ipinfo.go similarity index 96% rename from internal/publicip/api/ipinfo.go rename to pkg/publicip/api/ipinfo.go index 48bf9a30..dd9d5b2e 100644 --- a/internal/publicip/api/ipinfo.go +++ b/pkg/publicip/api/ipinfo.go @@ -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 ipInfo struct { diff --git a/internal/publicip/api/multi.go b/pkg/publicip/api/multi.go similarity index 96% rename from internal/publicip/api/multi.go rename to pkg/publicip/api/multi.go index fbd30fa6..ec97fc1f 100644 --- a/internal/publicip/api/multi.go +++ b/pkg/publicip/api/multi.go @@ -4,7 +4,7 @@ import ( "context" "net/netip" - "github.com/qdm12/gluetun/internal/models" + "github.com/qdm12/gluetun/pkg/publicip/models" ) // FetchMultiInfo obtains the public IP address information for every IP diff --git a/internal/publicip/api/resilient.go b/pkg/publicip/api/resilient.go similarity index 99% rename from internal/publicip/api/resilient.go rename to pkg/publicip/api/resilient.go index ca66a6ad..18b57f46 100644 --- a/internal/publicip/api/resilient.go +++ b/pkg/publicip/api/resilient.go @@ -10,7 +10,7 @@ import ( "time" "unicode" - "github.com/qdm12/gluetun/internal/models" + "github.com/qdm12/gluetun/pkg/publicip/models" "golang.org/x/text/runes" "golang.org/x/text/transform" "golang.org/x/text/unicode/norm" diff --git a/internal/publicip/api/resilient_test.go b/pkg/publicip/api/resilient_test.go similarity index 97% rename from internal/publicip/api/resilient_test.go rename to pkg/publicip/api/resilient_test.go index 15bfd740..d413ba9a 100644 --- a/internal/publicip/api/resilient_test.go +++ b/pkg/publicip/api/resilient_test.go @@ -3,7 +3,7 @@ package api import ( "testing" - "github.com/qdm12/gluetun/internal/models" + "github.com/qdm12/gluetun/pkg/publicip/models" "github.com/stretchr/testify/assert" ) diff --git a/internal/models/publicip.go b/pkg/publicip/models/publicip.go similarity index 100% rename from internal/models/publicip.go rename to pkg/publicip/models/publicip.go diff --git a/pkg/updaters/common/errors.go b/pkg/updaters/common/errors.go new file mode 100644 index 00000000..d3d82467 --- /dev/null +++ b/pkg/updaters/common/errors.go @@ -0,0 +1,8 @@ +package common + +import "errors" + +var ( + ErrNotEnoughServers = errors.New("not enough servers found") + ErrCredentialsMissing = errors.New("credentials are missing") +) diff --git a/internal/provider/common/updater.go b/pkg/updaters/common/interfaces.go similarity index 63% rename from internal/provider/common/updater.go rename to pkg/updaters/common/interfaces.go index 3cc72391..78dd4b06 100644 --- a/internal/provider/common/updater.go +++ b/pkg/updaters/common/interfaces.go @@ -2,20 +2,17 @@ package common import ( "context" - "errors" "net/netip" - "github.com/qdm12/gluetun/internal/models" - "github.com/qdm12/gluetun/internal/updater/resolver" -) - -var ( - ErrNotEnoughServers = errors.New("not enough servers found") - ErrCredentialsMissing = errors.New("credentials are missing") + pubipmodels "github.com/qdm12/gluetun/pkg/publicip/models" + "github.com/qdm12/gluetun/pkg/updaters/models" + "github.com/qdm12/gluetun/pkg/updaters/resolver" ) type Fetcher interface { FetchServers(ctx context.Context, minServers int) (servers []models.Server, err error) + Version() uint16 + Name() string } type ParallelResolver interface { @@ -35,5 +32,5 @@ type Warner interface { type IPFetcher interface { String() string CanFetchAnyIP() bool - FetchInfo(ctx context.Context, ip netip.Addr) (result models.PublicIP, err error) + FetchInfo(ctx context.Context, ip netip.Addr) (result pubipmodels.PublicIP, err error) } diff --git a/pkg/updaters/common/mocks.go b/pkg/updaters/common/mocks.go new file mode 100644 index 00000000..0d2459c0 --- /dev/null +++ b/pkg/updaters/common/mocks.go @@ -0,0 +1,126 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/qdm12/gluetun/pkg/updaters/common (interfaces: ParallelResolver,Unzipper,Warner) + +// Package common is a generated GoMock package. +package common + +import ( + context "context" + netip "net/netip" + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + resolver "github.com/qdm12/gluetun/pkg/updaters/resolver" +) + +// 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) +} + +// 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) +} diff --git a/pkg/updaters/common/mocks_generate_test.go b/pkg/updaters/common/mocks_generate_test.go new file mode 100644 index 00000000..9f6a657d --- /dev/null +++ b/pkg/updaters/common/mocks_generate_test.go @@ -0,0 +1,6 @@ +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,Unzipper,Warner diff --git a/internal/constants/countries.go b/pkg/updaters/constants/countries.go similarity index 100% rename from internal/constants/countries.go rename to pkg/updaters/constants/countries.go diff --git a/internal/constants/protocol.go b/pkg/updaters/constants/protocol.go similarity index 100% rename from internal/constants/protocol.go rename to pkg/updaters/constants/protocol.go diff --git a/internal/constants/vpn/protocol.go b/pkg/updaters/constants/vpn.go similarity index 82% rename from internal/constants/vpn/protocol.go rename to pkg/updaters/constants/vpn.go index 48daf0f2..5788e289 100644 --- a/internal/constants/vpn/protocol.go +++ b/pkg/updaters/constants/vpn.go @@ -1,4 +1,4 @@ -package vpn +package constants const ( AmneziaWg = "amneziawg" diff --git a/internal/updater/html/attribute.go b/pkg/updaters/html/attribute.go similarity index 100% rename from internal/updater/html/attribute.go rename to pkg/updaters/html/attribute.go diff --git a/internal/updater/html/bfs.go b/pkg/updaters/html/bfs.go similarity index 100% rename from internal/updater/html/bfs.go rename to pkg/updaters/html/bfs.go diff --git a/internal/updater/html/css.go b/pkg/updaters/html/css.go similarity index 100% rename from internal/updater/html/css.go rename to pkg/updaters/html/css.go diff --git a/internal/updater/html/errors.go b/pkg/updaters/html/errors.go similarity index 100% rename from internal/updater/html/errors.go rename to pkg/updaters/html/errors.go diff --git a/internal/updater/html/fetch.go b/pkg/updaters/html/fetch.go similarity index 100% rename from internal/updater/html/fetch.go rename to pkg/updaters/html/fetch.go diff --git a/internal/updater/html/fetch_test.go b/pkg/updaters/html/fetch_test.go similarity index 100% rename from internal/updater/html/fetch_test.go rename to pkg/updaters/html/fetch_test.go diff --git a/internal/updater/html/match.go b/pkg/updaters/html/match.go similarity index 100% rename from internal/updater/html/match.go rename to pkg/updaters/html/match.go diff --git a/internal/models/server.go b/pkg/updaters/models/server.go similarity index 87% rename from internal/models/server.go rename to pkg/updaters/models/server.go index 8c52ad66..72aa5a06 100644 --- a/internal/models/server.go +++ b/pkg/updaters/models/server.go @@ -7,9 +7,11 @@ import ( "reflect" "strings" - "github.com/qdm12/gluetun/internal/constants/vpn" + "github.com/qdm12/gluetun/pkg/updaters/constants" ) +// Server is a mirror of the Server struct in gluetun's internal/models package. +// A unit test in gluetun ensures this is maintained. type Server struct { VPN string `json:"vpn,omitempty"` // Surfshark: country is also used for multi-hop @@ -44,11 +46,11 @@ func (s *Server) HasMinimumInformation() (err error) { return errors.New("vpn field is empty") case len(s.IPs) == 0: return errors.New("ips field is empty") - case s.VPN == vpn.Wireguard && (s.TCP || s.UDP): + case s.VPN == constants.Wireguard && (s.TCP || s.UDP): return errors.New("no network protocol should be set") - case s.VPN == vpn.OpenVPN && !s.TCP && !s.UDP: + case s.VPN == constants.OpenVPN && !s.TCP && !s.UDP: return errors.New("both TCP and UDP fields are false for OpenVPN") - case s.VPN == vpn.Wireguard && s.WgPubKey == "": + case s.VPN == constants.Wireguard && s.WgPubKey == "": return errors.New("wireguard public key field is empty") default: return nil diff --git a/internal/models/server_test.go b/pkg/updaters/models/server_test.go similarity index 100% rename from internal/models/server_test.go rename to pkg/updaters/models/server_test.go diff --git a/pkg/updaters/models/servers.go b/pkg/updaters/models/servers.go new file mode 100644 index 00000000..a2c7623f --- /dev/null +++ b/pkg/updaters/models/servers.go @@ -0,0 +1,7 @@ +package models + +type Servers struct { + Version uint16 `json:"version"` + Timestamp int64 `json:"timestamp"` + Servers []Server `json:"servers,omitempty"` +} diff --git a/internal/models/sort.go b/pkg/updaters/models/sort.go similarity index 92% rename from internal/models/sort.go rename to pkg/updaters/models/sort.go index 44f6d4f9..3d23e985 100644 --- a/internal/models/sort.go +++ b/pkg/updaters/models/sort.go @@ -1,9 +1,5 @@ package models -import "sort" - -var _ sort.Interface = (*SortableServers)(nil) - type SortableServers []Server func (s SortableServers) Len() int { diff --git a/internal/updater/openvpn/extract.go b/pkg/updaters/openvpn/extract.go similarity index 100% rename from internal/updater/openvpn/extract.go rename to pkg/updaters/openvpn/extract.go diff --git a/internal/updater/openvpn/fetch.go b/pkg/updaters/openvpn/fetch.go similarity index 100% rename from internal/updater/openvpn/fetch.go rename to pkg/updaters/openvpn/fetch.go diff --git a/internal/updater/openvpn/multifetch.go b/pkg/updaters/openvpn/multifetch.go similarity index 100% rename from internal/updater/openvpn/multifetch.go rename to pkg/updaters/openvpn/multifetch.go diff --git a/internal/provider/airvpn/updater/api.go b/pkg/updaters/providers/airvpn/api.go similarity index 99% rename from internal/provider/airvpn/updater/api.go rename to pkg/updaters/providers/airvpn/api.go index 39635a6d..a715cf77 100644 --- a/internal/provider/airvpn/updater/api.go +++ b/pkg/updaters/providers/airvpn/api.go @@ -1,4 +1,4 @@ -package updater +package airvpn import ( "context" diff --git a/internal/provider/airvpn/updater/servers.go b/pkg/updaters/providers/airvpn/servers.go similarity index 93% rename from internal/provider/airvpn/updater/servers.go rename to pkg/updaters/providers/airvpn/servers.go index d5105e1a..e676e717 100644 --- a/internal/provider/airvpn/updater/servers.go +++ b/pkg/updaters/providers/airvpn/servers.go @@ -1,4 +1,4 @@ -package updater +package airvpn import ( "context" @@ -7,9 +7,9 @@ import ( "sort" "strings" - "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/common" + "github.com/qdm12/gluetun/pkg/updaters/constants" + "github.com/qdm12/gluetun/pkg/updaters/models" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( @@ -54,7 +54,7 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) ( } baseWireguardServer := baseServer - baseWireguardServer.VPN = vpn.Wireguard + baseWireguardServer.VPN = constants.Wireguard baseWireguardServer.WgPubKey = "PyLCXAQT8KkM4T+dUsOQfn+Ub3pGxfGlxkIApuig+hk=" ipv4WireguadServer := baseWireguardServer @@ -68,7 +68,7 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) ( servers = append(servers, ipv6WireguadServer) baseOpenVPNServer := baseServer - baseOpenVPNServer.VPN = vpn.OpenVPN + baseOpenVPNServer.VPN = constants.OpenVPN baseOpenVPNServer.UDP = true baseOpenVPNServer.TCP = true diff --git a/internal/provider/mullvad/updater/updater.go b/pkg/updaters/providers/airvpn/updater.go similarity index 56% rename from internal/provider/mullvad/updater/updater.go rename to pkg/updaters/providers/airvpn/updater.go index a987c0fd..ff28543c 100644 --- a/internal/provider/mullvad/updater/updater.go +++ b/pkg/updaters/providers/airvpn/updater.go @@ -1,4 +1,4 @@ -package updater +package airvpn import ( "net/http" @@ -13,3 +13,11 @@ func New(client *http.Client) *Updater { client: client, } } + +func (u *Updater) Version() uint16 { + return 1 +} + +func (u *Updater) Name() string { + return "airvpn" +} diff --git a/internal/provider/cyberghost/updater/constants.go b/pkg/updaters/providers/cyberghost/constants.go similarity index 98% rename from internal/provider/cyberghost/updater/constants.go rename to pkg/updaters/providers/cyberghost/constants.go index 698fa986..cae332f1 100644 --- a/internal/provider/cyberghost/updater/constants.go +++ b/pkg/updaters/providers/cyberghost/constants.go @@ -1,6 +1,6 @@ -package updater +package cyberghost -import "github.com/qdm12/gluetun/internal/constants" +import "github.com/qdm12/gluetun/pkg/updaters/constants" func getGroupIDToProtocol() map[string]string { return map[string]string{ diff --git a/internal/provider/cyberghost/updater/countries.go b/pkg/updaters/providers/cyberghost/countries.go similarity index 95% rename from internal/provider/cyberghost/updater/countries.go rename to pkg/updaters/providers/cyberghost/countries.go index 0b0263be..4a770201 100644 --- a/internal/provider/cyberghost/updater/countries.go +++ b/pkg/updaters/providers/cyberghost/countries.go @@ -1,4 +1,4 @@ -package updater +package cyberghost func mergeCountryCodes(base, extend map[string]string) (merged map[string]string) { merged = make(map[string]string, len(base)) diff --git a/internal/provider/cyberghost/updater/hosttoserver.go b/pkg/updaters/providers/cyberghost/hosttoserver.go similarity index 89% rename from internal/provider/cyberghost/updater/hosttoserver.go rename to pkg/updaters/providers/cyberghost/hosttoserver.go index 32b6ad3f..7bf3be79 100644 --- a/internal/provider/cyberghost/updater/hosttoserver.go +++ b/pkg/updaters/providers/cyberghost/hosttoserver.go @@ -1,11 +1,10 @@ -package updater +package cyberghost import ( "net/netip" - "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" + "github.com/qdm12/gluetun/pkg/updaters/models" ) type hostToServer map[string]models.Server @@ -26,7 +25,7 @@ func getPossibleServers() (possibleServers hostToServer) { const domain = "cg-dialup.net" possibleHost := groupID + "-" + countryCode + "." + domain possibleServer := models.Server{ - VPN: vpn.OpenVPN, + VPN: constants.OpenVPN, Hostname: possibleHost, Country: country, TCP: protocol == constants.TCP, diff --git a/internal/provider/cyberghost/updater/resolve.go b/pkg/updaters/providers/cyberghost/resolve.go similarity index 88% rename from internal/provider/cyberghost/updater/resolve.go rename to pkg/updaters/providers/cyberghost/resolve.go index 49e984cb..6756f310 100644 --- a/internal/provider/cyberghost/updater/resolve.go +++ b/pkg/updaters/providers/cyberghost/resolve.go @@ -1,9 +1,9 @@ -package updater +package cyberghost import ( "time" - "github.com/qdm12/gluetun/internal/updater/resolver" + "github.com/qdm12/gluetun/pkg/updaters/resolver" ) func parallelResolverSettings(hosts []string) (settings resolver.ParallelSettings) { diff --git a/internal/provider/cyberghost/updater/servers.go b/pkg/updaters/providers/cyberghost/servers.go similarity index 88% rename from internal/provider/cyberghost/updater/servers.go rename to pkg/updaters/providers/cyberghost/servers.go index 4b6fd4b5..a6eaee63 100644 --- a/internal/provider/cyberghost/updater/servers.go +++ b/pkg/updaters/providers/cyberghost/servers.go @@ -1,4 +1,4 @@ -package updater +package cyberghost import ( "context" @@ -6,8 +6,8 @@ import ( "sort" "strings" - "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" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( diff --git a/internal/provider/cyberghost/updater/updater.go b/pkg/updaters/providers/cyberghost/updater.go similarity index 60% rename from internal/provider/cyberghost/updater/updater.go rename to pkg/updaters/providers/cyberghost/updater.go index b6f3aae5..91f8b58e 100644 --- a/internal/provider/cyberghost/updater/updater.go +++ b/pkg/updaters/providers/cyberghost/updater.go @@ -1,7 +1,7 @@ -package updater +package cyberghost import ( - "github.com/qdm12/gluetun/internal/provider/common" + "github.com/qdm12/gluetun/pkg/updaters/common" ) type Updater struct { @@ -15,3 +15,11 @@ func New(parallelResolver common.ParallelResolver, warner common.Warner) *Update warner: warner, } } + +func (u *Updater) Version() uint16 { + return 5 //nolint:mnd +} + +func (u *Updater) Name() string { + return "cyberghost" +} diff --git a/internal/provider/example/updater/api.go b/pkg/updaters/providers/example/api.go similarity index 98% rename from internal/provider/example/updater/api.go rename to pkg/updaters/providers/example/api.go index 3d89df09..f8b5726f 100644 --- a/internal/provider/example/updater/api.go +++ b/pkg/updaters/providers/example/api.go @@ -1,4 +1,4 @@ -package updater +package example import ( "context" diff --git a/internal/provider/example/updater/resolve.go b/pkg/updaters/providers/example/resolve.go similarity index 91% rename from internal/provider/example/updater/resolve.go rename to pkg/updaters/providers/example/resolve.go index 4f976861..45c26657 100644 --- a/internal/provider/example/updater/resolve.go +++ b/pkg/updaters/providers/example/resolve.go @@ -1,9 +1,9 @@ -package updater +package example import ( "time" - "github.com/qdm12/gluetun/internal/updater/resolver" + "github.com/qdm12/gluetun/pkg/updaters/resolver" ) // TODO: remove this file if the parallel resolver is not used diff --git a/internal/provider/example/updater/servers.go b/pkg/updaters/providers/example/servers.go similarity index 94% rename from internal/provider/example/updater/servers.go rename to pkg/updaters/providers/example/servers.go index 8e38e765..ae866130 100644 --- a/internal/provider/example/updater/servers.go +++ b/pkg/updaters/providers/example/servers.go @@ -1,13 +1,13 @@ -package updater +package example import ( "context" "fmt" "sort" - "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/common" + "github.com/qdm12/gluetun/pkg/updaters/constants" + "github.com/qdm12/gluetun/pkg/updaters/models" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( @@ -103,7 +103,7 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) ( } if serverData.OpenVPNHostname != "" { openvpnServer := baseServer - openvpnServer.VPN = vpn.OpenVPN + openvpnServer.VPN = constants.OpenVPN openvpnServer.UDP = true openvpnServer.TCP = true openvpnServer.Hostname = serverData.OpenVPNHostname @@ -112,7 +112,7 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) ( } if serverData.WireguardHostname != "" { wireguardServer := baseServer - wireguardServer.VPN = vpn.Wireguard + wireguardServer.VPN = constants.Wireguard wireguardServer.Hostname = serverData.WireguardHostname wireguardServer.IPs = hostToIPs[serverData.WireguardHostname] servers = append(servers, wireguardServer) diff --git a/internal/provider/example/updater/updater.go b/pkg/updaters/providers/example/updater.go similarity index 77% rename from internal/provider/example/updater/updater.go rename to pkg/updaters/providers/example/updater.go index a3abfbdb..fb470f7b 100644 --- a/internal/provider/example/updater/updater.go +++ b/pkg/updaters/providers/example/updater.go @@ -1,9 +1,9 @@ -package updater +package example import ( "net/http" - "github.com/qdm12/gluetun/internal/provider/common" + "github.com/qdm12/gluetun/pkg/updaters/common" ) type Updater struct { @@ -25,3 +25,11 @@ func New(warner common.Warner, unzipper common.Unzipper, warner: warner, } } + +func (u *Updater) Version() uint16 { + return 1 +} + +func (u *Updater) Name() string { + return "example" +} diff --git a/internal/provider/expressvpn/updater/hardcoded.go b/pkg/updaters/providers/expressvpn/hardcoded.go similarity index 99% rename from internal/provider/expressvpn/updater/hardcoded.go rename to pkg/updaters/providers/expressvpn/hardcoded.go index 7961f973..c654cdf0 100644 --- a/internal/provider/expressvpn/updater/hardcoded.go +++ b/pkg/updaters/providers/expressvpn/hardcoded.go @@ -1,7 +1,7 @@ -package updater +package expressvpn import ( - "github.com/qdm12/gluetun/internal/models" + "github.com/qdm12/gluetun/pkg/updaters/models" ) func hardcodedServers() (servers []models.Server) { diff --git a/internal/provider/expressvpn/updater/resolve.go b/pkg/updaters/providers/expressvpn/resolve.go similarity index 85% rename from internal/provider/expressvpn/updater/resolve.go rename to pkg/updaters/providers/expressvpn/resolve.go index e51b05d7..5a711971 100644 --- a/internal/provider/expressvpn/updater/resolve.go +++ b/pkg/updaters/providers/expressvpn/resolve.go @@ -1,9 +1,9 @@ -package updater +package expressvpn import ( "time" - "github.com/qdm12/gluetun/internal/updater/resolver" + "github.com/qdm12/gluetun/pkg/updaters/resolver" ) func parallelResolverSettings(hosts []string) (settings resolver.ParallelSettings) { diff --git a/internal/provider/expressvpn/updater/servers.go b/pkg/updaters/providers/expressvpn/servers.go similarity index 83% rename from internal/provider/expressvpn/updater/servers.go rename to pkg/updaters/providers/expressvpn/servers.go index eed1b8a9..98d7ceb8 100644 --- a/internal/provider/expressvpn/updater/servers.go +++ b/pkg/updaters/providers/expressvpn/servers.go @@ -1,13 +1,13 @@ -package updater +package expressvpn import ( "context" "fmt" "sort" - "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/common" + "github.com/qdm12/gluetun/pkg/updaters/constants" + "github.com/qdm12/gluetun/pkg/updaters/models" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( @@ -36,7 +36,7 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) ( if len(server.IPs) == 0 { continue } - server.VPN = vpn.OpenVPN + server.VPN = constants.OpenVPN server.UDP = true // no TCP support servers[i] = server i++ diff --git a/pkg/updaters/providers/expressvpn/updater.go b/pkg/updaters/providers/expressvpn/updater.go new file mode 100644 index 00000000..469edb45 --- /dev/null +++ b/pkg/updaters/providers/expressvpn/updater.go @@ -0,0 +1,29 @@ +package expressvpn + +import ( + "github.com/qdm12/gluetun/pkg/updaters/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, + } +} + +func (u *Updater) Version() uint16 { + return 2 //nolint:mnd +} + +func (u *Updater) Name() string { + return "expressvpn" +} diff --git a/internal/provider/fastestvpn/updater/api.go b/pkg/updaters/providers/fastestvpn/api.go similarity index 99% rename from internal/provider/fastestvpn/updater/api.go rename to pkg/updaters/providers/fastestvpn/api.go index ca832cbd..a74cc39e 100644 --- a/internal/provider/fastestvpn/updater/api.go +++ b/pkg/updaters/providers/fastestvpn/api.go @@ -1,4 +1,4 @@ -package updater +package fastestvpn import ( "bytes" diff --git a/internal/provider/fastestvpn/updater/api_test.go b/pkg/updaters/providers/fastestvpn/api_test.go similarity index 99% rename from internal/provider/fastestvpn/updater/api_test.go rename to pkg/updaters/providers/fastestvpn/api_test.go index 81918c2b..f5c8c05c 100644 --- a/internal/provider/fastestvpn/updater/api_test.go +++ b/pkg/updaters/providers/fastestvpn/api_test.go @@ -1,4 +1,4 @@ -package updater +package fastestvpn import ( "context" diff --git a/internal/provider/fastestvpn/updater/hosttoserver.go b/pkg/updaters/providers/fastestvpn/hosttoserver.go similarity index 88% rename from internal/provider/fastestvpn/updater/hosttoserver.go rename to pkg/updaters/providers/fastestvpn/hosttoserver.go index f2be88be..8bbbfefe 100644 --- a/internal/provider/fastestvpn/updater/hosttoserver.go +++ b/pkg/updaters/providers/fastestvpn/hosttoserver.go @@ -1,10 +1,10 @@ -package updater +package fastestvpn import ( "net/netip" - "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" ) type hostToServerData map[string]serverData @@ -22,11 +22,11 @@ type serverData struct { func (hts hostToServerData) add(host, vpnType, country, city string, tcp, udp bool) { serverData, ok := hts[host] switch vpnType { - case vpn.OpenVPN: + case constants.OpenVPN: serverData.openvpn = true serverData.openvpnTCP = serverData.openvpnTCP || tcp serverData.openvpnUDP = serverData.openvpnUDP || udp - case vpn.Wireguard: + case constants.Wireguard: serverData.wireguard = true default: panic("protocol not supported") @@ -76,14 +76,14 @@ func (hts hostToServerData) toServersSlice() (servers []models.Server) { } if serverData.openvpn { openvpnServer := baseServer - openvpnServer.VPN = vpn.OpenVPN + openvpnServer.VPN = constants.OpenVPN openvpnServer.TCP = serverData.openvpnTCP openvpnServer.UDP = serverData.openvpnUDP servers = append(servers, openvpnServer) } if serverData.wireguard { wireguardServer := baseServer - wireguardServer.VPN = vpn.Wireguard + wireguardServer.VPN = constants.Wireguard const wireguardPublicKey = "658QxufMbjOTmB61Z7f+c7Rjg7oqWLnepTalqBERjF0=" wireguardServer.WgPubKey = wireguardPublicKey servers = append(servers, wireguardServer) diff --git a/internal/provider/fastestvpn/updater/resolve.go b/pkg/updaters/providers/fastestvpn/resolve.go similarity index 86% rename from internal/provider/fastestvpn/updater/resolve.go rename to pkg/updaters/providers/fastestvpn/resolve.go index 9af5b9ee..f18c175d 100644 --- a/internal/provider/fastestvpn/updater/resolve.go +++ b/pkg/updaters/providers/fastestvpn/resolve.go @@ -1,9 +1,9 @@ -package updater +package fastestvpn import ( "time" - "github.com/qdm12/gluetun/internal/updater/resolver" + "github.com/qdm12/gluetun/pkg/updaters/resolver" ) func parallelResolverSettings(hosts []string) (settings resolver.ParallelSettings) { diff --git a/internal/provider/fastestvpn/updater/servers.go b/pkg/updaters/providers/fastestvpn/servers.go similarity index 79% rename from internal/provider/fastestvpn/updater/servers.go rename to pkg/updaters/providers/fastestvpn/servers.go index 0401ab35..063c78ec 100644 --- a/internal/provider/fastestvpn/updater/servers.go +++ b/pkg/updaters/providers/fastestvpn/servers.go @@ -1,13 +1,13 @@ -package updater +package fastestvpn import ( "context" "fmt" "sort" - "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/common" + "github.com/qdm12/gluetun/pkg/updaters/constants" + "github.com/qdm12/gluetun/pkg/updaters/models" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( @@ -25,14 +25,14 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) ( // all hostnames from the protocols TCP, UDP and IKEV2 support Wireguard // per https://github.com/qdm12/gluetun-wiki/issues/76#issuecomment-2125420536 const wgTCP, wgUDP = false, false // ignored - hts.add(apiServer.hostname, vpn.Wireguard, apiServer.country, apiServer.city, wgTCP, wgUDP) + hts.add(apiServer.hostname, constants.Wireguard, apiServer.country, apiServer.city, wgTCP, wgUDP) tcp := protocol == "tcp" udp := protocol == "udp" if !tcp && !udp { // not an OpenVPN protocol, for example ikev2 continue } - hts.add(apiServer.hostname, vpn.OpenVPN, apiServer.country, apiServer.city, tcp, udp) + hts.add(apiServer.hostname, constants.OpenVPN, apiServer.country, apiServer.city, tcp, udp) } } diff --git a/pkg/updaters/providers/fastestvpn/updater.go b/pkg/updaters/providers/fastestvpn/updater.go new file mode 100644 index 00000000..ebd5f62a --- /dev/null +++ b/pkg/updaters/providers/fastestvpn/updater.go @@ -0,0 +1,31 @@ +package fastestvpn + +import ( + "net/http" + + "github.com/qdm12/gluetun/pkg/updaters/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, + } +} + +func (u *Updater) Version() uint16 { + return 2 //nolint:mnd +} + +func (u *Updater) Name() string { + return "fastestvpn" +} diff --git a/internal/provider/vyprvpn/updater/filename.go b/pkg/updaters/providers/giganews/filename.go similarity index 95% rename from internal/provider/vyprvpn/updater/filename.go rename to pkg/updaters/providers/giganews/filename.go index 4f017431..c67fd60d 100644 --- a/internal/provider/vyprvpn/updater/filename.go +++ b/pkg/updaters/providers/giganews/filename.go @@ -1,4 +1,4 @@ -package updater +package giganews import ( "fmt" diff --git a/internal/provider/giganews/updater/hosttoserver.go b/pkg/updaters/providers/giganews/hosttoserver.go similarity index 86% rename from internal/provider/giganews/updater/hosttoserver.go rename to pkg/updaters/providers/giganews/hosttoserver.go index df9e9369..f24b4f34 100644 --- a/internal/provider/giganews/updater/hosttoserver.go +++ b/pkg/updaters/providers/giganews/hosttoserver.go @@ -1,10 +1,10 @@ -package updater +package giganews import ( "net/netip" - "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" ) type hostToServer map[string]models.Server @@ -12,7 +12,7 @@ type hostToServer map[string]models.Server func (hts hostToServer) add(host, region string, tcp, udp bool) { server, ok := hts[host] if !ok { - server.VPN = vpn.OpenVPN + server.VPN = constants.OpenVPN server.Hostname = host server.Region = region } diff --git a/internal/provider/vyprvpn/updater/resolve.go b/pkg/updaters/providers/giganews/resolve.go similarity index 88% rename from internal/provider/vyprvpn/updater/resolve.go rename to pkg/updaters/providers/giganews/resolve.go index fde66d47..24f6341e 100644 --- a/internal/provider/vyprvpn/updater/resolve.go +++ b/pkg/updaters/providers/giganews/resolve.go @@ -1,9 +1,9 @@ -package updater +package giganews import ( "time" - "github.com/qdm12/gluetun/internal/updater/resolver" + "github.com/qdm12/gluetun/pkg/updaters/resolver" ) func parallelResolverSettings(hosts []string) (settings resolver.ParallelSettings) { diff --git a/internal/provider/giganews/updater/servers.go b/pkg/updaters/providers/giganews/servers.go similarity index 92% rename from internal/provider/giganews/updater/servers.go rename to pkg/updaters/providers/giganews/servers.go index c75085ec..97acac30 100644 --- a/internal/provider/giganews/updater/servers.go +++ b/pkg/updaters/providers/giganews/servers.go @@ -1,4 +1,4 @@ -package updater +package giganews import ( "context" @@ -6,9 +6,9 @@ import ( "sort" "strings" - "github.com/qdm12/gluetun/internal/models" - "github.com/qdm12/gluetun/internal/provider/common" - "github.com/qdm12/gluetun/internal/updater/openvpn" + "github.com/qdm12/gluetun/pkg/updaters/common" + "github.com/qdm12/gluetun/pkg/updaters/models" + "github.com/qdm12/gluetun/pkg/updaters/openvpn" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( diff --git a/internal/provider/ipvanish/updater/updater.go b/pkg/updaters/providers/giganews/updater.go similarity index 68% rename from internal/provider/ipvanish/updater/updater.go rename to pkg/updaters/providers/giganews/updater.go index c2f9d7f2..df035e35 100644 --- a/internal/provider/ipvanish/updater/updater.go +++ b/pkg/updaters/providers/giganews/updater.go @@ -1,13 +1,13 @@ -package updater +package giganews import ( - "github.com/qdm12/gluetun/internal/provider/common" + "github.com/qdm12/gluetun/pkg/updaters/common" ) type Updater struct { unzipper common.Unzipper - warner common.Warner parallelResolver common.ParallelResolver + warner common.Warner } func New(unzipper common.Unzipper, warner common.Warner, @@ -15,7 +15,15 @@ func New(unzipper common.Unzipper, warner common.Warner, ) *Updater { return &Updater{ unzipper: unzipper, - warner: warner, parallelResolver: parallelResolver, + warner: warner, } } + +func (u *Updater) Version() uint16 { + return 1 +} + +func (u *Updater) Name() string { + return "giganews" +} diff --git a/internal/provider/hidemyass/updater/hosts.go b/pkg/updaters/providers/hidemyass/hosts.go similarity index 95% rename from internal/provider/hidemyass/updater/hosts.go rename to pkg/updaters/providers/hidemyass/hosts.go index 22fcbd0a..0fe2b8eb 100644 --- a/internal/provider/hidemyass/updater/hosts.go +++ b/pkg/updaters/providers/hidemyass/hosts.go @@ -1,4 +1,4 @@ -package updater +package hidemyass func getUniqueHosts(tcpHostToURL, udpHostToURL map[string]string) ( hosts []string, diff --git a/internal/provider/hidemyass/updater/hosttourl.go b/pkg/updaters/providers/hidemyass/hosttourl.go similarity index 93% rename from internal/provider/hidemyass/updater/hosttourl.go rename to pkg/updaters/providers/hidemyass/hosttourl.go index 3e0c09de..b7d928d4 100644 --- a/internal/provider/hidemyass/updater/hosttourl.go +++ b/pkg/updaters/providers/hidemyass/hosttourl.go @@ -1,11 +1,11 @@ -package updater +package hidemyass import ( "context" "net/http" "strings" - "github.com/qdm12/gluetun/internal/updater/openvpn" + "github.com/qdm12/gluetun/pkg/updaters/openvpn" ) func getAllHostToURL(ctx context.Context, client *http.Client) ( diff --git a/internal/provider/hidemyass/updater/index.go b/pkg/updaters/providers/hidemyass/index.go similarity index 98% rename from internal/provider/hidemyass/updater/index.go rename to pkg/updaters/providers/hidemyass/index.go index 6829baaf..1640266c 100644 --- a/internal/provider/hidemyass/updater/index.go +++ b/pkg/updaters/providers/hidemyass/index.go @@ -1,4 +1,4 @@ -package updater +package hidemyass import ( "context" diff --git a/internal/provider/hidemyass/updater/resolve.go b/pkg/updaters/providers/hidemyass/resolve.go similarity index 88% rename from internal/provider/hidemyass/updater/resolve.go rename to pkg/updaters/providers/hidemyass/resolve.go index e3f76174..e6edc9dc 100644 --- a/internal/provider/hidemyass/updater/resolve.go +++ b/pkg/updaters/providers/hidemyass/resolve.go @@ -1,9 +1,9 @@ -package updater +package hidemyass import ( "time" - "github.com/qdm12/gluetun/internal/updater/resolver" + "github.com/qdm12/gluetun/pkg/updaters/resolver" ) func parallelResolverSettings(hosts []string) (settings resolver.ParallelSettings) { diff --git a/internal/provider/hidemyass/updater/servers.go b/pkg/updaters/providers/hidemyass/servers.go similarity index 88% rename from internal/provider/hidemyass/updater/servers.go rename to pkg/updaters/providers/hidemyass/servers.go index 83a765a3..3090031d 100644 --- a/internal/provider/hidemyass/updater/servers.go +++ b/pkg/updaters/providers/hidemyass/servers.go @@ -1,13 +1,13 @@ -package updater +package hidemyass import ( "context" "fmt" "sort" - "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/common" + "github.com/qdm12/gluetun/pkg/updaters/constants" + "github.com/qdm12/gluetun/pkg/updaters/models" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( @@ -56,7 +56,7 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) ( country, region, city := parseOpenvpnURL(url, protocol) server := models.Server{ - VPN: vpn.OpenVPN, + VPN: constants.OpenVPN, Country: country, Region: region, City: city, diff --git a/internal/provider/hidemyass/updater/updater.go b/pkg/updaters/providers/hidemyass/updater.go similarity index 67% rename from internal/provider/hidemyass/updater/updater.go rename to pkg/updaters/providers/hidemyass/updater.go index df4427cc..070b8800 100644 --- a/internal/provider/hidemyass/updater/updater.go +++ b/pkg/updaters/providers/hidemyass/updater.go @@ -1,9 +1,9 @@ -package updater +package hidemyass import ( "net/http" - "github.com/qdm12/gluetun/internal/provider/common" + "github.com/qdm12/gluetun/pkg/updaters/common" ) type Updater struct { @@ -21,3 +21,11 @@ func New(client *http.Client, warner common.Warner, warner: warner, } } + +func (u *Updater) Version() uint16 { + return 2 //nolint:mnd +} + +func (u *Updater) Name() string { + return "hidemyass" +} diff --git a/internal/provider/hidemyass/updater/url.go b/pkg/updaters/providers/hidemyass/url.go similarity index 98% rename from internal/provider/hidemyass/updater/url.go rename to pkg/updaters/providers/hidemyass/url.go index b9976c58..2a9eadad 100644 --- a/internal/provider/hidemyass/updater/url.go +++ b/pkg/updaters/providers/hidemyass/url.go @@ -1,4 +1,4 @@ -package updater +package hidemyass import ( "strings" diff --git a/internal/provider/ipvanish/updater/filename.go b/pkg/updaters/providers/ipvanish/filename.go similarity index 91% rename from internal/provider/ipvanish/updater/filename.go rename to pkg/updaters/providers/ipvanish/filename.go index 1cada331..93624edf 100644 --- a/internal/provider/ipvanish/updater/filename.go +++ b/pkg/updaters/providers/ipvanish/filename.go @@ -1,10 +1,10 @@ -package updater +package ipvanish import ( "fmt" "strings" - "github.com/qdm12/gluetun/internal/constants" + "github.com/qdm12/gluetun/pkg/updaters/constants" "golang.org/x/text/cases" ) diff --git a/internal/provider/ipvanish/updater/filename_test.go b/pkg/updaters/providers/ipvanish/filename_test.go similarity index 98% rename from internal/provider/ipvanish/updater/filename_test.go rename to pkg/updaters/providers/ipvanish/filename_test.go index 50a6d702..97418de4 100644 --- a/internal/provider/ipvanish/updater/filename_test.go +++ b/pkg/updaters/providers/ipvanish/filename_test.go @@ -1,4 +1,4 @@ -package updater +package ipvanish import ( "errors" diff --git a/internal/provider/ipvanish/updater/hosttoserver.go b/pkg/updaters/providers/ipvanish/hosttoserver.go similarity index 87% rename from internal/provider/ipvanish/updater/hosttoserver.go rename to pkg/updaters/providers/ipvanish/hosttoserver.go index 9295ef60..572c77fe 100644 --- a/internal/provider/ipvanish/updater/hosttoserver.go +++ b/pkg/updaters/providers/ipvanish/hosttoserver.go @@ -1,11 +1,11 @@ -package updater +package ipvanish import ( "net/netip" "sort" - "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" ) type hostToServer map[string]models.Server @@ -13,7 +13,7 @@ type hostToServer map[string]models.Server func (hts hostToServer) add(host, country, city string, tcp, udp bool) { server, ok := hts[host] if !ok { - server.VPN = vpn.OpenVPN + server.VPN = constants.OpenVPN server.Hostname = host server.Country = country server.City = city diff --git a/internal/provider/ipvanish/updater/hosttoserver_test.go b/pkg/updaters/providers/ipvanish/hosttoserver_test.go similarity index 94% rename from internal/provider/ipvanish/updater/hosttoserver_test.go rename to pkg/updaters/providers/ipvanish/hosttoserver_test.go index 41d384cf..6bdc36c1 100644 --- a/internal/provider/ipvanish/updater/hosttoserver_test.go +++ b/pkg/updaters/providers/ipvanish/hosttoserver_test.go @@ -1,11 +1,11 @@ -package updater +package ipvanish import ( "net/netip" "testing" - "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" "github.com/stretchr/testify/assert" ) @@ -29,7 +29,7 @@ func Test_hostToServer_add(t *testing.T) { udp: true, expectedHTS: hostToServer{ "host": { - VPN: vpn.OpenVPN, + VPN: constants.OpenVPN, Hostname: "host", Country: "country", City: "city", @@ -50,7 +50,7 @@ func Test_hostToServer_add(t *testing.T) { expectedHTS: hostToServer{ "existing host": {}, "host": models.Server{ - VPN: vpn.OpenVPN, + VPN: constants.OpenVPN, Hostname: "host", Country: "country", City: "city", @@ -62,7 +62,7 @@ func Test_hostToServer_add(t *testing.T) { "extend existing server": { initialHTS: hostToServer{ "host": models.Server{ - VPN: vpn.OpenVPN, + VPN: constants.OpenVPN, Hostname: "host", Country: "country", City: "city", @@ -76,7 +76,7 @@ func Test_hostToServer_add(t *testing.T) { udp: true, expectedHTS: hostToServer{ "host": models.Server{ - VPN: vpn.OpenVPN, + VPN: constants.OpenVPN, Hostname: "host", Country: "country", City: "city", diff --git a/internal/provider/ipvanish/updater/resolve.go b/pkg/updaters/providers/ipvanish/resolve.go similarity index 88% rename from internal/provider/ipvanish/updater/resolve.go rename to pkg/updaters/providers/ipvanish/resolve.go index d0b3fa0c..965534a3 100644 --- a/internal/provider/ipvanish/updater/resolve.go +++ b/pkg/updaters/providers/ipvanish/resolve.go @@ -1,9 +1,9 @@ -package updater +package ipvanish import ( "time" - "github.com/qdm12/gluetun/internal/updater/resolver" + "github.com/qdm12/gluetun/pkg/updaters/resolver" ) func parallelResolverSettings(hosts []string) (settings resolver.ParallelSettings) { diff --git a/internal/provider/ipvanish/updater/servers.go b/pkg/updaters/providers/ipvanish/servers.go similarity index 92% rename from internal/provider/ipvanish/updater/servers.go rename to pkg/updaters/providers/ipvanish/servers.go index fa0d29c8..995df62f 100644 --- a/internal/provider/ipvanish/updater/servers.go +++ b/pkg/updaters/providers/ipvanish/servers.go @@ -1,4 +1,4 @@ -package updater +package ipvanish import ( "context" @@ -6,9 +6,9 @@ import ( "sort" "strings" - "github.com/qdm12/gluetun/internal/models" - "github.com/qdm12/gluetun/internal/provider/common" - "github.com/qdm12/gluetun/internal/updater/openvpn" + "github.com/qdm12/gluetun/pkg/updaters/common" + "github.com/qdm12/gluetun/pkg/updaters/models" + "github.com/qdm12/gluetun/pkg/updaters/openvpn" "golang.org/x/text/cases" "golang.org/x/text/language" ) diff --git a/internal/provider/ipvanish/updater/servers_test.go b/pkg/updaters/providers/ipvanish/servers_test.go similarity index 95% rename from internal/provider/ipvanish/updater/servers_test.go rename to pkg/updaters/providers/ipvanish/servers_test.go index d416a5fe..8826fc9b 100644 --- a/internal/provider/ipvanish/updater/servers_test.go +++ b/pkg/updaters/providers/ipvanish/servers_test.go @@ -1,4 +1,4 @@ -package updater +package ipvanish import ( "context" @@ -8,10 +8,10 @@ import ( "time" "github.com/golang/mock/gomock" - "github.com/qdm12/gluetun/internal/constants/vpn" - "github.com/qdm12/gluetun/internal/models" - "github.com/qdm12/gluetun/internal/provider/common" - "github.com/qdm12/gluetun/internal/updater/resolver" + "github.com/qdm12/gluetun/pkg/updaters/common" + "github.com/qdm12/gluetun/pkg/updaters/constants" + "github.com/qdm12/gluetun/pkg/updaters/models" + "github.com/qdm12/gluetun/pkg/updaters/resolver" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -168,7 +168,7 @@ func Test_Updater_GetServers(t *testing.T) { resolveWarnings: []string{"resolve warning"}, servers: []models.Server{ { - VPN: vpn.OpenVPN, + VPN: constants.OpenVPN, Country: "Canada", City: "City A", Hostname: "hosta", @@ -176,7 +176,7 @@ func Test_Updater_GetServers(t *testing.T) { IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1}), netip.AddrFrom4([4]byte{2, 2, 2, 2})}, }, { - VPN: vpn.OpenVPN, + VPN: constants.OpenVPN, Country: "Luxembourg", City: "City B", Hostname: "hostb", diff --git a/internal/provider/privatevpn/updater/updater.go b/pkg/updaters/providers/ipvanish/updater.go similarity index 67% rename from internal/provider/privatevpn/updater/updater.go rename to pkg/updaters/providers/ipvanish/updater.go index d61e235d..ddebe763 100644 --- a/internal/provider/privatevpn/updater/updater.go +++ b/pkg/updaters/providers/ipvanish/updater.go @@ -1,13 +1,13 @@ -package updater +package ipvanish import ( - "github.com/qdm12/gluetun/internal/provider/common" + "github.com/qdm12/gluetun/pkg/updaters/common" ) type Updater struct { unzipper common.Unzipper - parallelResolver common.ParallelResolver warner common.Warner + parallelResolver common.ParallelResolver } func New(unzipper common.Unzipper, warner common.Warner, @@ -15,7 +15,15 @@ func New(unzipper common.Unzipper, warner common.Warner, ) *Updater { return &Updater{ unzipper: unzipper, - parallelResolver: parallelResolver, warner: warner, + parallelResolver: parallelResolver, } } + +func (u *Updater) Version() uint16 { + return 2 //nolint:mnd +} + +func (u *Updater) Name() string { + return "ipvanish" +} diff --git a/internal/provider/ivpn/updater/api.go b/pkg/updaters/providers/ivpn/api.go similarity index 98% rename from internal/provider/ivpn/updater/api.go rename to pkg/updaters/providers/ivpn/api.go index a45f2685..920c83ba 100644 --- a/internal/provider/ivpn/updater/api.go +++ b/pkg/updaters/providers/ivpn/api.go @@ -1,4 +1,4 @@ -package updater +package ivpn import ( "context" diff --git a/internal/provider/ivpn/updater/api_test.go b/pkg/updaters/providers/ivpn/api_test.go similarity index 99% rename from internal/provider/ivpn/updater/api_test.go rename to pkg/updaters/providers/ivpn/api_test.go index 9472e2a9..58774e48 100644 --- a/internal/provider/ivpn/updater/api_test.go +++ b/pkg/updaters/providers/ivpn/api_test.go @@ -1,4 +1,4 @@ -package updater +package ivpn import ( "context" diff --git a/internal/provider/purevpn/updater/resolve.go b/pkg/updaters/providers/ivpn/resolve.go similarity index 88% rename from internal/provider/purevpn/updater/resolve.go rename to pkg/updaters/providers/ivpn/resolve.go index d0b3fa0c..02efb3ae 100644 --- a/internal/provider/purevpn/updater/resolve.go +++ b/pkg/updaters/providers/ivpn/resolve.go @@ -1,9 +1,9 @@ -package updater +package ivpn import ( "time" - "github.com/qdm12/gluetun/internal/updater/resolver" + "github.com/qdm12/gluetun/pkg/updaters/resolver" ) func parallelResolverSettings(hosts []string) (settings resolver.ParallelSettings) { diff --git a/internal/provider/surfshark/updater/roundtrip_test.go b/pkg/updaters/providers/ivpn/roundtrip_test.go similarity index 91% rename from internal/provider/surfshark/updater/roundtrip_test.go rename to pkg/updaters/providers/ivpn/roundtrip_test.go index 9df23788..f8ee5d95 100644 --- a/internal/provider/surfshark/updater/roundtrip_test.go +++ b/pkg/updaters/providers/ivpn/roundtrip_test.go @@ -1,4 +1,4 @@ -package updater +package ivpn import "net/http" diff --git a/internal/provider/ivpn/updater/servers.go b/pkg/updaters/providers/ivpn/servers.go similarity index 91% rename from internal/provider/ivpn/updater/servers.go rename to pkg/updaters/providers/ivpn/servers.go index 33c2abe9..a269fca7 100644 --- a/internal/provider/ivpn/updater/servers.go +++ b/pkg/updaters/providers/ivpn/servers.go @@ -1,4 +1,4 @@ -package updater +package ivpn import ( "context" @@ -6,9 +6,9 @@ import ( "sort" "strings" - "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/common" + "github.com/qdm12/gluetun/pkg/updaters/constants" + "github.com/qdm12/gluetun/pkg/updaters/models" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( @@ -79,7 +79,7 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) ( if openVPNHostname != "" { openVPNServer := server openVPNServer.Hostname = openVPNHostname - openVPNServer.VPN = vpn.OpenVPN + openVPNServer.VPN = constants.OpenVPN openVPNServer.UDP = true openVPNServer.TCP = true openVPNServer.IPs = hostToIPs[openVPNHostname] @@ -89,7 +89,7 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) ( if wireguardHostname != "" { wireguardServer := server wireguardServer.Hostname = wireguardHostname - wireguardServer.VPN = vpn.Wireguard + wireguardServer.VPN = constants.Wireguard wireguardServer.IPs = hostToIPs[wireguardHostname] wireguardServer.WgPubKey = serverData.WgPubKey servers = append(servers, wireguardServer) diff --git a/internal/provider/ivpn/updater/servers_test.go b/pkg/updaters/providers/ivpn/servers_test.go similarity index 93% rename from internal/provider/ivpn/updater/servers_test.go rename to pkg/updaters/providers/ivpn/servers_test.go index 68a709e3..d7a20076 100644 --- a/internal/provider/ivpn/updater/servers_test.go +++ b/pkg/updaters/providers/ivpn/servers_test.go @@ -1,4 +1,4 @@ -package updater +package ivpn import ( "context" @@ -11,10 +11,10 @@ import ( "time" "github.com/golang/mock/gomock" - "github.com/qdm12/gluetun/internal/constants/vpn" - "github.com/qdm12/gluetun/internal/models" - "github.com/qdm12/gluetun/internal/provider/common" - "github.com/qdm12/gluetun/internal/updater/resolver" + "github.com/qdm12/gluetun/pkg/updaters/common" + "github.com/qdm12/gluetun/pkg/updaters/constants" + "github.com/qdm12/gluetun/pkg/updaters/models" + "github.com/qdm12/gluetun/pkg/updaters/resolver" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -117,17 +117,17 @@ func Test_Updater_GetServers(t *testing.T) { resolveWarnings: []string{"resolve warning"}, servers: []models.Server{ { - VPN: vpn.OpenVPN, Country: "Country1", + VPN: constants.OpenVPN, Country: "Country1", City: "City A", Hostname: "hosta", TCP: true, UDP: true, IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1}), netip.AddrFrom4([4]byte{2, 2, 2, 2})}, }, { - VPN: vpn.OpenVPN, Country: "Country2", + VPN: constants.OpenVPN, Country: "Country2", City: "City B", Hostname: "hostb", TCP: true, UDP: true, IPs: []netip.Addr{netip.AddrFrom4([4]byte{3, 3, 3, 3}), netip.AddrFrom4([4]byte{4, 4, 4, 4})}, }, { - VPN: vpn.Wireguard, + VPN: constants.Wireguard, Country: "Country3", City: "City C", Hostname: "hostc", WgPubKey: "xyz", diff --git a/internal/provider/slickvpn/updater/updater.go b/pkg/updaters/providers/ivpn/updater.go similarity index 68% rename from internal/provider/slickvpn/updater/updater.go rename to pkg/updaters/providers/ivpn/updater.go index df4427cc..69b081a7 100644 --- a/internal/provider/slickvpn/updater/updater.go +++ b/pkg/updaters/providers/ivpn/updater.go @@ -1,9 +1,9 @@ -package updater +package ivpn import ( "net/http" - "github.com/qdm12/gluetun/internal/provider/common" + "github.com/qdm12/gluetun/pkg/updaters/common" ) type Updater struct { @@ -21,3 +21,11 @@ func New(client *http.Client, warner common.Warner, warner: warner, } } + +func (u *Updater) Version() uint16 { + return 3 //nolint:mnd +} + +func (u *Updater) Name() string { + return "ivpn" +} diff --git a/internal/provider/mullvad/updater/api.go b/pkg/updaters/providers/mullvad/api.go similarity index 98% rename from internal/provider/mullvad/updater/api.go rename to pkg/updaters/providers/mullvad/api.go index ee41ed8f..2caf823f 100644 --- a/internal/provider/mullvad/updater/api.go +++ b/pkg/updaters/providers/mullvad/api.go @@ -1,4 +1,4 @@ -package updater +package mullvad import ( "context" diff --git a/internal/provider/mullvad/updater/hosttoserver.go b/pkg/updaters/providers/mullvad/hosttoserver.go similarity index 91% rename from internal/provider/mullvad/updater/hosttoserver.go rename to pkg/updaters/providers/mullvad/hosttoserver.go index eb616b8a..e89d6f04 100644 --- a/internal/provider/mullvad/updater/hosttoserver.go +++ b/pkg/updaters/providers/mullvad/hosttoserver.go @@ -1,4 +1,4 @@ -package updater +package mullvad import ( "errors" @@ -6,8 +6,8 @@ import ( "net/netip" "strings" - "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" ) type hostToServer map[string]models.Server @@ -28,7 +28,7 @@ func (hts hostToServer) add(data serverData) (err error) { switch data.Type { case "wireguard": - server.VPN = vpn.Wireguard + server.VPN = constants.Wireguard case "bridge": // ignore bridge servers return nil diff --git a/internal/provider/mullvad/updater/ips.go b/pkg/updaters/providers/mullvad/ips.go similarity index 97% rename from internal/provider/mullvad/updater/ips.go rename to pkg/updaters/providers/mullvad/ips.go index 14fb730e..ebc4d7a7 100644 --- a/internal/provider/mullvad/updater/ips.go +++ b/pkg/updaters/providers/mullvad/ips.go @@ -1,4 +1,4 @@ -package updater +package mullvad import ( "net/netip" diff --git a/internal/provider/mullvad/updater/ips_test.go b/pkg/updaters/providers/mullvad/ips_test.go similarity index 98% rename from internal/provider/mullvad/updater/ips_test.go rename to pkg/updaters/providers/mullvad/ips_test.go index 3b06bb47..5d327d5e 100644 --- a/internal/provider/mullvad/updater/ips_test.go +++ b/pkg/updaters/providers/mullvad/ips_test.go @@ -1,4 +1,4 @@ -package updater +package mullvad import ( "net/netip" diff --git a/internal/provider/mullvad/updater/servers.go b/pkg/updaters/providers/mullvad/servers.go similarity index 84% rename from internal/provider/mullvad/updater/servers.go rename to pkg/updaters/providers/mullvad/servers.go index b6587b10..3b0c5bd2 100644 --- a/internal/provider/mullvad/updater/servers.go +++ b/pkg/updaters/providers/mullvad/servers.go @@ -1,12 +1,12 @@ -package updater +package mullvad import ( "context" "fmt" "sort" - "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" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( diff --git a/internal/provider/privateinternetaccess/updater/updater.go b/pkg/updaters/providers/mullvad/updater.go similarity index 53% rename from internal/provider/privateinternetaccess/updater/updater.go rename to pkg/updaters/providers/mullvad/updater.go index a987c0fd..7f1d0cd3 100644 --- a/internal/provider/privateinternetaccess/updater/updater.go +++ b/pkg/updaters/providers/mullvad/updater.go @@ -1,4 +1,4 @@ -package updater +package mullvad import ( "net/http" @@ -13,3 +13,11 @@ func New(client *http.Client) *Updater { client: client, } } + +func (u *Updater) Version() uint16 { + return 4 //nolint:mnd +} + +func (u *Updater) Name() string { + return "mullvad" +} diff --git a/internal/provider/nordvpn/updater/api.go b/pkg/updaters/providers/nordvpn/api.go similarity index 98% rename from internal/provider/nordvpn/updater/api.go rename to pkg/updaters/providers/nordvpn/api.go index 096e29ad..0a8cc014 100644 --- a/internal/provider/nordvpn/updater/api.go +++ b/pkg/updaters/providers/nordvpn/api.go @@ -1,4 +1,4 @@ -package updater +package nordvpn import ( "context" diff --git a/internal/provider/nordvpn/updater/models.go b/pkg/updaters/providers/nordvpn/models.go similarity index 99% rename from internal/provider/nordvpn/updater/models.go rename to pkg/updaters/providers/nordvpn/models.go index 8aea49a3..6bc0ae99 100644 --- a/internal/provider/nordvpn/updater/models.go +++ b/pkg/updaters/providers/nordvpn/models.go @@ -1,4 +1,4 @@ -package updater +package nordvpn import ( "encoding/base64" diff --git a/internal/provider/nordvpn/updater/name.go b/pkg/updaters/providers/nordvpn/name.go similarity index 97% rename from internal/provider/nordvpn/updater/name.go rename to pkg/updaters/providers/nordvpn/name.go index 55464c46..764305f9 100644 --- a/internal/provider/nordvpn/updater/name.go +++ b/pkg/updaters/providers/nordvpn/name.go @@ -1,4 +1,4 @@ -package updater +package nordvpn import ( "errors" diff --git a/internal/provider/nordvpn/updater/servers.go b/pkg/updaters/providers/nordvpn/servers.go similarity index 94% rename from internal/provider/nordvpn/updater/servers.go rename to pkg/updaters/providers/nordvpn/servers.go index 826f78b4..0d328551 100644 --- a/internal/provider/nordvpn/updater/servers.go +++ b/pkg/updaters/providers/nordvpn/servers.go @@ -1,4 +1,4 @@ -package updater +package nordvpn import ( "context" @@ -6,9 +6,9 @@ import ( "fmt" "sort" - "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/common" + "github.com/qdm12/gluetun/pkg/updaters/constants" + "github.com/qdm12/gluetun/pkg/updaters/models" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( @@ -98,9 +98,9 @@ func extractServers(jsonServer serverData, groups map[uint32]groupData, var wireguardFound, openvpnFound bool wireguardServer := server - wireguardServer.VPN = vpn.Wireguard + wireguardServer.VPN = constants.Wireguard openVPNServer := server // accumulate UDP+TCP technologies - openVPNServer.VPN = vpn.OpenVPN + openVPNServer.VPN = constants.OpenVPN for _, technology := range jsonServer.Technologies { if technology.Status != "online" { diff --git a/internal/provider/nordvpn/updater/updater.go b/pkg/updaters/providers/nordvpn/updater.go similarity index 54% rename from internal/provider/nordvpn/updater/updater.go rename to pkg/updaters/providers/nordvpn/updater.go index ff0d41cd..568d7286 100644 --- a/internal/provider/nordvpn/updater/updater.go +++ b/pkg/updaters/providers/nordvpn/updater.go @@ -1,9 +1,9 @@ -package updater +package nordvpn import ( "net/http" - "github.com/qdm12/gluetun/internal/provider/common" + "github.com/qdm12/gluetun/pkg/updaters/common" ) type Updater struct { @@ -17,3 +17,11 @@ func New(client *http.Client, warner common.Warner) *Updater { warner: warner, } } + +func (u *Updater) Version() uint16 { + return 5 //nolint:mnd +} + +func (u *Updater) Name() string { + return "nordvpn" +} diff --git a/internal/provider/perfectprivacy/updater/citytoserver.go b/pkg/updaters/providers/perfectprivacy/citytoserver.go similarity index 84% rename from internal/provider/perfectprivacy/updater/citytoserver.go rename to pkg/updaters/providers/perfectprivacy/citytoserver.go index 39b2c8f1..0504147a 100644 --- a/internal/provider/perfectprivacy/updater/citytoserver.go +++ b/pkg/updaters/providers/perfectprivacy/citytoserver.go @@ -1,10 +1,10 @@ -package updater +package perfectprivacy import ( "net/netip" - "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" ) type cityToServer map[string]models.Server @@ -12,7 +12,7 @@ type cityToServer map[string]models.Server func (cts cityToServer) add(city string, ips []netip.Addr) { server, ok := cts[city] if !ok { - server.VPN = vpn.OpenVPN + server.VPN = constants.OpenVPN server.City = city server.IPs = ips server.TCP = true diff --git a/internal/provider/perfectprivacy/updater/filename.go b/pkg/updaters/providers/perfectprivacy/filename.go similarity index 91% rename from internal/provider/perfectprivacy/updater/filename.go rename to pkg/updaters/providers/perfectprivacy/filename.go index 6b379392..7378ac9d 100644 --- a/internal/provider/perfectprivacy/updater/filename.go +++ b/pkg/updaters/providers/perfectprivacy/filename.go @@ -1,4 +1,4 @@ -package updater +package perfectprivacy import ( "strings" diff --git a/internal/provider/perfectprivacy/updater/servers.go b/pkg/updaters/providers/perfectprivacy/servers.go similarity index 89% rename from internal/provider/perfectprivacy/updater/servers.go rename to pkg/updaters/providers/perfectprivacy/servers.go index ea79e54c..349da384 100644 --- a/internal/provider/perfectprivacy/updater/servers.go +++ b/pkg/updaters/providers/perfectprivacy/servers.go @@ -1,4 +1,4 @@ -package updater +package perfectprivacy import ( "context" @@ -7,9 +7,9 @@ import ( "sort" "strings" - "github.com/qdm12/gluetun/internal/models" - "github.com/qdm12/gluetun/internal/provider/common" - "github.com/qdm12/gluetun/internal/updater/openvpn" + "github.com/qdm12/gluetun/pkg/updaters/common" + "github.com/qdm12/gluetun/pkg/updaters/models" + "github.com/qdm12/gluetun/pkg/updaters/openvpn" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( diff --git a/internal/provider/perfectprivacy/updater/updater.go b/pkg/updaters/providers/perfectprivacy/updater.go similarity index 54% rename from internal/provider/perfectprivacy/updater/updater.go rename to pkg/updaters/providers/perfectprivacy/updater.go index 66a2b327..7944360c 100644 --- a/internal/provider/perfectprivacy/updater/updater.go +++ b/pkg/updaters/providers/perfectprivacy/updater.go @@ -1,7 +1,7 @@ -package updater +package perfectprivacy import ( - "github.com/qdm12/gluetun/internal/provider/common" + "github.com/qdm12/gluetun/pkg/updaters/common" ) type Updater struct { @@ -15,3 +15,11 @@ func New(unzipper common.Unzipper, warner common.Warner) *Updater { warner: warner, } } + +func (u *Updater) Version() uint16 { + return 1 +} + +func (u *Updater) Name() string { + return "perfect privacy" +} diff --git a/internal/provider/privado/updater/servers.go b/pkg/updaters/providers/privado/servers.go similarity index 88% rename from internal/provider/privado/updater/servers.go rename to pkg/updaters/providers/privado/servers.go index ee3742d6..588cb602 100644 --- a/internal/provider/privado/updater/servers.go +++ b/pkg/updaters/providers/privado/servers.go @@ -1,4 +1,4 @@ -package updater +package privado import ( "context" @@ -8,9 +8,9 @@ import ( "net/netip" "sort" - "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/common" + "github.com/qdm12/gluetun/pkg/updaters/constants" + "github.com/qdm12/gluetun/pkg/updaters/models" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( @@ -55,7 +55,7 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) ( servers = make([]models.Server, len(data.Servers)) for i, server := range data.Servers { servers[i] = models.Server{ - VPN: vpn.OpenVPN, + VPN: constants.OpenVPN, Country: server.Country, City: server.City, Hostname: server.Hostname, diff --git a/internal/provider/privado/updater/updater.go b/pkg/updaters/providers/privado/updater.go similarity index 54% rename from internal/provider/privado/updater/updater.go rename to pkg/updaters/providers/privado/updater.go index ff0d41cd..d402ebae 100644 --- a/internal/provider/privado/updater/updater.go +++ b/pkg/updaters/providers/privado/updater.go @@ -1,9 +1,9 @@ -package updater +package privado import ( "net/http" - "github.com/qdm12/gluetun/internal/provider/common" + "github.com/qdm12/gluetun/pkg/updaters/common" ) type Updater struct { @@ -17,3 +17,11 @@ func New(client *http.Client, warner common.Warner) *Updater { warner: warner, } } + +func (u *Updater) Version() uint16 { + return 6 //nolint:mnd +} + +func (u *Updater) Name() string { + return "privado" +} diff --git a/internal/provider/privateinternetaccess/updater/api.go b/pkg/updaters/providers/privateinternetaccess/api.go similarity index 97% rename from internal/provider/privateinternetaccess/updater/api.go rename to pkg/updaters/providers/privateinternetaccess/api.go index 584a470f..f4e07870 100644 --- a/internal/provider/privateinternetaccess/updater/api.go +++ b/pkg/updaters/providers/privateinternetaccess/api.go @@ -1,4 +1,4 @@ -package updater +package privateinternetaccess import ( "bytes" diff --git a/internal/provider/privateinternetaccess/updater/hosttoserver.go b/pkg/updaters/providers/privateinternetaccess/hosttoserver.go similarity index 85% rename from internal/provider/privateinternetaccess/updater/hosttoserver.go rename to pkg/updaters/providers/privateinternetaccess/hosttoserver.go index 93464106..75f9a021 100644 --- a/internal/provider/privateinternetaccess/updater/hosttoserver.go +++ b/pkg/updaters/providers/privateinternetaccess/hosttoserver.go @@ -1,10 +1,10 @@ -package updater +package privateinternetaccess import ( "net/netip" - "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" ) type nameToServer map[string]models.Server @@ -15,7 +15,7 @@ func (nts nameToServer) add(name, hostname, region string, server, ok := nts[name] if !ok { change = true - server.VPN = vpn.OpenVPN + server.VPN = constants.OpenVPN server.ServerName = name server.Hostname = hostname server.Region = region diff --git a/internal/provider/privateinternetaccess/updater/servers.go b/pkg/updaters/providers/privateinternetaccess/servers.go similarity index 93% rename from internal/provider/privateinternetaccess/updater/servers.go rename to pkg/updaters/providers/privateinternetaccess/servers.go index c2b81304..6360cb8a 100644 --- a/internal/provider/privateinternetaccess/updater/servers.go +++ b/pkg/updaters/providers/privateinternetaccess/servers.go @@ -1,4 +1,4 @@ -package updater +package privateinternetaccess import ( "context" @@ -6,8 +6,8 @@ import ( "sort" "time" - "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" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( diff --git a/internal/provider/airvpn/updater/updater.go b/pkg/updaters/providers/privateinternetaccess/updater.go similarity index 50% rename from internal/provider/airvpn/updater/updater.go rename to pkg/updaters/providers/privateinternetaccess/updater.go index a987c0fd..78abfac8 100644 --- a/internal/provider/airvpn/updater/updater.go +++ b/pkg/updaters/providers/privateinternetaccess/updater.go @@ -1,4 +1,4 @@ -package updater +package privateinternetaccess import ( "net/http" @@ -13,3 +13,11 @@ func New(client *http.Client) *Updater { client: client, } } + +func (u *Updater) Version() uint16 { + return 1 +} + +func (u *Updater) Name() string { + return "private internet access" +} diff --git a/internal/provider/protonvpn/updater/countries.go b/pkg/updaters/providers/privatevpn/countries.go similarity index 94% rename from internal/provider/protonvpn/updater/countries.go rename to pkg/updaters/providers/privatevpn/countries.go index 6ea6f107..2faa3743 100644 --- a/internal/provider/protonvpn/updater/countries.go +++ b/pkg/updaters/providers/privatevpn/countries.go @@ -1,4 +1,4 @@ -package updater +package privatevpn import "strings" diff --git a/internal/provider/privatevpn/updater/filename.go b/pkg/updaters/providers/privatevpn/filename.go similarity index 98% rename from internal/provider/privatevpn/updater/filename.go rename to pkg/updaters/providers/privatevpn/filename.go index 4ba8b844..cccb0593 100644 --- a/internal/provider/privatevpn/updater/filename.go +++ b/pkg/updaters/providers/privatevpn/filename.go @@ -1,4 +1,4 @@ -package updater +package privatevpn import ( "fmt" diff --git a/internal/provider/privatevpn/updater/hosttoserver.go b/pkg/updaters/providers/privatevpn/hosttoserver.go similarity index 86% rename from internal/provider/privatevpn/updater/hosttoserver.go rename to pkg/updaters/providers/privatevpn/hosttoserver.go index bd015721..1a1a0545 100644 --- a/internal/provider/privatevpn/updater/hosttoserver.go +++ b/pkg/updaters/providers/privatevpn/hosttoserver.go @@ -1,10 +1,10 @@ -package updater +package privatevpn import ( "net/netip" - "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" ) type hostToServer map[string]models.Server @@ -15,7 +15,7 @@ func (hts hostToServer) add(host, country, city string) { if ok { return } - server.VPN = vpn.OpenVPN + server.VPN = constants.OpenVPN server.Hostname = host server.Country = country server.City = city diff --git a/internal/provider/privatevpn/updater/resolve.go b/pkg/updaters/providers/privatevpn/resolve.go similarity index 88% rename from internal/provider/privatevpn/updater/resolve.go rename to pkg/updaters/providers/privatevpn/resolve.go index e01ff836..167c44d6 100644 --- a/internal/provider/privatevpn/updater/resolve.go +++ b/pkg/updaters/providers/privatevpn/resolve.go @@ -1,9 +1,9 @@ -package updater +package privatevpn import ( "time" - "github.com/qdm12/gluetun/internal/updater/resolver" + "github.com/qdm12/gluetun/pkg/updaters/resolver" ) func parallelResolverSettings(hosts []string) (settings resolver.ParallelSettings) { diff --git a/internal/provider/privatevpn/updater/servers.go b/pkg/updaters/providers/privatevpn/servers.go similarity index 89% rename from internal/provider/privatevpn/updater/servers.go rename to pkg/updaters/providers/privatevpn/servers.go index 5976def4..3a57475b 100644 --- a/internal/provider/privatevpn/updater/servers.go +++ b/pkg/updaters/providers/privatevpn/servers.go @@ -1,4 +1,4 @@ -package updater +package privatevpn import ( "context" @@ -6,11 +6,10 @@ import ( "sort" "strings" - "github.com/qdm12/gluetun/internal/constants" - "github.com/qdm12/gluetun/internal/constants/vpn" - "github.com/qdm12/gluetun/internal/models" - "github.com/qdm12/gluetun/internal/provider/common" - "github.com/qdm12/gluetun/internal/updater/openvpn" + "github.com/qdm12/gluetun/pkg/updaters/common" + "github.com/qdm12/gluetun/pkg/updaters/constants" + "github.com/qdm12/gluetun/pkg/updaters/models" + "github.com/qdm12/gluetun/pkg/updaters/openvpn" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( @@ -66,7 +65,7 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) ( continue } server := models.Server{ - VPN: vpn.OpenVPN, + VPN: constants.OpenVPN, Country: country, City: city, IPs: ips, diff --git a/pkg/updaters/providers/privatevpn/updater.go b/pkg/updaters/providers/privatevpn/updater.go new file mode 100644 index 00000000..395a845c --- /dev/null +++ b/pkg/updaters/providers/privatevpn/updater.go @@ -0,0 +1,29 @@ +package privatevpn + +import ( + "github.com/qdm12/gluetun/pkg/updaters/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, + } +} + +func (u *Updater) Version() uint16 { + return 4 //nolint:mnd +} + +func (u *Updater) Name() string { + return "privatevpn" +} diff --git a/internal/provider/protonvpn/updater/api.go b/pkg/updaters/providers/protonvpn/api.go similarity index 99% rename from internal/provider/protonvpn/updater/api.go rename to pkg/updaters/providers/protonvpn/api.go index dab78eb4..42aa37ae 100644 --- a/internal/provider/protonvpn/updater/api.go +++ b/pkg/updaters/providers/protonvpn/api.go @@ -1,4 +1,4 @@ -package updater +package protonvpn import ( "bytes" diff --git a/internal/provider/privatevpn/updater/countries.go b/pkg/updaters/providers/protonvpn/countries.go similarity index 94% rename from internal/provider/privatevpn/updater/countries.go rename to pkg/updaters/providers/protonvpn/countries.go index 6ea6f107..6cce5bea 100644 --- a/internal/provider/privatevpn/updater/countries.go +++ b/pkg/updaters/providers/protonvpn/countries.go @@ -1,4 +1,4 @@ -package updater +package protonvpn import "strings" diff --git a/internal/provider/protonvpn/updater/iptoserver.go b/pkg/updaters/providers/protonvpn/iptoserver.go similarity index 87% rename from internal/provider/protonvpn/updater/iptoserver.go rename to pkg/updaters/providers/protonvpn/iptoserver.go index 973cc5e6..c4103523 100644 --- a/internal/provider/protonvpn/updater/iptoserver.go +++ b/pkg/updaters/providers/protonvpn/iptoserver.go @@ -1,10 +1,10 @@ -package updater +package protonvpn import ( "net/netip" - "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" ) type ipToServers map[string][2]models.Server // first server is OpenVPN, second is Wireguard. @@ -40,12 +40,12 @@ func (its ipToServers) add(country, region, city, name, hostname, wgPubKey strin IPs: []netip.Addr{entryIP}, } openvpnServer := baseServer - openvpnServer.VPN = vpn.OpenVPN + openvpnServer.VPN = constants.OpenVPN openvpnServer.UDP = true openvpnServer.TCP = true servers[0] = openvpnServer wireguardServer := baseServer - wireguardServer.VPN = vpn.Wireguard + wireguardServer.VPN = constants.Wireguard wireguardServer.WgPubKey = wgPubKey servers[1] = wireguardServer its[key] = servers diff --git a/internal/provider/protonvpn/updater/servers.go b/pkg/updaters/providers/protonvpn/servers.go similarity index 95% rename from internal/provider/protonvpn/updater/servers.go rename to pkg/updaters/providers/protonvpn/servers.go index ff919937..be70e5b3 100644 --- a/internal/provider/protonvpn/updater/servers.go +++ b/pkg/updaters/providers/protonvpn/servers.go @@ -1,13 +1,13 @@ -package updater +package protonvpn import ( "context" "fmt" "sort" - "github.com/qdm12/gluetun/internal/constants" - "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/constants" + "github.com/qdm12/gluetun/pkg/updaters/models" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( diff --git a/internal/provider/protonvpn/updater/updater.go b/pkg/updaters/providers/protonvpn/updater.go similarity index 63% rename from internal/provider/protonvpn/updater/updater.go rename to pkg/updaters/providers/protonvpn/updater.go index bc62a778..8b7570e4 100644 --- a/internal/provider/protonvpn/updater/updater.go +++ b/pkg/updaters/providers/protonvpn/updater.go @@ -1,9 +1,9 @@ -package updater +package protonvpn import ( "net/http" - "github.com/qdm12/gluetun/internal/provider/common" + "github.com/qdm12/gluetun/pkg/updaters/common" ) type Updater struct { @@ -21,3 +21,11 @@ func New(client *http.Client, warner common.Warner, email, password string) *Upd warner: warner, } } + +func (u *Updater) Version() uint16 { + return 4 //nolint:mnd +} + +func (u *Updater) Name() string { + return "protonvpn" +} diff --git a/internal/provider/protonvpn/updater/version.go b/pkg/updaters/providers/protonvpn/version.go similarity index 99% rename from internal/provider/protonvpn/updater/version.go rename to pkg/updaters/providers/protonvpn/version.go index 1d305304..a133998e 100644 --- a/internal/provider/protonvpn/updater/version.go +++ b/pkg/updaters/providers/protonvpn/version.go @@ -1,4 +1,4 @@ -package updater +package protonvpn import ( "context" diff --git a/internal/provider/purevpn/updater/compare.go b/pkg/updaters/providers/purevpn/compare.go similarity index 98% rename from internal/provider/purevpn/updater/compare.go rename to pkg/updaters/providers/purevpn/compare.go index 05914526..b44ec966 100644 --- a/internal/provider/purevpn/updater/compare.go +++ b/pkg/updaters/providers/purevpn/compare.go @@ -1,4 +1,4 @@ -package updater +package purevpn import ( "strings" diff --git a/internal/provider/purevpn/updater/compare_test.go b/pkg/updaters/providers/purevpn/compare_test.go similarity index 98% rename from internal/provider/purevpn/updater/compare_test.go rename to pkg/updaters/providers/purevpn/compare_test.go index 8b889dec..c218dc20 100644 --- a/internal/provider/purevpn/updater/compare_test.go +++ b/pkg/updaters/providers/purevpn/compare_test.go @@ -1,4 +1,4 @@ -package updater +package purevpn import ( "testing" diff --git a/internal/provider/purevpn/updater/hosttoserver.go b/pkg/updaters/providers/purevpn/hosttoserver.go similarity index 86% rename from internal/provider/purevpn/updater/hosttoserver.go rename to pkg/updaters/providers/purevpn/hosttoserver.go index 3b6af538..1123de60 100644 --- a/internal/provider/purevpn/updater/hosttoserver.go +++ b/pkg/updaters/providers/purevpn/hosttoserver.go @@ -1,10 +1,10 @@ -package updater +package purevpn import ( "net/netip" - "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" ) type hostToServer map[string]models.Server @@ -12,7 +12,7 @@ type hostToServer map[string]models.Server func (hts hostToServer) add(host string, tcp, udp bool) { server, ok := hts[host] if !ok { - server.VPN = vpn.OpenVPN + server.VPN = constants.OpenVPN server.Hostname = host } if tcp { diff --git a/internal/provider/purevpn/updater/parse.go b/pkg/updaters/providers/purevpn/parse.go similarity index 96% rename from internal/provider/purevpn/updater/parse.go rename to pkg/updaters/providers/purevpn/parse.go index 5e54ed75..c1d4ecb9 100644 --- a/internal/provider/purevpn/updater/parse.go +++ b/pkg/updaters/providers/purevpn/parse.go @@ -1,10 +1,10 @@ -package updater +package purevpn import ( "fmt" "strings" - "github.com/qdm12/gluetun/internal/constants" + "github.com/qdm12/gluetun/pkg/updaters/constants" ) var countryCodeToName = constants.CountryCodes() //nolint:gochecknoglobals diff --git a/internal/provider/slickvpn/updater/resolve.go b/pkg/updaters/providers/purevpn/resolve.go similarity index 88% rename from internal/provider/slickvpn/updater/resolve.go rename to pkg/updaters/providers/purevpn/resolve.go index d0b3fa0c..c55afc76 100644 --- a/internal/provider/slickvpn/updater/resolve.go +++ b/pkg/updaters/providers/purevpn/resolve.go @@ -1,9 +1,9 @@ -package updater +package purevpn import ( "time" - "github.com/qdm12/gluetun/internal/updater/resolver" + "github.com/qdm12/gluetun/pkg/updaters/resolver" ) func parallelResolverSettings(hosts []string) (settings resolver.ParallelSettings) { diff --git a/internal/provider/purevpn/updater/servers.go b/pkg/updaters/providers/purevpn/servers.go similarity index 92% rename from internal/provider/purevpn/updater/servers.go rename to pkg/updaters/providers/purevpn/servers.go index 5735fde7..8d00b063 100644 --- a/internal/provider/purevpn/updater/servers.go +++ b/pkg/updaters/providers/purevpn/servers.go @@ -1,4 +1,4 @@ -package updater +package purevpn import ( "context" @@ -7,10 +7,10 @@ import ( "sort" "strings" - "github.com/qdm12/gluetun/internal/models" - "github.com/qdm12/gluetun/internal/provider/common" - "github.com/qdm12/gluetun/internal/publicip/api" - "github.com/qdm12/gluetun/internal/updater/openvpn" + "github.com/qdm12/gluetun/pkg/publicip/api" + "github.com/qdm12/gluetun/pkg/updaters/common" + "github.com/qdm12/gluetun/pkg/updaters/models" + "github.com/qdm12/gluetun/pkg/updaters/openvpn" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( diff --git a/internal/provider/purevpn/updater/updater.go b/pkg/updaters/providers/purevpn/updater.go similarity index 72% rename from internal/provider/purevpn/updater/updater.go rename to pkg/updaters/providers/purevpn/updater.go index 2136f8ee..01eb1f12 100644 --- a/internal/provider/purevpn/updater/updater.go +++ b/pkg/updaters/providers/purevpn/updater.go @@ -1,7 +1,7 @@ -package updater +package purevpn import ( - "github.com/qdm12/gluetun/internal/provider/common" + "github.com/qdm12/gluetun/pkg/updaters/common" ) type Updater struct { @@ -21,3 +21,11 @@ func New(ipFetcher common.IPFetcher, unzipper common.Unzipper, warner: warner, } } + +func (u *Updater) Version() uint16 { + return 3 //nolint:mnd +} + +func (u *Updater) Name() string { + return "purevpn" +} diff --git a/internal/provider/ivpn/updater/resolve.go b/pkg/updaters/providers/slickvpn/resolve.go similarity index 88% rename from internal/provider/ivpn/updater/resolve.go rename to pkg/updaters/providers/slickvpn/resolve.go index d0b3fa0c..45705b94 100644 --- a/internal/provider/ivpn/updater/resolve.go +++ b/pkg/updaters/providers/slickvpn/resolve.go @@ -1,9 +1,9 @@ -package updater +package slickvpn import ( "time" - "github.com/qdm12/gluetun/internal/updater/resolver" + "github.com/qdm12/gluetun/pkg/updaters/resolver" ) func parallelResolverSettings(hosts []string) (settings resolver.ParallelSettings) { diff --git a/internal/provider/slickvpn/updater/servers.go b/pkg/updaters/providers/slickvpn/servers.go similarity index 94% rename from internal/provider/slickvpn/updater/servers.go rename to pkg/updaters/providers/slickvpn/servers.go index 5a00d6b8..1dc1ba12 100644 --- a/internal/provider/slickvpn/updater/servers.go +++ b/pkg/updaters/providers/slickvpn/servers.go @@ -1,13 +1,13 @@ -package updater +package slickvpn import ( "context" "fmt" "sort" - "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/common" + "github.com/qdm12/gluetun/pkg/updaters/constants" + "github.com/qdm12/gluetun/pkg/updaters/models" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( @@ -64,7 +64,7 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) ( } for i := range servers { - servers[i].VPN = vpn.OpenVPN + servers[i].VPN = constants.OpenVPN servers[i].TCP = true servers[i].UDP = true servers[i].IPs = hostToIPs[servers[i].Hostname] diff --git a/internal/provider/fastestvpn/updater/updater.go b/pkg/updaters/providers/slickvpn/updater.go similarity index 69% rename from internal/provider/fastestvpn/updater/updater.go rename to pkg/updaters/providers/slickvpn/updater.go index df4427cc..6419e609 100644 --- a/internal/provider/fastestvpn/updater/updater.go +++ b/pkg/updaters/providers/slickvpn/updater.go @@ -1,9 +1,9 @@ -package updater +package slickvpn import ( "net/http" - "github.com/qdm12/gluetun/internal/provider/common" + "github.com/qdm12/gluetun/pkg/updaters/common" ) type Updater struct { @@ -21,3 +21,11 @@ func New(client *http.Client, warner common.Warner, warner: warner, } } + +func (u *Updater) Version() uint16 { + return 1 +} + +func (u *Updater) Name() string { + return "slickvpn" +} diff --git a/internal/provider/surfshark/updater/api.go b/pkg/updaters/providers/surfshark/api.go similarity index 96% rename from internal/provider/surfshark/updater/api.go rename to pkg/updaters/providers/surfshark/api.go index 9b326d14..26830f63 100644 --- a/internal/provider/surfshark/updater/api.go +++ b/pkg/updaters/providers/surfshark/api.go @@ -1,4 +1,4 @@ -package updater +package surfshark import ( "context" @@ -6,7 +6,7 @@ import ( "fmt" "net/http" - "github.com/qdm12/gluetun/internal/provider/surfshark/servers" + "github.com/qdm12/gluetun/pkg/updaters/providers/surfshark/servers" ) func addServersFromAPI(ctx context.Context, client *http.Client, diff --git a/internal/provider/surfshark/updater/api_test.go b/pkg/updaters/providers/surfshark/api_test.go similarity index 96% rename from internal/provider/surfshark/updater/api_test.go rename to pkg/updaters/providers/surfshark/api_test.go index 1d3ed986..11ba7354 100644 --- a/internal/provider/surfshark/updater/api_test.go +++ b/pkg/updaters/providers/surfshark/api_test.go @@ -1,4 +1,4 @@ -package updater +package surfshark import ( "context" @@ -8,8 +8,8 @@ import ( "strings" "testing" - "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" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -64,7 +64,7 @@ func Test_addServersFromAPI(t *testing.T) { expected: map[string][]models.Server{ "existinghost": {{Hostname: "existinghost"}}, "host1": {{ - VPN: vpn.OpenVPN, + VPN: constants.OpenVPN, Region: "region1", Country: "country1", City: "location1", @@ -72,7 +72,7 @@ func Test_addServersFromAPI(t *testing.T) { TCP: true, UDP: true, }, { - VPN: vpn.Wireguard, + VPN: constants.Wireguard, Region: "region1", Country: "country1", City: "location1", @@ -80,7 +80,7 @@ func Test_addServersFromAPI(t *testing.T) { WgPubKey: "pubKeyValue", }}, "host2": {{ - VPN: vpn.OpenVPN, + VPN: constants.OpenVPN, Region: "region2", Country: "country1", City: "location2", diff --git a/internal/provider/surfshark/updater/hosttoserver.go b/pkg/updaters/providers/surfshark/hosttoserver.go similarity index 88% rename from internal/provider/surfshark/updater/hosttoserver.go rename to pkg/updaters/providers/surfshark/hosttoserver.go index c70a3b0a..a3efac67 100644 --- a/internal/provider/surfshark/updater/hosttoserver.go +++ b/pkg/updaters/providers/surfshark/hosttoserver.go @@ -1,10 +1,10 @@ -package updater +package surfshark import ( "net/netip" - "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" ) type hostToServers map[string][]models.Server @@ -16,7 +16,7 @@ func (hts hostToServers) addOpenVPN(host, region, country, city, servers := hts[host] for i, existingServer := range servers { if existingServer.Hostname != host || - existingServer.VPN != vpn.OpenVPN { + existingServer.VPN != constants.OpenVPN { continue } @@ -31,7 +31,7 @@ func (hts hostToServers) addOpenVPN(host, region, country, city, } server := models.Server{ - VPN: vpn.OpenVPN, + VPN: constants.OpenVPN, Region: region, Country: country, City: city, @@ -50,14 +50,14 @@ func (hts hostToServers) addWireguard(host, region, country, city, retroLoc, servers := hts[host] for _, existingServer := range servers { if existingServer.Hostname == host && - existingServer.VPN == vpn.Wireguard { + existingServer.VPN == constants.Wireguard { // No update necessary for Wireguard return } } server := models.Server{ - VPN: vpn.Wireguard, + VPN: constants.Wireguard, Region: region, Country: country, City: city, diff --git a/internal/provider/surfshark/updater/location.go b/pkg/updaters/providers/surfshark/location.go similarity index 88% rename from internal/provider/surfshark/updater/location.go rename to pkg/updaters/providers/surfshark/location.go index 72fb3dd6..5ccf9ebe 100644 --- a/internal/provider/surfshark/updater/location.go +++ b/pkg/updaters/providers/surfshark/location.go @@ -1,9 +1,9 @@ -package updater +package surfshark import ( "fmt" - "github.com/qdm12/gluetun/internal/provider/surfshark/servers" + "github.com/qdm12/gluetun/pkg/updaters/providers/surfshark/servers" ) func getHostInformation(host string, hostnameToLocation map[string]servers.ServerLocation) ( diff --git a/internal/provider/surfshark/updater/remaining.go b/pkg/updaters/providers/surfshark/remaining.go similarity index 87% rename from internal/provider/surfshark/updater/remaining.go rename to pkg/updaters/providers/surfshark/remaining.go index 56c19138..bd645550 100644 --- a/internal/provider/surfshark/updater/remaining.go +++ b/pkg/updaters/providers/surfshark/remaining.go @@ -1,7 +1,7 @@ -package updater +package surfshark import ( - "github.com/qdm12/gluetun/internal/provider/surfshark/servers" + "github.com/qdm12/gluetun/pkg/updaters/providers/surfshark/servers" ) // getRemainingServers finds extra servers not found in the API or in the ZIP file. diff --git a/pkg/updaters/providers/surfshark/resolve.go b/pkg/updaters/providers/surfshark/resolve.go new file mode 100644 index 00000000..1e78ff1e --- /dev/null +++ b/pkg/updaters/providers/surfshark/resolve.go @@ -0,0 +1,28 @@ +package surfshark + +import ( + "time" + + "github.com/qdm12/gluetun/pkg/updaters/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, + }, + } +} diff --git a/internal/provider/ivpn/updater/roundtrip_test.go b/pkg/updaters/providers/surfshark/roundtrip_test.go similarity index 90% rename from internal/provider/ivpn/updater/roundtrip_test.go rename to pkg/updaters/providers/surfshark/roundtrip_test.go index 9df23788..d8d58399 100644 --- a/internal/provider/ivpn/updater/roundtrip_test.go +++ b/pkg/updaters/providers/surfshark/roundtrip_test.go @@ -1,4 +1,4 @@ -package updater +package surfshark import "net/http" diff --git a/internal/provider/surfshark/updater/servers.go b/pkg/updaters/providers/surfshark/servers.go similarity index 90% rename from internal/provider/surfshark/updater/servers.go rename to pkg/updaters/providers/surfshark/servers.go index 1eb9d461..44fb90d3 100644 --- a/internal/provider/surfshark/updater/servers.go +++ b/pkg/updaters/providers/surfshark/servers.go @@ -1,12 +1,12 @@ -package updater +package surfshark import ( "context" "fmt" "sort" - "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" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( diff --git a/internal/provider/surfshark/servers/locationdata.go b/pkg/updaters/providers/surfshark/servers/locationdata.go similarity index 100% rename from internal/provider/surfshark/servers/locationdata.go rename to pkg/updaters/providers/surfshark/servers/locationdata.go diff --git a/internal/provider/surfshark/updater/updater.go b/pkg/updaters/providers/surfshark/updater.go similarity index 71% rename from internal/provider/surfshark/updater/updater.go rename to pkg/updaters/providers/surfshark/updater.go index e9b95c54..2a0a5705 100644 --- a/internal/provider/surfshark/updater/updater.go +++ b/pkg/updaters/providers/surfshark/updater.go @@ -1,9 +1,9 @@ -package updater +package surfshark import ( "net/http" - "github.com/qdm12/gluetun/internal/provider/common" + "github.com/qdm12/gluetun/pkg/updaters/common" ) type Updater struct { @@ -23,3 +23,11 @@ func New(client *http.Client, unzipper common.Unzipper, warner: warner, } } + +func (u *Updater) Version() uint16 { + return 4 //nolint:mnd +} + +func (u *Updater) Name() string { + return "surfshark" +} diff --git a/internal/provider/surfshark/updater/zip.go b/pkg/updaters/providers/surfshark/zip.go similarity index 90% rename from internal/provider/surfshark/updater/zip.go rename to pkg/updaters/providers/surfshark/zip.go index 92dabf55..766e30cc 100644 --- a/internal/provider/surfshark/updater/zip.go +++ b/pkg/updaters/providers/surfshark/zip.go @@ -1,12 +1,12 @@ -package updater +package surfshark import ( "context" "strings" - "github.com/qdm12/gluetun/internal/provider/common" - "github.com/qdm12/gluetun/internal/provider/surfshark/servers" - "github.com/qdm12/gluetun/internal/updater/openvpn" + "github.com/qdm12/gluetun/pkg/updaters/common" + "github.com/qdm12/gluetun/pkg/updaters/openvpn" + "github.com/qdm12/gluetun/pkg/updaters/providers/surfshark/servers" ) func addOpenVPNServersFromZip(ctx context.Context, diff --git a/internal/provider/torguard/updater/filename.go b/pkg/updaters/providers/torguard/filename.go similarity index 97% rename from internal/provider/torguard/updater/filename.go rename to pkg/updaters/providers/torguard/filename.go index a4a1d8ea..39b5b912 100644 --- a/internal/provider/torguard/updater/filename.go +++ b/pkg/updaters/providers/torguard/filename.go @@ -1,4 +1,4 @@ -package updater +package torguard import ( "strings" diff --git a/internal/provider/torguard/updater/hosttoserver.go b/pkg/updaters/providers/torguard/hosttoserver.go similarity index 88% rename from internal/provider/torguard/updater/hosttoserver.go rename to pkg/updaters/providers/torguard/hosttoserver.go index 5edecf74..d3aa3a7a 100644 --- a/internal/provider/torguard/updater/hosttoserver.go +++ b/pkg/updaters/providers/torguard/hosttoserver.go @@ -1,10 +1,10 @@ -package updater +package torguard import ( "net/netip" - "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" ) type hostToServer map[string]models.Server @@ -14,7 +14,7 @@ func (hts hostToServer) add(host, country, city string, ) { server, ok := hts[host] if !ok { - server.VPN = vpn.OpenVPN + server.VPN = constants.OpenVPN server.Hostname = host server.Country = country server.City = city diff --git a/pkg/updaters/providers/torguard/resolve.go b/pkg/updaters/providers/torguard/resolve.go new file mode 100644 index 00000000..5a2013cc --- /dev/null +++ b/pkg/updaters/providers/torguard/resolve.go @@ -0,0 +1,28 @@ +package torguard + +import ( + "time" + + "github.com/qdm12/gluetun/pkg/updaters/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, + }, + } +} diff --git a/internal/provider/torguard/updater/servers.go b/pkg/updaters/providers/torguard/servers.go similarity index 94% rename from internal/provider/torguard/updater/servers.go rename to pkg/updaters/providers/torguard/servers.go index 6974c5b0..afa22101 100644 --- a/internal/provider/torguard/updater/servers.go +++ b/pkg/updaters/providers/torguard/servers.go @@ -1,4 +1,4 @@ -package updater +package torguard import ( "context" @@ -6,9 +6,9 @@ import ( "sort" "strings" - "github.com/qdm12/gluetun/internal/models" - "github.com/qdm12/gluetun/internal/provider/common" - "github.com/qdm12/gluetun/internal/updater/openvpn" + "github.com/qdm12/gluetun/pkg/updaters/common" + "github.com/qdm12/gluetun/pkg/updaters/models" + "github.com/qdm12/gluetun/pkg/updaters/openvpn" "golang.org/x/text/cases" "golang.org/x/text/language" ) diff --git a/pkg/updaters/providers/torguard/updater.go b/pkg/updaters/providers/torguard/updater.go new file mode 100644 index 00000000..5d86800c --- /dev/null +++ b/pkg/updaters/providers/torguard/updater.go @@ -0,0 +1,29 @@ +package torguard + +import ( + "github.com/qdm12/gluetun/pkg/updaters/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, + } +} + +func (u *Updater) Version() uint16 { + return 3 //nolint:mnd +} + +func (u *Updater) Name() string { + return "torguard" +} diff --git a/internal/provider/vpnsecure/updater/helpers_test.go b/pkg/updaters/providers/vpnsecure/helpers_test.go similarity index 96% rename from internal/provider/vpnsecure/updater/helpers_test.go rename to pkg/updaters/providers/vpnsecure/helpers_test.go index 7025a6b0..ed107c35 100644 --- a/internal/provider/vpnsecure/updater/helpers_test.go +++ b/pkg/updaters/providers/vpnsecure/helpers_test.go @@ -1,4 +1,4 @@ -package updater +package vpnsecure import ( "os" diff --git a/internal/provider/vpnunlimited/updater/hosttoserver.go b/pkg/updaters/providers/vpnsecure/hosttoserver.go similarity index 91% rename from internal/provider/vpnunlimited/updater/hosttoserver.go rename to pkg/updaters/providers/vpnsecure/hosttoserver.go index 605775b3..d3fb4610 100644 --- a/internal/provider/vpnunlimited/updater/hosttoserver.go +++ b/pkg/updaters/providers/vpnsecure/hosttoserver.go @@ -1,9 +1,9 @@ -package updater +package vpnsecure import ( "net/netip" - "github.com/qdm12/gluetun/internal/models" + "github.com/qdm12/gluetun/pkg/updaters/models" ) type hostToServer map[string]models.Server diff --git a/internal/provider/vpnsecure/updater/resolve.go b/pkg/updaters/providers/vpnsecure/resolve.go similarity index 86% rename from internal/provider/vpnsecure/updater/resolve.go rename to pkg/updaters/providers/vpnsecure/resolve.go index 1758fab1..e07399f9 100644 --- a/internal/provider/vpnsecure/updater/resolve.go +++ b/pkg/updaters/providers/vpnsecure/resolve.go @@ -1,9 +1,9 @@ -package updater +package vpnsecure import ( "time" - "github.com/qdm12/gluetun/internal/updater/resolver" + "github.com/qdm12/gluetun/pkg/updaters/resolver" ) func parallelResolverSettings(hosts []string) (settings resolver.ParallelSettings) { diff --git a/internal/provider/vpnsecure/updater/servers.go b/pkg/updaters/providers/vpnsecure/servers.go similarity index 85% rename from internal/provider/vpnsecure/updater/servers.go rename to pkg/updaters/providers/vpnsecure/servers.go index 05445b4c..6afa6945 100644 --- a/internal/provider/vpnsecure/updater/servers.go +++ b/pkg/updaters/providers/vpnsecure/servers.go @@ -1,13 +1,13 @@ -package updater +package vpnsecure import ( "context" "fmt" "sort" - "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/common" + "github.com/qdm12/gluetun/pkg/updaters/constants" + "github.com/qdm12/gluetun/pkg/updaters/models" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( @@ -47,7 +47,7 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) ( servers = hts.toServersSlice() for i := range servers { - servers[i].VPN = vpn.OpenVPN + servers[i].VPN = constants.OpenVPN servers[i].UDP = true servers[i].TCP = true } diff --git a/internal/provider/vpnsecure/updater/testdata/index.html b/pkg/updaters/providers/vpnsecure/testdata/index.html similarity index 100% rename from internal/provider/vpnsecure/updater/testdata/index.html rename to pkg/updaters/providers/vpnsecure/testdata/index.html diff --git a/internal/provider/ivpn/updater/updater.go b/pkg/updaters/providers/vpnsecure/updater.go similarity index 68% rename from internal/provider/ivpn/updater/updater.go rename to pkg/updaters/providers/vpnsecure/updater.go index df4427cc..7aad568a 100644 --- a/internal/provider/ivpn/updater/updater.go +++ b/pkg/updaters/providers/vpnsecure/updater.go @@ -1,9 +1,9 @@ -package updater +package vpnsecure import ( "net/http" - "github.com/qdm12/gluetun/internal/provider/common" + "github.com/qdm12/gluetun/pkg/updaters/common" ) type Updater struct { @@ -21,3 +21,11 @@ func New(client *http.Client, warner common.Warner, warner: warner, } } + +func (u *Updater) Version() uint16 { + return 1 +} + +func (u *Updater) Name() string { + return "vpnsecure" +} diff --git a/internal/provider/vpnsecure/updater/website.go b/pkg/updaters/providers/vpnsecure/website.go similarity index 97% rename from internal/provider/vpnsecure/updater/website.go rename to pkg/updaters/providers/vpnsecure/website.go index 652306bb..77b57d3c 100644 --- a/internal/provider/vpnsecure/updater/website.go +++ b/pkg/updaters/providers/vpnsecure/website.go @@ -1,4 +1,4 @@ -package updater +package vpnsecure import ( "context" @@ -7,9 +7,9 @@ import ( "net/http" "strings" - "github.com/qdm12/gluetun/internal/models" - "github.com/qdm12/gluetun/internal/provider/common" - htmlutils "github.com/qdm12/gluetun/internal/updater/html" + "github.com/qdm12/gluetun/pkg/updaters/common" + htmlutils "github.com/qdm12/gluetun/pkg/updaters/html" + "github.com/qdm12/gluetun/pkg/updaters/models" "golang.org/x/net/html" ) diff --git a/internal/provider/vpnsecure/updater/website_test.go b/pkg/updaters/providers/vpnsecure/website_test.go similarity index 99% rename from internal/provider/vpnsecure/updater/website_test.go rename to pkg/updaters/providers/vpnsecure/website_test.go index ac4c0aea..3bebb7d6 100644 --- a/internal/provider/vpnsecure/updater/website_test.go +++ b/pkg/updaters/providers/vpnsecure/website_test.go @@ -1,4 +1,4 @@ -package updater +package vpnsecure import ( "context" @@ -8,8 +8,8 @@ import ( "testing" "github.com/golang/mock/gomock" - "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" "github.com/stretchr/testify/assert" "golang.org/x/net/html" ) diff --git a/internal/provider/vpnunlimited/updater/constants.go b/pkg/updaters/providers/vpnunlimited/constants.go similarity index 91% rename from internal/provider/vpnunlimited/updater/constants.go rename to pkg/updaters/providers/vpnunlimited/constants.go index a88edbb1..1501e5a9 100644 --- a/internal/provider/vpnunlimited/updater/constants.go +++ b/pkg/updaters/providers/vpnunlimited/constants.go @@ -1,11 +1,10 @@ -package updater +package vpnunlimited import ( "strings" - "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" + "github.com/qdm12/gluetun/pkg/updaters/models" ) func getHostToServer() (hts hostToServer, warnings []string) { @@ -124,7 +123,7 @@ func getHostToServer() (hts hostToServer, warnings []string) { countryCodesMap := constants.CountryCodes() for shortHost, server := range shortHTS { - server.VPN = vpn.OpenVPN + server.VPN = constants.OpenVPN server.UDP = true server.Hostname = shortHost + ".vpnunlimitedapp.com" countryCode := strings.Split(shortHost, "-")[0] diff --git a/internal/provider/vpnsecure/updater/hosttoserver.go b/pkg/updaters/providers/vpnunlimited/hosttoserver.go similarity index 91% rename from internal/provider/vpnsecure/updater/hosttoserver.go rename to pkg/updaters/providers/vpnunlimited/hosttoserver.go index 605775b3..755246b4 100644 --- a/internal/provider/vpnsecure/updater/hosttoserver.go +++ b/pkg/updaters/providers/vpnunlimited/hosttoserver.go @@ -1,9 +1,9 @@ -package updater +package vpnunlimited import ( "net/netip" - "github.com/qdm12/gluetun/internal/models" + "github.com/qdm12/gluetun/pkg/updaters/models" ) type hostToServer map[string]models.Server diff --git a/pkg/updaters/providers/vpnunlimited/resolve.go b/pkg/updaters/providers/vpnunlimited/resolve.go new file mode 100644 index 00000000..81e5ae67 --- /dev/null +++ b/pkg/updaters/providers/vpnunlimited/resolve.go @@ -0,0 +1,28 @@ +package vpnunlimited + +import ( + "time" + + "github.com/qdm12/gluetun/pkg/updaters/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, + }, + } +} diff --git a/internal/provider/vpnunlimited/updater/servers.go b/pkg/updaters/providers/vpnunlimited/servers.go similarity index 88% rename from internal/provider/vpnunlimited/updater/servers.go rename to pkg/updaters/providers/vpnunlimited/servers.go index 799273f9..85c9708c 100644 --- a/internal/provider/vpnunlimited/updater/servers.go +++ b/pkg/updaters/providers/vpnunlimited/servers.go @@ -1,12 +1,12 @@ -package updater +package vpnunlimited import ( "context" "fmt" "sort" - "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" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( diff --git a/internal/provider/giganews/updater/updater.go b/pkg/updaters/providers/vpnunlimited/updater.go similarity index 67% rename from internal/provider/giganews/updater/updater.go rename to pkg/updaters/providers/vpnunlimited/updater.go index d61e235d..914d7b23 100644 --- a/internal/provider/giganews/updater/updater.go +++ b/pkg/updaters/providers/vpnunlimited/updater.go @@ -1,7 +1,7 @@ -package updater +package vpnunlimited import ( - "github.com/qdm12/gluetun/internal/provider/common" + "github.com/qdm12/gluetun/pkg/updaters/common" ) type Updater struct { @@ -19,3 +19,11 @@ func New(unzipper common.Unzipper, warner common.Warner, warner: warner, } } + +func (u *Updater) Version() uint16 { + return 1 +} + +func (u *Updater) Name() string { + return "vpn unlimited" +} diff --git a/internal/provider/giganews/updater/filename.go b/pkg/updaters/providers/vyprvpn/filename.go similarity index 95% rename from internal/provider/giganews/updater/filename.go rename to pkg/updaters/providers/vyprvpn/filename.go index 4f017431..5ee140e0 100644 --- a/internal/provider/giganews/updater/filename.go +++ b/pkg/updaters/providers/vyprvpn/filename.go @@ -1,4 +1,4 @@ -package updater +package vyprvpn import ( "fmt" diff --git a/internal/provider/vyprvpn/updater/hosttoserver.go b/pkg/updaters/providers/vyprvpn/hosttoserver.go similarity index 86% rename from internal/provider/vyprvpn/updater/hosttoserver.go rename to pkg/updaters/providers/vyprvpn/hosttoserver.go index df9e9369..96b339f8 100644 --- a/internal/provider/vyprvpn/updater/hosttoserver.go +++ b/pkg/updaters/providers/vyprvpn/hosttoserver.go @@ -1,10 +1,10 @@ -package updater +package vyprvpn import ( "net/netip" - "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" ) type hostToServer map[string]models.Server @@ -12,7 +12,7 @@ type hostToServer map[string]models.Server func (hts hostToServer) add(host, region string, tcp, udp bool) { server, ok := hts[host] if !ok { - server.VPN = vpn.OpenVPN + server.VPN = constants.OpenVPN server.Hostname = host server.Region = region } diff --git a/internal/provider/giganews/updater/resolve.go b/pkg/updaters/providers/vyprvpn/resolve.go similarity index 88% rename from internal/provider/giganews/updater/resolve.go rename to pkg/updaters/providers/vyprvpn/resolve.go index fde66d47..07bb2067 100644 --- a/internal/provider/giganews/updater/resolve.go +++ b/pkg/updaters/providers/vyprvpn/resolve.go @@ -1,9 +1,9 @@ -package updater +package vyprvpn import ( "time" - "github.com/qdm12/gluetun/internal/updater/resolver" + "github.com/qdm12/gluetun/pkg/updaters/resolver" ) func parallelResolverSettings(hosts []string) (settings resolver.ParallelSettings) { diff --git a/internal/provider/vyprvpn/updater/servers.go b/pkg/updaters/providers/vyprvpn/servers.go similarity index 92% rename from internal/provider/vyprvpn/updater/servers.go rename to pkg/updaters/providers/vyprvpn/servers.go index 33d05eb7..7e609966 100644 --- a/internal/provider/vyprvpn/updater/servers.go +++ b/pkg/updaters/providers/vyprvpn/servers.go @@ -1,4 +1,4 @@ -package updater +package vyprvpn import ( "context" @@ -6,9 +6,9 @@ import ( "sort" "strings" - "github.com/qdm12/gluetun/internal/models" - "github.com/qdm12/gluetun/internal/provider/common" - "github.com/qdm12/gluetun/internal/updater/openvpn" + "github.com/qdm12/gluetun/pkg/updaters/common" + "github.com/qdm12/gluetun/pkg/updaters/models" + "github.com/qdm12/gluetun/pkg/updaters/openvpn" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( diff --git a/internal/provider/expressvpn/updater/updater.go b/pkg/updaters/providers/vyprvpn/updater.go similarity index 67% rename from internal/provider/expressvpn/updater/updater.go rename to pkg/updaters/providers/vyprvpn/updater.go index d61e235d..355ca425 100644 --- a/internal/provider/expressvpn/updater/updater.go +++ b/pkg/updaters/providers/vyprvpn/updater.go @@ -1,7 +1,7 @@ -package updater +package vyprvpn import ( - "github.com/qdm12/gluetun/internal/provider/common" + "github.com/qdm12/gluetun/pkg/updaters/common" ) type Updater struct { @@ -19,3 +19,11 @@ func New(unzipper common.Unzipper, warner common.Warner, warner: warner, } } + +func (u *Updater) Version() uint16 { + return 3 //nolint:mnd +} + +func (u *Updater) Name() string { + return "vyprvpn" +} diff --git a/internal/provider/windscribe/updater/api.go b/pkg/updaters/providers/windscribe/api.go similarity index 98% rename from internal/provider/windscribe/updater/api.go rename to pkg/updaters/providers/windscribe/api.go index 3891457f..7d2382f1 100644 --- a/internal/provider/windscribe/updater/api.go +++ b/pkg/updaters/providers/windscribe/api.go @@ -1,4 +1,4 @@ -package updater +package windscribe import ( "context" diff --git a/internal/provider/windscribe/updater/servers.go b/pkg/updaters/providers/windscribe/servers.go similarity index 86% rename from internal/provider/windscribe/updater/servers.go rename to pkg/updaters/providers/windscribe/servers.go index 3f07edfa..3882cb7a 100644 --- a/internal/provider/windscribe/updater/servers.go +++ b/pkg/updaters/providers/windscribe/servers.go @@ -1,4 +1,4 @@ -package updater +package windscribe import ( "context" @@ -6,9 +6,9 @@ import ( "net/netip" "sort" - "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/common" + "github.com/qdm12/gluetun/pkg/updaters/constants" + "github.com/qdm12/gluetun/pkg/updaters/models" ) func (u *Updater) FetchServers(ctx context.Context, minServers int) ( @@ -34,7 +34,7 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) ( ips = append(ips, node.IP2) } server := models.Server{ - VPN: vpn.OpenVPN, + VPN: constants.OpenVPN, TCP: true, UDP: true, Region: region, @@ -51,7 +51,7 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) ( return nil, fmt.Errorf("no wireguard public key found: for node %s", node.Hostname) } - server.VPN = vpn.Wireguard + server.VPN = constants.Wireguard server.UDP = false server.TCP = false server.OvpnX509 = "" diff --git a/internal/provider/windscribe/updater/updater.go b/pkg/updaters/providers/windscribe/updater.go similarity index 53% rename from internal/provider/windscribe/updater/updater.go rename to pkg/updaters/providers/windscribe/updater.go index ff0d41cd..1e6463e0 100644 --- a/internal/provider/windscribe/updater/updater.go +++ b/pkg/updaters/providers/windscribe/updater.go @@ -1,9 +1,9 @@ -package updater +package windscribe import ( "net/http" - "github.com/qdm12/gluetun/internal/provider/common" + "github.com/qdm12/gluetun/pkg/updaters/common" ) type Updater struct { @@ -17,3 +17,11 @@ func New(client *http.Client, warner common.Warner) *Updater { warner: warner, } } + +func (u *Updater) Version() uint16 { + return 2 //nolint:mnd +} + +func (u *Updater) Name() string { + return "windscribe" +} diff --git a/internal/updater/resolver/interfaces.go b/pkg/updaters/resolver/interfaces.go similarity index 100% rename from internal/updater/resolver/interfaces.go rename to pkg/updaters/resolver/interfaces.go diff --git a/internal/updater/resolver/ips.go b/pkg/updaters/resolver/ips.go similarity index 100% rename from internal/updater/resolver/ips.go rename to pkg/updaters/resolver/ips.go diff --git a/internal/updater/resolver/ips_test.go b/pkg/updaters/resolver/ips_test.go similarity index 100% rename from internal/updater/resolver/ips_test.go rename to pkg/updaters/resolver/ips_test.go diff --git a/internal/updater/resolver/net.go b/pkg/updaters/resolver/net.go similarity index 100% rename from internal/updater/resolver/net.go rename to pkg/updaters/resolver/net.go diff --git a/internal/updater/resolver/parallel.go b/pkg/updaters/resolver/parallel.go similarity index 100% rename from internal/updater/resolver/parallel.go rename to pkg/updaters/resolver/parallel.go diff --git a/internal/updater/resolver/repeat.go b/pkg/updaters/resolver/repeat.go similarity index 100% rename from internal/updater/resolver/repeat.go rename to pkg/updaters/resolver/repeat.go diff --git a/internal/updater/unzip/extract.go b/pkg/updaters/unzip/extract.go similarity index 100% rename from internal/updater/unzip/extract.go rename to pkg/updaters/unzip/extract.go diff --git a/internal/updater/unzip/fetch.go b/pkg/updaters/unzip/fetch.go similarity index 100% rename from internal/updater/unzip/fetch.go rename to pkg/updaters/unzip/fetch.go diff --git a/internal/updater/unzip/unzip.go b/pkg/updaters/unzip/unzip.go similarity index 100% rename from internal/updater/unzip/unzip.go rename to pkg/updaters/unzip/unzip.go diff --git a/pkg/updaters/updateall.go b/pkg/updaters/updateall.go new file mode 100644 index 00000000..ae6dd8c9 --- /dev/null +++ b/pkg/updaters/updateall.go @@ -0,0 +1,300 @@ +package updaters + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "net/http" + "os" + "path/filepath" + "slices" + "strings" + "time" + + "github.com/qdm12/dns/v2/pkg/doh" + dnsprovider "github.com/qdm12/dns/v2/pkg/provider" + publicipapi "github.com/qdm12/gluetun/pkg/publicip/api" + "github.com/qdm12/gluetun/pkg/updaters/common" + "github.com/qdm12/gluetun/pkg/updaters/models" + "github.com/qdm12/gluetun/pkg/updaters/providers/airvpn" + "github.com/qdm12/gluetun/pkg/updaters/providers/cyberghost" + "github.com/qdm12/gluetun/pkg/updaters/providers/expressvpn" + "github.com/qdm12/gluetun/pkg/updaters/providers/fastestvpn" + "github.com/qdm12/gluetun/pkg/updaters/providers/giganews" + "github.com/qdm12/gluetun/pkg/updaters/providers/hidemyass" + "github.com/qdm12/gluetun/pkg/updaters/providers/ipvanish" + "github.com/qdm12/gluetun/pkg/updaters/providers/ivpn" + "github.com/qdm12/gluetun/pkg/updaters/providers/mullvad" + "github.com/qdm12/gluetun/pkg/updaters/providers/nordvpn" + "github.com/qdm12/gluetun/pkg/updaters/providers/perfectprivacy" + "github.com/qdm12/gluetun/pkg/updaters/providers/privado" + "github.com/qdm12/gluetun/pkg/updaters/providers/privateinternetaccess" + "github.com/qdm12/gluetun/pkg/updaters/providers/privatevpn" + "github.com/qdm12/gluetun/pkg/updaters/providers/protonvpn" + "github.com/qdm12/gluetun/pkg/updaters/providers/purevpn" + "github.com/qdm12/gluetun/pkg/updaters/providers/slickvpn" + "github.com/qdm12/gluetun/pkg/updaters/providers/surfshark" + "github.com/qdm12/gluetun/pkg/updaters/providers/torguard" + "github.com/qdm12/gluetun/pkg/updaters/providers/vpnsecure" + "github.com/qdm12/gluetun/pkg/updaters/providers/vpnunlimited" + "github.com/qdm12/gluetun/pkg/updaters/providers/vyprvpn" + "github.com/qdm12/gluetun/pkg/updaters/providers/windscribe" + "github.com/qdm12/gluetun/pkg/updaters/resolver" + "github.com/qdm12/gluetun/pkg/updaters/unzip" + "github.com/qdm12/gosettings" +) + +// UpdateAllSettings contains the configuration for the [UpdateAll] function. +type UpdateAllSettings struct { + // OutputPath is the directory where the provider JSON files will be written. + // It defaults to the current directory if left unset. + OutputPath *string + // ProtonEmail is the email for the ProtonVPN account, which is required + // to update ProtonVPN servers. + ProtonEmail *string + // ProtonPassword is the password for the ProtonVPN account, which is required + // to update ProtonVPN servers. + ProtonPassword *string + // IpinfoToken is the API token for the IPInfo public IP API. + // If not provided, the IP fetcher will still work but may be + // subject to stricter rate limits for ipinfo.io. + IpinfoToken *string + // MinServers is a map of provider name to minimum number of servers required for a successful update. + // If a provider has fewer servers than the specified minimum, the update will be considered a failure + // for that provider. If the provider name is not found in this map, it is assumed that there is no + // minimum server requirement for that provider. + MinServers map[string]uint +} + +func (s *UpdateAllSettings) setDefaults() { + s.OutputPath = gosettings.DefaultPointer(s.OutputPath, "") + s.ProtonEmail = gosettings.DefaultPointer(s.ProtonEmail, "") + s.ProtonPassword = gosettings.DefaultPointer(s.ProtonPassword, "") + s.IpinfoToken = gosettings.DefaultPointer(s.IpinfoToken, "") + if s.MinServers == nil { + s.MinServers = make(map[string]uint) + } +} + +var ( + errProtonEmailRequired = errors.New("proton email is required for updating ProtonVPN servers") + errProtonPasswordRequired = errors.New("proton password is required for updating ProtonVPN servers") + errMinServersProviderNotFound = errors.New("provider name in MinServers not found in list of all providers") +) + +func (s *UpdateAllSettings) validate() error { + switch { + case *s.ProtonEmail == "": + return fmt.Errorf("%w", errProtonEmailRequired) + case *s.ProtonPassword == "": + return fmt.Errorf("%w", errProtonPasswordRequired) + } + + allProviders := ListAllNames() + for providerName := range s.MinServers { + if !slices.Contains(allProviders, providerName) { + return fmt.Errorf("%w: %s", errMinServersProviderNotFound, providerName) + } + } + + return nil +} + +// ListAllNames returns a list of all provider names supported by [UpdateAll]. +// It is exported notably to validate from the gluetun repository if it matches +// the list of providers in the internal/constants/providers package. +func ListAllNames() []string { + fetchers := [...]interface { + Name() string + }{ + &airvpn.Updater{}, + &cyberghost.Updater{}, + &expressvpn.Updater{}, + &fastestvpn.Updater{}, + &giganews.Updater{}, + &hidemyass.Updater{}, + &ipvanish.Updater{}, + &ivpn.Updater{}, + &mullvad.Updater{}, + &nordvpn.Updater{}, + &perfectprivacy.Updater{}, + &privado.Updater{}, + &privateinternetaccess.Updater{}, + &privatevpn.Updater{}, + &protonvpn.Updater{}, + &purevpn.Updater{}, + &slickvpn.Updater{}, + &surfshark.Updater{}, + &torguard.Updater{}, + &vpnsecure.Updater{}, + &vpnunlimited.Updater{}, + &vyprvpn.Updater{}, + &windscribe.Updater{}, + } + names := make([]string, len(fetchers)) + for i, fetcher := range fetchers { + names[i] = fetcher.Name() + } + return names +} + +type Logger interface { + Warn(message string) +} + +var errUpdateAllFailed = errors.New("update failed for one or more providers") + +// UpdateAll fetches server data for all providers in parallel and writes each +// provider's data as .json into the output path specified. +// Errors for individual providers are collected and returned as a combined error. +func UpdateAll(ctx context.Context, client *http.Client, logger Logger, settings UpdateAllSettings) error { + settings.setDefaults() + err := settings.validate() + if err != nil { + return fmt.Errorf("validating settings: %w", err) + } + + const permission = 0o755 + err = os.MkdirAll(*settings.OutputPath, permission) + if err != nil { + return fmt.Errorf("creating output directory: %w", err) + } + + dohDialer, err := doh.New(doh.Settings{ + UpstreamResolvers: []dnsprovider.Provider{ + dnsprovider.Cloudflare(), + dnsprovider.Google(), + }, + }) + if err != nil { + return fmt.Errorf("creating updater DoH dialer: %w", err) + } + parallelResolver := resolver.NewParallelResolver(dohDialer) + unzipper := unzip.New(client) + ipFetcher, err := buildIPFetcher(client, logger, *settings.IpinfoToken) + if err != nil { + return fmt.Errorf("creating IP fetcher: %w", err) + } + fetchers := buildFetchers(client, parallelResolver, unzipper, ipFetcher, + logger, *settings.ProtonEmail, *settings.ProtonPassword) + + results := make(chan error) + + allProviders := ListAllNames() + for _, providerName := range allProviders { + go func(providerName string) { + fetcher := fetchers[providerName] + minServers := settings.MinServers[providerName] + err := fetchAndWrite(ctx, providerName, fetcher, minServers, *settings.OutputPath) + if err != nil { + err = fmt.Errorf("provider %s: %w", providerName, err) + } + results <- err + }(providerName) + } + + errs := make([]string, 0, len(allProviders)) + for range allProviders { + err := <-results + if err != nil { + errs = append(errs, err.Error()) + } + } + + if len(errs) > 0 { + return fmt.Errorf("%w:\n%s", errUpdateAllFailed, strings.Join(errs, "\n")) + } + return nil +} + +func buildIPFetcher(client *http.Client, logger Logger, ipinfoToken string) ( + fetcher *publicipapi.ResilientFetcher, err error, +) { + nameTokenPairs := []publicipapi.NameToken{ + {Name: string(publicipapi.IPInfo), Token: ipinfoToken}, + {Name: string(publicipapi.IP2Location)}, + {Name: string(publicipapi.IfConfigCo)}, + } + fetchers, err := publicipapi.New(nameTokenPairs, client) + if err != nil { + return nil, fmt.Errorf("creating public IP fetchers: %w", err) + } + fetcher = publicipapi.NewResilient(fetchers, logger) + return fetcher, nil +} + +func buildFetchers(client *http.Client, parallelResolver common.ParallelResolver, + unzipper common.Unzipper, ipFetcher common.IPFetcher, + logger Logger, protonEmail, protonPassword string, +) map[string]common.Fetcher { + fetchers := [...]common.Fetcher{ + airvpn.New(client), + cyberghost.New(parallelResolver, logger), + expressvpn.New(unzipper, logger, parallelResolver), + fastestvpn.New(client, logger, parallelResolver), + giganews.New(unzipper, logger, parallelResolver), + hidemyass.New(client, logger, parallelResolver), + ipvanish.New(unzipper, logger, parallelResolver), + ivpn.New(client, logger, parallelResolver), + mullvad.New(client), + nordvpn.New(client, logger), + perfectprivacy.New(unzipper, logger), + privado.New(client, logger), + privateinternetaccess.New(client), + privatevpn.New(unzipper, logger, parallelResolver), + protonvpn.New(client, logger, protonEmail, protonPassword), + purevpn.New(ipFetcher, unzipper, logger, parallelResolver), + slickvpn.New(client, logger, parallelResolver), + surfshark.New(client, unzipper, logger, parallelResolver), + torguard.New(unzipper, logger, parallelResolver), + vpnsecure.New(client, logger, parallelResolver), + vpnunlimited.New(unzipper, logger, parallelResolver), + vyprvpn.New(unzipper, logger, parallelResolver), + windscribe.New(client, logger), + } + nameToFetcher := make(map[string]common.Fetcher, len(fetchers)) + for _, fetcher := range fetchers { + nameToFetcher[fetcher.Name()] = fetcher + } + return nameToFetcher +} + +func fetchAndWrite(ctx context.Context, providerName string, fetcher common.Fetcher, + minServers uint, outputDirPath string, +) error { + filename := strings.ToLower(strings.ReplaceAll(providerName, " ", "")) + ".json" + destinationPath := filepath.Join(outputDirPath, filename) + const permission = 0o644 + file, err := os.OpenFile(destinationPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, permission) + if err != nil { + return fmt.Errorf("opening output file: %w", err) + } + + servers, err := fetcher.FetchServers(ctx, int(minServers)) //nolint:gosec + if err != nil { + _ = file.Close() + _ = os.Remove(destinationPath) + return fmt.Errorf("fetching servers: %w", err) + } + data := models.Servers{ + Version: fetcher.Version(), + Timestamp: time.Now().Unix(), + Servers: servers, + } + + encoder := json.NewEncoder(file) + encoder.SetIndent("", " ") + err = encoder.Encode(data) + if err != nil { + _ = file.Close() + return fmt.Errorf("encoding servers to JSON: %w", err) + } + + err = file.Close() + if err != nil { + return fmt.Errorf("closing output file: %w", err) + } + + return nil +}