diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-07-12 14:21:58 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-07-12 14:21:58 +0200 |
| commit | f287501fde1be3bd7cb2bc2c163d309738e507a0 (patch) | |
| tree | b20a2489a2b8fd1f86b9e5446f9813b123caeab4 | |
| parent | 3dc35af5e0b194c0f23b6b8cfd24337a2861380a (diff) | |
State + FSM: Implement a loading server state
| -rw-r--r-- | internal/fsm/fsm.go | 8 | ||||
| -rw-r--r-- | state.go | 3 |
2 files changed, 10 insertions, 1 deletions
diff --git a/internal/fsm/fsm.go b/internal/fsm/fsm.go index be27b09..f07a2fd 100644 --- a/internal/fsm/fsm.go +++ b/internal/fsm/fsm.go @@ -42,6 +42,9 @@ const ( // The user is currently selecting a server in the UI SEARCH_SERVER + // We are loading the server details + LOADING_SERVER + // Chosen Server means the user has chosen a server to connect to CHOSEN_SERVER @@ -74,6 +77,8 @@ func (s FSMStateID) String() string { return "Ask_Location" case SEARCH_SERVER: return "Search_Server" + case LOADING_SERVER: + return "Loading_Server" case CHOSEN_SERVER: return "Chosen_Server" case OAUTH_STARTED: @@ -125,7 +130,8 @@ func (fsm *FSM) Init(name string, callback func(string, string, string), logger DEREGISTERED: FSMState{Transitions: []FSMTransition{{NO_SERVER, "Client registers"}}, MainState: true}, NO_SERVER: FSMState{Transitions: []FSMTransition{{CHOSEN_SERVER, "User chooses a server"}, {SEARCH_SERVER, "The user is trying to choose a Server in the UI"}, {ASK_LOCATION, "User chooses a Secure Internet server but no location is configured"}}, MainState: true}, ASK_LOCATION: FSMState{Transitions: []FSMTransition{{CHOSEN_SERVER, "Location chosen"}, {NO_SERVER, "Cancel or Error"}}}, - SEARCH_SERVER: FSMState{Transitions: []FSMTransition{{CHOSEN_SERVER, "User clicks a server in the UI"}, {NO_SERVER, "Cancel or Error"}}, MainState: true}, + SEARCH_SERVER: FSMState{Transitions: []FSMTransition{{LOADING_SERVER, "User clicks a server in the UI"}, {NO_SERVER, "Cancel or Error"}}, MainState: true}, + LOADING_SERVER: FSMState{Transitions: []FSMTransition{{CHOSEN_SERVER, "Server info loaded"}}}, CHOSEN_SERVER: FSMState{Transitions: []FSMTransition{{AUTHORIZED, "Found tokens in config"}, {OAUTH_STARTED, "No tokens found in config"}}}, OAUTH_STARTED: FSMState{Transitions: []FSMTransition{{AUTHORIZED, "User authorizes with browser"}, {NO_SERVER, "Cancel or Error"}, {SEARCH_SERVER, "Cancel or Error"}}}, AUTHORIZED: FSMState{Transitions: []FSMTransition{{OAUTH_STARTED, "Re-authorize with OAuth"}, {REQUEST_CONFIG, "Client requests a config"}}}, @@ -194,6 +194,7 @@ func (state *VPNState) addSecureInternetHomeServer(orgID string) (server.Server, func (state *VPNState) GetConfigSecureInternet(orgID string, forceTCP bool) (string, string, error) { errorMessage := fmt.Sprintf("failed getting a configuration for Secure Internet organization %s", orgID) + state.FSM.GoTransition(fsm.LOADING_SERVER) server, serverErr := state.addSecureInternetHomeServer(orgID) if serverErr != nil { @@ -242,6 +243,7 @@ func (state *VPNState) addCustomServer(url string) (server.Server, error) { func (state *VPNState) GetConfigInstituteAccess(url string, forceTCP bool) (string, string, error) { errorMessage := fmt.Sprintf("failed getting a configuration for Institute Access %s", url) + state.FSM.GoTransition(fsm.LOADING_SERVER) server, serverErr := state.addInstituteServer(url) if serverErr != nil { @@ -253,6 +255,7 @@ func (state *VPNState) GetConfigInstituteAccess(url string, forceTCP bool) (stri func (state *VPNState) GetConfigCustomServer(url string, forceTCP bool) (string, string, error) { errorMessage := fmt.Sprintf("failed getting a configuration for custom server %s", url) + state.FSM.GoTransition(fsm.LOADING_SERVER) server, serverErr := state.addCustomServer(url) if serverErr != nil { |
