chore(models): streamline all server models IPs (#942)

- Use `IPs []net.IP` for all server models
- Use `ips` JSON field for all server models
- Merge IPv4 and IPv6 addresses together for Mullvad
This commit is contained in:
Quentin McGaw
2022-04-16 21:58:42 +02:00
parent 54b7e23974
commit aa729515b9
18 changed files with 26277 additions and 12234 deletions

View File

@@ -8,14 +8,18 @@ import (
type hostToServer map[string]models.TorguardServer
func (hts hostToServer) add(host, country, city string, tcp, udp bool, ip net.IP) {
func (hts hostToServer) add(host, country, city string,
tcp, udp bool, ips []net.IP) {
server, ok := hts[host]
if !ok {
server.Hostname = host
server.Country = country
server.City = city
server.IPs = append(server.IPs, ip) // used if DNS resolution fails downstream
server.IPs = ips // used if DNS resolution fails downstream
} else {
server.IPs = append(server.IPs, ips...)
}
if tcp {
server.TCP = tcp
}

View File

@@ -90,10 +90,7 @@ func addServerFromOvpn(fileName string, content []byte,
return warnings
}
ip, warning, err := openvpn.ExtractIP(content)
if warning != "" {
warnings = append(warnings, warning)
}
ips, err := openvpn.ExtractIPs(content)
if err != nil {
// treat error as warning and go to next file
warning := err.Error() + " in " + fileName
@@ -101,6 +98,6 @@ func addServerFromOvpn(fileName string, content []byte,
return warnings
}
hts.add(host, country, city, tcp, udp, ip)
hts.add(host, country, city, tcp, udp, ips)
return warnings
}