From 948d986fda345ff41da699adf2dbf26144269145 Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Thu, 14 Mar 2024 17:19:25 +0100 Subject: Client + Server: Cache secure internet profile choice per location --- internal/config/v2/v2.go | 3 +++ internal/server/server.go | 21 ++++++++------------- 2 files changed, 11 insertions(+), 13 deletions(-) (limited to 'internal') diff --git a/internal/config/v2/v2.go b/internal/config/v2/v2.go index 050eadd..143d5f2 100644 --- a/internal/config/v2/v2.go +++ b/internal/config/v2/v2.go @@ -25,6 +25,9 @@ type Server struct { // CountryCode is the country code for the server in case of secure internet // Otherwise it is an empty string CountryCode string `json:"country_code,omitempty"` + + // LocationProfiles are current profiles for each secure internet location + LocationProfiles map[string]string `json:"location_profiles,omitempty"` } // ServerKey is the key type of the server map diff --git a/internal/server/server.go b/internal/server/server.go index 1182f15..2148f85 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -178,7 +178,15 @@ func (s *Server) SetProfileID(id string) error { if err != nil { return err } + oldP := cs.Profiles.Current cs.Profiles.Current = id + + if s.t == srvtypes.TypeSecureInternet { + if cs.LocationProfiles == nil { + cs.LocationProfiles = make(map[string]string) + } + cs.LocationProfiles[cs.CountryCode] = oldP + } return nil } @@ -211,19 +219,6 @@ func (s *Server) ProfileID() (string, error) { return cs.Profiles.Current, nil } -// SetLocation sets the secure internet location for the server -func (s *Server) SetLocation(loc string) error { - if s.t != srvtypes.TypeSecureInternet { - return errors.New("changing secure internet location is only possible when the server is a secure location") - } - cs, err := s.cfgServer() - if err != nil { - return err - } - cs.CountryCode = loc - return nil -} - // SetCurrent sets the current server in the state file to this one func (s *Server) SetCurrent() error { if s.storage == nil { -- cgit v1.2.3