diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-20 14:18:01 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-20 14:18:01 +0200 |
commit | cdb8c53cdea8d8ac6e6f2112e4a5e844bffd01a4 (patch) | |
tree | db88ec568dfc508da863e67164de909448c66742 /manager/updatestate.go | |
parent | service: move route monitor and account for changing index (diff) | |
download | wireguard-windows-cdb8c53cdea8d8ac6e6f2112e4a5e844bffd01a4.tar.xz wireguard-windows-cdb8c53cdea8d8ac6e6f2112e4a5e844bffd01a4.zip |
service: split into tunnel and manager
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'manager/updatestate.go')
-rw-r--r-- | manager/updatestate.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/manager/updatestate.go b/manager/updatestate.go new file mode 100644 index 00000000..2e82baf8 --- /dev/null +++ b/manager/updatestate.go @@ -0,0 +1,57 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2019 WireGuard LLC. All Rights Reserved. + */ + +package manager + +import ( + "log" + "time" + + "golang.zx2c4.com/wireguard/windows/updater" + "golang.zx2c4.com/wireguard/windows/version" +) + +type UpdateState uint32 + +const ( + UpdateStateUnknown UpdateState = iota + UpdateStateFoundUpdate + UpdateStateUpdatesDisabledUnofficialBuild +) + +var updateState = UpdateStateUnknown + +func checkForUpdates() { + if !version.IsRunningOfficialVersion() { + log.Println("Build is not official, so updates are disabled") + updateState = UpdateStateUpdatesDisabledUnofficialBuild + IPCServerNotifyUpdateFound(updateState) + return + } + + time.Sleep(time.Second * 10) + + first := true + for { + update, err := updater.CheckForUpdate() + if err == nil && update != nil { + log.Println("An update is available") + updateState = UpdateStateFoundUpdate + IPCServerNotifyUpdateFound(updateState) + return + } + if err != nil { + log.Printf("Update checker: %v", err) + if first { + time.Sleep(time.Minute * 4) + first = false + } else { + time.Sleep(time.Minute * 25) + } + } else { + time.Sleep(time.Hour) + } + } +} |