2021-05-11 17:10:51 +00:00
|
|
|
package protonvpn
|
|
|
|
|
|
|
|
|
|
import (
|
2022-01-06 06:40:23 -05:00
|
|
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
2021-05-11 17:10:51 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/constants"
|
|
|
|
|
"github.com/qdm12/gluetun/internal/models"
|
|
|
|
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
|
|
|
|
)
|
|
|
|
|
|
2022-01-06 06:40:23 -05:00
|
|
|
func (p *Protonvpn) GetConnection(selection settings.ServerSelection) (
|
2021-08-19 14:09:41 +00:00
|
|
|
connection models.Connection, err error) {
|
2021-05-11 17:10:51 +00:00
|
|
|
protocol := constants.UDP
|
2022-01-06 06:40:23 -05:00
|
|
|
if *selection.OpenVPN.TCP {
|
2021-05-11 17:10:51 +00:00
|
|
|
protocol = constants.TCP
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-06 06:40:23 -05:00
|
|
|
port, err := getPort(*selection.OpenVPN.TCP, *selection.OpenVPN.CustomPort)
|
2021-05-11 17:10:51 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return connection, err
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 17:06:57 +00:00
|
|
|
servers, err := utils.FilterServers(p.servers, selection)
|
2021-05-11 17:10:51 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return connection, err
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-16 21:58:42 +02:00
|
|
|
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)
|
2021-05-11 17:10:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-28 19:07:44 +00:00
|
|
|
return utils.PickConnection(connections, selection, p.randSource)
|
2021-05-11 17:10:51 +00:00
|
|
|
}
|