Skip to content

Commit

Permalink
chore(provider): use type assertion for port forwarders
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Sep 23, 2023
1 parent 84300db commit aa6dc78
Show file tree
Hide file tree
Showing 29 changed files with 129 additions and 185 deletions.
9 changes: 3 additions & 6 deletions internal/provider/airvpn/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,20 @@ import (
"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"
)

type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}

func New(storage common.Storage, randSource rand.Source,
client *http.Client) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Example),
Fetcher: updater.New(client),
storage: storage,
randSource: randSource,
Fetcher: updater.New(client),
}
}

Expand Down
6 changes: 2 additions & 4 deletions internal/provider/custom/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import (

type Provider struct {
extractor Extractor
utils.NoPortForwarder
common.Fetcher
}

func New(extractor Extractor) *Provider {
return &Provider{
extractor: extractor,
NoPortForwarder: utils.NewNoPortForwarding(providers.Custom),
Fetcher: utils.NewNoFetcher(providers.Custom),
extractor: extractor,
Fetcher: utils.NewNoFetcher(providers.Custom),
}
}

Expand Down
9 changes: 3 additions & 6 deletions internal/provider/cyberghost/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,20 @@ 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"
)

type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}

func New(storage common.Storage, randSource rand.Source,
parallelResolver common.ParallelResolver) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Cyberghost),
Fetcher: updater.New(parallelResolver),
storage: storage,
randSource: randSource,
Fetcher: updater.New(parallelResolver),
}
}

Expand Down
9 changes: 3 additions & 6 deletions internal/provider/example/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ 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"
)

type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}

Expand All @@ -22,10 +20,9 @@ func New(storage common.Storage, randSource rand.Source,
updaterWarner common.Warner, client *http.Client,
unzipper common.Unzipper, parallelResolver common.ParallelResolver) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Example),
Fetcher: updater.New(updaterWarner, unzipper, client, parallelResolver),
storage: storage,
randSource: randSource,
Fetcher: updater.New(updaterWarner, unzipper, client, parallelResolver),
}
}

Expand Down
9 changes: 3 additions & 6 deletions internal/provider/expressvpn/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,21 @@ 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"
)

type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}

func New(storage common.Storage, randSource rand.Source,
unzipper common.Unzipper, updaterWarner common.Warner,
parallelResolver common.ParallelResolver) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Expressvpn),
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
storage: storage,
randSource: randSource,
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
}
}

Expand Down
9 changes: 3 additions & 6 deletions internal/provider/fastestvpn/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,21 @@ 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"
)

type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}

func New(storage common.Storage, randSource rand.Source,
unzipper common.Unzipper, updaterWarner common.Warner,
parallelResolver common.ParallelResolver) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Fastestvpn),
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
storage: storage,
randSource: randSource,
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
}
}

Expand Down
9 changes: 3 additions & 6 deletions internal/provider/hidemyass/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,21 @@ 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"
)

type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}

func New(storage common.Storage, randSource rand.Source,
client *http.Client, updaterWarner common.Warner,
parallelResolver common.ParallelResolver) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.HideMyAss),
Fetcher: updater.New(client, updaterWarner, parallelResolver),
storage: storage,
randSource: randSource,
Fetcher: updater.New(client, updaterWarner, parallelResolver),
}
}

Expand Down
9 changes: 3 additions & 6 deletions internal/provider/ipvanish/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,21 @@ 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"
)

type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}

func New(storage common.Storage, randSource rand.Source,
unzipper common.Unzipper, updaterWarner common.Warner,
parallelResolver common.ParallelResolver) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Ipvanish),
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
storage: storage,
randSource: randSource,
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
}
}

Expand Down
9 changes: 3 additions & 6 deletions internal/provider/ivpn/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,21 @@ 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"
)

type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}

func New(storage common.Storage, randSource rand.Source,
client *http.Client, updaterWarner common.Warner,
parallelResolver common.ParallelResolver) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Ivpn),
Fetcher: updater.New(client, updaterWarner, parallelResolver),
storage: storage,
randSource: randSource,
Fetcher: updater.New(client, updaterWarner, parallelResolver),
}
}

Expand Down
9 changes: 3 additions & 6 deletions internal/provider/mullvad/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,20 @@ 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"
)

type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}

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),
storage: storage,
randSource: randSource,
Fetcher: updater.New(client),
}
}

Expand Down
9 changes: 3 additions & 6 deletions internal/provider/nordvpn/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,20 @@ 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"
)

type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}

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),
storage: storage,
randSource: randSource,
Fetcher: updater.New(client, updaterWarner),
}
}

Expand Down
9 changes: 3 additions & 6 deletions internal/provider/perfectprivacy/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,20 @@ 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"
)

type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}

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),
storage: storage,
randSource: randSource,
Fetcher: updater.New(unzipper, updaterWarner),
}
}

Expand Down
9 changes: 3 additions & 6 deletions internal/provider/privado/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ 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"
)

type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}

Expand All @@ -21,10 +19,9 @@ func New(storage common.Storage, randSource rand.Source,
updaterWarner common.Warner,
parallelResolver common.ParallelResolver) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Privado),
Fetcher: updater.New(ipFetcher, unzipper, updaterWarner, parallelResolver),
storage: storage,
randSource: randSource,
Fetcher: updater.New(ipFetcher, unzipper, updaterWarner, parallelResolver),
}
}

Expand Down
9 changes: 3 additions & 6 deletions internal/provider/privatevpn/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,21 @@ 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"
)

type Provider struct {
storage common.Storage
randSource rand.Source
utils.NoPortForwarder
common.Fetcher
}

func New(storage common.Storage, randSource rand.Source,
unzipper common.Unzipper, updaterWarner common.Warner,
parallelResolver common.ParallelResolver) *Provider {
return &Provider{
storage: storage,
randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(providers.Privatevpn),
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
storage: storage,
randSource: randSource,
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
}
}

Expand Down
9 changes: 0 additions & 9 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,13 @@ import (

"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
)

// Provider contains methods to read and modify the openvpn configuration to connect as a client.
type Provider interface {
GetConnection(selection settings.ServerSelection, ipv6Supported bool) (connection models.Connection, err error)
OpenVPNConfig(connection models.Connection, settings settings.OpenVPN, ipv6Supported bool) (lines []string)
Name() string
PortForwarder
FetchServers(ctx context.Context, minServers int) (
servers []models.Server, err error)
}

type PortForwarder interface {
Name() string
PortForward(ctx context.Context, objects utils.PortForwardObjects) (
port uint16, err error)
KeepPortForward(ctx context.Context, objects utils.PortForwardObjects) (err error)
}
Loading

0 comments on commit aa6dc78

Please sign in to comment.