summaryrefslogtreecommitdiff
path: root/src/state.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-14 13:57:55 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-14 13:57:55 +0200
commit667508f25afda611e64ac8423d6ef0108fb51cec (patch)
tree06840ad79187fe95f00ef22267ef2434142a865b /src/state.go
parent680067ed6154bebcf2c097d407b030b3f786d10c (diff)
Simplify FSM by removing hierarchy
Diffstat (limited to 'src/state.go')
-rw-r--r--src/state.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/state.go b/src/state.go
index ec927f9..c6f0f79 100644
--- a/src/state.go
+++ b/src/state.go
@@ -28,7 +28,7 @@ type VPNState struct {
func (state *VPNState) Register(name string, directory string, stateCallback func(string, string, string), debug bool) error {
state.InitializeFSM()
- if !state.HasTransition(APP_REGISTERED) {
+ if !state.InState(DEREGISTERED) {
return errors.New("app already registered")
}
state.Name = name
@@ -50,13 +50,13 @@ func (state *VPNState) Register(name string, directory string, stateCallback fun
// This error can be safely ignored, as when the config does not load, the struct will not be filled
state.Log(LOG_INFO, "Previous configuration not found")
}
- state.GoTransition(APP_REGISTERED, "HALLO")
+ state.GoTransition(NO_SERVER, "")
return nil
}
func (state *VPNState) Deregister() error {
- if !state.HasTransition(APP_DEREGISTERED) {
- return errors.New("app cannot deregister")
+ if state.InState(DEREGISTERED) {
+ return errors.New("app already deregistered")
}
// Close the log file
state.CloseLog()
@@ -90,7 +90,7 @@ func (state *VPNState) Connect(url string) (string, error) {
return "", configErr
}
- if !state.HasTransition(SERVER_CONNECTED) {
+ if !state.HasTransition(CONNECTED) {
return "", errors.New("cannot connect to server, invalid state")
}