Files
gluetun/internal/provider/protonvpn/connection.go
Quentin McGaw (desktop) 119cac5a67 Feat: OPENVPN_TARGET_IP overrides IP
- Check target IP matches a server for Wireguard since we need the public key
- Streamline connection picking for all providers
2021-08-28 19:07:44 +00:00

39 lines
943 B
Go

package protonvpn
import (
"github.com/qdm12/gluetun/internal/configuration"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
)
func (p *Protonvpn) GetConnection(selection configuration.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, len(servers))
for i := range servers {
connections[i] = models.Connection{
Type: selection.VPN,
IP: servers[i].EntryIP,
Port: port,
Protocol: protocol,
}
}
return utils.PickConnection(connections, selection, p.randSource)
}