Maint: configuration Openvpn selection structure
- Move network protocol from ServerSelection to OpenVPNSelection child - Move PIA encryption preset from ServerSelection to OpenVPNSelection child - Move custom port from ServerSelection to OpenVPNSelection child
This commit is contained in:
@@ -10,11 +10,11 @@ import (
|
||||
func (p *PIA) GetOpenVPNConnection(selection configuration.ServerSelection) (
|
||||
connection models.OpenVPNConnection, err error) {
|
||||
protocol := constants.UDP
|
||||
if selection.TCP {
|
||||
if selection.OpenVPN.TCP {
|
||||
protocol = constants.TCP
|
||||
}
|
||||
|
||||
port, err := getPort(selection.TCP, selection.EncryptionPreset, selection.CustomPort)
|
||||
port, err := getPort(selection.OpenVPN)
|
||||
if err != nil {
|
||||
return connection, err
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ func (p *PIA) filterServers(selection configuration.ServerSelection) (
|
||||
utils.FilterByPossibilities(server.Region, selection.Regions),
|
||||
utils.FilterByPossibilities(server.Hostname, selection.Hostnames),
|
||||
utils.FilterByPossibilities(server.ServerName, selection.Names),
|
||||
selection.TCP && !server.TCP,
|
||||
!selection.TCP && !server.UDP:
|
||||
selection.OpenVPN.TCP && !server.TCP,
|
||||
!selection.OpenVPN.TCP && !server.UDP:
|
||||
default:
|
||||
servers = append(servers, server)
|
||||
}
|
||||
|
||||
@@ -4,20 +4,21 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
)
|
||||
|
||||
func getPort(tcp bool, encryptionPreset string, customPort uint16) (
|
||||
func getPort(openvpnSelection configuration.OpenVPNSelection) (
|
||||
port uint16, err error) {
|
||||
if customPort == 0 {
|
||||
return getDefaultPort(tcp, encryptionPreset), nil
|
||||
if openvpnSelection.CustomPort == 0 {
|
||||
return getDefaultPort(openvpnSelection.TCP, openvpnSelection.EncPreset), nil
|
||||
}
|
||||
|
||||
if err := checkPort(customPort, tcp); err != nil {
|
||||
if err := checkPort(openvpnSelection.CustomPort, openvpnSelection.TCP); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return customPort, nil
|
||||
return openvpnSelection.CustomPort, nil
|
||||
}
|
||||
|
||||
func getDefaultPort(tcp bool, encryptionPreset string) (port uint16) {
|
||||
|
||||
Reference in New Issue
Block a user