mirror of
https://github.com/qdm12/gluetun.git
synced 2026-06-20 11:02:59 +02:00
chore(updater): move updater packages to pkg/updaters/<name>
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
package vpnunlimited
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func getHostToServer() (hts hostToServer, warnings []string) {
|
||||
shortHTS := map[string]models.Server{
|
||||
"ae": {},
|
||||
"at": {},
|
||||
"au-syd": {
|
||||
City: "Sydney",
|
||||
},
|
||||
"ba": {},
|
||||
"be": {},
|
||||
"bg": {},
|
||||
"br": {},
|
||||
"ca-tr": {
|
||||
City: "Toronto",
|
||||
},
|
||||
"ca-vn": {
|
||||
City: "Vancouver",
|
||||
},
|
||||
"ca": {},
|
||||
"ch": {},
|
||||
"cz": {},
|
||||
"de-dus": {
|
||||
City: "Düsseldorf",
|
||||
},
|
||||
"ee": {},
|
||||
"es": {},
|
||||
"fi": {},
|
||||
"fr-rbx": {
|
||||
City: "Roubaix",
|
||||
},
|
||||
"fr": {},
|
||||
"gr": {},
|
||||
"hr": {},
|
||||
"hu": {},
|
||||
"ie-dub": {
|
||||
City: "Dublin",
|
||||
},
|
||||
"il": {},
|
||||
"in": {},
|
||||
"is": {},
|
||||
"it-mil": {
|
||||
City: "Milan",
|
||||
},
|
||||
"jp": {},
|
||||
"kr": {},
|
||||
"lt": {},
|
||||
"md": {},
|
||||
"mx": {},
|
||||
"nl": {},
|
||||
"no": {},
|
||||
"nz": {},
|
||||
"pl": {},
|
||||
"pt": {},
|
||||
"ro": {},
|
||||
"se": {},
|
||||
"sg-free": {
|
||||
Free: true,
|
||||
},
|
||||
"sg": {},
|
||||
"si": {},
|
||||
"sk": {},
|
||||
"uk-cv": {
|
||||
City: "London",
|
||||
},
|
||||
"uk-lon": {
|
||||
City: "London",
|
||||
},
|
||||
"uk": {},
|
||||
"us-chi": {
|
||||
City: "Chicago",
|
||||
},
|
||||
"us-dal": {
|
||||
City: "Dallas",
|
||||
},
|
||||
"us-den": {
|
||||
City: "Denver",
|
||||
},
|
||||
"us-hou": {
|
||||
City: "Houston",
|
||||
},
|
||||
"us-la": {
|
||||
City: "Los Angeles",
|
||||
},
|
||||
"us-lv": {
|
||||
City: "Las Vegas",
|
||||
},
|
||||
"us-mia": {
|
||||
City: "Miami",
|
||||
},
|
||||
"us-ny-free": {
|
||||
City: "New York",
|
||||
Free: true,
|
||||
},
|
||||
"us-ny": {
|
||||
City: "New York",
|
||||
},
|
||||
"us-sea": {
|
||||
City: "Seattle",
|
||||
},
|
||||
"us-sf": {
|
||||
City: "San Francisco",
|
||||
},
|
||||
"us-slc": {
|
||||
City: "Salt Lake City",
|
||||
},
|
||||
"us-stream": {
|
||||
Stream: true,
|
||||
},
|
||||
"us": {},
|
||||
"vn": {},
|
||||
"za": {},
|
||||
}
|
||||
|
||||
hts = make(hostToServer, len(shortHTS))
|
||||
|
||||
countryCodesMap := constants.CountryCodes()
|
||||
for shortHost, server := range shortHTS {
|
||||
server.VPN = vpn.OpenVPN
|
||||
server.UDP = true
|
||||
server.Hostname = shortHost + ".vpnunlimitedapp.com"
|
||||
countryCode := strings.Split(shortHost, "-")[0]
|
||||
country, ok := countryCodesMap[countryCode]
|
||||
if !ok {
|
||||
warnings = append(warnings, "country code not found: "+countryCode)
|
||||
continue
|
||||
}
|
||||
server.Country = country
|
||||
hts[server.Hostname] = server
|
||||
}
|
||||
|
||||
return hts, warnings
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package vpnunlimited
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
type hostToServer map[string]models.Server
|
||||
|
||||
func (hts hostToServer) toHostsSlice() (hosts []string) {
|
||||
hosts = make([]string, 0, len(hts))
|
||||
for host := range hts {
|
||||
hosts = append(hosts, host)
|
||||
}
|
||||
return hosts
|
||||
}
|
||||
|
||||
func (hts hostToServer) adaptWithIPs(hostToIPs map[string][]netip.Addr) {
|
||||
for host, IPs := range hostToIPs {
|
||||
server := hts[host]
|
||||
server.IPs = IPs
|
||||
hts[host] = server
|
||||
}
|
||||
for host, server := range hts {
|
||||
if len(server.IPs) == 0 {
|
||||
delete(hts, host)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (hts hostToServer) toServersSlice() (servers []models.Server) {
|
||||
servers = make([]models.Server, 0, len(hts))
|
||||
for _, server := range hts {
|
||||
servers = append(servers, server)
|
||||
}
|
||||
return servers
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package vpnunlimited
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
||||
)
|
||||
|
||||
func parallelResolverSettings(hosts []string) (settings resolver.ParallelSettings) {
|
||||
const (
|
||||
maxFailRatio = 0.1
|
||||
maxDuration = 20 * time.Second
|
||||
betweenDuration = time.Second
|
||||
maxNoNew = 2
|
||||
maxFails = 2
|
||||
)
|
||||
return resolver.ParallelSettings{
|
||||
Hosts: hosts,
|
||||
MaxFailRatio: maxFailRatio,
|
||||
Repeat: resolver.RepeatSettings{
|
||||
MaxDuration: maxDuration,
|
||||
BetweenDuration: betweenDuration,
|
||||
MaxNoNew: maxNoNew,
|
||||
MaxFails: maxFails,
|
||||
SortIPs: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package vpnunlimited
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/common"
|
||||
)
|
||||
|
||||
func (u *Updater) FetchServers(ctx context.Context, minServers int) (
|
||||
servers []models.Server, err error,
|
||||
) {
|
||||
// Hardcoded data from a user provided ZIP file since it's behind a login wall
|
||||
hts, warnings := getHostToServer()
|
||||
for _, warning := range warnings {
|
||||
u.warner.Warn(warning)
|
||||
}
|
||||
|
||||
hosts := hts.toHostsSlice()
|
||||
resolveSettings := parallelResolverSettings(hosts)
|
||||
hostToIPs, warnings, err := u.parallelResolver.Resolve(ctx, resolveSettings)
|
||||
for _, warning := range warnings {
|
||||
u.warner.Warn(warning)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(hostToIPs) < minServers {
|
||||
return nil, fmt.Errorf("%w: %d and expected at least %d",
|
||||
common.ErrNotEnoughServers, len(servers), minServers)
|
||||
}
|
||||
|
||||
hts.adaptWithIPs(hostToIPs)
|
||||
|
||||
servers = hts.toServersSlice()
|
||||
|
||||
sort.Sort(models.SortableServers(servers))
|
||||
|
||||
return servers, nil
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package vpnunlimited
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/provider/common"
|
||||
)
|
||||
|
||||
type Updater struct {
|
||||
unzipper common.Unzipper
|
||||
parallelResolver common.ParallelResolver
|
||||
warner common.Warner
|
||||
}
|
||||
|
||||
func New(unzipper common.Unzipper, warner common.Warner,
|
||||
parallelResolver common.ParallelResolver,
|
||||
) *Updater {
|
||||
return &Updater{
|
||||
unzipper: unzipper,
|
||||
parallelResolver: parallelResolver,
|
||||
warner: warner,
|
||||
}
|
||||
}
|
||||
|
||||
func (u *Updater) Version() uint16 {
|
||||
return 1
|
||||
}
|
||||
Reference in New Issue
Block a user