-
-
Notifications
You must be signed in to change notification settings - Fork 328
/
hosttoserver.go
69 lines (57 loc) · 1.71 KB
/
hosttoserver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package updater
import (
"net/netip"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
)
type hostToServer map[string]models.Server
func getPossibleServers() (possibleServers hostToServer) {
groupIDToProtocol := getGroupIDToProtocol()
cyberghostCountryCodes := getSubdomainToRegion()
allCountryCodes := constants.CountryCodes()
possibleCountryCodes := mergeCountryCodes(cyberghostCountryCodes, allCountryCodes)
n := len(groupIDToProtocol) * len(possibleCountryCodes)
possibleServers = make(hostToServer, n) // key is the host
for groupID, protocol := range groupIDToProtocol {
for countryCode, country := range possibleCountryCodes {
const domain = "cg-dialup.net"
possibleHost := groupID + "-" + countryCode + "." + domain
possibleServer := models.Server{
VPN: vpn.OpenVPN,
Hostname: possibleHost,
Country: country,
TCP: protocol == constants.TCP,
UDP: protocol == constants.UDP,
}
possibleServers[possibleHost] = possibleServer
}
}
return possibleServers
}
func (hts hostToServer) hostsSlice() (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) toSlice() (servers []models.Server) {
servers = make([]models.Server, 0, len(hts))
for _, server := range hts {
servers = append(servers, server)
}
return servers
}