From fe5f8c80298e46a6940e3ad087f559942edb4a06 Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Wed, 7 Feb 2024 13:45:10 +0100 Subject: API + Server: Support vpn_proto_transport_list --- internal/api/profiles/profiles.go | 18 ++++++++++++++++++ internal/server/server.go | 1 + 2 files changed, 19 insertions(+) (limited to 'internal') diff --git a/internal/api/profiles/profiles.go b/internal/api/profiles/profiles.go index 2f4fed7..7b9dafc 100644 --- a/internal/api/profiles/profiles.go +++ b/internal/api/profiles/profiles.go @@ -9,6 +9,7 @@ type Profile struct { ID string `json:"profile_id"` DisplayName string `json:"display_name"` VPNProtoList []string `json:"vpn_proto_list"` + VPNProtoTransportList []string `json:"vpn_proto_transport_list"` DefaultGateway bool `json:"default_gateway"` DNSSearchDomains []string `json:"dns_search_domain_list"` } @@ -47,6 +48,23 @@ func hasProtocol(protos []string, proto protocol.Protocol) bool { return false } +func (p *Profile) ShouldFailover() bool { + // old servers don't support it, only failover in case OpenVPN is supported + if len(p.VPNProtoTransportList) == 0 { + // this checks VPNProtoList + return p.HasOpenVPN() + } + for _, c := range p.VPNProtoTransportList { + if c == "wireguard+tcp" { + return true + } + if c == "openvpn+tcp" { + return true + } + } + return false +} + func (p *Profile) HasOpenVPN() bool { return hasProtocol(p.VPNProtoList, protocol.OpenVPN) } diff --git a/internal/server/server.go b/internal/server/server.go index 97dafff..1f73791 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -150,6 +150,7 @@ func (s *Server) connect(ctx context.Context, wgSupport bool, pTCP bool) (*srvty Protocol: apicfg.Protocol, DefaultGateway: chosenP.DefaultGateway, DNSSearchDomains: chosenP.DNSSearchDomains, + ShouldFailover: chosenP.ShouldFailover(), Proxy: proxy, }, nil } -- cgit v1.2.3