This commit is contained in:
partisan 2024-08-09 15:55:14 +02:00
parent 6b99213ec4
commit d7039b64bb
14 changed files with 466 additions and 465 deletions

View file

@ -7,6 +7,7 @@ import (
"os"
"strconv"
"strings"
"sync"
"github.com/fsnotify/fsnotify"
"gopkg.in/ini.v1"
@ -55,6 +56,8 @@ func createConfig() error {
fmt.Printf("Generated connection code: %s\n", config.AuthCode)
}
config.NodesEnabled = len(config.Peers) > 0
saveConfig(config)
return nil
}
@ -69,6 +72,7 @@ func saveConfig(config Config) {
peers := strings.Join(config.Peers, ",")
sec.Key("Peers").SetValue(peers)
sec.Key("Domain").SetValue(config.Domain)
sec.Key("NodesEnabled").SetValue(strconv.FormatBool(config.NodesEnabled))
err := cfg.SaveTo(configFilePath)
if err != nil {
@ -101,17 +105,25 @@ func loadConfig() Config {
domain = "localhost" // Default to localhost if not set
}
nodesEnabled, err := cfg.Section("").Key("NodesEnabled").Bool()
if err != nil { // If NodesEnabled is not found in config
nodesEnabled = len(peers) > 0 // Enable nodes if peers are configured
}
config = Config{
Port: port,
AuthCode: cfg.Section("").Key("AuthCode").String(),
PeerID: cfg.Section("").Key("PeerID").String(),
Peers: peers,
Domain: domain,
Port: port,
AuthCode: cfg.Section("").Key("AuthCode").String(),
PeerID: cfg.Section("").Key("PeerID").String(),
Peers: peers,
Domain: domain,
NodesEnabled: nodesEnabled,
}
return config
}
var configLock sync.RWMutex
func startFileWatcher() {
watcher, err := fsnotify.NewWatcher()
if err != nil {