Refactor
This commit is contained in:
@@ -8,8 +8,8 @@ import (
|
||||
"vppn/m"
|
||||
)
|
||||
|
||||
type localConfig struct {
|
||||
PeerIP byte
|
||||
type LocalConfig struct {
|
||||
LocalPeerIP byte
|
||||
Network []byte
|
||||
PubKey []byte
|
||||
PrivKey []byte
|
||||
@@ -17,6 +17,10 @@ type localConfig struct {
|
||||
PrivSignKey []byte
|
||||
}
|
||||
|
||||
type startupCount struct {
|
||||
Count uint16
|
||||
}
|
||||
|
||||
func configDir(netName string) string {
|
||||
d, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
@@ -33,6 +37,10 @@ func peerStatePath(netName string) string {
|
||||
return filepath.Join(configDir(netName), "state.json")
|
||||
}
|
||||
|
||||
func startupCountPath(netName string) string {
|
||||
return filepath.Join(configDir(netName), "startup_count.json")
|
||||
}
|
||||
|
||||
func storeJson(x any, outPath string) error {
|
||||
outDir := filepath.Dir(outPath)
|
||||
_ = os.MkdirAll(outDir, 0700)
|
||||
@@ -65,7 +73,7 @@ func storeJson(x any, outPath string) error {
|
||||
return os.Rename(tmpPath, outPath)
|
||||
}
|
||||
|
||||
func storePeerConfig(netName string, pc localConfig) error {
|
||||
func storePeerConfig(netName string, pc LocalConfig) error {
|
||||
return storeJson(pc, peerConfigPath(netName))
|
||||
}
|
||||
|
||||
@@ -82,10 +90,18 @@ func loadJson(dataPath string, ptr any) error {
|
||||
return json.Unmarshal(data, ptr)
|
||||
}
|
||||
|
||||
func loadPeerConfig(netName string) (pc localConfig, err error) {
|
||||
func loadPeerConfig(netName string) (pc LocalConfig, err error) {
|
||||
return pc, loadJson(peerConfigPath(netName), &pc)
|
||||
}
|
||||
|
||||
func loadNetworkState(netName string) (ps m.NetworkState, err error) {
|
||||
return ps, loadJson(peerStatePath(netName), &ps)
|
||||
}
|
||||
|
||||
func loadStartupCount(netName string) (c startupCount, err error) {
|
||||
return c, loadJson(startupCountPath(netName), &c)
|
||||
}
|
||||
|
||||
func storeStartupCount(netName string, c startupCount) error {
|
||||
return storeJson(c, startupCountPath(netName))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user