From 48bbbdc23c9db6653de59be7271535eb3c96dfe6 Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Thu, 14 Apr 2022 14:51:16 +0200 Subject: FSM Transitions: Add descriptions --- src/fsm.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/fsm.go b/src/fsm.go index 1624e0a..2d41a34 100644 --- a/src/fsm.go +++ b/src/fsm.go @@ -46,8 +46,13 @@ func (s FSMStateID) String() string { } } +type FSMTransition struct { + To FSMStateID + Description string +} + type ( - FSMTransitions []FSMStateID + FSMTransitions []FSMTransition FSMStates map[FSMStateID]FSMTransitions ) @@ -58,7 +63,7 @@ type FSM struct { func (eduvpn *VPNState) HasTransition(check FSMStateID) bool { for _, transition_state := range eduvpn.FSM.States[eduvpn.FSM.Current] { - if transition_state == check { + if transition_state.To == check { return true } } @@ -105,8 +110,8 @@ rankdir = LR;` graph += "\nnode[color=blue]; " + eduvpn.FSM.Current.String() + ";\n" graph += "node [color=black];\n" for state, transitions := range eduvpn.FSM.States { - for _, transition_state := range transitions { - graph += state.String() + " -> " + transition_state.String() + "\n" + for _, transition := range transitions { + graph += state.String() + " -> " + transition.To.String() + " [label=\"" + transition.Description + "\"]\n" } } graph += "}" @@ -116,12 +121,12 @@ rankdir = LR;` func (eduvpn *VPNState) InitializeFSM() { eduvpn.FSM = &FSM{ States: FSMStates { - DEREGISTERED: {NO_SERVER}, - NO_SERVER: {CHOSEN_SERVER}, - CHOSEN_SERVER: {AUTHENTICATED, OAUTH_STARTED}, - OAUTH_STARTED: {AUTHENTICATED}, - AUTHENTICATED: {CONNECTED}, - CONNECTED: {AUTHENTICATED}, + DEREGISTERED: {{NO_SERVER, "Client registers"}}, + NO_SERVER: {{CHOSEN_SERVER, "User chooses a server"}}, + CHOSEN_SERVER: {{AUTHENTICATED, "Found tokens in config"}, {OAUTH_STARTED, "No tokens found in config"}}, + OAUTH_STARTED: {{AUTHENTICATED, "User authorizes with browser"}}, + AUTHENTICATED: {{CONNECTED, "OS reports connected"}}, + CONNECTED: {{AUTHENTICATED, "OS reports disconnected"}}, }, Current: DEREGISTERED, } -- cgit v1.2.3