Browse Source

cleaning logs, fixing mac apply

afeiszli 3 years ago
parent
commit
d5bae019b3

+ 0 - 2
mq/mq.go

@@ -112,10 +112,8 @@ func PublishPeerUpdate(newNode *models.Node) error {
 	for _, node := range networkNodes {
 
 		if node.IsServer == "yes" || node.ID == newNode.ID {
-			log.Println("skipping update on " + node.Name + " : " + node.ID)
 			continue
 		}
-		log.Println("running update on " + node.Name + " : " + node.ID)
 		peerUpdate, err := logic.GetPeerUpdate(&node)
 		if err != nil {
 			logger.Log(1, "error getting peer update for node", node.ID, err.Error())

+ 1 - 1
netclient/daemon/macos.go

@@ -95,7 +95,7 @@ func MacDaemonString(interval string) string {
 	<key>Label</key><string>com.gravitl.netclient</string>
 	<key>ProgramArguments</key>
 		<array>
-			<string>/sbin/netclient</string>
+			<string>/usr/local/bin/netclient</string>
 			<string>daemon</string>
 		</array>
 	<key>StandardOutPath</key><string>/etc/netclient/com.gravitl.netclient.log</string>

+ 40 - 29
netclient/functions/daemon.go

@@ -53,7 +53,7 @@ func read(network, which string) string {
 		if readMessage.LastSeen.IsZero() {
 			return ""
 		}
-		if time.Now().After(readMessage.LastSeen.Add(time.Minute)) { // check if message has been there over a minute
+		if time.Now().After(readMessage.LastSeen.Add(time.Minute * 10)) { // check if message has been there over a minute
 			messageCache.Delete(fmt.Sprintf("%s%s", network, which)) // remove old message if expired
 			return ""
 		}
@@ -134,6 +134,7 @@ func SetupMQTT(cfg *config.ClientConfig, publish bool) mqtt.Client {
 		if err != nil {
 			ncutils.Log("could not run pull, please restart daemon or examine network connectivity --- " + err.Error())
 		}
+		ncutils.Log("connection re-established with mqtt server")
 	})
 
 	client := mqtt.NewClient(opts)
@@ -173,32 +174,35 @@ func MessageQueue(ctx context.Context, network string) {
 	ncutils.Log("netclient go routine started for " + network)
 	var cfg config.ClientConfig
 	cfg.Network = network
-	var configPath = fmt.Sprintf("%snetconfig-%s", ncutils.GetNetclientPathSpecific(), network)
-	fileInfo, err := os.Stat(configPath)
-	if err != nil {
-		ncutils.Log("could not stat config file: " + configPath)
-	}
-	// speed up UDP rest
-	if time.Now().After(fileInfo.ModTime().Add(time.Minute)) {
-		sleepTime := 2
-		ncutils.Log("pulling latest config for " + cfg.Network)
-		for {
-			_, err := Pull(network, true)
-			if err == nil {
-				break
-			} else {
-				ncutils.PrintLog("error pulling config for "+network+": "+err.Error(), 1)
-			}
-			if sleepTime > 3600 {
-				sleepTime = 3600
+	/*
+			var configPath = fmt.Sprintf("%snetconfig-%s", ncutils.GetNetclientPathSpecific(), network)
+			fileInfo, err := os.Stat(configPath)
+			if err != nil {
+				ncutils.Log("could not stat config file: " + configPath)
 			}
-			ncutils.Log("failed to pull for network " + network)
-			ncutils.Log(fmt.Sprintf("waiting %d seconds to retry...", sleepTime))
-			time.Sleep(time.Second * time.Duration(sleepTime))
-			sleepTime = sleepTime * 2
-		}
-	}
-	time.Sleep(time.Second << 1)
+			// speed up UDP rest
+				if time.Now().After(fileInfo.ModTime().Add(time.Minute)) {
+					sleepTime := 2
+					ncutils.Log("pulling latest config for " + cfg.Network)
+					for {
+						_, err := Pull(network, true)
+						if err == nil {
+							break
+						} else {
+							ncutils.PrintLog("error pulling config for "+network+": "+err.Error(), 1)
+						}
+						if sleepTime > 3600 {
+							sleepTime = 3600
+						}
+						ncutils.Log("failed to pull for network " + network)
+						ncutils.Log(fmt.Sprintf("waiting %d seconds to retry...", sleepTime))
+						time.Sleep(time.Second * time.Duration(sleepTime))
+						sleepTime = sleepTime * 2
+					}
+				}
+
+		time.Sleep(time.Second << 1)
+	*/
 	cfg.ReadConfig()
 	ncutils.Log("daemon started for network: " + network)
 	client := SetupMQTT(&cfg, false)
@@ -365,12 +369,19 @@ func UpdatePeers(client mqtt.Client, msg mqtt.Message) {
 		return
 	}
 	//err = wireguard.SyncWGQuickConf(cfg.Node.Interface, file)
-	err = wireguard.SetPeers(cfg.Node.Interface, cfg.Node.Address, cfg.Node.PersistentKeepalive, peerUpdate.Peers)
+	var iface = cfg.Node.Interface
+	if ncutils.IsMac() {
+		iface, err = local.GetMacIface(cfg.Node.Address)
+		if err != nil {
+			ncutils.Log("error retrieving mac iface: " + err.Error())
+			return
+		}
+	}
+	err = wireguard.SetPeers(iface, cfg.Node.Address, cfg.Node.PersistentKeepalive, peerUpdate.Peers)
 	if err != nil {
-		ncutils.Log("error syncing wg after peer update " + err.Error())
+		ncutils.Log("error syncing wg after peer update: " + err.Error())
 		return
 	}
-	ncutils.Log(fmt.Sprintf("received peer update on network, %s", cfg.Network))
 }
 
 // MonitorKeepalive - checks time last server keepalive received.  If more than 3+ minutes, notify and resubscribe

+ 2 - 2
netclient/ncutils/netclientutils.go

@@ -570,9 +570,9 @@ func CheckWG() {
 			PrintLog(err.Error(), 0)
 			log.Fatal("WireGuard not installed. Please install WireGuard (wireguard-tools) and try again.")
 		}
-		PrintLog("Running with userspace wireguard: "+uspace, 0)
+		PrintLog("running with userspace wireguard: "+uspace, 0)
 	} else if uspace != "wg" {
-		log.Println("running userspace WireGuard with " + uspace)
+		PrintLog("running userspace WireGuard with "+uspace, 0)
 	}
 }
 

+ 1 - 2
netclient/wireguard/common.go

@@ -174,7 +174,7 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
 		time.Sleep(time.Second >> 2)
 		d, _ = wgclient.Device(deviceiface)
 	}
-	ApplyConf(node, deviceiface, confPath)          // Apply initially
+	ApplyConf(node, ifacename, confPath)            // Apply initially
 	ncutils.PrintLog("waiting for interface...", 1) // ensure interface is created
 	output, _ := ncutils.RunCmd("wg", false)
 	starttime := time.Now()
@@ -355,7 +355,6 @@ func UpdateWgPeers(file string, peers []wgtypes.PeerConfig) error {
 		AllowNonUniqueSections: true,
 		AllowShadows:           true,
 	}
-	ncutils.Log("updating " + file)
 	wireguard, err := ini.LoadSources(options, file)
 	if err != nil {
 		return err