2019-03-31 10:17:11 +02:00
|
|
|
/* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package wintun
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/sys/windows/registry"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2019-05-03 00:11:59 +02:00
|
|
|
numRetries = 50
|
|
|
|
retryTimeout = 100 * time.Millisecond
|
2019-03-31 10:17:11 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func registryOpenKeyRetry(k registry.Key, path string, access uint32) (key registry.Key, err error) {
|
|
|
|
for i := 0; i < numRetries; i++ {
|
|
|
|
key, err = registry.OpenKey(k, path, access)
|
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
2019-05-02 23:53:15 +02:00
|
|
|
if i != numRetries-1 {
|
2019-03-31 10:17:11 +02:00
|
|
|
time.Sleep(retryTimeout)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func keyGetStringValueRetry(k registry.Key, name string) (val string, valtype uint32, err error) {
|
|
|
|
for i := 0; i < numRetries; i++ {
|
|
|
|
val, valtype, err = k.GetStringValue(name)
|
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
2019-05-02 23:53:15 +02:00
|
|
|
if i != numRetries-1 {
|
2019-03-31 10:17:11 +02:00
|
|
|
time.Sleep(retryTimeout)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|