2021-05-11 17:10:51 +00:00
|
|
|
package cyberghost
|
|
|
|
|
|
|
|
|
|
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 (c *Cyberghost) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
|
|
|
|
connection models.OpenVPNConnection, err error) {
|
|
|
|
|
const port = 443
|
|
|
|
|
protocol := constants.UDP
|
2021-08-17 16:54:22 +00:00
|
|
|
if selection.OpenVPN.TCP {
|
2021-05-11 17:10:51 +00:00
|
|
|
protocol = constants.TCP
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
servers, err := c.filterServers(selection)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return connection, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var connections []models.OpenVPNConnection
|
|
|
|
|
for _, server := range servers {
|
|
|
|
|
for _, IP := range server.IPs {
|
|
|
|
|
connection := models.OpenVPNConnection{
|
|
|
|
|
IP: IP,
|
|
|
|
|
Port: port,
|
|
|
|
|
Protocol: protocol,
|
|
|
|
|
}
|
|
|
|
|
connections = append(connections, connection)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if selection.TargetIP != nil {
|
2021-08-17 14:08:53 +00:00
|
|
|
return utils.GetTargetIPOpenVPNConnection(connections, selection.TargetIP)
|
2021-05-11 17:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-17 14:08:53 +00:00
|
|
|
return utils.PickRandomOpenVPNConnection(connections, c.randSource), nil
|
2021-05-11 17:10:51 +00:00
|
|
|
}
|