chore(all): Providers containing all provider objects

- Share the same providers for updater and vpn
- Initialise all providers at start
- Get from `Providers` instead of constructing on every run
This commit is contained in:
Quentin McGaw
2022-06-10 00:47:56 +00:00
parent ebd94723c1
commit 0378fe4a7b
9 changed files with 136 additions and 112 deletions

View File

@@ -3,37 +3,12 @@ package provider
import (
"context"
"math/rand"
"net"
"net/http"
"time"
"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"
"github.com/qdm12/gluetun/internal/provider/fastestvpn"
"github.com/qdm12/gluetun/internal/provider/hidemyass"
"github.com/qdm12/gluetun/internal/provider/ipvanish"
"github.com/qdm12/gluetun/internal/provider/ivpn"
"github.com/qdm12/gluetun/internal/provider/mullvad"
"github.com/qdm12/gluetun/internal/provider/nordvpn"
"github.com/qdm12/gluetun/internal/provider/perfectprivacy"
"github.com/qdm12/gluetun/internal/provider/privado"
"github.com/qdm12/gluetun/internal/provider/privateinternetaccess"
"github.com/qdm12/gluetun/internal/provider/privatevpn"
"github.com/qdm12/gluetun/internal/provider/protonvpn"
"github.com/qdm12/gluetun/internal/provider/purevpn"
"github.com/qdm12/gluetun/internal/provider/surfshark"
"github.com/qdm12/gluetun/internal/provider/torguard"
"github.com/qdm12/gluetun/internal/provider/utils"
"github.com/qdm12/gluetun/internal/provider/vpnunlimited"
"github.com/qdm12/gluetun/internal/provider/vyprvpn"
"github.com/qdm12/gluetun/internal/provider/wevpn"
"github.com/qdm12/gluetun/internal/provider/windscribe"
)
// Provider contains methods to read and modify the openvpn configuration to connect as a client.
@@ -53,60 +28,3 @@ type PortForwarder interface {
KeepPortForward(ctx context.Context, client *http.Client,
port uint16, gateway net.IP, serverName string) (err error)
}
type Storage interface {
FilterServers(provider string, selection settings.ServerSelection) (
servers []models.Server, err error)
GetServerByName(provider, name string) (server models.Server, ok bool)
}
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:
return custom.New()
case providers.Cyberghost:
return cyberghost.New(storage, randSource)
case providers.Expressvpn:
return expressvpn.New(storage, randSource, unzipper, updaterWarner)
case providers.Fastestvpn:
return fastestvpn.New(storage, randSource, unzipper, updaterWarner)
case providers.HideMyAss:
return hidemyass.New(storage, randSource, client, updaterWarner)
case providers.Ipvanish:
return ipvanish.New(storage, randSource, unzipper, updaterWarner)
case providers.Ivpn:
return ivpn.New(storage, randSource, client, updaterWarner)
case providers.Mullvad:
return mullvad.New(storage, randSource, client)
case providers.Nordvpn:
return nordvpn.New(storage, randSource, client, updaterWarner)
case providers.Perfectprivacy:
return perfectprivacy.New(storage, randSource, unzipper, updaterWarner)
case providers.Privado:
return privado.New(storage, randSource, client, unzipper, updaterWarner)
case providers.PrivateInternetAccess:
return privateinternetaccess.New(storage, randSource, timeNow, client)
case providers.Privatevpn:
return privatevpn.New(storage, randSource, unzipper, updaterWarner)
case providers.Protonvpn:
return protonvpn.New(storage, randSource, client, updaterWarner)
case providers.Purevpn:
return purevpn.New(storage, randSource, client, unzipper, updaterWarner)
case providers.Surfshark:
return surfshark.New(storage, randSource, client, unzipper, updaterWarner)
case providers.Torguard:
return torguard.New(storage, randSource, unzipper, updaterWarner)
case providers.VPNUnlimited:
return vpnunlimited.New(storage, randSource, unzipper, updaterWarner)
case providers.Vyprvpn:
return vyprvpn.New(storage, randSource, unzipper, updaterWarner)
case providers.Wevpn:
return wevpn.New(storage, randSource, updaterWarner)
case providers.Windscribe:
return windscribe.New(storage, randSource, client, updaterWarner)
default:
panic("provider " + provider + " is unknown") // should never occur
}
}