Remove PIA v3 servers support
This commit is contained in:
@@ -5,7 +5,6 @@ type Options struct {
|
||||
Mullvad bool
|
||||
Nordvpn bool
|
||||
PIA bool
|
||||
PIAold bool
|
||||
Purevpn bool
|
||||
Surfshark bool
|
||||
Vyprvpn bool
|
||||
@@ -21,7 +20,6 @@ func NewOptions(dnsAddress string) Options {
|
||||
Mullvad: true,
|
||||
Nordvpn: true,
|
||||
PIA: true,
|
||||
PIAold: true,
|
||||
Purevpn: true,
|
||||
Surfshark: true,
|
||||
Vyprvpn: true,
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
package updater
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func (u *updater) updatePIAOld(ctx context.Context) (err error) {
|
||||
const zipURL = "https://www.privateinternetaccess.com/openvpn/openvpn.zip"
|
||||
contents, err := fetchAndExtractFiles(ctx, u.client, zipURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
const maxGoroutines = 10
|
||||
guard := make(chan struct{}, maxGoroutines)
|
||||
errors := make(chan error)
|
||||
serversCh := make(chan models.PIAOldServer)
|
||||
servers := make([]models.PIAOldServer, 0, len(contents))
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
wg := &sync.WaitGroup{}
|
||||
defer func() {
|
||||
cancel()
|
||||
wg.Wait()
|
||||
defer close(guard)
|
||||
defer close(errors)
|
||||
defer close(serversCh)
|
||||
}()
|
||||
for fileName, content := range contents {
|
||||
remoteLines := extractRemoteLinesFromOpenvpn(content)
|
||||
if len(remoteLines) == 0 {
|
||||
return fmt.Errorf("cannot find any remote lines in %s", fileName)
|
||||
}
|
||||
hosts := extractHostnamesFromRemoteLines(remoteLines)
|
||||
if len(hosts) == 0 {
|
||||
return fmt.Errorf("cannot find any hosts in %s", fileName)
|
||||
}
|
||||
region := strings.TrimSuffix(fileName, ".ovpn")
|
||||
wg.Add(1)
|
||||
go resolvePIAv3Hostname(ctx, wg, region, hosts, u.lookupIP, errors, serversCh, guard)
|
||||
}
|
||||
for range contents {
|
||||
select {
|
||||
case err := <-errors:
|
||||
return err
|
||||
case server := <-serversCh:
|
||||
servers = append(servers, server)
|
||||
}
|
||||
}
|
||||
sort.Slice(servers, func(i, j int) bool {
|
||||
return servers[i].Region < servers[j].Region
|
||||
})
|
||||
if u.options.Stdout {
|
||||
u.println(stringifyPIAOldServers(servers))
|
||||
}
|
||||
u.servers.PiaOld.Timestamp = u.timeNow().Unix()
|
||||
u.servers.PiaOld.Servers = servers
|
||||
return nil
|
||||
}
|
||||
|
||||
func resolvePIAv3Hostname(ctx context.Context, wg *sync.WaitGroup,
|
||||
region string, hosts []string, lookupIP lookupIPFunc,
|
||||
errors chan<- error, serversCh chan<- models.PIAOldServer, guard chan struct{}) {
|
||||
guard <- struct{}{}
|
||||
defer func() {
|
||||
<-guard
|
||||
wg.Done()
|
||||
}()
|
||||
var IPs []net.IP //nolint:prealloc
|
||||
// usually one single host in this case
|
||||
// so no need to run in goroutines the for loop below
|
||||
for _, host := range hosts {
|
||||
const repetition = 5
|
||||
newIPs, err := resolveRepeat(ctx, lookupIP, host, repetition)
|
||||
if err != nil {
|
||||
errors <- err
|
||||
return
|
||||
}
|
||||
IPs = append(IPs, newIPs...)
|
||||
}
|
||||
serversCh <- models.PIAOldServer{
|
||||
Region: region,
|
||||
IPs: uniqueSortedIPs(IPs),
|
||||
}
|
||||
}
|
||||
|
||||
func stringifyPIAOldServers(servers []models.PIAOldServer) (s string) {
|
||||
s = "func PIAOldServers() []models.PIAOldServer {\n"
|
||||
s += " return []models.PIAOldServer{\n"
|
||||
for _, server := range servers {
|
||||
s += " " + server.String() + ",\n"
|
||||
}
|
||||
s += " }\n"
|
||||
s += "}"
|
||||
return s
|
||||
}
|
||||
@@ -90,16 +90,6 @@ func (u *updater) UpdateServers(ctx context.Context) (allServers models.AllServe
|
||||
}
|
||||
}
|
||||
|
||||
if u.options.PIAold {
|
||||
u.logger.Info("updating Private Internet Access old (v3) servers...")
|
||||
if err := u.updatePIAOld(ctx); err != nil {
|
||||
if ctxErr := ctx.Err(); ctxErr != nil {
|
||||
return allServers, ctxErr
|
||||
}
|
||||
u.logger.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
if u.options.Purevpn {
|
||||
u.logger.Info("updating PureVPN servers...")
|
||||
// TODO support servers offering only TCP or only UDP
|
||||
|
||||
Reference in New Issue
Block a user