Maint: make VPN connection not specific to OpenVPN

- Add VPN field to ServerSelection struct
- Set VPN type to server selection at start using VPN_TYPE
- Change OpenVPNConnection to Connection with Type field
- Rename Provider GetOpenVPNConnection to GetConnection
- Rename GetTargetIPOpenVPNConnection to GetTargetIPConnection
- Rename PickRandomOpenVPNConnection to PickRandomConnection
- Add 'OpenVPN' prefix to OpenVPN specific methods on connection
This commit is contained in:
Quentin McGaw (desktop)
2021-08-19 14:09:41 +00:00
parent 105d81c018
commit 3d8e61900b
54 changed files with 283 additions and 255 deletions

View File

@@ -7,8 +7,8 @@ import (
"github.com/qdm12/gluetun/internal/provider/utils"
)
func (p *PIA) GetOpenVPNConnection(selection configuration.ServerSelection) (
connection models.OpenVPNConnection, err error) {
func (p *PIA) GetConnection(selection configuration.ServerSelection) (
connection models.Connection, err error) {
protocol := constants.UDP
if selection.OpenVPN.TCP {
protocol = constants.TCP
@@ -24,10 +24,11 @@ func (p *PIA) GetOpenVPNConnection(selection configuration.ServerSelection) (
return connection, err
}
var connections []models.OpenVPNConnection
var connections []models.Connection
for _, server := range servers {
for _, IP := range server.IPs {
connection := models.OpenVPNConnection{
connection := models.Connection{
Type: selection.VPN,
IP: IP,
Port: port,
Protocol: protocol,
@@ -38,9 +39,9 @@ func (p *PIA) GetOpenVPNConnection(selection configuration.ServerSelection) (
}
if selection.TargetIP != nil {
connection, err = utils.GetTargetIPOpenVPNConnection(connections, selection.TargetIP)
connection, err = utils.GetTargetIPConnection(connections, selection.TargetIP)
} else {
connection, err = utils.PickRandomOpenVPNConnection(connections, p.randSource), nil
connection, err = utils.PickRandomConnection(connections, p.randSource), nil
}
if err != nil {