Feat: IVPN supports TCP and custom port

This commit is contained in:
Quentin McGaw (desktop)
2021-08-23 13:34:00 +00:00
parent c348343b22
commit f41fec57ed
8 changed files with 454 additions and 86 deletions

View File

@@ -1,23 +1,16 @@
package ivpn
import (
"errors"
"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 (i *Ivpn) GetConnection(selection configuration.ServerSelection) (
connection models.Connection, err error) {
const port = 2049
const protocol = constants.UDP
if selection.OpenVPN.TCP {
return connection, ErrProtocolUnsupported
}
port := getPort(selection)
protocol := getProtocol(selection.OpenVPN.TCP)
servers, err := i.filterServers(selection)
if err != nil {
@@ -44,3 +37,22 @@ func (i *Ivpn) GetConnection(selection configuration.ServerSelection) (
return utils.PickRandomConnection(connections, i.randSource), nil
}
func getPort(selection configuration.ServerSelection) (port uint16) {
customPort := selection.OpenVPN.CustomPort
if customPort > 0 {
return customPort
}
port = 1194
if selection.OpenVPN.TCP {
port = 443
}
return port
}
func getProtocol(tcp bool) (protocol string) {
if tcp {
return constants.TCP
}
return constants.UDP
}