Files
gluetun/internal/provider/protonvpn/connection.go
Quentin McGaw aa729515b9 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
2022-04-17 16:18:34 +00:00

42 lines
1.0 KiB
Go

package protonvpn
import (
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
)
func (p *Protonvpn) GetConnection(selection settings.ServerSelection) (
connection models.Connection, err error) {
protocol := constants.UDP
if *selection.OpenVPN.TCP {
protocol = constants.TCP
}
port, err := getPort(*selection.OpenVPN.TCP, *selection.OpenVPN.CustomPort)
if err != nil {
return connection, err
}
servers, err := p.filterServers(selection)
if err != nil {
return connection, err
}
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)
}
}
return utils.PickConnection(connections, selection, p.randSource)
}