removing peer cache

This commit is contained in:
afeiszli
2022-02-02 00:02:36 -05:00
parent 7c4e8b2b4a
commit 03a30b6bbc
7 changed files with 54 additions and 8 deletions

View File

@@ -3,6 +3,7 @@ package daemon
import ( import (
"errors" "errors"
"runtime" "runtime"
"time"
"github.com/gravitl/netmaker/netclient/config" "github.com/gravitl/netmaker/netclient/config"
) )
@@ -29,3 +30,22 @@ func InstallDaemon(cfg config.ClientConfig) error {
} }
return err return err
} }
func Restart() error {
os := runtime.GOOS
var err error
time.Sleep(time.Second)
switch os {
case "windows":
RestartWindowsDaemon()
case "darwin":
RestartLaunchD()
case "linux":
RestartSystemD()
default:
err = errors.New("this os is not yet supported for daemon mode. Run join cmd with flag '--daemon off'")
}
return err
}

View File

@@ -5,6 +5,7 @@ import (
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
"time"
"github.com/gravitl/netmaker/netclient/ncutils" "github.com/gravitl/netmaker/netclient/ncutils"
) )
@@ -54,6 +55,12 @@ func CleanupMac() {
os.Remove(EXEC_DIR + "netclient") os.Remove(EXEC_DIR + "netclient")
} }
func RestartLaunchD() {
ncutils.RunCmd("launchctl unload /Library/LaunchDaemons/"+MAC_SERVICE_NAME+".plist", true)
time.Sleep(time.Second >> 2)
ncutils.RunCmd("launchctl load /Library/LaunchDaemons/"+MAC_SERVICE_NAME+".plist", true)
}
// CreateMacService - Creates the mac service file for LaunchDaemons // CreateMacService - Creates the mac service file for LaunchDaemons
func CreateMacService(servicename string, interval string) error { func CreateMacService(servicename string, interval string) error {
_, err := os.Stat("/Library/LaunchDaemons") _, err := os.Stat("/Library/LaunchDaemons")

View File

@@ -73,6 +73,10 @@ WantedBy=multi-user.target
return nil return nil
} }
func RestartSystemD() {
_, _ = ncutils.RunCmd("systemctl start netclient.service", true)
}
func CleanupLinux() { func CleanupLinux() {
if err := os.RemoveAll(ncutils.GetNetclientPath()); err != nil { if err := os.RemoveAll(ncutils.GetNetclientPath()); err != nil {
ncutils.PrintLog("Removing netclient configs: "+err.Error(), 1) ncutils.PrintLog("Removing netclient configs: "+err.Error(), 1)

View File

@@ -34,6 +34,13 @@ func SetupWindowsDaemon() error {
return nil return nil
} }
func RestartWindowsDaemon() {
StopWindowsDaemon()
// start daemon, will not restart or start another
ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe start`, false)
ncutils.Log(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1) + `winsw.exe start`)
}
// CleanupWindows - cleans up windows files // CleanupWindows - cleans up windows files
func CleanupWindows() { func CleanupWindows() {
if !ncutils.FileExists(ncutils.GetNetclientPathSpecific() + "winsw.xml") { if !ncutils.FileExists(ncutils.GetNetclientPathSpecific() + "winsw.xml") {

View File

@@ -43,20 +43,21 @@ func getPrivateAddr() (string, error) {
var local string var local string
conn, err := net.Dial("udp", "8.8.8.8:80") conn, err := net.Dial("udp", "8.8.8.8:80")
if err != nil { if err == nil {
log.Fatal(err) defer conn.Close()
}
defer conn.Close()
localAddr := conn.LocalAddr().(*net.UDPAddr) localAddr := conn.LocalAddr().(*net.UDPAddr)
localIP := localAddr.IP localIP := localAddr.IP
local = localIP.String() local = localIP.String()
}
if local == "" { if local == "" {
local, err = getPrivateAddrBackup() local, err = getPrivateAddrBackup()
} }
if local == "" { if local == "" {
err = errors.New("could not find local ip") err = errors.New("could not find local ip")
} }
return local, err return local, err
} }

View File

@@ -357,7 +357,7 @@ func MonitorKeepalive(ctx context.Context, client mqtt.Client, cfg *config.Clien
ncutils.Log("unable to parse timestamp " + keepalivetime.String()) ncutils.Log("unable to parse timestamp " + keepalivetime.String())
continue continue
} }
if time.Since(keepalivetime) > time.Second*200 { // more than 3+ minutes if time.Since(keepalivetime) > time.Second*120 { // more than 2+ minutes
ncutils.Log("server keepalive not recieved recently, resubscribe to message queue") ncutils.Log("server keepalive not recieved recently, resubscribe to message queue")
err := Resubscribe(client, cfg) err := Resubscribe(client, cfg)
if err != nil { if err != nil {

View File

@@ -69,6 +69,11 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error {
if cfg.Node.LocalRange != "" && cfg.Node.LocalAddress == "" { if cfg.Node.LocalRange != "" && cfg.Node.LocalAddress == "" {
log.Println("local vpn, getting local address from range: " + cfg.Node.LocalRange) log.Println("local vpn, getting local address from range: " + cfg.Node.LocalRange)
cfg.Node.LocalAddress = getLocalIP(cfg.Node) cfg.Node.LocalAddress = getLocalIP(cfg.Node)
} else if cfg.Node.LocalAddress == "" {
intIP, err := getPrivateAddr()
if err == nil {
cfg.Node.LocalAddress = intIP
}
} }
// set endpoint if blank. set to local if local net, retrieve from function if not // set endpoint if blank. set to local if local net, retrieve from function if not
@@ -233,6 +238,8 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error {
} }
if err != nil { if err != nil {
return err return err
} else {
daemon.Restart()
} }
return err return err