chore(updater): incorporate FetchServers method in Provider interface

- Each provider interface can now fetch updated servers data
- Rename each provider updater subpackage name to `updater`
- Updater constructor does not take a settings struct
- Updater update method takes in a slice of provider strings
This commit is contained in:
Quentin McGaw
2022-06-09 23:47:12 +00:00
parent 11b55abff3
commit ebd94723c1
148 changed files with 374 additions and 281 deletions

View File

@@ -2,6 +2,7 @@ package cli
import (
"fmt"
"net/http"
"strings"
"time"
@@ -9,6 +10,7 @@ import (
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/provider"
"github.com/qdm12/gluetun/internal/storage"
"github.com/qdm12/gluetun/internal/updater/unzip"
)
type OpenvpnConfigMaker interface {
@@ -35,7 +37,13 @@ func (c *CLI) OpenvpnConfig(logger OpenvpnConfigLogger, source sources.Source) e
return err
}
providerConf := provider.New(*allSettings.VPN.Provider.Name, storage, time.Now)
// Unused by this CLI command
unzipper := (unzip.Unzipper)(nil)
client := (*http.Client)(nil)
warner := (Warner)(nil)
providerConf := provider.New(*allSettings.VPN.Provider.Name, storage, time.Now,
warner, client, unzipper)
connection, err := providerConf.GetConnection(allSettings.VPN.Provider.ServerSelection)
if err != nil {
return err

View File

@@ -81,8 +81,8 @@ func (c *CLI) Update(ctx context.Context, args []string, logger UpdaterLogger) e
return fmt.Errorf("cannot create servers storage: %w", err)
}
updater := updater.New(options, httpClient, storage, logger)
err = updater.UpdateServers(ctx)
updater := updater.New(httpClient, storage, logger)
err = updater.UpdateServers(ctx, options.Providers)
if err != nil {
return fmt.Errorf("cannot update server information: %w", err)
}

View File

@@ -4,11 +4,25 @@ import (
"context"
"errors"
"net"
"github.com/qdm12/gluetun/internal/models"
)
var ErrNotEnoughServers = errors.New("not enough servers found")
type Fetcher interface {
FetchServers(ctx context.Context, minServers int) (servers []models.Server, err error)
}
type ParallelResolver interface {
Resolve(ctx context.Context, hosts []string, minToFind int) (
hostToIPs map[string][]net.IP, warnings []string, err error)
}
type Unzipper interface {
FetchAndExtract(ctx context.Context, url string) (contents map[string][]byte, err error)
}
type Warner interface {
Warn(s string)
}

View File

@@ -3,18 +3,21 @@ package custom
import (
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/openvpn/extract"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/utils"
)
type Provider struct {
extractor extract.Interface
utils.NoPortForwarder
common.Fetcher
}
func New() *Provider {
return &Provider{
extractor: extract.New(),
NoPortForwarder: utils.NewNoPortForwarding(providers.Custom),
Fetcher: utils.NewNoFetcher(providers.Custom),
}
}

View File

@@ -5,6 +5,7 @@ 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"
)
@@ -12,6 +13,7 @@ type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}
func New(storage common.Storage, randSource rand.Source) *Provider {
@@ -19,6 +21,7 @@ func New(storage common.Storage, randSource rand.Source) *Provider {
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Cyberghost),
Fetcher: updater.New(),
}
}

View File

@@ -1,4 +1,4 @@
package cyberghost
package updater
import "github.com/qdm12/gluetun/internal/constants"

View File

@@ -1,4 +1,4 @@
package cyberghost
package updater
func mergeCountryCodes(base, extend map[string]string) (merged map[string]string) {
merged = make(map[string]string, len(base))

View File

@@ -1,4 +1,4 @@
package cyberghost
package updater
import (
"net"

View File

@@ -1,4 +1,4 @@
package cyberghost
package updater
import (
"time"

View File

@@ -1,6 +1,6 @@
// Package cyberghost contains code to obtain the server information
// Package updater contains code to obtain the server information
// for the Cyberghost provider.
package cyberghost
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package cyberghost
package updater
import (
"github.com/qdm12/gluetun/internal/provider/common"

View File

@@ -87,7 +87,9 @@ func Test_Provider_GetConnection(t *testing.T) {
Return(testCase.filteredServers, testCase.storageErr)
randSource := rand.NewSource(0)
provider := New(storage, randSource)
unzipper := (common.Unzipper)(nil)
warner := (common.Warner)(nil)
provider := New(storage, randSource, unzipper, warner)
if testCase.panicMessage != "" {
assert.PanicsWithValue(t, testCase.panicMessage, func() {

View File

@@ -5,6 +5,7 @@ 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"
)
@@ -12,13 +13,16 @@ type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}
func New(storage common.Storage, randSource rand.Source) *Provider {
func New(storage common.Storage, randSource rand.Source,
unzipper common.Unzipper, updaterWarner common.Warner) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Expressvpn),
Fetcher: updater.New(unzipper, updaterWarner),
}
}

View File

@@ -1,4 +1,4 @@
package expressvpn
package updater
import (
"github.com/qdm12/gluetun/internal/models"

View File

@@ -1,4 +1,4 @@
package expressvpn
package updater
import (
"time"

View File

@@ -1,6 +1,6 @@
// package expressvpn contains code to obtain the server information
// Package updater contains code to obtain the server information
// for the ExpressVPN provider.
package expressvpn
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package expressvpn
package updater
import (
"github.com/qdm12/gluetun/internal/provider/common"

View File

@@ -5,6 +5,7 @@ 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"
)
@@ -12,13 +13,16 @@ type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}
func New(storage common.Storage, randSource rand.Source) *Provider {
func New(storage common.Storage, randSource rand.Source,
unzipper common.Unzipper, updaterWarner common.Warner) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Fastestvpn),
Fetcher: updater.New(unzipper, updaterWarner),
}
}

View File

@@ -1,4 +1,4 @@
package fastestvpn
package updater
import (
"errors"

View File

@@ -1,4 +1,4 @@
package fastestvpn
package updater
import (
"net"

View File

@@ -1,4 +1,4 @@
package fastestvpn
package updater
import (
"time"

View File

@@ -1,6 +1,6 @@
// Package fastestvpn contains code to obtain the server information
// Package updater contains code to obtain the server information
// for the FastestVPN provider.
package fastestvpn
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package fastestvpn
package updater
import (
"github.com/qdm12/gluetun/internal/provider/common"

View File

@@ -2,9 +2,11 @@ package hidemyass
import (
"math/rand"
"net/http"
"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"
)
@@ -12,13 +14,16 @@ type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}
func New(storage common.Storage, randSource rand.Source) *Provider {
func New(storage common.Storage, randSource rand.Source,
client *http.Client, updaterWarner common.Warner) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.HideMyAss),
Fetcher: updater.New(client, updaterWarner),
}
}

View File

@@ -1,4 +1,4 @@
package hidemyass
package updater
func getUniqueHosts(tcpHostToURL, udpHostToURL map[string]string) (
hosts []string) {

View File

@@ -1,4 +1,4 @@
package hidemyass
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package hidemyass
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package hidemyass
package updater
import (
"time"

View File

@@ -1,6 +1,6 @@
// Package hidemyass contains code to obtain the server information
// Package updater contains code to obtain the server information
// for the HideMyAss provider.
package hidemyass
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package hidemyass
package updater
import (
"net/http"

View File

@@ -1,4 +1,4 @@
package hidemyass
package updater
import (
"strings"

View File

@@ -5,6 +5,7 @@ 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"
)
@@ -12,13 +13,16 @@ type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}
func New(storage common.Storage, randSource rand.Source) *Provider {
func New(storage common.Storage, randSource rand.Source,
unzipper common.Unzipper, updaterWarner common.Warner) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Ipvanish),
Fetcher: updater.New(unzipper, updaterWarner),
}
}

View File

@@ -1,4 +1,4 @@
package ipvanish
package updater
import (
"errors"

View File

@@ -1,4 +1,4 @@
package ipvanish
package updater
import (
"errors"

View File

@@ -1,4 +1,4 @@
package ipvanish
package updater
import (
"net"

View File

@@ -1,4 +1,4 @@
package ipvanish
package updater
import (
"net"

View File

@@ -1,3 +1,3 @@
package ipvanish
package updater
//go:generate mockgen -destination=mocks_test.go -package $GOPACKAGE . Warner

View File

@@ -2,7 +2,7 @@
// Source: github.com/qdm12/gluetun/internal/provider/ipvanish/updater (interfaces: Warner)
// Package ipvanish is a generated GoMock package.
package ipvanish
package updater
import (
reflect "reflect"

View File

@@ -1,4 +1,4 @@
package ipvanish
package updater
import (
"time"

View File

@@ -1,6 +1,6 @@
// Package ipvanish contains code to obtain the server information
// Package updater contains code to obtain the server information
// for the Surshark provider.
package ipvanish
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package ipvanish
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package ipvanish
package updater
import (
"github.com/qdm12/gluetun/internal/provider/common"

View File

@@ -4,6 +4,7 @@ import (
"errors"
"math/rand"
"net"
"net/http"
"testing"
"github.com/golang/mock/gomock"
@@ -96,7 +97,9 @@ func Test_Provider_GetConnection(t *testing.T) {
Return(testCase.filteredServers, testCase.storageErr)
randSource := rand.NewSource(0)
provider := New(storage, randSource)
client := (*http.Client)(nil)
warner := (common.Warner)(nil)
provider := New(storage, randSource, client, warner)
connection, err := provider.GetConnection(testCase.selection)

View File

@@ -2,9 +2,11 @@ package ivpn
import (
"math/rand"
"net/http"
"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"
)
@@ -12,13 +14,16 @@ type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}
func New(storage common.Storage, randSource rand.Source) *Provider {
func New(storage common.Storage, randSource rand.Source,
client *http.Client, updaterWarner common.Warner) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Ivpn),
Fetcher: updater.New(client, updaterWarner),
}
}

View File

@@ -1,4 +1,4 @@
package ivpn
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package ivpn
package updater
import (
"context"

View File

@@ -1,3 +1,3 @@
package ivpn
package updater
//go:generate mockgen -destination=mocks_test.go -package $GOPACKAGE . Warner

View File

@@ -2,7 +2,7 @@
// Source: github.com/qdm12/gluetun/internal/provider/ivpn/updater (interfaces: Warner)
// Package ivpn is a generated GoMock package.
package ivpn
package updater
import (
reflect "reflect"

View File

@@ -1,4 +1,4 @@
package ivpn
package updater
import (
"time"

View File

@@ -1,4 +1,4 @@
package ivpn
package updater
import "net/http"

View File

@@ -1,6 +1,6 @@
// Package ivpn contains code to obtain the server information
// Package updater contains code to obtain the server information
// for the Surshark provider.
package ivpn
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package ivpn
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package ivpn
package updater
import (
"net/http"

View File

@@ -4,6 +4,7 @@ import (
"errors"
"math/rand"
"net"
"net/http"
"testing"
"github.com/golang/mock/gomock"
@@ -96,7 +97,8 @@ func Test_Provider_GetConnection(t *testing.T) {
Return(testCase.filteredServers, testCase.storageErr)
randSource := rand.NewSource(0)
provider := New(storage, randSource)
client := (*http.Client)(nil)
provider := New(storage, randSource, client)
connection, err := provider.GetConnection(testCase.selection)

View File

@@ -2,9 +2,11 @@ package mullvad
import (
"math/rand"
"net/http"
"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"
)
@@ -12,13 +14,16 @@ type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}
func New(storage common.Storage, randSource rand.Source) *Provider {
func New(storage common.Storage, randSource rand.Source,
client *http.Client) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Mullvad),
Fetcher: updater.New(client),
}
}

View File

@@ -1,4 +1,4 @@
package mullvad
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package mullvad
package updater
import (
"errors"

View File

@@ -1,4 +1,4 @@
package mullvad
package updater
import (
"bytes"

View File

@@ -1,4 +1,4 @@
package mullvad
package updater
import (
"net"

View File

@@ -1,6 +1,6 @@
// Package mullvad contains code to obtain the server information
// Package updater contains code to obtain the server information
// for the Mullvad provider.
package mullvad
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package mullvad
package updater
import (
"net/http"

View File

@@ -2,9 +2,11 @@ package nordvpn
import (
"math/rand"
"net/http"
"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"
)
@@ -12,13 +14,16 @@ type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}
func New(storage common.Storage, randSource rand.Source) *Provider {
func New(storage common.Storage, randSource rand.Source,
client *http.Client, updaterWarner common.Warner) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Nordvpn),
Fetcher: updater.New(client, updaterWarner),
}
}

View File

@@ -1,4 +1,4 @@
package nordvpn
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package nordvpn
package updater
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package nordvpn
package updater
import (
"errors"

View File

@@ -1,6 +1,6 @@
// Package nordvpn contains code to obtain the server information
// Package updater contains code to obtain the server information
// for the NordVPN provider.
package nordvpn
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package nordvpn
package updater
import (
"net/http"

View File

@@ -5,6 +5,7 @@ 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"
)
@@ -12,13 +13,16 @@ type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}
func New(storage common.Storage, randSource rand.Source) *Provider {
func New(storage common.Storage, randSource rand.Source,
unzipper common.Unzipper, updaterWarner common.Warner) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Perfectprivacy),
Fetcher: updater.New(unzipper, updaterWarner),
}
}

View File

@@ -1,4 +1,4 @@
package perfectprivacy
package updater
import (
"net"

View File

@@ -1,4 +1,4 @@
package perfectprivacy
package updater
import (
"strings"

View File

@@ -1,4 +1,4 @@
package perfectprivacy
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package perfectprivacy
package updater
import "github.com/qdm12/gluetun/internal/updater/unzip"

View File

@@ -2,9 +2,11 @@ package privado
import (
"math/rand"
"net/http"
"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"
)
@@ -12,13 +14,17 @@ type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}
func New(storage common.Storage, randSource rand.Source) *Provider {
func New(storage common.Storage, randSource rand.Source,
client *http.Client, unzipper common.Unzipper,
updaterWarner common.Warner) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Privado),
Fetcher: updater.New(client, unzipper, updaterWarner),
}
}

View File

@@ -1,4 +1,4 @@
package privado
package updater
import (
"net"

View File

@@ -1,4 +1,4 @@
package privado
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package privado
package updater
import (
"time"

View File

@@ -1,6 +1,6 @@
// Package privado contains code to obtain the server information
// Package updater contains code to obtain the server information
// for the Privado provider.
package privado
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package privado
package updater
import (
"net/http"

View File

@@ -2,24 +2,27 @@ package privateinternetaccess
import (
"math/rand"
"net/http"
"time"
"github.com/qdm12/gluetun/internal/constants/openvpn"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/internal/provider/privateinternetaccess/updater"
)
type Provider struct {
storage common.Storage
randSource rand.Source
timeNow func() time.Time
common.Fetcher
// Port forwarding
portForwardPath string
authFilePath string
}
func New(storage common.Storage, randSource rand.Source,
timeNow func() time.Time) *Provider {
timeNow func() time.Time, client *http.Client) *Provider {
const jsonPortForwardPath = "/gluetun/piaportforward.json"
return &Provider{
storage: storage,
@@ -27,6 +30,7 @@ func New(storage common.Storage, randSource rand.Source,
randSource: randSource,
portForwardPath: jsonPortForwardPath,
authFilePath: openvpn.AuthConf,
Fetcher: updater.New(client),
}
}

View File

@@ -1,4 +1,4 @@
package privateinternetaccess
package updater
import (
"bytes"

View File

@@ -1,4 +1,4 @@
package privateinternetaccess
package updater
import (
"net"

View File

@@ -1,6 +1,6 @@
// Package pia contains code to obtain the server information
// Package updater contains code to obtain the server information
// for the Private Internet Access provider.
package privateinternetaccess
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package privateinternetaccess
package updater
import (
"net/http"

View File

@@ -5,6 +5,7 @@ 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"
)
@@ -12,13 +13,16 @@ type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}
func New(storage common.Storage, randSource rand.Source) *Provider {
func New(storage common.Storage, randSource rand.Source,
unzipper common.Unzipper, updaterWarner common.Warner) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Privatevpn),
Fetcher: updater.New(unzipper, updaterWarner),
}
}

View File

@@ -1,4 +1,4 @@
package privatevpn
package updater
import "strings"

View File

@@ -1,4 +1,4 @@
package privatevpn
package updater
import (
"errors"

View File

@@ -1,4 +1,4 @@
package privatevpn
package updater
import (
"net"

View File

@@ -1,4 +1,4 @@
package privatevpn
package updater
import (
"time"

View File

@@ -1,6 +1,6 @@
// Package privatevpn contains code to obtain the server information
// Package updater contains code to obtain the server information
// for the PrivateVPN provider.
package privatevpn
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package privatevpn
package updater
import (
"github.com/qdm12/gluetun/internal/provider/common"

View File

@@ -2,9 +2,11 @@ package protonvpn
import (
"math/rand"
"net/http"
"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"
)
@@ -12,13 +14,16 @@ type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}
func New(storage common.Storage, randSource rand.Source) *Provider {
func New(storage common.Storage, randSource rand.Source,
client *http.Client, updaterWarner common.Warner) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Protonvpn),
Fetcher: updater.New(client, updaterWarner),
}
}

View File

@@ -1,4 +1,4 @@
package protonvpn
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package protonvpn
package updater
import "strings"

View File

@@ -1,4 +1,4 @@
package protonvpn
package updater
import (
"net"

View File

@@ -1,6 +1,6 @@
// Package protonvpn contains code to obtain the server information
// Package updater contains code to obtain the server information
// for the ProtonVPN provider.
package protonvpn
package updater
import (
"context"

View File

@@ -1,4 +1,4 @@
package protonvpn
package updater
import (
"net/http"

View File

@@ -11,6 +11,7 @@ import (
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/models"
"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"
@@ -41,6 +42,8 @@ type Provider interface {
OpenVPNConfig(connection models.Connection, settings settings.OpenVPN) (lines []string)
Name() string
PortForwarder
FetchServers(ctx context.Context, minServers int) (
servers []models.Server, err error)
}
type PortForwarder interface {
@@ -57,7 +60,8 @@ type Storage interface {
GetServerByName(provider, name string) (server models.Server, ok bool)
}
func New(provider string, storage Storage, timeNow func() time.Time) Provider {
func New(provider string, storage Storage, timeNow func() time.Time,
updaterWarner common.Warner, client *http.Client, unzipper common.Unzipper) Provider {
randSource := rand.NewSource(timeNow().UnixNano())
switch provider {
case providers.Custom:
@@ -65,43 +69,43 @@ func New(provider string, storage Storage, timeNow func() time.Time) Provider {
case providers.Cyberghost:
return cyberghost.New(storage, randSource)
case providers.Expressvpn:
return expressvpn.New(storage, randSource)
return expressvpn.New(storage, randSource, unzipper, updaterWarner)
case providers.Fastestvpn:
return fastestvpn.New(storage, randSource)
return fastestvpn.New(storage, randSource, unzipper, updaterWarner)
case providers.HideMyAss:
return hidemyass.New(storage, randSource)
return hidemyass.New(storage, randSource, client, updaterWarner)
case providers.Ipvanish:
return ipvanish.New(storage, randSource)
return ipvanish.New(storage, randSource, unzipper, updaterWarner)
case providers.Ivpn:
return ivpn.New(storage, randSource)
return ivpn.New(storage, randSource, client, updaterWarner)
case providers.Mullvad:
return mullvad.New(storage, randSource)
return mullvad.New(storage, randSource, client)
case providers.Nordvpn:
return nordvpn.New(storage, randSource)
return nordvpn.New(storage, randSource, client, updaterWarner)
case providers.Perfectprivacy:
return perfectprivacy.New(storage, randSource)
return perfectprivacy.New(storage, randSource, unzipper, updaterWarner)
case providers.Privado:
return privado.New(storage, randSource)
return privado.New(storage, randSource, client, unzipper, updaterWarner)
case providers.PrivateInternetAccess:
return privateinternetaccess.New(storage, randSource, timeNow)
return privateinternetaccess.New(storage, randSource, timeNow, client)
case providers.Privatevpn:
return privatevpn.New(storage, randSource)
return privatevpn.New(storage, randSource, unzipper, updaterWarner)
case providers.Protonvpn:
return protonvpn.New(storage, randSource)
return protonvpn.New(storage, randSource, client, updaterWarner)
case providers.Purevpn:
return purevpn.New(storage, randSource)
return purevpn.New(storage, randSource, client, unzipper, updaterWarner)
case providers.Surfshark:
return surfshark.New(storage, randSource)
return surfshark.New(storage, randSource, client, unzipper, updaterWarner)
case providers.Torguard:
return torguard.New(storage, randSource)
return torguard.New(storage, randSource, unzipper, updaterWarner)
case providers.VPNUnlimited:
return vpnunlimited.New(storage, randSource)
return vpnunlimited.New(storage, randSource, unzipper, updaterWarner)
case providers.Vyprvpn:
return vyprvpn.New(storage, randSource)
return vyprvpn.New(storage, randSource, unzipper, updaterWarner)
case providers.Wevpn:
return wevpn.New(storage, randSource)
return wevpn.New(storage, randSource, updaterWarner)
case providers.Windscribe:
return windscribe.New(storage, randSource)
return windscribe.New(storage, randSource, client, updaterWarner)
default:
panic("provider " + provider + " is unknown") // should never occur
}

View File

@@ -2,9 +2,11 @@ package purevpn
import (
"math/rand"
"net/http"
"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"
)
@@ -12,13 +14,16 @@ type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}
func New(storage common.Storage, randSource rand.Source) *Provider {
func New(storage common.Storage, randSource rand.Source,
client *http.Client, unzipper common.Unzipper, updaterWarner common.Warner) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Purevpn),
Fetcher: updater.New(client, unzipper, updaterWarner),
}
}

View File

@@ -1,4 +1,4 @@
package purevpn
package updater
import (
"net"

View File

@@ -1,4 +1,4 @@
package purevpn
package updater
import (
"time"

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