mirror of
https://github.com/qdm12/gluetun.git
synced 2026-05-07 04:20:12 +02:00
@@ -11,5 +11,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(443, 1194, 1637) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(443, 1194, 1637) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,24 @@
|
|||||||
package airvpn
|
package airvpn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/airvpn/updater"
|
"github.com/qdm12/gluetun/internal/provider/airvpn/updater"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, client *http.Client) *Provider {
|
||||||
client *http.Client,
|
|
||||||
) *Provider {
|
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(client),
|
Fetcher: updater.New(client),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(443, 443, 0) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(443, 443, 0) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,24 @@
|
|||||||
package cyberghost
|
package cyberghost
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/provider/cyberghost/updater"
|
"github.com/qdm12/gluetun/internal/provider/cyberghost/updater"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, updaterWarner common.Warner,
|
||||||
updaterWarner common.Warner, parallelResolver common.ParallelResolver,
|
parallelResolver common.ParallelResolver,
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(parallelResolver, updaterWarner),
|
Fetcher: updater.New(parallelResolver, updaterWarner),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,5 +13,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
// combination. If one combination is not supported, set it to `0`.
|
// combination. If one combination is not supported, set it to `0`.
|
||||||
defaults := utils.NewConnectionDefaults(443, 1194, 51820) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(443, 1194, 51820) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,27 @@
|
|||||||
package example
|
package example
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/provider/example/updater"
|
"github.com/qdm12/gluetun/internal/provider/example/updater"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove unneeded arguments once the updater is implemented.
|
// TODO: remove unneeded arguments once the updater is implemented.
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, updaterWarner common.Warner, client *http.Client,
|
||||||
updaterWarner common.Warner, client *http.Client,
|
|
||||||
unzipper common.Unzipper, parallelResolver common.ParallelResolver,
|
unzipper common.Unzipper, parallelResolver common.ParallelResolver,
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(updaterWarner, unzipper, client, parallelResolver),
|
Fetcher: updater.New(updaterWarner, unzipper, client, parallelResolver),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(0, 1195, 0) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(0, 1195, 0) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package expressvpn
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"math/rand"
|
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -80,12 +79,11 @@ func Test_Provider_GetConnection(t *testing.T) {
|
|||||||
storage := common.NewMockStorage(ctrl)
|
storage := common.NewMockStorage(ctrl)
|
||||||
storage.EXPECT().FilterServers(provider, testCase.selection).
|
storage.EXPECT().FilterServers(provider, testCase.selection).
|
||||||
Return(testCase.filteredServers, testCase.storageErr)
|
Return(testCase.filteredServers, testCase.storageErr)
|
||||||
randSource := rand.NewSource(0)
|
|
||||||
|
|
||||||
unzipper := (common.Unzipper)(nil)
|
unzipper := (common.Unzipper)(nil)
|
||||||
warner := (common.Warner)(nil)
|
warner := (common.Warner)(nil)
|
||||||
parallelResolver := (common.ParallelResolver)(nil)
|
parallelResolver := (common.ParallelResolver)(nil)
|
||||||
provider := New(storage, randSource, unzipper, warner, parallelResolver)
|
provider := New(storage, unzipper, warner, parallelResolver)
|
||||||
|
|
||||||
if testCase.panicMessage != "" {
|
if testCase.panicMessage != "" {
|
||||||
assert.PanicsWithValue(t, testCase.panicMessage, func() {
|
assert.PanicsWithValue(t, testCase.panicMessage, func() {
|
||||||
|
|||||||
@@ -1,26 +1,24 @@
|
|||||||
package expressvpn
|
package expressvpn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/provider/expressvpn/updater"
|
"github.com/qdm12/gluetun/internal/provider/expressvpn/updater"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, unzipper common.Unzipper, updaterWarner common.Warner,
|
||||||
unzipper common.Unzipper, updaterWarner common.Warner,
|
|
||||||
parallelResolver common.ParallelResolver,
|
parallelResolver common.ParallelResolver,
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
|
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(4443, 4443, 51820) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(4443, 4443, 51820) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,26 @@
|
|||||||
package fastestvpn
|
package fastestvpn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/provider/fastestvpn/updater"
|
"github.com/qdm12/gluetun/internal/provider/fastestvpn/updater"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, client *http.Client, updaterWarner common.Warner,
|
||||||
client *http.Client, updaterWarner common.Warner,
|
|
||||||
parallelResolver common.ParallelResolver,
|
parallelResolver common.ParallelResolver,
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(client, updaterWarner, parallelResolver),
|
Fetcher: updater.New(client, updaterWarner, parallelResolver),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(0, 443, 0) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(0, 443, 0) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,24 @@
|
|||||||
package giganews
|
package giganews
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/provider/giganews/updater"
|
"github.com/qdm12/gluetun/internal/provider/giganews/updater"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, unzipper common.Unzipper, updaterWarner common.Warner,
|
||||||
unzipper common.Unzipper, updaterWarner common.Warner,
|
|
||||||
parallelResolver common.ParallelResolver,
|
parallelResolver common.ParallelResolver,
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
|
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(8080, 553, 0) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(8080, 553, 0) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,26 @@
|
|||||||
package hidemyass
|
package hidemyass
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/provider/hidemyass/updater"
|
"github.com/qdm12/gluetun/internal/provider/hidemyass/updater"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, client *http.Client, updaterWarner common.Warner,
|
||||||
client *http.Client, updaterWarner common.Warner,
|
|
||||||
parallelResolver common.ParallelResolver,
|
parallelResolver common.ParallelResolver,
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(client, updaterWarner, parallelResolver),
|
Fetcher: updater.New(client, updaterWarner, parallelResolver),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(0, 443, 0) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(0, 443, 0) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,24 @@
|
|||||||
package ipvanish
|
package ipvanish
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/provider/ipvanish/updater"
|
"github.com/qdm12/gluetun/internal/provider/ipvanish/updater"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, unzipper common.Unzipper, updaterWarner common.Warner,
|
||||||
unzipper common.Unzipper, updaterWarner common.Warner,
|
|
||||||
parallelResolver common.ParallelResolver,
|
parallelResolver common.ParallelResolver,
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
|
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(443, 1194, 58237) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(443, 1194, 58237) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package ivpn
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -91,12 +90,11 @@ func Test_Provider_GetConnection(t *testing.T) {
|
|||||||
storage := common.NewMockStorage(ctrl)
|
storage := common.NewMockStorage(ctrl)
|
||||||
storage.EXPECT().FilterServers(provider, testCase.selection).
|
storage.EXPECT().FilterServers(provider, testCase.selection).
|
||||||
Return(testCase.filteredServers, testCase.storageErr)
|
Return(testCase.filteredServers, testCase.storageErr)
|
||||||
randSource := rand.NewSource(0)
|
|
||||||
|
|
||||||
client := (*http.Client)(nil)
|
client := (*http.Client)(nil)
|
||||||
warner := (common.Warner)(nil)
|
warner := (common.Warner)(nil)
|
||||||
parallelResolver := (common.ParallelResolver)(nil)
|
parallelResolver := (common.ParallelResolver)(nil)
|
||||||
provider := New(storage, randSource, client, warner, parallelResolver)
|
provider := New(storage, client, warner, parallelResolver)
|
||||||
|
|
||||||
connection, err := provider.GetConnection(testCase.selection, testCase.ipv6Supported)
|
connection, err := provider.GetConnection(testCase.selection, testCase.ipv6Supported)
|
||||||
|
|
||||||
|
|||||||
@@ -1,27 +1,26 @@
|
|||||||
package ivpn
|
package ivpn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/provider/ivpn/updater"
|
"github.com/qdm12/gluetun/internal/provider/ivpn/updater"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, client *http.Client, updaterWarner common.Warner,
|
||||||
client *http.Client, updaterWarner common.Warner,
|
|
||||||
parallelResolver common.ParallelResolver,
|
parallelResolver common.ParallelResolver,
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(client, updaterWarner, parallelResolver),
|
Fetcher: updater.New(client, updaterWarner, parallelResolver),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(0, 0, 51820) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(0, 0, 51820) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package mullvad
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -59,10 +58,9 @@ func Test_Provider_GetConnection(t *testing.T) {
|
|||||||
storage := common.NewMockStorage(ctrl)
|
storage := common.NewMockStorage(ctrl)
|
||||||
storage.EXPECT().FilterServers(provider, testCase.selection).
|
storage.EXPECT().FilterServers(provider, testCase.selection).
|
||||||
Return(testCase.filteredServers, testCase.storageErr)
|
Return(testCase.filteredServers, testCase.storageErr)
|
||||||
randSource := rand.NewSource(0)
|
|
||||||
|
|
||||||
client := (*http.Client)(nil)
|
client := (*http.Client)(nil)
|
||||||
provider := New(storage, randSource, client)
|
provider := New(storage, client)
|
||||||
|
|
||||||
connection, err := provider.GetConnection(testCase.selection, testCase.ipv6Supported)
|
connection, err := provider.GetConnection(testCase.selection, testCase.ipv6Supported)
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +1,25 @@
|
|||||||
package mullvad
|
package mullvad
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/provider/mullvad/updater"
|
"github.com/qdm12/gluetun/internal/provider/mullvad/updater"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, client *http.Client,
|
||||||
client *http.Client,
|
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(client),
|
Fetcher: updater.New(client),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(443, 1194, 51820) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(443, 1194, 51820) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,25 @@
|
|||||||
package nordvpn
|
package nordvpn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/provider/nordvpn/updater"
|
"github.com/qdm12/gluetun/internal/provider/nordvpn/updater"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, client *http.Client, updaterWarner common.Warner,
|
||||||
client *http.Client, updaterWarner common.Warner,
|
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(client, updaterWarner),
|
Fetcher: updater.New(client, updaterWarner),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(443, 443, 0) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(443, 443, 0) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,23 @@
|
|||||||
package perfectprivacy
|
package perfectprivacy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/provider/perfectprivacy/updater"
|
"github.com/qdm12/gluetun/internal/provider/perfectprivacy/updater"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, unzipper common.Unzipper, updaterWarner common.Warner,
|
||||||
unzipper common.Unzipper, updaterWarner common.Warner,
|
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(unzipper, updaterWarner),
|
Fetcher: updater.New(unzipper, updaterWarner),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(1194, 1194, 0) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(1194, 1194, 0) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,25 @@
|
|||||||
package privado
|
package privado
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/provider/privado/updater"
|
"github.com/qdm12/gluetun/internal/provider/privado/updater"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, client *http.Client, updaterWarner common.Warner,
|
||||||
client *http.Client, updaterWarner common.Warner,
|
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(client, updaterWarner),
|
Fetcher: updater.New(client, updaterWarner),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,5 +22,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
}
|
}
|
||||||
|
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package privateinternetaccess
|
package privateinternetaccess
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"time"
|
"time"
|
||||||
@@ -9,11 +8,12 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/provider/privateinternetaccess/updater"
|
"github.com/qdm12/gluetun/internal/provider/privateinternetaccess/updater"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
timeNow func() time.Time
|
timeNow func() time.Time
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
// Port forwarding
|
// Port forwarding
|
||||||
@@ -21,14 +21,14 @@ type Provider struct {
|
|||||||
apiIP netip.Addr
|
apiIP netip.Addr
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, timeNow func() time.Time,
|
||||||
timeNow func() time.Time, client *http.Client,
|
client *http.Client,
|
||||||
) *Provider {
|
) *Provider {
|
||||||
const jsonPortForwardPath = "/gluetun/piaportforward.json"
|
const jsonPortForwardPath = "/gluetun/piaportforward.json"
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
timeNow: timeNow,
|
timeNow: timeNow,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
portForwardPath: jsonPortForwardPath,
|
portForwardPath: jsonPortForwardPath,
|
||||||
Fetcher: updater.New(client),
|
Fetcher: updater.New(client),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(443, 1194, 0) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(443, 1194, 0) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,24 @@
|
|||||||
package privatevpn
|
package privatevpn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/provider/privatevpn/updater"
|
"github.com/qdm12/gluetun/internal/provider/privatevpn/updater"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, unzipper common.Unzipper, updaterWarner common.Warner,
|
||||||
unzipper common.Unzipper, updaterWarner common.Warner,
|
|
||||||
parallelResolver common.ParallelResolver,
|
parallelResolver common.ParallelResolver,
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
|
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(443, 1194, 51820) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(443, 1194, 51820) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,27 @@
|
|||||||
package protonvpn
|
package protonvpn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/provider/protonvpn/updater"
|
"github.com/qdm12/gluetun/internal/provider/protonvpn/updater"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
internalToExternalPorts map[uint16]uint16
|
internalToExternalPorts map[uint16]uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, client *http.Client, updaterWarner common.Warner,
|
||||||
client *http.Client, updaterWarner common.Warner,
|
|
||||||
email, password string,
|
email, password string,
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(client, updaterWarner, email, password),
|
Fetcher: updater.New(client, updaterWarner, email, password),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package provider
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -55,34 +54,32 @@ func NewProviders(storage Storage, timeNow func() time.Time,
|
|||||||
parallelResolver common.ParallelResolver, ipFetcher common.IPFetcher,
|
parallelResolver common.ParallelResolver, ipFetcher common.IPFetcher,
|
||||||
extractor custom.Extractor, credentials settings.Updater,
|
extractor custom.Extractor, credentials settings.Updater,
|
||||||
) *Providers {
|
) *Providers {
|
||||||
randSource := rand.NewSource(timeNow().UnixNano())
|
|
||||||
|
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
providerNameToProvider := map[string]Provider{
|
providerNameToProvider := map[string]Provider{
|
||||||
providers.Airvpn: airvpn.New(storage, randSource, client),
|
providers.Airvpn: airvpn.New(storage, client),
|
||||||
providers.Custom: custom.New(extractor),
|
providers.Custom: custom.New(extractor),
|
||||||
providers.Cyberghost: cyberghost.New(storage, randSource, updaterWarner, parallelResolver),
|
providers.Cyberghost: cyberghost.New(storage, updaterWarner, parallelResolver),
|
||||||
providers.Expressvpn: expressvpn.New(storage, randSource, unzipper, updaterWarner, parallelResolver),
|
providers.Expressvpn: expressvpn.New(storage, unzipper, updaterWarner, parallelResolver),
|
||||||
providers.Fastestvpn: fastestvpn.New(storage, randSource, client, updaterWarner, parallelResolver),
|
providers.Fastestvpn: fastestvpn.New(storage, client, updaterWarner, parallelResolver),
|
||||||
providers.Giganews: giganews.New(storage, randSource, unzipper, updaterWarner, parallelResolver),
|
providers.Giganews: giganews.New(storage, unzipper, updaterWarner, parallelResolver),
|
||||||
providers.HideMyAss: hidemyass.New(storage, randSource, client, updaterWarner, parallelResolver),
|
providers.HideMyAss: hidemyass.New(storage, client, updaterWarner, parallelResolver),
|
||||||
providers.Ipvanish: ipvanish.New(storage, randSource, unzipper, updaterWarner, parallelResolver),
|
providers.Ipvanish: ipvanish.New(storage, unzipper, updaterWarner, parallelResolver),
|
||||||
providers.Ivpn: ivpn.New(storage, randSource, client, updaterWarner, parallelResolver),
|
providers.Ivpn: ivpn.New(storage, client, updaterWarner, parallelResolver),
|
||||||
providers.Mullvad: mullvad.New(storage, randSource, client),
|
providers.Mullvad: mullvad.New(storage, client),
|
||||||
providers.Nordvpn: nordvpn.New(storage, randSource, client, updaterWarner),
|
providers.Nordvpn: nordvpn.New(storage, client, updaterWarner),
|
||||||
providers.Perfectprivacy: perfectprivacy.New(storage, randSource, unzipper, updaterWarner),
|
providers.Perfectprivacy: perfectprivacy.New(storage, unzipper, updaterWarner),
|
||||||
providers.Privado: privado.New(storage, randSource, client, updaterWarner),
|
providers.Privado: privado.New(storage, client, updaterWarner),
|
||||||
providers.PrivateInternetAccess: privateinternetaccess.New(storage, randSource, timeNow, client),
|
providers.PrivateInternetAccess: privateinternetaccess.New(storage, timeNow, client),
|
||||||
providers.Privatevpn: privatevpn.New(storage, randSource, unzipper, updaterWarner, parallelResolver),
|
providers.Privatevpn: privatevpn.New(storage, unzipper, updaterWarner, parallelResolver),
|
||||||
providers.Protonvpn: protonvpn.New(storage, randSource, client, updaterWarner, *credentials.ProtonEmail, *credentials.ProtonPassword),
|
providers.Protonvpn: protonvpn.New(storage, client, updaterWarner, *credentials.ProtonEmail, *credentials.ProtonPassword),
|
||||||
providers.Purevpn: purevpn.New(storage, randSource, ipFetcher, unzipper, updaterWarner, parallelResolver),
|
providers.Purevpn: purevpn.New(storage, ipFetcher, unzipper, updaterWarner, parallelResolver),
|
||||||
providers.SlickVPN: slickvpn.New(storage, randSource, client, updaterWarner, parallelResolver),
|
providers.SlickVPN: slickvpn.New(storage, client, updaterWarner, parallelResolver),
|
||||||
providers.Surfshark: surfshark.New(storage, randSource, client, unzipper, updaterWarner, parallelResolver),
|
providers.Surfshark: surfshark.New(storage, client, unzipper, updaterWarner, parallelResolver),
|
||||||
providers.Torguard: torguard.New(storage, randSource, unzipper, updaterWarner, parallelResolver),
|
providers.Torguard: torguard.New(storage, unzipper, updaterWarner, parallelResolver),
|
||||||
providers.VPNSecure: vpnsecure.New(storage, randSource, client, updaterWarner, parallelResolver),
|
providers.VPNSecure: vpnsecure.New(storage, client, updaterWarner, parallelResolver),
|
||||||
providers.VPNUnlimited: vpnunlimited.New(storage, randSource, unzipper, updaterWarner, parallelResolver),
|
providers.VPNUnlimited: vpnunlimited.New(storage, unzipper, updaterWarner, parallelResolver),
|
||||||
providers.Vyprvpn: vyprvpn.New(storage, randSource, unzipper, updaterWarner, parallelResolver),
|
providers.Vyprvpn: vyprvpn.New(storage, unzipper, updaterWarner, parallelResolver),
|
||||||
providers.Windscribe: windscribe.New(storage, randSource, client, updaterWarner),
|
providers.Windscribe: windscribe.New(storage, client, updaterWarner),
|
||||||
}
|
}
|
||||||
|
|
||||||
targetLength := len(providers.AllWithCustom())
|
targetLength := len(providers.AllWithCustom())
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(80, 53, 0) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(80, 53, 0) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,24 @@
|
|||||||
package purevpn
|
package purevpn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/provider/purevpn/updater"
|
"github.com/qdm12/gluetun/internal/provider/purevpn/updater"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, ipFetcher common.IPFetcher, unzipper common.Unzipper,
|
||||||
ipFetcher common.IPFetcher, unzipper common.Unzipper,
|
|
||||||
updaterWarner common.Warner, parallelResolver common.ParallelResolver,
|
updaterWarner common.Warner, parallelResolver common.ParallelResolver,
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(ipFetcher, unzipper, updaterWarner, parallelResolver),
|
Fetcher: updater.New(ipFetcher, unzipper, updaterWarner, parallelResolver),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,5 +10,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
connection models.Connection, err error,
|
connection models.Connection, err error,
|
||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(443, 443, 0) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(443, 443, 0) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.randSource)
|
return utils.GetConnection(p.Name(), p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,26 @@
|
|||||||
package slickvpn
|
package slickvpn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/provider/slickvpn/updater"
|
"github.com/qdm12/gluetun/internal/provider/slickvpn/updater"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, client *http.Client, updaterWarner common.Warner,
|
||||||
client *http.Client, updaterWarner common.Warner,
|
|
||||||
parallelResolver common.ParallelResolver,
|
parallelResolver common.ParallelResolver,
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(client, updaterWarner, parallelResolver),
|
Fetcher: updater.New(client, updaterWarner, parallelResolver),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(1443, 1194, 51820) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(1443, 1194, 51820) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,26 @@
|
|||||||
package surfshark
|
package surfshark
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/provider/surfshark/updater"
|
"github.com/qdm12/gluetun/internal/provider/surfshark/updater"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, client *http.Client, unzipper common.Unzipper,
|
||||||
client *http.Client, unzipper common.Unzipper, updaterWarner common.Warner,
|
updaterWarner common.Warner, parallelResolver common.ParallelResolver,
|
||||||
parallelResolver common.ParallelResolver,
|
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(client, unzipper, updaterWarner, parallelResolver),
|
Fetcher: updater.New(client, unzipper, updaterWarner, parallelResolver),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(1912, 1912, 0) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(1912, 1912, 0) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,24 @@
|
|||||||
package torguard
|
package torguard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/provider/torguard/updater"
|
"github.com/qdm12/gluetun/internal/provider/torguard/updater"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, unzipper common.Unzipper, updaterWarner common.Warner,
|
||||||
unzipper common.Unzipper, updaterWarner common.Warner,
|
|
||||||
parallelResolver common.ParallelResolver,
|
parallelResolver common.ParallelResolver,
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
|
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
@@ -35,7 +34,8 @@ func GetConnection(provider string,
|
|||||||
selection settings.ServerSelection,
|
selection settings.ServerSelection,
|
||||||
defaults ConnectionDefaults,
|
defaults ConnectionDefaults,
|
||||||
ipv6Supported bool,
|
ipv6Supported bool,
|
||||||
randSource rand.Source) (
|
connPicker *ConnectionPicker,
|
||||||
|
) (
|
||||||
connection models.Connection, err error,
|
connection models.Connection, err error,
|
||||||
) {
|
) {
|
||||||
servers, err := storage.FilterServers(provider, selection)
|
servers, err := storage.FilterServers(provider, selection)
|
||||||
@@ -75,5 +75,5 @@ func GetConnection(provider string,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pickConnection(connections, selection, randSource)
|
return pickConnection(connections, selection, connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,6 +183,7 @@ func Test_GetConnection(t *testing.T) {
|
|||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
ctrl := gomock.NewController(t)
|
ctrl := gomock.NewController(t)
|
||||||
|
connPicker := NewConnectionPicker()
|
||||||
|
|
||||||
storage := common.NewMockStorage(ctrl)
|
storage := common.NewMockStorage(ctrl)
|
||||||
storage.EXPECT().
|
storage.EXPECT().
|
||||||
@@ -191,7 +192,7 @@ func Test_GetConnection(t *testing.T) {
|
|||||||
|
|
||||||
connection, err := GetConnection(testCase.provider, storage,
|
connection, err := GetConnection(testCase.provider, storage,
|
||||||
testCase.serverSelection, testCase.defaults, testCase.ipv6Supported,
|
testCase.serverSelection, testCase.defaults, testCase.ipv6Supported,
|
||||||
testCase.randSource)
|
connPicker)
|
||||||
|
|
||||||
assert.Equal(t, testCase.connection, connection)
|
assert.Equal(t, testCase.connection, connection)
|
||||||
if testCase.errMessage != "" {
|
if testCase.errMessage != "" {
|
||||||
|
|||||||
@@ -1,23 +1,86 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"hash/fnv"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ConnectionPicker is a struct that holds the state of the connection pool cycler.
|
||||||
|
type ConnectionPicker struct {
|
||||||
|
mutex sync.Mutex
|
||||||
|
fingerprint uint64
|
||||||
|
nextIndex uint
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewConnectionPicker() *ConnectionPicker {
|
||||||
|
return &ConnectionPicker{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ConnectionPicker) pickConnection(connections []models.Connection,
|
||||||
|
) models.Connection {
|
||||||
|
fingerprint := fingerprintPool(connections)
|
||||||
|
|
||||||
|
c.mutex.Lock()
|
||||||
|
defer c.mutex.Unlock()
|
||||||
|
|
||||||
|
if c.fingerprint != fingerprint || c.nextIndex >= uint(len(connections)) {
|
||||||
|
c.fingerprint = fingerprint
|
||||||
|
c.nextIndex = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
connection := connections[c.nextIndex]
|
||||||
|
c.nextIndex++
|
||||||
|
if c.nextIndex >= uint(len(connections)) {
|
||||||
|
c.nextIndex = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return connection
|
||||||
|
}
|
||||||
|
|
||||||
|
func fingerprintPool(connections []models.Connection) uint64 {
|
||||||
|
hasher := fnv.New64a()
|
||||||
|
|
||||||
|
for _, connection := range connections {
|
||||||
|
_, _ = hasher.Write([]byte(connection.Type))
|
||||||
|
_, _ = hasher.Write([]byte("|"))
|
||||||
|
_, _ = hasher.Write(connection.IP.AsSlice())
|
||||||
|
_, _ = hasher.Write([]byte("|"))
|
||||||
|
_, _ = hasher.Write(binary.BigEndian.AppendUint16(nil, connection.Port))
|
||||||
|
_, _ = hasher.Write([]byte("|"))
|
||||||
|
_, _ = hasher.Write([]byte(connection.Protocol))
|
||||||
|
_, _ = hasher.Write([]byte("|"))
|
||||||
|
_, _ = hasher.Write([]byte(connection.Hostname))
|
||||||
|
_, _ = hasher.Write([]byte("|"))
|
||||||
|
_, _ = hasher.Write([]byte(connection.PubKey))
|
||||||
|
_, _ = hasher.Write([]byte("|"))
|
||||||
|
_, _ = hasher.Write([]byte(connection.ServerName))
|
||||||
|
_, _ = hasher.Write([]byte("|"))
|
||||||
|
if connection.PortForward {
|
||||||
|
_, _ = hasher.Write([]byte("1"))
|
||||||
|
} else {
|
||||||
|
_, _ = hasher.Write([]byte("0"))
|
||||||
|
}
|
||||||
|
_, _ = hasher.Write([]byte("\n"))
|
||||||
|
}
|
||||||
|
|
||||||
|
return hasher.Sum64()
|
||||||
|
}
|
||||||
|
|
||||||
// pickConnection picks a connection from a pool of connections.
|
// pickConnection picks a connection from a pool of connections.
|
||||||
// If the VPN protocol is Wireguard and the target IP is set,
|
// If the VPN protocol is Wireguard and the target IP is set,
|
||||||
// it finds the connection corresponding to this target IP.
|
// it finds the connection corresponding to this target IP.
|
||||||
// Otherwise, it picks a random connection from the pool of connections
|
// Otherwise, it cycles through the pool of connections.
|
||||||
// and sets the target IP address as the IP if this one is set.
|
// and sets the target IP address as the IP if this one is set.
|
||||||
func pickConnection(connections []models.Connection,
|
func pickConnection(connections []models.Connection,
|
||||||
selection settings.ServerSelection, randSource rand.Source) (
|
selection settings.ServerSelection, picker *ConnectionPicker) (
|
||||||
connection models.Connection, err error,
|
connection models.Connection, err error,
|
||||||
) {
|
) {
|
||||||
if len(connections) == 0 {
|
if len(connections) == 0 {
|
||||||
@@ -40,7 +103,7 @@ func pickConnection(connections []models.Connection,
|
|||||||
return getTargetIPConnection(connections, targetIP)
|
return getTargetIPConnection(connections, targetIP)
|
||||||
}
|
}
|
||||||
|
|
||||||
connection = pickRandomConnection(connections, randSource)
|
connection = picker.pickConnection(connections)
|
||||||
if targetIPSet {
|
if targetIPSet {
|
||||||
connection.IP = targetIP
|
connection.IP = targetIP
|
||||||
}
|
}
|
||||||
@@ -48,12 +111,6 @@ func pickConnection(connections []models.Connection,
|
|||||||
return connection, nil
|
return connection, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func pickRandomConnection(connections []models.Connection,
|
|
||||||
source rand.Source,
|
|
||||||
) models.Connection {
|
|
||||||
return connections[rand.New(source).Intn(len(connections))] //nolint:gosec
|
|
||||||
}
|
|
||||||
|
|
||||||
func getTargetIPConnection(connections []models.Connection,
|
func getTargetIPConnection(connections []models.Connection,
|
||||||
targetIP netip.Addr,
|
targetIP netip.Addr,
|
||||||
) (connection models.Connection, err error) {
|
) (connection models.Connection, err error) {
|
||||||
|
|||||||
@@ -1,26 +1,137 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"net/netip"
|
||||||
"testing"
|
"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/internal/models"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_pickRandomConnection(t *testing.T) {
|
func Test_ConnectionPicker_pickConnection(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
connections := []models.Connection{
|
|
||||||
{Port: 1}, {Port: 2}, {Port: 3}, {Port: 4},
|
picker := NewConnectionPicker()
|
||||||
|
|
||||||
|
poolA := []models.Connection{
|
||||||
|
{Port: 1}, {Port: 2}, {Port: 3},
|
||||||
}
|
}
|
||||||
source := rand.NewSource(0)
|
connection := picker.pickConnection(poolA)
|
||||||
|
assert.Equal(t, models.Connection{Port: 1}, connection)
|
||||||
|
|
||||||
connection := pickRandomConnection(connections, source)
|
connection = picker.pickConnection(poolA)
|
||||||
assert.Equal(t, models.Connection{Port: 3}, connection)
|
|
||||||
|
|
||||||
connection = pickRandomConnection(connections, source)
|
|
||||||
assert.Equal(t, models.Connection{Port: 3}, connection)
|
|
||||||
|
|
||||||
connection = pickRandomConnection(connections, source)
|
|
||||||
assert.Equal(t, models.Connection{Port: 2}, connection)
|
assert.Equal(t, models.Connection{Port: 2}, connection)
|
||||||
|
|
||||||
|
connection = picker.pickConnection(poolA)
|
||||||
|
assert.Equal(t, models.Connection{Port: 3}, connection)
|
||||||
|
|
||||||
|
connection = picker.pickConnection(poolA)
|
||||||
|
assert.Equal(t, models.Connection{Port: 1}, connection)
|
||||||
|
|
||||||
|
poolB := []models.Connection{
|
||||||
|
{Port: 10}, {Port: 20},
|
||||||
|
}
|
||||||
|
connection = picker.pickConnection(poolB)
|
||||||
|
assert.Equal(t, models.Connection{Port: 10}, connection)
|
||||||
|
|
||||||
|
connection = picker.pickConnection(poolB)
|
||||||
|
assert.Equal(t, models.Connection{Port: 20}, connection)
|
||||||
|
|
||||||
|
connection = picker.pickConnection(poolB)
|
||||||
|
assert.Equal(t, models.Connection{Port: 10}, connection)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_pickConnection(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
testCases := map[string]struct {
|
||||||
|
connections []models.Connection
|
||||||
|
selection settings.ServerSelection
|
||||||
|
connection1 models.Connection
|
||||||
|
connection2 models.Connection
|
||||||
|
errMessage string
|
||||||
|
}{
|
||||||
|
"empty_connections": {
|
||||||
|
errMessage: "no connection to pick from",
|
||||||
|
},
|
||||||
|
"openvpn_cycles": {
|
||||||
|
connections: []models.Connection{
|
||||||
|
{Type: vpn.OpenVPN, Port: 1, Hostname: "one"},
|
||||||
|
{Type: vpn.OpenVPN, Port: 2, Hostname: "two"},
|
||||||
|
},
|
||||||
|
selection: settings.ServerSelection{VPN: vpn.OpenVPN},
|
||||||
|
connection1: models.Connection{
|
||||||
|
Type: vpn.OpenVPN, Port: 1,
|
||||||
|
Hostname: "one",
|
||||||
|
},
|
||||||
|
connection2: models.Connection{
|
||||||
|
Type: vpn.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})},
|
||||||
|
},
|
||||||
|
selection: settings.ServerSelection{
|
||||||
|
VPN: vpn.OpenVPN,
|
||||||
|
OpenVPN: settings.OpenVPNSelection{
|
||||||
|
EndpointIP: netip.AddrFrom4([4]byte{9, 9, 9, 9}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
connection1: models.Connection{
|
||||||
|
Type: vpn.OpenVPN, Hostname: "one",
|
||||||
|
IP: netip.AddrFrom4([4]byte{9, 9, 9, 9}),
|
||||||
|
},
|
||||||
|
connection2: models.Connection{
|
||||||
|
Type: vpn.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})},
|
||||||
|
},
|
||||||
|
selection: settings.ServerSelection{
|
||||||
|
VPN: vpn.Wireguard,
|
||||||
|
Wireguard: settings.WireguardSelection{
|
||||||
|
EndpointIP: netip.AddrFrom4([4]byte{2, 2, 2, 2}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
connection1: models.Connection{
|
||||||
|
Type: vpn.Wireguard, Hostname: "two",
|
||||||
|
IP: netip.AddrFrom4([4]byte{2, 2, 2, 2}),
|
||||||
|
},
|
||||||
|
connection2: models.Connection{
|
||||||
|
Type: vpn.Wireguard, Hostname: "two",
|
||||||
|
IP: netip.AddrFrom4([4]byte{2, 2, 2, 2}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for name, testCase := range testCases {
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
connPicker := NewConnectionPicker()
|
||||||
|
|
||||||
|
connection, err := pickConnection(testCase.connections,
|
||||||
|
testCase.selection, connPicker)
|
||||||
|
if testCase.errMessage != "" {
|
||||||
|
assert.EqualError(t, err, testCase.errMessage)
|
||||||
|
assert.Equal(t, models.Connection{}, connection)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, testCase.connection1, connection)
|
||||||
|
|
||||||
|
connection, err = pickConnection(testCase.connections,
|
||||||
|
testCase.selection, connPicker)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, testCase.connection2, connection)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(110, 1282, 0) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(110, 1282, 0) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,26 @@
|
|||||||
package vpnsecure
|
package vpnsecure
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
"github.com/qdm12/gluetun/internal/provider/vpnsecure/updater"
|
"github.com/qdm12/gluetun/internal/provider/vpnsecure/updater"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, client *http.Client, updaterWarner common.Warner,
|
||||||
client *http.Client, updaterWarner common.Warner,
|
|
||||||
parallelResolver common.ParallelResolver,
|
parallelResolver common.ParallelResolver,
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(client, updaterWarner, parallelResolver),
|
Fetcher: updater.New(client, updaterWarner, parallelResolver),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(1197, 1197, 0) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(1197, 1197, 0) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,24 @@
|
|||||||
package vpnunlimited
|
package vpnunlimited
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
"github.com/qdm12/gluetun/internal/provider/vpnunlimited/updater"
|
"github.com/qdm12/gluetun/internal/provider/vpnunlimited/updater"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, unzipper common.Unzipper, updaterWarner common.Warner,
|
||||||
unzipper common.Unzipper, updaterWarner common.Warner,
|
|
||||||
parallelResolver common.ParallelResolver,
|
parallelResolver common.ParallelResolver,
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
|
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(0, 443, 0) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(0, 443, 0) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,24 @@
|
|||||||
package vyprvpn
|
package vyprvpn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
"github.com/qdm12/gluetun/internal/provider/vyprvpn/updater"
|
"github.com/qdm12/gluetun/internal/provider/vyprvpn/updater"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, unzipper common.Unzipper, updaterWarner common.Warner,
|
||||||
unzipper common.Unzipper, updaterWarner common.Warner,
|
|
||||||
parallelResolver common.ParallelResolver,
|
parallelResolver common.ParallelResolver,
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
|
Fetcher: updater.New(unzipper, updaterWarner, parallelResolver),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Support
|
|||||||
) {
|
) {
|
||||||
defaults := utils.NewConnectionDefaults(443, 1194, 1194) //nolint:mnd
|
defaults := utils.NewConnectionDefaults(443, 1194, 1194) //nolint:mnd
|
||||||
return utils.GetConnection(p.Name(),
|
return utils.GetConnection(p.Name(),
|
||||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
p.storage, selection, defaults, ipv6Supported, p.connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package windscribe
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -92,11 +91,10 @@ func Test_Provider_GetConnection(t *testing.T) {
|
|||||||
storage := common.NewMockStorage(ctrl)
|
storage := common.NewMockStorage(ctrl)
|
||||||
storage.EXPECT().FilterServers(provider, testCase.selection).
|
storage.EXPECT().FilterServers(provider, testCase.selection).
|
||||||
Return(testCase.filteredServers, testCase.storageErr)
|
Return(testCase.filteredServers, testCase.storageErr)
|
||||||
randSource := rand.NewSource(0)
|
|
||||||
|
|
||||||
client := (*http.Client)(nil)
|
client := (*http.Client)(nil)
|
||||||
warner := (common.Warner)(nil)
|
warner := (common.Warner)(nil)
|
||||||
provider := New(storage, randSource, client, warner)
|
provider := New(storage, client, warner)
|
||||||
|
|
||||||
if testCase.panicMessage != "" {
|
if testCase.panicMessage != "" {
|
||||||
assert.PanicsWithValue(t, testCase.panicMessage, func() {
|
assert.PanicsWithValue(t, testCase.panicMessage, func() {
|
||||||
|
|||||||
@@ -1,26 +1,25 @@
|
|||||||
package windscribe
|
package windscribe
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
"github.com/qdm12/gluetun/internal/provider/windscribe/updater"
|
"github.com/qdm12/gluetun/internal/provider/windscribe/updater"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
storage common.Storage
|
storage common.Storage
|
||||||
randSource rand.Source
|
connPicker *utils.ConnectionPicker
|
||||||
common.Fetcher
|
common.Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(storage common.Storage, randSource rand.Source,
|
func New(storage common.Storage, client *http.Client, updaterWarner common.Warner,
|
||||||
client *http.Client, updaterWarner common.Warner,
|
|
||||||
) *Provider {
|
) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
randSource: randSource,
|
connPicker: utils.NewConnectionPicker(),
|
||||||
Fetcher: updater.New(client, updaterWarner),
|
Fetcher: updater.New(client, updaterWarner),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user