2021-05-11 17:10:51 +00:00
|
|
|
package privado
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"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"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var ErrProtocolUnsupported = errors.New("network protocol is not supported")
|
|
|
|
|
|
|
|
|
|
func (p *Privado) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
|
|
|
|
connection models.OpenVPNConnection, err error) {
|
|
|
|
|
const port = 1194
|
|
|
|
|
const protocol = constants.UDP
|
2021-08-17 16:54:22 +00:00
|
|
|
if selection.OpenVPN.TCP {
|
2021-05-11 17:10:51 +00:00
|
|
|
return connection, fmt.Errorf("%w: TCP for provider Privado", ErrProtocolUnsupported)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
servers, err := p.filterServers(selection)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return connection, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connections := make([]models.OpenVPNConnection, len(servers))
|
|
|
|
|
for i := range servers {
|
|
|
|
|
connection := models.OpenVPNConnection{
|
|
|
|
|
IP: servers[i].IP,
|
|
|
|
|
Port: port,
|
|
|
|
|
Protocol: protocol,
|
|
|
|
|
Hostname: servers[i].Hostname,
|
|
|
|
|
}
|
|
|
|
|
connections[i] = 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, p.randSource), nil
|
2021-05-11 17:10:51 +00:00
|
|
|
}
|