Browse Source

fixed issues around windows

0xdcarns 3 years ago
parent
commit
98023deeb9
2 changed files with 10 additions and 5 deletions
  1. 2 2
      netclient/daemon/windows.go
  2. 8 3
      netclient/wireguard/common.go

+ 2 - 2
netclient/daemon/windows.go

@@ -39,7 +39,7 @@ func RestartWindowsDaemon() {
 	StopWindowsDaemon()
 	StopWindowsDaemon()
 	// start daemon, will not restart or start another
 	// start daemon, will not restart or start another
 	ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe start`, false)
 	ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe start`, false)
-	ncutils.Log(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1) + `winsw.exe start`)
+	// ncutils.Log(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1) + `winsw.exe start`)
 }
 }
 
 
 // CleanupWindows - cleans up windows files
 // CleanupWindows - cleans up windows files
@@ -78,7 +78,7 @@ func writeServiceConfig() error {
 
 
 // StopWindowsDaemon - stops the Windows daemon
 // StopWindowsDaemon - stops the Windows daemon
 func StopWindowsDaemon() {
 func StopWindowsDaemon() {
-	ncutils.Log("no networks detected, stopping Windows, Netclient daemon")
+	ncutils.Log("stopping Windows, Netclient daemon")
 	// stop daemon, will not overwrite
 	// stop daemon, will not overwrite
 	ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe stop`, true)
 	ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe stop`, true)
 }
 }

+ 8 - 3
netclient/wireguard/common.go

@@ -167,6 +167,7 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
 	}
 	}
 	// ensure you clear any existing interface first
 	// ensure you clear any existing interface first
 	d, _ := wgclient.Device(deviceiface)
 	d, _ := wgclient.Device(deviceiface)
+	startTime := time.Now()
 	for d != nil && d.Name == deviceiface {
 	for d != nil && d.Name == deviceiface {
 		if err = RemoveConf(deviceiface, false); err != nil { // remove interface first
 		if err = RemoveConf(deviceiface, false); err != nil { // remove interface first
 			if strings.Contains(err.Error(), "does not exist") {
 			if strings.Contains(err.Error(), "does not exist") {
@@ -176,6 +177,9 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
 		}
 		}
 		time.Sleep(time.Second >> 2)
 		time.Sleep(time.Second >> 2)
 		d, _ = wgclient.Device(deviceiface)
 		d, _ = wgclient.Device(deviceiface)
+		if time.Now().After(startTime.Add(time.Second << 4)) {
+			break
+		}
 	}
 	}
 	ApplyConf(node, ifacename, confPath)            // Apply initially
 	ApplyConf(node, ifacename, confPath)            // Apply initially
 	ncutils.PrintLog("waiting for interface...", 1) // ensure interface is created
 	ncutils.PrintLog("waiting for interface...", 1) // ensure interface is created
@@ -207,6 +211,7 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
 	}
 	}
 	ncutils.PrintLog("interface ready - netclient.. ENGAGE", 1)
 	ncutils.PrintLog("interface ready - netclient.. ENGAGE", 1)
 	if syncconf { // should never be called really.
 	if syncconf { // should never be called really.
+		fmt.Println("why here")
 		err = SyncWGQuickConf(ifacename, confPath)
 		err = SyncWGQuickConf(ifacename, confPath)
 	}
 	}
 	if !ncutils.HasWgQuick() && ncutils.IsLinux() {
 	if !ncutils.HasWgQuick() && ncutils.IsLinux() {
@@ -269,7 +274,7 @@ func SetWGConfig(network string, peerupdate bool) error {
 // RemoveConf - removes a configuration for a given WireGuard interface
 // RemoveConf - removes a configuration for a given WireGuard interface
 func RemoveConf(iface string, printlog bool) error {
 func RemoveConf(iface string, printlog bool) error {
 	os := runtime.GOOS
 	os := runtime.GOOS
-	if !ncutils.HasWgQuick() {
+	if ncutils.IsLinux() && !ncutils.HasWgQuick() {
 		os = "nowgquick"
 		os = "nowgquick"
 	}
 	}
 	var err error
 	var err error
@@ -295,12 +300,12 @@ func ApplyConf(node *models.Node, ifacename string, confPath string) error {
 	}
 	}
 	var err error
 	var err error
 	switch os {
 	switch os {
-	case "nowgquick":
-		ApplyWithoutWGQuick(node, ifacename, confPath)
 	case "windows":
 	case "windows":
 		ApplyWindowsConf(confPath)
 		ApplyWindowsConf(confPath)
 	case "darwin":
 	case "darwin":
 		ApplyMacOSConf(node, ifacename, confPath)
 		ApplyMacOSConf(node, ifacename, confPath)
+	case "nowgquick":
+		ApplyWithoutWGQuick(node, ifacename, confPath)
 	default:
 	default:
 		ApplyWGQuickConf(confPath, ifacename)
 		ApplyWGQuickConf(confPath, ifacename)
 	}
 	}