diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2024-03-14 12:21:20 +0100 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2024-03-14 16:04:20 +0100 |
| commit | b98fbee125dd15bbd083de62f7b636ccd0e0248e (patch) | |
| tree | 9ae45596806e0f4e6a16d78c9675e936b5fc278e /internal | |
| parent | c1c2011ec83553a2de7661f89383be4b29883db6 (diff) | |
All: Make WireGuard support mandatory
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/api/profiles/profiles.go | 15 | ||||
| -rw-r--r-- | internal/server/server.go | 28 | ||||
| -rw-r--r-- | internal/server/servers.go | 9 |
3 files changed, 11 insertions, 41 deletions
diff --git a/internal/api/profiles/profiles.go b/internal/api/profiles/profiles.go index 1df17e3..eba5ece 100644 --- a/internal/api/profiles/profiles.go +++ b/internal/api/profiles/profiles.go @@ -100,21 +100,6 @@ func (p *Profile) HasWireGuard() bool { return hasProtocol(p.VPNProtoList, protocol.WireGuard) } -// FilterWireGuard gets a profile list but without WireGuard profiles -func (i Info) FilterWireGuard() *Info { - var ret []Profile - for _, p := range i.Info.ProfileList { - if !p.HasOpenVPN() { - continue - } - } - return &Info{ - Info: ListInfo{ - ProfileList: ret, - }, - } -} - // Public gets the server list as a structure that we return to clients func (i Info) Public() server.Profiles { m := make(map[string]server.Profile) diff --git a/internal/server/server.go b/internal/server/server.go index 97a25b4..1182f15 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -72,30 +72,20 @@ func (s *Server) api() (*api.API, error) { return s.apiw, nil } -func (s *Server) findProfile(ctx context.Context, wgSupport bool) (*profiles.Profile, error) { +func (s *Server) findProfile(ctx context.Context) (*profiles.Profile, error) { // Get the profiles by ignoring the cache prfs, err := s.FreshProfiles(ctx) if err != nil { return nil, err } - // No profiles available - if prfs.Len() == 0 { - return nil, errors.New("the server has no available profiles for your account") - } - - // No WireGuard support, we have to filter the profiles that only have WireGuard - if !wgSupport { - prfs = prfs.FilterWireGuard() - } - var chosenP profiles.Profile n := prfs.Len() switch n { // If we now get no profiles then that means a profile with only WireGuard was removed case 0: - return nil, errors.New("the server has only WireGuard profiles but the client does not support WireGuard") + return nil, errors.New("the server has no available profiles for your account") case 1: // Only one profile, make sure it is set chosenP = prfs.MustIndex(0) @@ -114,14 +104,14 @@ func (s *Server) findProfile(ctx context.Context, wgSupport bool) (*profiles.Pro return &chosenP, nil } -func (s *Server) connect(ctx context.Context, wgSupport bool, pTCP bool) (*srvtypes.Configuration, error) { +func (s *Server) connect(ctx context.Context, pTCP bool) (*srvtypes.Configuration, error) { a, err := s.api() if err != nil { return nil, err } // find a suitable profile to connect - chosenP, err := s.findProfile(ctx, wgSupport) + chosenP, err := s.findProfile(ctx) if err != nil { return nil, err } @@ -130,13 +120,11 @@ func (s *Server) connect(ctx context.Context, wgSupport bool, pTCP bool) (*srvty return nil, err } - protos := []protocol.Protocol{protocol.OpenVPN} - if wgSupport { - protos = append(protos, protocol.WireGuard) - } - // If the client supports WireGuard and the profile supports both protocols we remove openvpn from client support if EDUVPN_PREFER_WG is set to "1" + // protos supported by the client + protos := []protocol.Protocol{protocol.OpenVPN, protocol.WireGuard} + // If profile supports both protocols we remove openvpn from client support if EDUVPN_PREFER_WG is set to "1" // This also only happens if prefer TCP is set to false - if wgSupport && os.Getenv("EDUVPN_PREFER_WG") == "1" { + if os.Getenv("EDUVPN_PREFER_WG") == "1" { if chosenP.HasWireGuard() && chosenP.HasOpenVPN() { protos = []protocol.Protocol{protocol.WireGuard} } diff --git a/internal/server/servers.go b/internal/server/servers.go index 64e64b6..36f9ea7 100644 --- a/internal/server/servers.go +++ b/internal/server/servers.go @@ -26,8 +26,6 @@ type Callbacks interface { type Servers struct { clientID string cb Callbacks - // WGSupport defines whether or not wireguard support is enabled - WGSupport bool config *v2.V2 } @@ -37,11 +35,10 @@ func (s *Servers) Remove(identifier string, t srvtypes.Type) error { } // NewServers creates a new servers struct -func NewServers(name string, cb Callbacks, wgSupport bool, cfg *v2.V2) Servers { +func NewServers(name string, cb Callbacks, cfg *v2.V2) Servers { return Servers{ clientID: name, cb: cb, - WGSupport: wgSupport, config: cfg, } } @@ -107,7 +104,7 @@ func (s *Servers) ConnectWithCallbacks(ctx context.Context, srv *Server, pTCP bo if err != nil { return nil, err } - cfg, err := srv.connect(ctx, s.WGSupport, pTCP) + cfg, err := srv.connect(ctx, pTCP) if err == nil { return cfg, nil } @@ -127,5 +124,5 @@ func (s *Servers) ConnectWithCallbacks(ctx context.Context, srv *Server, pTCP bo if err != nil { return nil, err } - return srv.connect(ctx, s.WGSupport, pTCP) + return srv.connect(ctx, pTCP) } |
