chore(resolver): export structs instead of interfaces
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
// Code generated by MockGen. DO NOT EDIT.
|
// Code generated by MockGen. DO NOT EDIT.
|
||||||
// Source: github.com/qdm12/gluetun/internal/provider/common (interfaces: Storage)
|
// Source: github.com/qdm12/gluetun/internal/provider/common (interfaces: ParallelResolver,Storage)
|
||||||
|
|
||||||
// Package common is a generated GoMock package.
|
// Package common is a generated GoMock package.
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
context "context"
|
||||||
|
net "net"
|
||||||
reflect "reflect"
|
reflect "reflect"
|
||||||
|
|
||||||
gomock "github.com/golang/mock/gomock"
|
gomock "github.com/golang/mock/gomock"
|
||||||
@@ -12,6 +14,45 @@ import (
|
|||||||
models "github.com/qdm12/gluetun/internal/models"
|
models "github.com/qdm12/gluetun/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// MockParallelResolver is a mock of ParallelResolver interface.
|
||||||
|
type MockParallelResolver struct {
|
||||||
|
ctrl *gomock.Controller
|
||||||
|
recorder *MockParallelResolverMockRecorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// MockParallelResolverMockRecorder is the mock recorder for MockParallelResolver.
|
||||||
|
type MockParallelResolverMockRecorder struct {
|
||||||
|
mock *MockParallelResolver
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMockParallelResolver creates a new mock instance.
|
||||||
|
func NewMockParallelResolver(ctrl *gomock.Controller) *MockParallelResolver {
|
||||||
|
mock := &MockParallelResolver{ctrl: ctrl}
|
||||||
|
mock.recorder = &MockParallelResolverMockRecorder{mock}
|
||||||
|
return mock
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||||
|
func (m *MockParallelResolver) EXPECT() *MockParallelResolverMockRecorder {
|
||||||
|
return m.recorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolve mocks base method.
|
||||||
|
func (m *MockParallelResolver) Resolve(arg0 context.Context, arg1 []string, arg2 int) (map[string][]net.IP, []string, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "Resolve", arg0, arg1, arg2)
|
||||||
|
ret0, _ := ret[0].(map[string][]net.IP)
|
||||||
|
ret1, _ := ret[1].([]string)
|
||||||
|
ret2, _ := ret[2].(error)
|
||||||
|
return ret0, ret1, ret2
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolve indicates an expected call of Resolve.
|
||||||
|
func (mr *MockParallelResolverMockRecorder) Resolve(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Resolve", reflect.TypeOf((*MockParallelResolver)(nil).Resolve), arg0, arg1, arg2)
|
||||||
|
}
|
||||||
|
|
||||||
// MockStorage is a mock of Storage interface.
|
// MockStorage is a mock of Storage interface.
|
||||||
type MockStorage struct {
|
type MockStorage struct {
|
||||||
ctrl *gomock.Controller
|
ctrl *gomock.Controller
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
// Exceptionally, the storage mock is exported since it is used by all
|
// Exceptionally, these mocks are exported since they are used by all
|
||||||
// provider subpackages tests, and it reduces test code duplication a lot.
|
// provider subpackages tests, and it reduces test code duplication a lot.
|
||||||
//go:generate mockgen -destination=mocks.go -package $GOPACKAGE . Storage
|
//go:generate mockgen -destination=mocks.go -package $GOPACKAGE . ParallelResolver,Storage
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import "errors"
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"net"
|
||||||
|
)
|
||||||
|
|
||||||
var ErrNotEnoughServers = errors.New("not enough servers found")
|
var ErrNotEnoughServers = errors.New("not enough servers found")
|
||||||
|
|
||||||
|
type ParallelResolver interface {
|
||||||
|
Resolve(ctx context.Context, hosts []string, minToFind int) (
|
||||||
|
hostToIPs map[string][]net.IP, warnings []string, err error)
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/updater/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newParallelResolver() (parallelResolver resolver.Parallel) {
|
func newParallelResolver() (parallelResolver *resolver.Parallel) {
|
||||||
const (
|
const (
|
||||||
maxFailRatio = 1
|
maxFailRatio = 1
|
||||||
maxDuration = 20 * time.Second
|
maxDuration = 20 * time.Second
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package cyberghost
|
package cyberghost
|
||||||
|
|
||||||
import "github.com/qdm12/gluetun/internal/updater/resolver"
|
import (
|
||||||
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
|
)
|
||||||
|
|
||||||
type Updater struct {
|
type Updater struct {
|
||||||
presolver resolver.Parallel
|
presolver common.ParallelResolver
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *Updater {
|
func New() *Updater {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/updater/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newParallelResolver() resolver.Parallel {
|
func newParallelResolver() *resolver.Parallel {
|
||||||
const (
|
const (
|
||||||
maxFailRatio = 0.1
|
maxFailRatio = 0.1
|
||||||
maxNoNew = 1
|
maxNoNew = 1
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package expressvpn
|
package expressvpn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/updater/unzip"
|
"github.com/qdm12/gluetun/internal/updater/unzip"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Updater struct {
|
type Updater struct {
|
||||||
unzipper unzip.Unzipper
|
unzipper unzip.Unzipper
|
||||||
presolver resolver.Parallel
|
presolver common.ParallelResolver
|
||||||
warner Warner
|
warner Warner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/updater/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newParallelResolver() resolver.Parallel {
|
func newParallelResolver() *resolver.Parallel {
|
||||||
const (
|
const (
|
||||||
maxFailRatio = 0.1
|
maxFailRatio = 0.1
|
||||||
maxNoNew = 1
|
maxNoNew = 1
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package fastestvpn
|
package fastestvpn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/updater/unzip"
|
"github.com/qdm12/gluetun/internal/updater/unzip"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Updater struct {
|
type Updater struct {
|
||||||
unzipper unzip.Unzipper
|
unzipper unzip.Unzipper
|
||||||
presolver resolver.Parallel
|
presolver common.ParallelResolver
|
||||||
warner Warner
|
warner Warner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/updater/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newParallelResolver() resolver.Parallel {
|
func newParallelResolver() *resolver.Parallel {
|
||||||
const (
|
const (
|
||||||
maxFailRatio = 0.1
|
maxFailRatio = 0.1
|
||||||
maxDuration = 15 * time.Second
|
maxDuration = 15 * time.Second
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ package hidemyass
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Updater struct {
|
type Updater struct {
|
||||||
client *http.Client
|
client *http.Client
|
||||||
presolver resolver.Parallel
|
presolver common.ParallelResolver
|
||||||
warner Warner
|
warner Warner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/updater/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newParallelResolver() (parallelResolver resolver.Parallel) {
|
func newParallelResolver() (parallelResolver *resolver.Parallel) {
|
||||||
const (
|
const (
|
||||||
maxFailRatio = 0.1
|
maxFailRatio = 0.1
|
||||||
maxDuration = 20 * time.Second
|
maxDuration = 20 * time.Second
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
"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"
|
||||||
"github.com/qdm12/gluetun/internal/updater/resolver/mock_resolver"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/updater/unzip/mock_unzip"
|
"github.com/qdm12/gluetun/internal/updater/unzip/mock_unzip"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -168,7 +168,7 @@ func Test_Updater_GetServers(t *testing.T) {
|
|||||||
unzipper.EXPECT().FetchAndExtract(ctx, zipURL).
|
unzipper.EXPECT().FetchAndExtract(ctx, zipURL).
|
||||||
Return(testCase.unzipContents, testCase.unzipErr)
|
Return(testCase.unzipContents, testCase.unzipErr)
|
||||||
|
|
||||||
presolver := mock_resolver.NewMockParallel(ctrl)
|
presolver := common.NewMockParallelResolver(ctrl)
|
||||||
if testCase.expectResolve {
|
if testCase.expectResolve {
|
||||||
presolver.EXPECT().Resolve(ctx, testCase.hostsToResolve, testCase.minServers).
|
presolver.EXPECT().Resolve(ctx, testCase.hostsToResolve, testCase.minServers).
|
||||||
Return(testCase.hostToIPs, testCase.resolveWarnings, testCase.resolveErr)
|
Return(testCase.hostToIPs, testCase.resolveWarnings, testCase.resolveErr)
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package ipvanish
|
package ipvanish
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/updater/unzip"
|
"github.com/qdm12/gluetun/internal/updater/unzip"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Updater struct {
|
type Updater struct {
|
||||||
unzipper unzip.Unzipper
|
unzipper unzip.Unzipper
|
||||||
warner Warner
|
warner Warner
|
||||||
presolver resolver.Parallel
|
presolver common.ParallelResolver
|
||||||
}
|
}
|
||||||
|
|
||||||
type Warner interface {
|
type Warner interface {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/updater/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newParallelResolver() (parallelResolver resolver.Parallel) {
|
func newParallelResolver() (parallelResolver *resolver.Parallel) {
|
||||||
const (
|
const (
|
||||||
maxFailRatio = 0.1
|
maxFailRatio = 0.1
|
||||||
maxDuration = 20 * time.Second
|
maxDuration = 20 * time.Second
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
"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"
|
||||||
"github.com/qdm12/gluetun/internal/updater/resolver/mock_resolver"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@@ -128,7 +128,7 @@ func Test_Updater_GetServers(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
presolver := mock_resolver.NewMockParallel(ctrl)
|
presolver := common.NewMockParallelResolver(ctrl)
|
||||||
if testCase.expectResolve {
|
if testCase.expectResolve {
|
||||||
presolver.EXPECT().Resolve(ctx, testCase.hostsToResolve, testCase.minServers).
|
presolver.EXPECT().Resolve(ctx, testCase.hostsToResolve, testCase.minServers).
|
||||||
Return(testCase.hostToIPs, testCase.resolveWarnings, testCase.resolveErr)
|
Return(testCase.hostToIPs, testCase.resolveWarnings, testCase.resolveErr)
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ package ivpn
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Updater struct {
|
type Updater struct {
|
||||||
client *http.Client
|
client *http.Client
|
||||||
presolver resolver.Parallel
|
presolver common.ParallelResolver
|
||||||
warner Warner
|
warner Warner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/updater/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newParallelResolver() (parallelResolver resolver.Parallel) {
|
func newParallelResolver() (parallelResolver *resolver.Parallel) {
|
||||||
const (
|
const (
|
||||||
maxFailRatio = 0.1
|
maxFailRatio = 0.1
|
||||||
maxDuration = 30 * time.Second
|
maxDuration = 30 * time.Second
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ package privado
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/updater/unzip"
|
"github.com/qdm12/gluetun/internal/updater/unzip"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Updater struct {
|
type Updater struct {
|
||||||
client *http.Client
|
client *http.Client
|
||||||
unzipper unzip.Unzipper
|
unzipper unzip.Unzipper
|
||||||
presolver resolver.Parallel
|
presolver common.ParallelResolver
|
||||||
warner Warner
|
warner Warner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/updater/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newParallelResolver() (parallelResolver resolver.Parallel) {
|
func newParallelResolver() (parallelResolver *resolver.Parallel) {
|
||||||
const (
|
const (
|
||||||
maxFailRatio = 0.1
|
maxFailRatio = 0.1
|
||||||
maxDuration = 6 * time.Second
|
maxDuration = 6 * time.Second
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package privatevpn
|
package privatevpn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/updater/unzip"
|
"github.com/qdm12/gluetun/internal/updater/unzip"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Updater struct {
|
type Updater struct {
|
||||||
unzipper unzip.Unzipper
|
unzipper unzip.Unzipper
|
||||||
presolver resolver.Parallel
|
presolver common.ParallelResolver
|
||||||
warner Warner
|
warner Warner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/updater/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newParallelResolver() (parallelResolver resolver.Parallel) {
|
func newParallelResolver() (parallelResolver *resolver.Parallel) {
|
||||||
const (
|
const (
|
||||||
maxFailRatio = 0.1
|
maxFailRatio = 0.1
|
||||||
maxDuration = 20 * time.Second
|
maxDuration = 20 * time.Second
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ package purevpn
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/updater/unzip"
|
"github.com/qdm12/gluetun/internal/updater/unzip"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Updater struct {
|
type Updater struct {
|
||||||
client *http.Client
|
client *http.Client
|
||||||
unzipper unzip.Unzipper
|
unzipper unzip.Unzipper
|
||||||
presolver resolver.Parallel
|
presolver common.ParallelResolver
|
||||||
warner Warner
|
warner Warner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/updater/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newParallelResolver() (parallelResolver resolver.Parallel) {
|
func newParallelResolver() (parallelResolver *resolver.Parallel) {
|
||||||
const (
|
const (
|
||||||
maxFailRatio = 0.1
|
maxFailRatio = 0.1
|
||||||
maxDuration = 20 * time.Second
|
maxDuration = 20 * time.Second
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ package surfshark
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/updater/unzip"
|
"github.com/qdm12/gluetun/internal/updater/unzip"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Updater struct {
|
type Updater struct {
|
||||||
client *http.Client
|
client *http.Client
|
||||||
unzipper unzip.Unzipper
|
unzipper unzip.Unzipper
|
||||||
presolver resolver.Parallel
|
presolver common.ParallelResolver
|
||||||
warner Warner
|
warner Warner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/updater/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newParallelResolver() (parallelResolver resolver.Parallel) {
|
func newParallelResolver() (parallelResolver *resolver.Parallel) {
|
||||||
const (
|
const (
|
||||||
maxFailRatio = 0.1
|
maxFailRatio = 0.1
|
||||||
maxDuration = 20 * time.Second
|
maxDuration = 20 * time.Second
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package torguard
|
package torguard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/updater/unzip"
|
"github.com/qdm12/gluetun/internal/updater/unzip"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Updater struct {
|
type Updater struct {
|
||||||
unzipper unzip.Unzipper
|
unzipper unzip.Unzipper
|
||||||
presolver resolver.Parallel
|
presolver common.ParallelResolver
|
||||||
warner Warner
|
warner Warner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/updater/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newParallelResolver() (parallelResolver resolver.Parallel) {
|
func newParallelResolver() (parallelResolver *resolver.Parallel) {
|
||||||
const (
|
const (
|
||||||
maxFailRatio = 0.1
|
maxFailRatio = 0.1
|
||||||
maxDuration = 20 * time.Second
|
maxDuration = 20 * time.Second
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package vpnunlimited
|
package vpnunlimited
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/updater/unzip"
|
"github.com/qdm12/gluetun/internal/updater/unzip"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Updater struct {
|
type Updater struct {
|
||||||
unzipper unzip.Unzipper
|
unzipper unzip.Unzipper
|
||||||
presolver resolver.Parallel
|
presolver common.ParallelResolver
|
||||||
warner Warner
|
warner Warner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/updater/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newParallelResolver() (parallelResolver resolver.Parallel) {
|
func newParallelResolver() (parallelResolver *resolver.Parallel) {
|
||||||
const (
|
const (
|
||||||
maxFailRatio = 0.1
|
maxFailRatio = 0.1
|
||||||
maxDuration = 5 * time.Second
|
maxDuration = 5 * time.Second
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package vyprvpn
|
package vyprvpn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/updater/unzip"
|
"github.com/qdm12/gluetun/internal/updater/unzip"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Updater struct {
|
type Updater struct {
|
||||||
unzipper unzip.Unzipper
|
unzipper unzip.Unzipper
|
||||||
presolver resolver.Parallel
|
presolver common.ParallelResolver
|
||||||
warner Warner
|
warner Warner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
"github.com/qdm12/gluetun/internal/updater/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newParallelResolver() (parallelResolver resolver.Parallel) {
|
func newParallelResolver() (parallelResolver *resolver.Parallel) {
|
||||||
const (
|
const (
|
||||||
maxFailRatio = 0.1
|
maxFailRatio = 0.1
|
||||||
maxDuration = 20 * time.Second
|
maxDuration = 20 * time.Second
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
package wevpn
|
package wevpn
|
||||||
|
|
||||||
import (
|
import "github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Updater struct {
|
type Updater struct {
|
||||||
presolver resolver.Parallel
|
presolver common.ParallelResolver
|
||||||
warner Warner
|
warner Warner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
// Code generated by MockGen. DO NOT EDIT.
|
|
||||||
// Source: github.com/qdm12/gluetun/internal/updater/resolver (interfaces: Parallel)
|
|
||||||
|
|
||||||
// Package mock_resolver is a generated GoMock package.
|
|
||||||
package mock_resolver
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "context"
|
|
||||||
net "net"
|
|
||||||
reflect "reflect"
|
|
||||||
|
|
||||||
gomock "github.com/golang/mock/gomock"
|
|
||||||
)
|
|
||||||
|
|
||||||
// MockParallel is a mock of Parallel interface.
|
|
||||||
type MockParallel struct {
|
|
||||||
ctrl *gomock.Controller
|
|
||||||
recorder *MockParallelMockRecorder
|
|
||||||
}
|
|
||||||
|
|
||||||
// MockParallelMockRecorder is the mock recorder for MockParallel.
|
|
||||||
type MockParallelMockRecorder struct {
|
|
||||||
mock *MockParallel
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMockParallel creates a new mock instance.
|
|
||||||
func NewMockParallel(ctrl *gomock.Controller) *MockParallel {
|
|
||||||
mock := &MockParallel{ctrl: ctrl}
|
|
||||||
mock.recorder = &MockParallelMockRecorder{mock}
|
|
||||||
return mock
|
|
||||||
}
|
|
||||||
|
|
||||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
|
||||||
func (m *MockParallel) EXPECT() *MockParallelMockRecorder {
|
|
||||||
return m.recorder
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve mocks base method.
|
|
||||||
func (m *MockParallel) Resolve(arg0 context.Context, arg1 []string, arg2 int) (map[string][]net.IP, []string, error) {
|
|
||||||
m.ctrl.T.Helper()
|
|
||||||
ret := m.ctrl.Call(m, "Resolve", arg0, arg1, arg2)
|
|
||||||
ret0, _ := ret[0].(map[string][]net.IP)
|
|
||||||
ret1, _ := ret[1].([]string)
|
|
||||||
ret2, _ := ret[2].(error)
|
|
||||||
return ret0, ret1, ret2
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve indicates an expected call of Resolve.
|
|
||||||
func (mr *MockParallelMockRecorder) Resolve(arg0, arg1, arg2 interface{}) *gomock.Call {
|
|
||||||
mr.mock.ctrl.T.Helper()
|
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Resolve", reflect.TypeOf((*MockParallel)(nil).Resolve), arg0, arg1, arg2)
|
|
||||||
}
|
|
||||||
@@ -7,20 +7,13 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate mockgen -destination=mock_$GOPACKAGE/$GOFILE . Parallel
|
type Parallel struct {
|
||||||
|
repeatResolver *Repeat
|
||||||
type Parallel interface {
|
|
||||||
Resolve(ctx context.Context, hosts []string, minToFind int) (
|
|
||||||
hostToIPs map[string][]net.IP, warnings []string, err error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type parallel struct {
|
|
||||||
repeatResolver Repeat
|
|
||||||
settings ParallelSettings
|
settings ParallelSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewParallelResolver(settings ParallelSettings) Parallel {
|
func NewParallelResolver(settings ParallelSettings) *Parallel {
|
||||||
return ¶llel{
|
return &Parallel{
|
||||||
repeatResolver: NewRepeat(settings.Repeat),
|
repeatResolver: NewRepeat(settings.Repeat),
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
@@ -46,7 +39,7 @@ var (
|
|||||||
ErrMaxFailRatio = errors.New("maximum failure ratio reached")
|
ErrMaxFailRatio = errors.New("maximum failure ratio reached")
|
||||||
)
|
)
|
||||||
|
|
||||||
func (pr *parallel) Resolve(ctx context.Context, hosts []string, minToFind int) (
|
func (pr *Parallel) Resolve(ctx context.Context, hosts []string, minToFind int) (
|
||||||
hostToIPs map[string][]net.IP, warnings []string, err error) {
|
hostToIPs map[string][]net.IP, warnings []string, err error) {
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@@ -108,7 +101,7 @@ func (pr *parallel) Resolve(ctx context.Context, hosts []string, minToFind int)
|
|||||||
return hostToIPs, warnings, nil
|
return hostToIPs, warnings, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pr *parallel) resolveAsync(ctx context.Context, host string,
|
func (pr *Parallel) resolveAsync(ctx context.Context, host string,
|
||||||
results chan<- parallelResult, errors chan<- error) {
|
results chan<- parallelResult, errors chan<- error) {
|
||||||
IPs, err := pr.repeatResolver.Resolve(ctx, host)
|
IPs, err := pr.repeatResolver.Resolve(ctx, host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -10,17 +10,13 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Repeat interface {
|
type Repeat struct {
|
||||||
Resolve(ctx context.Context, host string) (IPs []net.IP, err error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type repeat struct {
|
|
||||||
resolver *net.Resolver
|
resolver *net.Resolver
|
||||||
settings RepeatSettings
|
settings RepeatSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRepeat(settings RepeatSettings) Repeat {
|
func NewRepeat(settings RepeatSettings) *Repeat {
|
||||||
return &repeat{
|
return &Repeat{
|
||||||
resolver: newResolver(settings.Address),
|
resolver: newResolver(settings.Address),
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
@@ -36,7 +32,7 @@ type RepeatSettings struct {
|
|||||||
SortIPs bool
|
SortIPs bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *repeat) Resolve(ctx context.Context, host string) (ips []net.IP, err error) {
|
func (r *Repeat) Resolve(ctx context.Context, host string) (ips []net.IP, err error) {
|
||||||
timedCtx, cancel := context.WithTimeout(ctx, r.settings.MaxDuration)
|
timedCtx, cancel := context.WithTimeout(ctx, r.settings.MaxDuration)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
@@ -71,7 +67,7 @@ var (
|
|||||||
ErrMaxFails = errors.New("reached the maximum number of consecutive failures")
|
ErrMaxFails = errors.New("reached the maximum number of consecutive failures")
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *repeat) resolveOnce(ctx, timedCtx context.Context, host string,
|
func (r *Repeat) resolveOnce(ctx, timedCtx context.Context, host string,
|
||||||
settings RepeatSettings, uniqueIPs map[string]struct{}, noNewCounter, failCounter int) (
|
settings RepeatSettings, uniqueIPs map[string]struct{}, noNewCounter, failCounter int) (
|
||||||
newNoNewCounter, newFailCounter int, err error) {
|
newNoNewCounter, newFailCounter int, err error) {
|
||||||
IPs, err := r.lookupIPs(timedCtx, host)
|
IPs, err := r.lookupIPs(timedCtx, host)
|
||||||
@@ -126,7 +122,7 @@ func (r *repeat) resolveOnce(ctx, timedCtx context.Context, host string,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *repeat) lookupIPs(ctx context.Context, host string) (ips []net.IP, err error) {
|
func (r *Repeat) lookupIPs(ctx context.Context, host string) (ips []net.IP, err error) {
|
||||||
addresses, err := r.resolver.LookupIPAddr(ctx, host)
|
addresses, err := r.resolver.LookupIPAddr(ctx, host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
// Package resolver defines custom resolvers to resolve
|
|
||||||
// hosts multiple times with adjustable settings.
|
|
||||||
package resolver
|
|
||||||
Reference in New Issue
Block a user