2021-05-11 17:10:51 +00:00
|
|
|
package vyprvpn
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
|
2021-08-19 14:09:41 +00:00
|
|
|
func (v *Vyprvpn) GetConnection(selection configuration.ServerSelection) (
|
|
|
|
|
connection models.Connection, err error) {
|
2021-05-11 17:10:51 +00:00
|
|
|
const port = 443
|
|
|
|
|
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 VyprVPN", ErrProtocolUnsupported)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
servers, err := v.filterServers(selection)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return connection, err
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-19 14:09:41 +00:00
|
|
|
var connections []models.Connection
|
2021-05-11 17:10:51 +00:00
|
|
|
for _, server := range servers {
|
|
|
|
|
for _, IP := range server.IPs {
|
2021-08-19 14:09:41 +00:00
|
|
|
connection := models.Connection{
|
|
|
|
|
Type: selection.VPN,
|
2021-05-11 17:10:51 +00:00
|
|
|
IP: IP,
|
|
|
|
|
Port: port,
|
|
|
|
|
Protocol: protocol,
|
|
|
|
|
}
|
|
|
|
|
connections = append(connections, connection)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-28 19:07:44 +00:00
|
|
|
return utils.PickConnection(connections, selection, v.randSource)
|
2021-05-11 17:10:51 +00:00
|
|
|
}
|