diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-07-15 14:29:29 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-07-15 14:29:29 +0200 |
| commit | 28ef64c0721e00780a6276cee33af259c7752c39 (patch) | |
| tree | 11a23fd70710eb0ad8ae5f53d2196c051a92e360 /state.go | |
| parent | 4067d4d8a476797d0e62b5f5f890cbccf7c8d67c (diff) | |
FSM + State + Python: Add a connecting state and improve back transitions
Diffstat (limited to 'state.go')
| -rw-r--r-- | state.go | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -338,6 +338,10 @@ func (state *VPNState) SetSearchServer() error { } func (state *VPNState) SetConnected() error { + if state.FSM.InState(fsm.CONNECTED) { + // already connected, show no error + return nil + } if !state.FSM.HasTransition(fsm.CONNECTED) { return &types.WrappedErrorMessage{Message: "failed to set connected", Err: fsm.WrongStateTransitionError{Got: state.FSM.Current, Want: fsm.CONNECTED}.CustomError()} } @@ -346,7 +350,24 @@ func (state *VPNState) SetConnected() error { return nil } +func (state *VPNState) SetConnecting() error { + if state.FSM.InState(fsm.CONNECTING) { + // already loading connection, show no error + return nil + } + if !state.FSM.HasTransition(fsm.CONNECTING) { + return &types.WrappedErrorMessage{Message: "failed to set connecting", Err: fsm.WrongStateTransitionError{Got: state.FSM.Current, Want: fsm.CONNECTING}.CustomError()} + } + + state.FSM.GoTransition(fsm.CONNECTING) + return nil +} + func (state *VPNState) SetDisconnected() error { + if state.FSM.InState(fsm.HAS_CONFIG) { + // already disconnected, show no error + return nil + } if !state.FSM.HasTransition(fsm.HAS_CONFIG) { return &types.WrappedErrorMessage{Message: "failed to set disconnected", Err: fsm.WrongStateTransitionError{Got: state.FSM.Current, Want: fsm.HAS_CONFIG}.CustomError()} } |
