chore(portforward): remove PIA dependency on storage package
This commit is contained in:
@@ -92,21 +92,6 @@ func (mr *MockStorageMockRecorder) FilterServers(arg0, arg1 interface{}) *gomock
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FilterServers", reflect.TypeOf((*MockStorage)(nil).FilterServers), arg0, arg1)
|
||||
}
|
||||
|
||||
// GetServerByName mocks base method.
|
||||
func (m *MockStorage) GetServerByName(arg0, arg1 string) (models.Server, bool) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetServerByName", arg0, arg1)
|
||||
ret0, _ := ret[0].(models.Server)
|
||||
ret1, _ := ret[1].(bool)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetServerByName indicates an expected call of GetServerByName.
|
||||
func (mr *MockStorageMockRecorder) GetServerByName(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetServerByName", reflect.TypeOf((*MockStorage)(nil).GetServerByName), arg0, arg1)
|
||||
}
|
||||
|
||||
// MockUnzipper is a mock of Unzipper interface.
|
||||
type MockUnzipper struct {
|
||||
ctrl *gomock.Controller
|
||||
|
||||
@@ -8,5 +8,4 @@ import (
|
||||
type Storage interface {
|
||||
FilterServers(provider string, selection settings.ServerSelection) (
|
||||
servers []models.Server, err error)
|
||||
GetServerByName(provider, name string) (server models.Server, ok bool)
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ func getOpenVPNConnection(extractor Extractor,
|
||||
// Set the server name for PIA port forwarding code used
|
||||
// together with the custom provider.
|
||||
connection.ServerName = selection.Names[0]
|
||||
connection.PortForward = true
|
||||
}
|
||||
|
||||
return connection, nil
|
||||
@@ -62,6 +63,7 @@ func getWireguardConnection(selection settings.ServerSelection) (
|
||||
// Set the server name for PIA port forwarding code used
|
||||
// together with the custom provider.
|
||||
connection.ServerName = selection.Names[0]
|
||||
connection.PortForward = true
|
||||
}
|
||||
return connection
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
"github.com/qdm12/golibs/format"
|
||||
)
|
||||
@@ -37,16 +36,10 @@ func (p *Provider) PortForward(ctx context.Context,
|
||||
|
||||
serverName := objects.ServerName
|
||||
|
||||
server, ok := p.storage.GetServerByName(providers.PrivateInternetAccess, serverName)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("%w: %s", ErrServerNameNotFound, serverName)
|
||||
}
|
||||
|
||||
logger := objects.Logger
|
||||
|
||||
if !server.PortForward {
|
||||
logger.Error("The server " + serverName +
|
||||
" (region " + server.Region + ") does not support port forwarding")
|
||||
if !objects.CanPortForward {
|
||||
logger.Error("The server " + serverName + " does not support port forwarding")
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,6 @@ type Providers struct {
|
||||
type Storage interface {
|
||||
FilterServers(provider string, selection settings.ServerSelection) (
|
||||
servers []models.Server, err error)
|
||||
GetServerByName(provider, name string) (server models.Server, ok bool)
|
||||
}
|
||||
|
||||
type Extractor interface {
|
||||
|
||||
@@ -60,13 +60,14 @@ func GetConnection(provider string,
|
||||
}
|
||||
|
||||
connection := models.Connection{
|
||||
Type: selection.VPN,
|
||||
IP: ip,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
Hostname: hostname,
|
||||
ServerName: server.ServerName,
|
||||
PubKey: server.WgPubKey, // Wireguard
|
||||
Type: selection.VPN,
|
||||
IP: ip,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
Hostname: hostname,
|
||||
ServerName: server.ServerName,
|
||||
PortForward: server.PortForward,
|
||||
PubKey: server.WgPubKey, // Wireguard
|
||||
}
|
||||
connections = append(connections, connection)
|
||||
}
|
||||
|
||||
@@ -15,11 +15,10 @@ type PortForwardObjects struct {
|
||||
Gateway netip.Addr
|
||||
// Client is used to query the VPN gateway for Private Internet Access.
|
||||
Client *http.Client
|
||||
// ServerName is used by Private Internet Access for port forwarding,
|
||||
// and to look up the server data from storage.
|
||||
// TODO use server data directly to remove storage dependency for port
|
||||
// forwarding implementation.
|
||||
// ServerName is used by Private Internet Access for port forwarding.
|
||||
ServerName string
|
||||
// CanPortForward is used by Private Internet Access for port forwarding.
|
||||
CanPortForward bool
|
||||
}
|
||||
|
||||
type Routing interface {
|
||||
|
||||
Reference in New Issue
Block a user