Browse Source

Merge pull request #809 from gravitl/feature_v0.11.0_efficiency

1
dcarns 3 years ago
parent
commit
7de3025237
3 changed files with 21 additions and 7 deletions
  1. 7 2
      controllers/network.go
  2. 1 1
      netclient/functions/daemon.go
  3. 13 4
      netclient/wireguard/common.go

+ 7 - 2
controllers/network.go

@@ -12,6 +12,7 @@ import (
 	"github.com/gravitl/netmaker/logger"
 	"github.com/gravitl/netmaker/logic"
 	"github.com/gravitl/netmaker/models"
+	"github.com/gravitl/netmaker/mq"
 	"github.com/gravitl/netmaker/servercfg"
 	"github.com/gravitl/netmaker/serverctl"
 )
@@ -118,7 +119,9 @@ func keyUpdate(w http.ResponseWriter, r *http.Request) {
 	}
 	for _, node := range nodes {
 		logger.Log(3, "updating node ", node.Name, " for a key update")
-		runUpdates(&node, true)
+		if node.IsServer != "yes" {
+			runUpdates(&node, false)
+		}
 	}
 }
 
@@ -188,7 +191,9 @@ func updateNetwork(w http.ResponseWriter, r *http.Request) {
 			return
 		}
 		for _, node := range nodes {
-			runUpdates(&node, true)
+			if err = mq.NodeUpdate(&node); err != nil {
+				logger.Log(1, "failed to send update to node during a network wide update", node.Name, node.ID, err.Error())
+			}
 		}
 	}
 

+ 1 - 1
netclient/functions/daemon.go

@@ -80,7 +80,7 @@ func Daemon() error {
 
 // UpdateKeys -- updates private key and returns new publickey
 func UpdateKeys(nodeCfg *config.ClientConfig, client mqtt.Client) error {
-	ncutils.Log("received message to update keys")
+	ncutils.Log("received message to update wireguard keys for network " + nodeCfg.Network)
 	key, err := wgtypes.GeneratePrivateKey()
 	if err != nil {
 		ncutils.Log("error generating privatekey " + err.Error())

+ 13 - 4
netclient/wireguard/common.go

@@ -293,14 +293,23 @@ func ApplyConf(node *models.Node, ifacename string, confPath string) error {
 	var err error
 	switch os {
 	case "nowgquick":
-		err = ApplyWithoutWGQuick(node, ifacename, confPath)
+		ApplyWithoutWGQuick(node, ifacename, confPath)
 	case "windows":
-		_ = ApplyWindowsConf(confPath)
+		ApplyWindowsConf(confPath)
 	case "darwin":
-		_ = ApplyMacOSConf(node, ifacename, confPath)
+		ApplyMacOSConf(node, ifacename, confPath)
 	default:
-		err = ApplyWGQuickConf(confPath, ifacename)
+		ApplyWGQuickConf(confPath, ifacename)
 	}
+
+	var nodeCfg config.ClientConfig
+	nodeCfg.Network = node.Network
+	nodeCfg.ReadConfig()
+	ip, cidr, err := net.ParseCIDR(nodeCfg.NetworkSettings.AddressRange)
+	if err == nil {
+		local.SetCIDRRoute(node.Interface, ip.String(), cidr)
+	}
+
 	return err
 }