Fix: restore PIA error if region does not support port forwarding
This commit is contained in:
@@ -48,3 +48,12 @@ func PIAServers() (servers []models.PIAServer) {
|
|||||||
copy(servers, allServers.Pia.Servers)
|
copy(servers, allServers.Pia.Servers)
|
||||||
return servers
|
return servers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PIAServerWhereName(serverName string) (server models.PIAServer) {
|
||||||
|
for _, server := range PIAServers() {
|
||||||
|
if server.ServerName == serverName {
|
||||||
|
return server
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return server
|
||||||
|
}
|
||||||
|
|||||||
@@ -47,20 +47,5 @@ func (p *PIA) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
|||||||
return connection, err
|
return connection, err
|
||||||
}
|
}
|
||||||
|
|
||||||
p.activeServer = findActiveServer(servers, connection)
|
|
||||||
|
|
||||||
return connection, nil
|
return connection, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func findActiveServer(servers []models.PIAServer,
|
|
||||||
connection models.OpenVPNConnection) (activeServer models.PIAServer) {
|
|
||||||
// Reverse lookup server using the randomly picked connection
|
|
||||||
for _, server := range servers {
|
|
||||||
for _, ip := range server.IPs {
|
|
||||||
if connection.IP.Equal(ip) {
|
|
||||||
return server
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return activeServer
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/qdm12/gluetun/internal/constants"
|
||||||
"github.com/qdm12/golibs/format"
|
"github.com/qdm12/golibs/format"
|
||||||
"github.com/qdm12/golibs/logging"
|
"github.com/qdm12/golibs/logging"
|
||||||
)
|
)
|
||||||
@@ -32,12 +33,12 @@ var (
|
|||||||
func (p *PIA) PortForward(ctx context.Context, client *http.Client,
|
func (p *PIA) PortForward(ctx context.Context, client *http.Client,
|
||||||
logger logging.Logger, gateway net.IP, serverName string) (
|
logger logging.Logger, gateway net.IP, serverName string) (
|
||||||
port uint16, err error) {
|
port uint16, err error) {
|
||||||
// commonName := p.activeServer.ServerName
|
server := constants.PIAServerWhereName(serverName)
|
||||||
// if !p.activeServer.PortForward {
|
if !server.PortForward {
|
||||||
// logger.Error("The server " + commonName +
|
logger.Error("The server " + serverName +
|
||||||
// " (region " + p.activeServer.Region + ") does not support port forwarding")
|
" (region " + server.Region + ") does not support port forwarding")
|
||||||
// return
|
return
|
||||||
// }
|
}
|
||||||
if gateway == nil {
|
if gateway == nil {
|
||||||
return 0, ErrGatewayIPIsNil
|
return 0, ErrGatewayIPIsNil
|
||||||
} else if serverName == "" {
|
} else if serverName == "" {
|
||||||
|
|||||||
@@ -9,10 +9,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type PIA struct {
|
type PIA struct {
|
||||||
servers []models.PIAServer
|
servers []models.PIAServer
|
||||||
randSource rand.Source
|
randSource rand.Source
|
||||||
timeNow func() time.Time
|
timeNow func() time.Time
|
||||||
activeServer models.PIAServer
|
|
||||||
// Port forwarding
|
// Port forwarding
|
||||||
portForwardPath string
|
portForwardPath string
|
||||||
authFilePath string
|
authFilePath string
|
||||||
|
|||||||
Reference in New Issue
Block a user