diff --git a/mq/handlers.go b/mq/handlers.go index 9638043f..ce0bed94 100644 --- a/mq/handlers.go +++ b/mq/handlers.go @@ -97,7 +97,11 @@ func UpdateNode(client mqtt.Client, msg mqtt.Message) { logger.Log(1, "error saving node", err.Error()) return } - updateNodePeers(¤tNode) + if ifaceDelta { // reduce number of unneeded updates, by only sending on iface changes + if err = PublishPeerUpdate(¤tNode, true); err != nil { + logger.Log(0, "error updating peers when node", currentNode.Name, currentNode.ID, "informed the server of an interface change", err.Error()) + } + } logger.Log(1, "updated node", id, newNode.Name) }() } diff --git a/netclient/functions/mqhandlers.go b/netclient/functions/mqhandlers.go index 95244f83..a959fb48 100644 --- a/netclient/functions/mqhandlers.go +++ b/netclient/functions/mqhandlers.go @@ -129,9 +129,6 @@ func NodeUpdate(client mqtt.Client, msg mqtt.Message) { wireguard.UpdateKeepAlive(file, newNode.PersistentKeepalive) } logger.Log(0, "applying WG conf to "+file) - if ncutils.IsWindows() { - wireguard.RemoveConfGraceful(nodeCfg.Node.Interface) - } err = wireguard.ApplyConf(&nodeCfg.Node, nodeCfg.Node.Interface, file) if err != nil { logger.Log(0, "error restarting wg after node update -", err.Error()) @@ -227,9 +224,6 @@ func UpdatePeers(client mqtt.Client, msg mqtt.Message) { if err := config.ModNodeConfig(&cfg.Node); err != nil { logger.Log(0, "failed to save internet gateway", err.Error()) } - if ncutils.IsWindows() { - wireguard.RemoveConfGraceful(cfg.Node.Interface) - } if err := wireguard.ApplyConf(&cfg.Node, cfg.Node.Interface, file); err != nil { logger.Log(0, "error applying internet gateway", err.Error()) } diff --git a/netclient/wireguard/common.go b/netclient/wireguard/common.go index 0ffddc43..d952aed0 100644 --- a/netclient/wireguard/common.go +++ b/netclient/wireguard/common.go @@ -277,7 +277,7 @@ func ApplyConf(node *models.Node, ifacename string, confPath string) error { var err error switch os { case "windows": - ApplyWindowsConf(confPath, isConnected) + ApplyWindowsConf(confPath, ifacename, isConnected) case "nowgquick": ApplyWithoutWGQuick(node, ifacename, confPath, isConnected) default: diff --git a/netclient/wireguard/unix.go b/netclient/wireguard/unix.go index 1d1e2d9d..1847b717 100644 --- a/netclient/wireguard/unix.go +++ b/netclient/wireguard/unix.go @@ -11,7 +11,7 @@ import ( // ApplyWGQuickConf - applies wg-quick commands if os supports func ApplyWGQuickConf(confPath, ifacename string, isConnected bool) error { if ncutils.IsWindows() { - return ApplyWindowsConf(confPath, isConnected) + return ApplyWindowsConf(confPath, ifacename, isConnected) } else { _, err := os.Stat(confPath) if err != nil { diff --git a/netclient/wireguard/windows.go b/netclient/wireguard/windows.go index 85170a0c..cafac90d 100644 --- a/netclient/wireguard/windows.go +++ b/netclient/wireguard/windows.go @@ -8,7 +8,9 @@ import ( ) // ApplyWindowsConf - applies the WireGuard configuration file on Windows -func ApplyWindowsConf(confPath string, isConnected bool) error { +func ApplyWindowsConf(confPath, iface string, isConnected bool) error { + RemoveConfGraceful(iface) // have to remove gracefully before applying windows conf + if !isConnected { return nil }