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

@@ -16,9 +16,13 @@ func (m *Mullvad) GetConnection(selection settings.ServerSelection) (
return connection, err
}
var connections []models.Connection
connections := make([]models.Connection, 0, len(servers))
for _, server := range servers {
for _, IP := range server.IPs {
if IP.To4() == nil {
// do not use IPv6 connections for now
continue
}
connection := models.Connection{
Type: selection.VPN,
IP: IP,

View File

@@ -21,15 +21,17 @@ func (n *Nordvpn) GetConnection(selection settings.ServerSelection) (
return connection, err
}
connections := make([]models.Connection, len(servers))
for i := range servers {
connection := models.Connection{
Type: selection.VPN,
IP: servers[i].IP,
Port: port,
Protocol: protocol,
connections := make([]models.Connection, 0, len(servers))
for _, server := range servers {
for _, ip := range server.IPs {
connection := models.Connection{
Type: selection.VPN,
IP: ip,
Port: port,
Protocol: protocol,
}
connections = append(connections, connection)
}
connections[i] = connection
}
return utils.PickConnection(connections, selection, n.randSource)

View File

@@ -17,16 +17,18 @@ func (p *Privado) GetConnection(selection settings.ServerSelection) (
return connection, err
}
connections := make([]models.Connection, len(servers))
for i := range servers {
connection := models.Connection{
Type: selection.VPN,
IP: servers[i].IP,
Port: port,
Protocol: protocol,
Hostname: servers[i].Hostname,
connections := make([]models.Connection, 0, len(servers))
for _, server := range servers {
for _, ip := range server.IPs {
connection := models.Connection{
Type: selection.VPN,
IP: ip,
Port: port,
Protocol: protocol,
Hostname: server.Hostname,
}
connections = append(connections, connection)
}
connections[i] = connection
}
return utils.PickConnection(connections, selection, p.randSource)

View File

@@ -24,13 +24,16 @@ func (p *Protonvpn) GetConnection(selection settings.ServerSelection) (
return connection, err
}
connections := make([]models.Connection, len(servers))
for i := range servers {
connections[i] = models.Connection{
Type: selection.VPN,
IP: servers[i].EntryIP,
Port: port,
Protocol: protocol,
connections := make([]models.Connection, 0, len(servers))
for _, server := range servers {
for _, ip := range server.IPs {
connection := models.Connection{
Type: selection.VPN,
IP: ip,
Port: port,
Protocol: protocol,
}
connections = append(connections, connection)
}
}