aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/conf
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-02-28 04:16:04 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-02-28 08:05:02 +0100
commit37ce1d0654ea7b69242097068ae4a75f40b3a2b2 (patch)
treee9ced18b3272875520c43f6ffea0c7e07cc8438a /conf
parentipc: implement event system with pipes (diff)
downloadwireguard-windows-37ce1d0654ea7b69242097068ae4a75f40b3a2b2.tar.xz
wireguard-windows-37ce1d0654ea7b69242097068ae4a75f40b3a2b2.zip
manager: wire up tunnels changed notifier
Diffstat (limited to 'conf')
-rw-r--r--conf/storewatcher.go34
-rw-r--r--conf/storewatcher_windows.go4
2 files changed, 12 insertions, 26 deletions
diff --git a/conf/storewatcher.go b/conf/storewatcher.go
index 4f9c2ef7..7a5ab387 100644
--- a/conf/storewatcher.go
+++ b/conf/storewatcher.go
@@ -5,34 +5,20 @@
package conf
-import "reflect"
-
-type StoreCallback func()
+type storeCallback struct {
+ cb func()
+}
-var storeCallbacks []StoreCallback
+var storeCallbacks = make(map[*storeCallback]bool)
-func RegisterStoreChangeCallback(cb StoreCallback) {
+func RegisterStoreChangeCallback(cb func()) *storeCallback {
startWatchingConfigDir()
cb()
- storeCallbacks = append(storeCallbacks, cb)
+ s := &storeCallback{cb}
+ storeCallbacks[s] = true
+ return s
}
-func UnregisterStoreChangeCallback(cb StoreCallback) {
- //TODO: this function is ridiculous, doing slow iteration like this and reflection too.
-
- index := -1
- for i, e := range storeCallbacks {
- if reflect.ValueOf(e).Pointer() == reflect.ValueOf(cb).Pointer() {
- index = i
- break
- }
- }
- if index == -1 {
- return
- }
- newList := storeCallbacks[0:index]
- if index < len(storeCallbacks)-1 {
- newList = append(newList, storeCallbacks[index+1:]...)
- }
- storeCallbacks = newList
+func UnregisterStoreChangeCallback(cb *storeCallback) {
+ delete(storeCallbacks, cb)
}
diff --git a/conf/storewatcher_windows.go b/conf/storewatcher_windows.go
index f3f38fef..ddfc8b92 100644
--- a/conf/storewatcher_windows.go
+++ b/conf/storewatcher_windows.go
@@ -46,8 +46,8 @@ func startWatchingConfigDir() {
log.Fatalf("Unable to wait on config directory watcher: %v", err)
}
- for _, cb := range storeCallbacks {
- cb()
+ for cb := range storeCallbacks {
+ cb.cb()
}
err = findNextChangeNotification(h)