Browse Source

moved checks around

Matthew R. Kasun 3 years ago
parent
commit
c481f27200
2 changed files with 15 additions and 13 deletions
  1. 9 9
      netclient/functions/mqhandlers.go
  2. 6 4
      netclient/functions/pull.go

+ 9 - 9
netclient/functions/mqhandlers.go

@@ -105,19 +105,19 @@ func NodeUpdate(client mqtt.Client, msg mqtt.Message) {
 	}
 	}
 	file := ncutils.GetNetclientPathSpecific() + nodeCfg.Node.Interface + ".conf"
 	file := ncutils.GetNetclientPathSpecific() + nodeCfg.Node.Interface + ".conf"
 
 
-	if err := wireguard.UpdateWgInterface(file, privateKey, nameserver, newNode); err != nil {
-		logger.Log(0, "error updating wireguard config "+err.Error())
-		return
-	}
-	if keepaliveChange {
-		wireguard.UpdateKeepAlive(file, newNode.PersistentKeepalive)
-	}
 	if ifaceDelta { // if a change caused an ifacedelta we need to notify the server to update the peers
 	if ifaceDelta { // if a change caused an ifacedelta we need to notify the server to update the peers
-		err = ncutils.ModPort(&nodeCfg.Node)
+		err = ncutils.ModPort(&newNode)
 		if err != nil {
 		if err != nil {
-			logger.Log(0, "error modifying node port on", nodeCfg.Node.Name, "-", err.Error())
+			logger.Log(0, "error modifying node port on", newNode.Name, "-", err.Error())
 			return
 			return
 		}
 		}
+		if err := wireguard.UpdateWgInterface(file, privateKey, nameserver, newNode); err != nil {
+			logger.Log(0, "error updating wireguard config "+err.Error())
+			return
+		}
+		if keepaliveChange {
+			wireguard.UpdateKeepAlive(file, newNode.PersistentKeepalive)
+		}
 		logger.Log(0, "applying WG conf to "+file)
 		logger.Log(0, "applying WG conf to "+file)
 		if ncutils.IsWindows() {
 		if ncutils.IsWindows() {
 			wireguard.RemoveConfGraceful(nodeCfg.Node.Interface)
 			wireguard.RemoveConfGraceful(nodeCfg.Node.Interface)

+ 6 - 4
netclient/functions/pull.go

@@ -63,10 +63,12 @@ func Pull(network string, iface bool) (*models.Node, error) {
 			logger.Log(0, "unable to update server config: "+err.Error())
 			logger.Log(0, "unable to update server config: "+err.Error())
 		}
 		}
 	}
 	}
-	err = ncutils.ModPort(&resNode)
-	logger.Log(0, "port is now", strconv.Itoa(int(resNode.ListenPort)))
-	if err != nil {
-		return nil, err
+	if nodeGET.Node.ListenPort != cfg.Node.ListenPort {
+		err = ncutils.ModPort(&resNode)
+		if err != nil {
+			return nil, err
+		}
+		logger.Log(0, "port is now", strconv.Itoa(int(resNode.ListenPort)))
 	}
 	}
 	if err = config.ModNodeConfig(&resNode); err != nil {
 	if err = config.ModNodeConfig(&resNode); err != nil {
 		return nil, err
 		return nil, err