diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2024-03-07 14:52:17 +0100 |
|---|---|---|
| committer | Jeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com> | 2024-03-07 15:19:43 +0100 |
| commit | 3be9c620fc7e9d7616124b5bcdaafa3d509ae1ff (patch) | |
| tree | 78f6dfbcc4a93ad17ad6d12fdca338ff77a2851b | |
| parent | 96092bf0f243da114e79d5e491295b69fadf9caa (diff) | |
Client + Server: Add a way to obtain the cached profiles list
| -rw-r--r-- | client/client.go | 9 | ||||
| -rw-r--r-- | internal/server/server.go | 16 |
2 files changed, 15 insertions, 10 deletions
diff --git a/client/client.go b/client/client.go index f6c8279..127c790 100644 --- a/client/client.go +++ b/client/client.go @@ -70,16 +70,11 @@ func (c *Client) GettingConfig() error { // It is called when a profile is invalid // Here we call the AskProfile transition func (c *Client) InvalidProfile(ctx context.Context, srv *server.Server) (string, error) { - // TODO: should this have profiles as a parameter ck := cookie.NewWithContext(ctx) - - prfs, err := srv.Profiles(ctx) + prfs, err := srv.Profiles() if err != nil { return "", err } - if !c.SupportsWireguard { - prfs = prfs.FilterWireGuard() - } // we are guaranteed to have profiles > 0 (even after filtering) // because internally this callback is only triggered if there is a choice to make @@ -87,7 +82,7 @@ func (c *Client) InvalidProfile(ctx context.Context, srv *server.Server) (string go func() { err := c.FSM.GoTransitionRequired(StateAskProfile, &srvtypes.RequiredAskTransition{ C: ck, - Data: prfs.Public(), + Data: prfs, }) if err != nil { errChan <- err diff --git a/internal/server/server.go b/internal/server/server.go index d622aef..97a25b4 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -35,10 +35,19 @@ func (s *Servers) NewServer(identifier string, t srvtypes.Type, api *api.API) Se } } -// Profiles gets the profiles for the server +// Profiles gets the cached profiles from the configuration/state file +func (s *Server) Profiles() (*srvtypes.Profiles, error) { + cfgs, err := s.cfgServer() + if err != nil { + return nil, err + } + return &cfgs.Profiles, nil +} + +// FreshProfiles gets the profiles for the server // It only does a /info network request if the profiles have not been cached // force indicates whether or not the profiles should be fetched fresh -func (s *Server) Profiles(ctx context.Context) (*profiles.Info, error) { +func (s *Server) FreshProfiles(ctx context.Context) (*profiles.Info, error) { a, err := s.api() if err != nil { return nil, err @@ -48,6 +57,7 @@ func (s *Server) Profiles(ctx context.Context) (*profiles.Info, error) { if err != nil { return nil, err } + // Update the profile list in the config err = s.SetProfileList(prfs.Public()) if err != nil { return nil, err @@ -64,7 +74,7 @@ func (s *Server) api() (*api.API, error) { func (s *Server) findProfile(ctx context.Context, wgSupport bool) (*profiles.Profile, error) { // Get the profiles by ignoring the cache - prfs, err := s.Profiles(ctx) + prfs, err := s.FreshProfiles(ctx) if err != nil { return nil, err } |
