diff options
Diffstat (limited to 'client')
| -rw-r--r-- | client/client.go | 10 | ||||
| -rw-r--r-- | client/client_test.go | 34 | ||||
| -rw-r--r-- | client/fsm.go | 246 | ||||
| -rw-r--r-- | client/server.go | 72 |
4 files changed, 181 insertions, 181 deletions
diff --git a/client/client.go b/client/client.go index 63e4f91..6ef9a9f 100644 --- a/client/client.go +++ b/client/client.go @@ -77,7 +77,7 @@ func (client *Client) Register( debug bool, ) error { errorMessage := "failed to register with the GO library" - if !client.InFSMState(STATE_DEREGISTERED) { + if !client.InFSMState(StateDeregistered) { return client.handleError( errorMessage, FSMDeregisteredError{}.CustomError(), @@ -89,9 +89,9 @@ func (client *Client) Register( client.Language = language // Initialize the logger - logLevel := log.LOG_WARNING + logLevel := log.LogWarning if debug { - logLevel = log.LOG_DEBUG + logLevel = log.LogDebug } loggerErr := client.Logger.Init(logLevel, directory) @@ -118,7 +118,7 @@ func (client *Client) Register( } // Go to the No Server state with the saved servers after we're done - defer client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers) + defer client.FSM.GoTransitionWithData(StateNoServer, client.Servers) // Let's Connect! doesn't care about discovery if client.isLetsConnect() { @@ -160,7 +160,7 @@ func (client *Client) askProfile(chosenServer server.Server) error { if profilesErr != nil { return types.NewWrappedError(errorMessage, profilesErr) } - goTransitionErr := client.FSM.GoTransitionRequired(STATE_ASK_PROFILE, profiles) + goTransitionErr := client.FSM.GoTransitionRequired(StateAskProfile, profiles) if goTransitionErr != nil { return types.NewWrappedError(errorMessage, goTransitionErr) } diff --git a/client/client_test.go b/client/client_test.go index adf5c75..ad4fead 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -63,7 +63,7 @@ func stateCallback( data interface{}, state *Client, ) { - if newState == STATE_OAUTH_STARTED { + if newState == StateOAuthStarted { url, ok := data.(string) if !ok { @@ -73,7 +73,7 @@ func stateCallback( } } -func Test_server(t *testing.T) { +func TestServer(t *testing.T) { serverURI := getServerURI(t) state := &Client{} @@ -101,7 +101,7 @@ func Test_server(t *testing.T) { } } -func test_connect_oauth_parameter( +func testConnectOAuthParameter( t *testing.T, parameters httpw.URLParameters, expectedErr interface{}, @@ -115,7 +115,7 @@ func test_connect_oauth_parameter( configDirectory, "en", func(oldState FSMStateID, newState FSMStateID, data interface{}) bool { - if newState == STATE_OAUTH_STARTED { + if newState == StateOAuthStarted { server, serverErr := state.Servers.GetCustomServer(serverURI) if serverErr != nil { t.Fatalf("No server with error: %v", serverErr) @@ -168,7 +168,7 @@ func test_connect_oauth_parameter( } } -func Test_connect_oauth_parameters(t *testing.T) { +func TestConnectOAuthParameters(t *testing.T) { var ( failedCallbackParameterError *oauth.OAuthCallbackParameterError failedCallbackStateMatchError *oauth.OAuthCallbackStateMatchError @@ -194,11 +194,11 @@ func Test_connect_oauth_parameters(t *testing.T) { } for _, test := range tests { - test_connect_oauth_parameter(t, test.parameters, test.expectedErr) + testConnectOAuthParameter(t, test.parameters, test.expectedErr) } } -func Test_token_expired(t *testing.T) { +func TestTokenExpired(t *testing.T) { serverURI := getServerURI(t) expiredTTL := os.Getenv("OAUTH_EXPIRED_TTL") if expiredTTL == "" { @@ -274,7 +274,7 @@ func Test_token_expired(t *testing.T) { } } -func Test_token_invalid(t *testing.T) { +func TestTokenInvalid(t *testing.T) { serverURI := getServerURI(t) state := &Client{} @@ -303,7 +303,7 @@ func Test_token_invalid(t *testing.T) { t.Fatalf("Connect error before invalid: %v", configErr) } - dummy_value := "37" + dummyValue := "37" currentServer, serverErr := state.Servers.GetCurrentServer() if serverErr != nil { @@ -313,8 +313,8 @@ func Test_token_invalid(t *testing.T) { oauth := currentServer.GetOAuth() // Override tokens with invalid values - oauth.Token.Access = dummy_value - oauth.Token.Refresh = dummy_value + oauth.Token.Access = dummyValue + oauth.Token.Refresh = dummyValue _, _, configErr = state.GetConfigCustomServer(serverURI, false) @@ -322,17 +322,17 @@ func Test_token_invalid(t *testing.T) { t.Fatalf("Connect error after invalid: %v", configErr) } - if oauth.Token.Access == dummy_value { - t.Errorf("Access token is equal to dummy value: %s", dummy_value) + if oauth.Token.Access == dummyValue { + t.Errorf("Access token is equal to dummy value: %s", dummyValue) } - if oauth.Token.Refresh == dummy_value { - t.Errorf("Refresh token is equal to dummy value: %s", dummy_value) + if oauth.Token.Refresh == dummyValue { + t.Errorf("Refresh token is equal to dummy value: %s", dummyValue) } } // Test if an invalid profile will be corrected -func Test_invalid_profile_corrected(t *testing.T) { +func TestInvalidProfileCorrected(t *testing.T) { serverURI := getServerURI(t) state := &Client{} @@ -390,7 +390,7 @@ func Test_invalid_profile_corrected(t *testing.T) { } // Test if prefer tcp is handled correctly by checking the returned config and config type -func Test_prefer_tcp(t *testing.T) { +func TestPreferTCP(t *testing.T) { serverURI := getServerURI(t) state := &Client{} diff --git a/client/fsm.go b/client/fsm.go index bfe9c63..2ce60ba 100644 --- a/client/fsm.go +++ b/client/fsm.go @@ -17,78 +17,78 @@ type ( ) const ( - // Deregistered means the app is not registered with the wrapper - STATE_DEREGISTERED FSMStateID = iota + // StateDeregistered means the app is not registered with the wrapper + StateDeregistered FSMStateID = iota - // No Server means the user has not chosen a server yet - STATE_NO_SERVER + // StateNoServer means the user has not chosen a server yet + StateNoServer - // The user selected a Secure Internet server but needs to choose a location - STATE_ASK_LOCATION + // StateAskLocation means the user selected a Secure Internet server but needs to choose a location + StateAskLocation - // The user is currently selecting a server in the UI - STATE_SEARCH_SERVER + // StateSearchServer means the user is currently selecting a server in the UI + StateSearchServer - // We are loading the server details - STATE_LOADING_SERVER + // StateLoadingServer means we are loading the server details + StateLoadingServer - // Chosen Server means the user has chosen a server to connect to - STATE_CHOSEN_SERVER + // StateChosenServer means the user has chosen a server to connect to + StateChosenServer - // OAuth Started means the OAuth process has started - STATE_OAUTH_STARTED + // StateOAuthStarted means the OAuth process has started + StateOAuthStarted - // Authorized means the OAuth process has finished and the user is now authorized with the server - STATE_AUTHORIZED + // StateAuthorized means the OAuth process has finished and the user is now authorized with the server + StateAuthorized - // Requested config means the user has requested a config for connecting - STATE_REQUEST_CONFIG + // StateRequestConfig means the user has requested a config for connecting + StateRequestConfig - // Ask profile means the go code is asking for a profile selection from the UI - STATE_ASK_PROFILE + // StateAskProfile means the go code is asking for a profile selection from the UI + StateAskProfile - // Disconnected means the user has gotten a config for a server but is not connected yet - STATE_DISCONNECTED + // StateDisconnected means the user has gotten a config for a server but is not connected yet + StateDisconnected - // Disconnecting means the OS is disconnecting and the Go code is doing the /disconnect - STATE_DISCONNECTING + // StateDisconnecting means the OS is disconnecting and the Go code is doing the /disconnect + StateDisconnecting - // Connecting means the OS is establishing a connection to the server - STATE_CONNECTING + // StateConnecting means the OS is establishing a connection to the server + StateConnecting - // Connected means the user has been connected to the server - STATE_CONNECTED + // StateConnected means the user has been connected to the server + StateConnected ) func GetStateName(s FSMStateID) string { switch s { - case STATE_DEREGISTERED: + case StateDeregistered: return "Deregistered" - case STATE_NO_SERVER: + case StateNoServer: return "No_Server" - case STATE_ASK_LOCATION: + case StateAskLocation: return "Ask_Location" - case STATE_SEARCH_SERVER: + case StateSearchServer: return "Search_Server" - case STATE_LOADING_SERVER: + case StateLoadingServer: return "Loading_Server" - case STATE_CHOSEN_SERVER: + case StateChosenServer: return "Chosen_Server" - case STATE_OAUTH_STARTED: + case StateOAuthStarted: return "OAuth_Started" - case STATE_DISCONNECTED: + case StateDisconnected: return "Disconnected" - case STATE_REQUEST_CONFIG: + case StateRequestConfig: return "Request_Config" - case STATE_ASK_PROFILE: + case StateAskProfile: return "Ask_Profile" - case STATE_AUTHORIZED: + case StateAuthorized: return "Authorized" - case STATE_DISCONNECTING: + case StateDisconnecting: return "Disconnecting" - case STATE_CONNECTING: + case StateConnecting: return "Connecting" - case STATE_CONNECTED: + case StateConnected: return "Connected" default: panic("unknown conversion of state to string") @@ -101,107 +101,107 @@ func newFSM( debug bool, ) fsm.FSM { states := FSMStates{ - STATE_DEREGISTERED: FSMState{ - Transitions: []FSMTransition{{To: STATE_NO_SERVER, Description: "Client registers"}}, + StateDeregistered: FSMState{ + Transitions: []FSMTransition{{To: StateNoServer, Description: "Client registers"}}, }, - STATE_NO_SERVER: FSMState{ + StateNoServer: FSMState{ Transitions: []FSMTransition{ - {To: STATE_NO_SERVER, Description: "Reload list"}, - {To: STATE_LOADING_SERVER, Description: "User clicks a server in the UI"}, - {To: STATE_CHOSEN_SERVER, Description: "The server has been chosen"}, - {To: STATE_SEARCH_SERVER, Description: "The user is trying to choose a new server in the UI"}, - {To: STATE_CONNECTED, Description: "The user is already connected"}, - {To: STATE_ASK_LOCATION, Description: "Change the location in the main screen"}, + {To: StateNoServer, Description: "Reload list"}, + {To: StateLoadingServer, Description: "User clicks a server in the UI"}, + {To: StateChosenServer, Description: "The server has been chosen"}, + {To: StateSearchServer, Description: "The user is trying to choose a new server in the UI"}, + {To: StateConnected, Description: "The user is already connected"}, + {To: StateAskLocation, Description: "Change the location in the main screen"}, }, }, - STATE_SEARCH_SERVER: FSMState{ + StateSearchServer: FSMState{ Transitions: []FSMTransition{ - {To: STATE_LOADING_SERVER, Description: "User clicks a server in the UI"}, - {To: STATE_NO_SERVER, Description: "Cancel or Error"}, + {To: StateLoadingServer, Description: "User clicks a server in the UI"}, + {To: StateNoServer, Description: "Cancel or Error"}, }, - BackState: STATE_NO_SERVER, + BackState: StateNoServer, }, - STATE_ASK_LOCATION: FSMState{ + StateAskLocation: FSMState{ Transitions: []FSMTransition{ - {To: STATE_CHOSEN_SERVER, Description: "Location chosen"}, - {To: STATE_NO_SERVER, Description: "Go back or Error"}, - {To: STATE_SEARCH_SERVER, Description: "Cancel or Error"}, + {To: StateChosenServer, Description: "Location chosen"}, + {To: StateNoServer, Description: "Go back or Error"}, + {To: StateSearchServer, Description: "Cancel or Error"}, }, }, - STATE_LOADING_SERVER: FSMState{ + StateLoadingServer: FSMState{ Transitions: []FSMTransition{ - {To: STATE_CHOSEN_SERVER, Description: "Server info loaded"}, + {To: StateChosenServer, Description: "Server info loaded"}, { - To: STATE_ASK_LOCATION, + To: StateAskLocation, Description: "User chooses a Secure Internet server but no location is configured", }, - {To: STATE_NO_SERVER, Description: "Go back or Error"}, + {To: StateNoServer, Description: "Go back or Error"}, }, - BackState: STATE_NO_SERVER, + BackState: StateNoServer, }, - STATE_CHOSEN_SERVER: FSMState{ + StateChosenServer: FSMState{ Transitions: []FSMTransition{ - {To: STATE_AUTHORIZED, Description: "Found tokens in config"}, - {To: STATE_OAUTH_STARTED, Description: "No tokens found in config"}, + {To: StateAuthorized, Description: "Found tokens in config"}, + {To: StateOAuthStarted, Description: "No tokens found in config"}, }, }, - STATE_OAUTH_STARTED: FSMState{ + StateOAuthStarted: FSMState{ Transitions: []FSMTransition{ - {To: STATE_AUTHORIZED, Description: "User authorizes with browser"}, - {To: STATE_NO_SERVER, Description: "Go back or Error"}, - {To: STATE_SEARCH_SERVER, Description: "Cancel or Error"}, + {To: StateAuthorized, Description: "User authorizes with browser"}, + {To: StateNoServer, Description: "Go back or Error"}, + {To: StateSearchServer, Description: "Cancel or Error"}, }, - BackState: STATE_NO_SERVER, + BackState: StateNoServer, }, - STATE_AUTHORIZED: FSMState{ + StateAuthorized: FSMState{ Transitions: []FSMTransition{ - {To: STATE_OAUTH_STARTED, Description: "Re-authorize with OAuth"}, - {To: STATE_REQUEST_CONFIG, Description: "Client requests a config"}, - {To: STATE_NO_SERVER, Description: "Client wants to go back to the main screen"}, + {To: StateOAuthStarted, Description: "Re-authorize with OAuth"}, + {To: StateRequestConfig, Description: "Client requests a config"}, + {To: StateNoServer, Description: "Client wants to go back to the main screen"}, }, }, - STATE_REQUEST_CONFIG: FSMState{ + StateRequestConfig: FSMState{ Transitions: []FSMTransition{ - {To: STATE_ASK_PROFILE, Description: "Multiple profiles found and no profile chosen"}, - {To: STATE_DISCONNECTED, Description: "Only one profile or profile already chosen"}, - {To: STATE_NO_SERVER, Description: "Cancel or Error"}, - {To: STATE_OAUTH_STARTED, Description: "Re-authorize"}, + {To: StateAskProfile, Description: "Multiple profiles found and no profile chosen"}, + {To: StateDisconnected, Description: "Only one profile or profile already chosen"}, + {To: StateNoServer, Description: "Cancel or Error"}, + {To: StateOAuthStarted, Description: "Re-authorize"}, }, }, - STATE_ASK_PROFILE: FSMState{ + StateAskProfile: FSMState{ Transitions: []FSMTransition{ - {To: STATE_DISCONNECTED, Description: "User chooses profile"}, - {To: STATE_NO_SERVER, Description: "Cancel or Error"}, - {To: STATE_SEARCH_SERVER, Description: "Cancel or Error"}, + {To: StateDisconnected, Description: "User chooses profile"}, + {To: StateNoServer, Description: "Cancel or Error"}, + {To: StateSearchServer, Description: "Cancel or Error"}, }, }, - STATE_DISCONNECTED: FSMState{ + StateDisconnected: FSMState{ Transitions: []FSMTransition{ - {To: STATE_CONNECTING, Description: "OS reports it is trying to connect"}, - {To: STATE_REQUEST_CONFIG, Description: "User reconnects"}, - {To: STATE_NO_SERVER, Description: "User wants to choose a new server"}, - {To: STATE_OAUTH_STARTED, Description: "Re-authorize with OAuth"}, + {To: StateConnecting, Description: "OS reports it is trying to connect"}, + {To: StateRequestConfig, Description: "User reconnects"}, + {To: StateNoServer, Description: "User wants to choose a new server"}, + {To: StateOAuthStarted, Description: "Re-authorize with OAuth"}, }, - BackState: STATE_NO_SERVER, + BackState: StateNoServer, }, - STATE_DISCONNECTING: FSMState{ + StateDisconnecting: FSMState{ Transitions: []FSMTransition{ - {To: STATE_DISCONNECTED, Description: "Cancel or Error"}, - {To: STATE_DISCONNECTED, Description: "Done disconnecting"}, + {To: StateDisconnected, Description: "Cancel or Error"}, + {To: StateDisconnected, Description: "Done disconnecting"}, }, }, - STATE_CONNECTING: FSMState{ + StateConnecting: FSMState{ Transitions: []FSMTransition{ - {To: STATE_DISCONNECTED, Description: "Cancel or Error"}, - {To: STATE_CONNECTED, Description: "Done connecting"}, + {To: StateDisconnected, Description: "Cancel or Error"}, + {To: StateConnected, Description: "Done connecting"}, }, }, - STATE_CONNECTED: FSMState{ - Transitions: []FSMTransition{{To: STATE_DISCONNECTING, Description: "App wants to disconnect"}}, + StateConnected: FSMState{ + Transitions: []FSMTransition{{To: StateDisconnecting, Description: "App wants to disconnect"}}, }, } returnedFSM := fsm.FSM{} - returnedFSM.Init(STATE_DEREGISTERED, states, callback, directory, GetStateName, debug) + returnedFSM.Init(StateDeregistered, states, callback, directory, GetStateName, debug) return returnedFSM } @@ -253,17 +253,17 @@ func (e FSMWrongStateError) CustomError() *types.WrappedErrorMessage { // This indicates that the user wants to search for a new server. // Returns an error if this state transition is not possible. func (client *Client) SetSearchServer() error { - if !client.FSM.HasTransition(STATE_SEARCH_SERVER) { + if !client.FSM.HasTransition(StateSearchServer) { return client.handleError( "failed to set search server", FSMWrongStateTransitionError{ Got: client.FSM.Current, - Want: STATE_SEARCH_SERVER, + Want: StateSearchServer, }.CustomError(), ) } - client.FSM.GoTransition(STATE_SEARCH_SERVER) + client.FSM.GoTransition(StateSearchServer) return nil } @@ -272,17 +272,17 @@ func (client *Client) SetSearchServer() error { // Returns an error if this state transition is not possible. func (client *Client) SetConnected() error { errorMessage := "failed to set connected" - if client.InFSMState(STATE_CONNECTED) { + if client.InFSMState(StateConnected) { // already connected, show no error client.Logger.Warning("Already connected") return nil } - if !client.FSM.HasTransition(STATE_CONNECTED) { + if !client.FSM.HasTransition(StateConnected) { return client.handleError( errorMessage, FSMWrongStateTransitionError{ Got: client.FSM.Current, - Want: STATE_CONNECTED, + Want: StateConnected, }.CustomError(), ) } @@ -292,7 +292,7 @@ func (client *Client) SetConnected() error { return client.handleError(errorMessage, currentServerErr) } - client.FSM.GoTransitionWithData(STATE_CONNECTED, currentServer) + client.FSM.GoTransitionWithData(StateConnected, currentServer) return nil } @@ -301,17 +301,17 @@ func (client *Client) SetConnected() error { // Returns an error if this state transition is not possible. func (client *Client) SetConnecting() error { errorMessage := "failed to set connecting" - if client.InFSMState(STATE_CONNECTING) { + if client.InFSMState(StateConnecting) { // already loading connection, show no error client.Logger.Warning("Already connecting") return nil } - if !client.FSM.HasTransition(STATE_CONNECTING) { + if !client.FSM.HasTransition(StateConnecting) { return client.handleError( errorMessage, FSMWrongStateTransitionError{ Got: client.FSM.Current, - Want: STATE_CONNECTING, + Want: StateConnecting, }.CustomError(), ) } @@ -321,7 +321,7 @@ func (client *Client) SetConnecting() error { return client.handleError(errorMessage, currentServerErr) } - client.FSM.GoTransitionWithData(STATE_CONNECTING, currentServer) + client.FSM.GoTransitionWithData(StateConnecting, currentServer) return nil } @@ -330,17 +330,17 @@ func (client *Client) SetConnecting() error { // Returns an error if this state transition is not possible. func (client *Client) SetDisconnecting() error { errorMessage := "failed to set disconnecting" - if client.InFSMState(STATE_DISCONNECTING) { + if client.InFSMState(StateDisconnecting) { // already disconnecting, show no error client.Logger.Warning("Already disconnecting") return nil } - if !client.FSM.HasTransition(STATE_DISCONNECTING) { + if !client.FSM.HasTransition(StateDisconnecting) { return client.handleError( errorMessage, FSMWrongStateTransitionError{ Got: client.FSM.Current, - Want: STATE_DISCONNECTING, + Want: StateDisconnecting, }.CustomError(), ) } @@ -350,7 +350,7 @@ func (client *Client) SetDisconnecting() error { return client.handleError(errorMessage, currentServerErr) } - client.FSM.GoTransitionWithData(STATE_DISCONNECTING, currentServer) + client.FSM.GoTransitionWithData(StateDisconnecting, currentServer) return nil } @@ -360,17 +360,17 @@ func (client *Client) SetDisconnecting() error { // Returns an error if this state transition is not possible. func (client *Client) SetDisconnected(cleanup bool) error { errorMessage := "failed to set disconnected" - if client.InFSMState(STATE_DISCONNECTED) { + if client.InFSMState(StateDisconnected) { // already disconnected, show no error client.Logger.Warning("Already disconnected") return nil } - if !client.FSM.HasTransition(STATE_DISCONNECTED) { + if !client.FSM.HasTransition(StateDisconnected) { return client.handleError( errorMessage, FSMWrongStateTransitionError{ Got: client.FSM.Current, - Want: STATE_DISCONNECTED, + Want: StateDisconnected, }.CustomError(), ) } @@ -385,7 +385,7 @@ func (client *Client) SetDisconnected(cleanup bool) error { server.Disconnect(currentServer) } - client.FSM.GoTransitionWithData(STATE_DISCONNECTED, currentServer) + client.FSM.GoTransitionWithData(StateDisconnected, currentServer) return nil } @@ -406,7 +406,7 @@ func (client *Client) goBackInternal() { // GoBack transitions the FSM back to the previous UI state, for now this is always the NO_SERVER state. func (client *Client) GoBack() error { errorMessage := "failed to go back" - if client.InFSMState(STATE_DEREGISTERED) { + if client.InFSMState(StateDeregistered) { return client.handleError( errorMessage, FSMDeregisteredError{}.CustomError(), @@ -414,7 +414,7 @@ func (client *Client) GoBack() error { } // FIXME: Abitrary back transitions don't work because we need the approriate data - client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers) + client.FSM.GoTransitionWithData(StateNoServer, client.Servers) return nil } @@ -423,12 +423,12 @@ func (client *Client) GoBack() error { // An error is also returned if OAuth is in progress but it fails to cancel it. func (client *Client) CancelOAuth() error { errorMessage := "failed to cancel OAuth" - if !client.InFSMState(STATE_OAUTH_STARTED) { + if !client.InFSMState(StateOAuthStarted) { return client.handleError( errorMessage, FSMWrongStateError{ Got: client.FSM.Current, - Want: STATE_OAUTH_STARTED, + Want: StateOAuthStarted, }.CustomError(), ) } diff --git a/client/server.go b/client/server.go index d22dc65..12e5932 100644 --- a/client/server.go +++ b/client/server.go @@ -20,7 +20,7 @@ func (client *Client) getConfigAuth( if loginErr != nil { return "", "", loginErr } - client.FSM.GoTransition(STATE_REQUEST_CONFIG) + client.FSM.GoTransition(StateRequestConfig) validProfile, profileErr := server.HasValidProfile(chosenServer, client.SupportsWireguard) if profileErr != nil { @@ -72,7 +72,7 @@ func (client *Client) getConfig( preferTCP bool, ) (string, string, error) { errorMessage := "failed to get a configuration for OpenVPN/Wireguard" - if client.InFSMState(STATE_DEREGISTERED) { + if client.InFSMState(StateDeregistered) { return "", "", types.NewWrappedError( errorMessage, FSMDeregisteredError{}.CustomError(), @@ -97,7 +97,7 @@ func (client *Client) getConfig( } // Signal the server display info - client.FSM.GoTransitionWithData(STATE_DISCONNECTED, currentServer) + client.FSM.GoTransitionWithData(StateDisconnected, currentServer) // Save the config saveErr := client.Config.Save(&client) @@ -139,7 +139,7 @@ func (client *Client) SetSecureLocation(countryCode string) error { // It returns an error if the server cannot be removed due to the state being DEREGISTERED. // Note that if the server does not exist, it returns nil as an error. func (client *Client) RemoveSecureInternet() error { - if client.InFSMState(STATE_DEREGISTERED) { + if client.InFSMState(StateDeregistered) { return client.handleError( "failed to remove Secure Internet", FSMDeregisteredError{}.CustomError(), @@ -147,7 +147,7 @@ func (client *Client) RemoveSecureInternet() error { } // No error because we can only have one secure internet server and if there are no secure internet servers, this is a NO-OP client.Servers.RemoveSecureInternet() - client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers) + client.FSM.GoTransitionWithData(StateNoServer, client.Servers) // Save the config saveErr := client.Config.Save(&client) if saveErr != nil { @@ -163,7 +163,7 @@ func (client *Client) RemoveSecureInternet() error { // It returns an error if the server cannot be removed due to the state being DEREGISTERED. // Note that if the server does not exist, it returns nil as an error. func (client *Client) RemoveInstituteAccess(url string) error { - if client.InFSMState(STATE_DEREGISTERED) { + if client.InFSMState(StateDeregistered) { return client.handleError( "failed to remove Institute Access", FSMDeregisteredError{}.CustomError(), @@ -171,7 +171,7 @@ func (client *Client) RemoveInstituteAccess(url string) error { } // No error because this is a NO-OP if the server doesn't exist client.Servers.RemoveInstituteAccess(url) - client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers) + client.FSM.GoTransitionWithData(StateNoServer, client.Servers) // Save the config saveErr := client.Config.Save(&client) if saveErr != nil { @@ -187,7 +187,7 @@ func (client *Client) RemoveInstituteAccess(url string) error { // It returns an error if the server cannot be removed due to the state being DEREGISTERED. // Note that if the server does not exist, it returns nil as an error. func (client *Client) RemoveCustomServer(url string) error { - if client.InFSMState(STATE_DEREGISTERED) { + if client.InFSMState(StateDeregistered) { return client.handleError( "failed to remove Custom Server", FSMDeregisteredError{}.CustomError(), @@ -195,7 +195,7 @@ func (client *Client) RemoveCustomServer(url string) error { } // No error because this is a NO-OP if the server doesn't exist client.Servers.RemoveCustomServer(url) - client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers) + client.FSM.GoTransitionWithData(StateNoServer, client.Servers) // Save the config saveErr := client.Config.Save(&client) if saveErr != nil { @@ -217,7 +217,7 @@ func (client *Client) AddInstituteServer(url string) (server.Server, error) { } // Indicate that we're loading the server - client.FSM.GoTransition(STATE_LOADING_SERVER) + client.FSM.GoTransition(StateLoadingServer) // FIXME: Do nothing with discovery here as the client already has it // So pass a server as the parameter @@ -242,7 +242,7 @@ func (client *Client) AddInstituteServer(url string) (server.Server, error) { } // Indicate that we want to authorize this server - client.FSM.GoTransition(STATE_CHOSEN_SERVER) + client.FSM.GoTransition(StateChosenServer) // Authorize it loginErr := client.ensureLogin(server) @@ -252,7 +252,7 @@ func (client *Client) AddInstituteServer(url string) (server.Server, error) { return nil, client.handleError(errorMessage, loginErr) } - client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers) + client.FSM.GoTransitionWithData(StateNoServer, client.Servers) return server, nil } @@ -270,7 +270,7 @@ func (client *Client) AddSecureInternetHomeServer(orgID string) (server.Server, } // Indicate that we're loading the server - client.FSM.GoTransition(STATE_LOADING_SERVER) + client.FSM.GoTransition(StateLoadingServer) // Get the secure internet URL from discovery secureOrg, secureServer, discoErr := client.Discovery.GetSecureHomeArgs(orgID) @@ -302,7 +302,7 @@ func (client *Client) AddSecureInternetHomeServer(orgID string) (server.Server, } // Server has been chosen for authentication - client.FSM.GoTransition(STATE_CHOSEN_SERVER) + client.FSM.GoTransition(StateChosenServer) // Authorize it loginErr := client.ensureLogin(server) @@ -311,7 +311,7 @@ func (client *Client) AddSecureInternetHomeServer(orgID string) (server.Server, _ = client.RemoveSecureInternet() return nil, client.handleError(errorMessage, loginErr) } - client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers) + client.FSM.GoTransitionWithData(StateNoServer, client.Servers) return server, nil } @@ -325,7 +325,7 @@ func (client *Client) AddCustomServer(url string) (server.Server, error) { } // Indicate that we're loading the server - client.FSM.GoTransition(STATE_LOADING_SERVER) + client.FSM.GoTransition(StateLoadingServer) customServer := &types.DiscoveryServer{ BaseURL: url, @@ -348,7 +348,7 @@ func (client *Client) AddCustomServer(url string) (server.Server, error) { } // Server has been chosen for authentication - client.FSM.GoTransition(STATE_CHOSEN_SERVER) + client.FSM.GoTransition(StateChosenServer) // Authorize it loginErr := client.ensureLogin(server) @@ -358,7 +358,7 @@ func (client *Client) AddCustomServer(url string) (server.Server, error) { return nil, client.handleError(errorMessage, loginErr) } - client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers) + client.FSM.GoTransitionWithData(StateNoServer, client.Servers) return server, nil } @@ -373,7 +373,7 @@ func (client *Client) GetConfigInstituteAccess(url string, preferTCP bool) (stri return "", "", client.handleError(errorMessage, LetsConnectNotSupportedError{}) } - client.FSM.GoTransition(STATE_LOADING_SERVER) + client.FSM.GoTransition(StateLoadingServer) // Get the server if it exists server, serverErr := client.Servers.GetInstituteAccess(url) @@ -389,7 +389,7 @@ func (client *Client) GetConfigInstituteAccess(url string, preferTCP bool) (stri } // The server has now been chosen - client.FSM.GoTransition(STATE_CHOSEN_SERVER) + client.FSM.GoTransition(StateChosenServer) config, configType, configErr := client.getConfig(server, preferTCP) if configErr != nil { @@ -416,7 +416,7 @@ func (client *Client) GetConfigSecureInternet( return "", "", client.handleError(errorMessage, LetsConnectNotSupportedError{}) } - client.FSM.GoTransition(STATE_LOADING_SERVER) + client.FSM.GoTransition(StateLoadingServer) // Get the server if it exists server, serverErr := client.Servers.GetSecureInternetHomeServer() @@ -431,7 +431,7 @@ func (client *Client) GetConfigSecureInternet( return "", "", client.handleError(errorMessage, currentErr) } - client.FSM.GoTransition(STATE_CHOSEN_SERVER) + client.FSM.GoTransition(StateChosenServer) config, configType, configErr := client.getConfig(server, preferTCP) if configErr != nil { @@ -452,7 +452,7 @@ func (client *Client) GetConfigCustomServer(url string, preferTCP bool) (string, return "", "", client.handleError(errorMessage, urlErr) } - client.FSM.GoTransition(STATE_LOADING_SERVER) + client.FSM.GoTransition(StateLoadingServer) // Get the server if it exists server, serverErr := client.Servers.GetCustomServer(url) @@ -467,7 +467,7 @@ func (client *Client) GetConfigCustomServer(url string, preferTCP bool) (string, return "", "", client.handleError(errorMessage, currentErr) } - client.FSM.GoTransition(STATE_CHOSEN_SERVER) + client.FSM.GoTransition(StateChosenServer) config, configType, configErr := client.getConfig(server, preferTCP) if configErr != nil { @@ -483,13 +483,13 @@ func (client *Client) askSecureLocation() error { locations := client.Discovery.GetSecureLocationList() // Ask for the location in the callback - goTransitionErr := client.FSM.GoTransitionRequired(STATE_ASK_LOCATION, locations) + goTransitionErr := client.FSM.GoTransitionRequired(StateAskLocation, locations) if goTransitionErr != nil { return types.NewWrappedError(errorMessage, goTransitionErr) } // The state has changed, meaning setting the secure location was not successful - if client.FSM.Current != STATE_ASK_LOCATION { + if client.FSM.Current != StateAskLocation { // TODO: maybe a custom type for this errors.new? return types.NewWrappedError( errorMessage, @@ -505,12 +505,12 @@ func (client *Client) askSecureLocation() error { func (client *Client) ChangeSecureLocation() error { errorMessage := "failed to change location from the main screen" - if !client.InFSMState(STATE_NO_SERVER) { + if !client.InFSMState(StateNoServer) { return client.handleError( errorMessage, FSMWrongStateError{ Got: client.FSM.Current, - Want: STATE_NO_SERVER, + Want: StateNoServer, }.CustomError(), ) } @@ -521,7 +521,7 @@ func (client *Client) ChangeSecureLocation() error { } // Go back to the main screen - client.FSM.GoTransitionWithData(STATE_NO_SERVER, client.Servers) + client.FSM.GoTransitionWithData(StateNoServer, client.Servers) return nil } @@ -538,8 +538,8 @@ func (client *Client) RenewSession() error { } // The server has not been chosen yet, this means that we want to manually renew - if client.FSM.InState(STATE_NO_SERVER) { - client.FSM.GoTransition(STATE_CHOSEN_SERVER) + if client.FSM.InState(StateNoServer) { + client.FSM.GoTransition(StateChosenServer) } server.MarkTokensForRenew(currentServer) @@ -555,9 +555,9 @@ func (client *Client) RenewSession() error { // If there is no server then this returns false and logs with INFO if so // In other cases it simply checks the expiry time and calculates according to: https://github.com/eduvpn/documentation/blob/b93854dcdd22050d5f23e401619e0165cb8bc591/API.md#session-expiry. func (client *Client) ShouldRenewButton() bool { - if !client.InFSMState(STATE_CONNECTED) && !client.InFSMState(STATE_CONNECTING) && - !client.InFSMState(STATE_DISCONNECTED) && - !client.InFSMState(STATE_DISCONNECTING) { + if !client.InFSMState(StateConnected) && !client.InFSMState(StateConnecting) && + !client.InFSMState(StateDisconnected) && + !client.InFSMState(StateDisconnecting) { return false } @@ -583,7 +583,7 @@ func (client *Client) ensureLogin(chosenServer server.Server) error { if server.NeedsRelogin(chosenServer) { url, urlErr := server.GetOAuthURL(chosenServer, client.Name) - goTransitionErr := client.FSM.GoTransitionRequired(STATE_OAUTH_STARTED, url) + goTransitionErr := client.FSM.GoTransitionRequired(StateOAuthStarted, url) if goTransitionErr != nil { return types.NewWrappedError(errorMessage, goTransitionErr) } @@ -601,7 +601,7 @@ func (client *Client) ensureLogin(chosenServer server.Server) error { } } // OAuth was valid, ensure we are in the authorized state - client.FSM.GoTransition(STATE_AUTHORIZED) + client.FSM.GoTransition(StateAuthorized) return nil } |
