summaryrefslogtreecommitdiff
path: root/src/state.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-05 10:05:32 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-05 10:05:32 +0200
commitc83d10b6813d171bf349da71256d719b9148bde4 (patch)
tree96ee789f2d434818dcc0408374eb830e26bd48e8 /src/state.go
parent93bb4bccdf2b1b201451e0130fbfa90f310dba7b (diff)
Add debug variable to save a live fsm graph
Diffstat (limited to 'src/state.go')
-rw-r--r--src/state.go28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/state.go b/src/state.go
index aa31513..ec927f9 100644
--- a/src/state.go
+++ b/src/state.go
@@ -19,29 +19,36 @@ type VPNState struct {
// The file we keep open for logging
LogFile *FileLogger `json:"-"`
+ // The fsm
FSM *FSM `json:"-"`
+
+ // Whether to enable debugging
+ Debug bool `json:"-"`
}
-func (state *VPNState) Register(name string, directory string, stateCallback func(string, string, string)) error {
- if state.FSM == nil {
- state.InitializeFSM()
- }
+func (state *VPNState) Register(name string, directory string, stateCallback func(string, string, string), debug bool) error {
+ state.InitializeFSM()
if !state.HasTransition(APP_REGISTERED) {
return errors.New("app already registered")
}
state.Name = name
state.ConfigDirectory = directory
state.StateCallback = stateCallback
+ state.Debug = debug
- // Initialize the logger
- // state.InitLog(LOG_WARNING)
+ LogLevel := LOG_WARNING
- // state.Log(LOG_INFO, "App registered")
+ if debug {
+ LogLevel = LOG_INFO
+ }
+
+ // Initialize the logger
+ state.InitLog(LogLevel)
// Try to load the previous configuration
if state.LoadConfig() != nil {
// 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.Log(LOG_INFO, "Previous configuration not found")
}
state.GoTransition(APP_REGISTERED, "HALLO")
return nil
@@ -54,9 +61,8 @@ func (state *VPNState) Deregister() error {
// Close the log file
state.CloseLog()
- // Re-initialize everything
- state = &VPNState{}
- state.GoTransition(APP_DEREGISTERED, "")
+ state.Server = &Server{}
+ state.InitializeFSM()
return nil
}