From 6981666c6d8f639a1ff9c09a3bc08769e19928af Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Tue, 20 Dec 2022 15:35:44 +0100 Subject: Failover: Initial implementation --- internal/server/base.go | 2 +- internal/server/profile.go | 4 ++-- internal/server/server.go | 8 +++++--- 3 files changed, 8 insertions(+), 6 deletions(-) (limited to 'internal/server') diff --git a/internal/server/base.go b/internal/server/base.go index 6eb305b..dd15aff 100644 --- a/internal/server/base.go +++ b/internal/server/base.go @@ -30,7 +30,7 @@ func (b *Base) ValidProfiles(wireguardSupport bool) ProfileInfo { for _, p := range b.Profiles.Info.ProfileList { // Not a valid profile because it does not support openvpn // Also the client does not support wireguard - if !p.supportsOpenVPN() && !wireguardSupport { + if !p.SupportsOpenVPN() && !wireguardSupport { continue } valid = append(valid, p) diff --git a/internal/server/profile.go b/internal/server/profile.go index 97781e4..d981421 100644 --- a/internal/server/profile.go +++ b/internal/server/profile.go @@ -35,10 +35,10 @@ func (profile *Profile) supportsProtocol(protocol string) bool { return false } -func (profile *Profile) supportsWireguard() bool { +func (profile *Profile) SupportsWireguard() bool { return profile.supportsProtocol("wireguard") } -func (profile *Profile) supportsOpenVPN() bool { +func (profile *Profile) SupportsOpenVPN() bool { return profile.supportsProtocol("openvpn") } diff --git a/internal/server/server.go b/internal/server/server.go index 9354883..78f6472 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -1,6 +1,7 @@ package server import ( + "os" "time" "github.com/eduvpn/eduvpn-common/internal/oauth" @@ -219,7 +220,7 @@ func HasValidProfile(srv Server, wireguardSupport bool) (bool, error) { return false, err } // Profile does not support OpenVPN but the client also doesn't support WireGuard - if !p.supportsOpenVPN() && !wireguardSupport { + if !p.SupportsOpenVPN() && !wireguardSupport { return false, nil } return true, nil @@ -242,8 +243,9 @@ func Config(server Server, wireguardSupport bool, preferTCP bool) (string, strin return "", "", err } - ovpn := p.supportsOpenVPN() - wg := p.supportsWireguard() && wireguardSupport + ovpn := p.SupportsOpenVPN() + wg := p.SupportsWireguard() && wireguardSupport + // If we don't prefer TCP and this profile and client supports wireguard, // we disable openvpn if the EDUVPN_PREFER_WG environment variable is set // This is useful to force WireGuard if the profile supports both OpenVPN and WireGuard but the server still prefers OpenVPN -- cgit v1.2.3