aboutsummaryrefslogtreecommitdiffstats
path: root/conf
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-05-07 12:00:58 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-05-07 12:01:42 +0200
commit279f32cbf734c0d7efa1a2d647259cebbf1e91e3 (patch)
treeabe11e11ef7a7da6b03aaa69a01f01560211fa67 /conf
parentinstaller: bump MSI database version to 4.0 (diff)
downloadwireguard-windows-279f32cbf734c0d7efa1a2d647259cebbf1e91e3.tar.xz
wireguard-windows-279f32cbf734c0d7efa1a2d647259cebbf1e91e3.zip
conf: only retry on no internet if system just booted
Diffstat (limited to 'conf')
-rw-r--r--conf/dnsresolver_windows.go5
-rw-r--r--conf/zsyscall_windows.go9
2 files changed, 11 insertions, 3 deletions
diff --git a/conf/dnsresolver_windows.go b/conf/dnsresolver_windows.go
index 9c1e817c..65ae383f 100644
--- a/conf/dnsresolver_windows.go
+++ b/conf/dnsresolver_windows.go
@@ -16,10 +16,11 @@ import (
)
//sys internetGetConnectedState(flags *uint32, reserved uint32) (connected bool) = wininet.InternetGetConnectedState
+//sys getTickCount64() (ms uint64) = kernel32.GetTickCount64
func resolveHostname(name string) (resolvedIpString string, err error) {
const maxTries = 10
-
+ systemJustBooted := getTickCount64() <= uint64(time.Minute*4/time.Millisecond)
for i := 0; i < maxTries; i++ {
resolvedIpString, err = resolveHostnameOnce(name)
if err == nil {
@@ -31,7 +32,7 @@ func resolveHostname(name string) (resolvedIpString string, err error) {
continue
}
var state uint32
- if err == windows.WSAHOST_NOT_FOUND && !internetGetConnectedState(&state, 0) {
+ if err == windows.WSAHOST_NOT_FOUND && systemJustBooted && !internetGetConnectedState(&state, 0) {
log.Printf("Host not found when resolving %s, but no Internet connection available, sleeping for 4 seconds", name)
time.Sleep(time.Second * 4)
continue
diff --git a/conf/zsyscall_windows.go b/conf/zsyscall_windows.go
index d8984bef..bfe54931 100644
--- a/conf/zsyscall_windows.go
+++ b/conf/zsyscall_windows.go
@@ -38,11 +38,12 @@ func errnoErr(e syscall.Errno) error {
var (
modwininet = windows.NewLazySystemDLL("wininet.dll")
+ modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
modole32 = windows.NewLazySystemDLL("ole32.dll")
modshell32 = windows.NewLazySystemDLL("shell32.dll")
- modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
procInternetGetConnectedState = modwininet.NewProc("InternetGetConnectedState")
+ procGetTickCount64 = modkernel32.NewProc("GetTickCount64")
procCoTaskMemFree = modole32.NewProc("CoTaskMemFree")
procSHGetKnownFolderPath = modshell32.NewProc("SHGetKnownFolderPath")
procFindFirstChangeNotificationW = modkernel32.NewProc("FindFirstChangeNotificationW")
@@ -55,6 +56,12 @@ func internetGetConnectedState(flags *uint32, reserved uint32) (connected bool)
return
}
+func getTickCount64() (ms uint64) {
+ r0, _, _ := syscall.Syscall(procGetTickCount64.Addr(), 0, 0, 0, 0)
+ ms = uint64(r0)
+ return
+}
+
func coTaskMemFree(pointer uintptr) {
syscall.Syscall(procCoTaskMemFree.Addr(), 1, uintptr(pointer), 0, 0)
return