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:
@@ -25,23 +25,17 @@ func (hts hostToServer) toHostsSlice() (hosts []string) {
|
||||
return hosts
|
||||
}
|
||||
|
||||
func (hts hostToServer) adaptWithIPs(hostToIPs map[string][]net.IP) (
|
||||
warnings []string) {
|
||||
func (hts hostToServer) adaptWithIPs(hostToIPs map[string][]net.IP) {
|
||||
for host, IPs := range hostToIPs {
|
||||
if len(IPs) > 1 {
|
||||
warning := "more than one IP address found for host " + host
|
||||
warnings = append(warnings, warning)
|
||||
}
|
||||
server := hts[host]
|
||||
server.IP = IPs[0]
|
||||
server.IPs = IPs
|
||||
hts[host] = server
|
||||
}
|
||||
for host, server := range hts {
|
||||
if server.IP == nil {
|
||||
if len(server.IPs) == 0 {
|
||||
delete(hts, host)
|
||||
}
|
||||
}
|
||||
return warnings
|
||||
}
|
||||
|
||||
func (hts hostToServer) toServersSlice() (servers []models.PrivadoServer) {
|
||||
|
||||
@@ -11,9 +11,9 @@ import (
|
||||
|
||||
func setLocationInfo(ctx context.Context, client *http.Client, servers []models.PrivadoServer) (err error) {
|
||||
// Get public IP address information
|
||||
ipsToGetInfo := make([]net.IP, len(servers))
|
||||
for i := range servers {
|
||||
ipsToGetInfo[i] = servers[i].IP
|
||||
ipsToGetInfo := make([]net.IP, 0, len(servers))
|
||||
for _, server := range servers {
|
||||
ipsToGetInfo = append(ipsToGetInfo, server.IPs...)
|
||||
}
|
||||
ipsInfo, err := publicip.MultiInfo(ctx, client, ipsToGetInfo)
|
||||
if err != nil {
|
||||
|
||||
@@ -62,8 +62,7 @@ func GetServers(ctx context.Context, unzipper unzip.Unzipper,
|
||||
return nil, warnings, err
|
||||
}
|
||||
|
||||
newWarnings = hts.adaptWithIPs(hostToIPs)
|
||||
warnings = append(warnings, newWarnings...)
|
||||
hts.adaptWithIPs(hostToIPs)
|
||||
|
||||
servers = hts.toServersSlice()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user