Fix: restore PIA error if region does not support port forwarding

This commit is contained in:
Quentin McGaw (desktop)
2021-08-16 19:16:05 +00:00
parent 74b7c81195
commit 2c73672e64
4 changed files with 19 additions and 25 deletions

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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 == "" {

View File

@@ -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