From 5abf00ab87a55662eefc7716de52ead9749293c6 Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Fri, 13 May 2022 12:12:22 +0200 Subject: Refactor: Adapt the API to the documentation --- state.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'state.go') diff --git a/state.go b/state.go index 64146c8..aa4a53c 100644 --- a/state.go +++ b/state.go @@ -100,22 +100,21 @@ func (state *VPNState) chooseServer(url string, isSecureInternet bool) (internal return server, nil } -func (state *VPNState) getConfigWithOptions(url string, isSecureInternet bool, forceTCP bool) (string, error) { - // FIXME: Do something with force tcp +func (state *VPNState) getConfigWithOptions(url string, isSecureInternet bool, forceTCP bool) (string, string, error) { if state.FSM.InState(internal.DEREGISTERED) { - return "", &StateFSMNotRegisteredError{} + return "", "", &StateFSMNotRegisteredError{} } // Go to no server if possible, else return an error if !state.FSM.InState(internal.NO_SERVER) && !state.FSM.GoTransition(internal.NO_SERVER) { - return "", &internal.FSMWrongStateTransitionError{Got: state.FSM.Current, Want: internal.NO_SERVER} + return "", "", &internal.FSMWrongStateTransitionError{Got: state.FSM.Current, Want: internal.NO_SERVER} } // Make sure the server is chosen server, serverErr := state.chooseServer(url, isSecureInternet) if serverErr != nil { - return "", &StateConnectError{URL: url, IsSecureInternet: isSecureInternet, Err: serverErr} + return "", "", &StateConnectError{URL: url, IsSecureInternet: isSecureInternet, Err: serverErr} } // Relogin with oauth // This moves the state to authorized @@ -126,7 +125,7 @@ func (state *VPNState) getConfigWithOptions(url string, isSecureInternet bool, f // We are possibly in oauth started // So go to no server state.FSM.GoTransition(internal.NO_SERVER) - return "", &StateConnectError{URL: url, IsSecureInternet: isSecureInternet, Err: loginErr} + return "", "", &StateConnectError{URL: url, IsSecureInternet: isSecureInternet, Err: loginErr} } } else { // OAuth was valid, ensure we are in the authorized state state.FSM.GoTransition(internal.AUTHORIZED) @@ -134,24 +133,24 @@ func (state *VPNState) getConfigWithOptions(url string, isSecureInternet bool, f state.FSM.GoTransition(internal.REQUEST_CONFIG) - config, configErr := internal.GetConfig(server, forceTCP) + config, configType, configErr := internal.GetConfig(server, forceTCP) if configErr != nil { // Go back to no server if possible state.FSM.GoTransition(internal.NO_SERVER) - return "", &StateConnectError{URL: url, IsSecureInternet: isSecureInternet, Err: configErr} + return "", "", &StateConnectError{URL: url, IsSecureInternet: isSecureInternet, Err: configErr} } else { state.FSM.GoTransition(internal.HAS_CONFIG) } - return config, nil + return config, configType, nil } -func (state *VPNState) GetConfigInstituteAccess(url string, forceTCP bool) (string, error) { +func (state *VPNState) GetConfigInstituteAccess(url string, forceTCP bool) (string, string, error) { return state.getConfigWithOptions(url, false, forceTCP) } -func (state *VPNState) GetConfigSecureInternet(url string, forceTCP bool) (string, error) { +func (state *VPNState) GetConfigSecureInternet(url string, forceTCP bool) (string, string, error) { return state.getConfigWithOptions(url, true, forceTCP) } -- cgit v1.2.3