summaryrefslogtreecommitdiff
path: root/internal/server/common.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-10-04 14:53:58 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-10-04 14:53:58 +0200
commit762a034cc1af55d09dc0a174947356e36bf15569 (patch)
tree4c29d0ebd131a919accc944599d3c10ba61b09d2 /internal/server/common.go
parent0096d0471fef972e305a61435623d64b7da4f0d9 (diff)
Server: Implement `prefer_tcp` according to spec
Diffstat (limited to 'internal/server/common.go')
-rw-r--r--internal/server/common.go19
1 files changed, 6 insertions, 13 deletions
diff --git a/internal/server/common.go b/internal/server/common.go
index 36dba32..6f57c7f 100644
--- a/internal/server/common.go
+++ b/internal/server/common.go
@@ -324,7 +324,7 @@ func getCurrentProfile(server Server) (*ServerProfile, error) {
}
}
-func wireguardGetConfig(server Server, supportsOpenVPN bool) (string, string, error) {
+func wireguardGetConfig(server Server, preferTCP bool, supportsOpenVPN bool) (string, string, error) {
errorMessage := "failed getting server WireGuard configuration"
base, baseErr := server.GetBase()
@@ -344,6 +344,7 @@ func wireguardGetConfig(server Server, supportsOpenVPN bool) (string, string, er
server,
profile_id,
wireguardPublicKey,
+ preferTCP,
supportsOpenVPN,
)
@@ -366,7 +367,7 @@ func wireguardGetConfig(server Server, supportsOpenVPN bool) (string, string, er
return config, content, nil
}
-func openVPNGetConfig(server Server) (string, string, error) {
+func openVPNGetConfig(server Server, preferTCP bool) (string, string, error) {
errorMessage := "failed getting server OpenVPN configuration"
base, baseErr := server.GetBase()
@@ -374,7 +375,7 @@ func openVPNGetConfig(server Server) (string, string, error) {
return "", "", &types.WrappedErrorMessage{Message: errorMessage, Err: baseErr}
}
profile_id := base.Profiles.Current
- configOpenVPN, expires, configErr := APIConnectOpenVPN(server, profile_id)
+ configOpenVPN, expires, configErr := APIConnectOpenVPN(server, profile_id, preferTCP)
// Store start and end time
base.StartTime = util.GetCurrentTime()
@@ -433,14 +434,6 @@ func GetConfig(server Server, preferTCP bool) (string, string, error) {
supportsOpenVPN := profile.supportsOpenVPN()
supportsWireguard := profile.supportsWireguard()
- // If preferTCP we must be able to get a config with OpenVPN
- if preferTCP && supportsOpenVPN {
- return "", "", &types.WrappedErrorMessage{
- Message: errorMessage,
- Err: &ServerGetConfigForceTCPError{},
- }
- }
-
var config string
var configType string
var configErr error
@@ -448,9 +441,9 @@ func GetConfig(server Server, preferTCP bool) (string, string, error) {
if supportsWireguard {
// A wireguard connect call needs to generate a wireguard key and add it to the config
// Also the server could send back an OpenVPN config if it supports OpenVPN
- config, configType, configErr = wireguardGetConfig(server, supportsOpenVPN)
+ config, configType, configErr = wireguardGetConfig(server, preferTCP, supportsOpenVPN)
} else {
- config, configType, configErr = openVPNGetConfig(server)
+ config, configType, configErr = openVPNGetConfig(server, preferTCP)
}
if configErr != nil {