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 (
"errors"
"runtime"
"time"
"github.com/gravitl/netmaker/netclient/config"
)
@ -29,3 +30,22 @@ func InstallDaemon(cfg config.ClientConfig) error {
}
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"
"os"
"path/filepath"
"time"
"github.com/gravitl/netmaker/netclient/ncutils"
)
@ -54,6 +55,12 @@ func CleanupMac() {
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
func CreateMacService(servicename string, interval string) error {
_, err := os.Stat("/Library/LaunchDaemons")

View file

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

View file

@ -34,6 +34,13 @@ func SetupWindowsDaemon() error {
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
func CleanupWindows() {
if !ncutils.FileExists(ncutils.GetNetclientPathSpecific() + "winsw.xml") {

View file

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

View file

@ -69,6 +69,11 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error {
if cfg.Node.LocalRange != "" && cfg.Node.LocalAddress == "" {
log.Println("local vpn, getting local address from range: " + cfg.Node.LocalRange)
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
@ -233,6 +238,8 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error {
}
if err != nil {
return err
} else {
daemon.Restart()
}
return err