Files
Roman Zakharchuk a780e4a5c7 restore update feature (#36)
* replace wg.exe with awg.exe

* update docs, update admin reg key

* rename awg modules

* build awg from source

* remove unused params

* improve work with tools

* safe rebranding: change upgrade code, windows class and name

* safe rebranding: wg -> awg

* update dependencies, fixed showing transfered KBs

* Revert "remove application update feature"

This reverts commit 9670f4298e.

* Revert "remove application update feature #2"

This reverts commit b0c96a9fd6.

* updatepage and tray change WireGuard to AmneziaWG

* move crypto from indirect to direct

---------

Signed-off-by: Roman Zakharchuk <romikb@mail.ru>
2025-03-10 09:58:37 +07:00

66 lines
1.6 KiB
Go

/* SPDX-License-Identifier: MIT
*
* Copyright (C) 2019-2022 WireGuard LLC. All Rights Reserved.
*/
package manager
import (
"log"
"time"
_ "unsafe"
"github.com/amnezia-vpn/amneziawg-windows-client/services"
"github.com/amnezia-vpn/amneziawg-windows-client/updater"
"github.com/amnezia-vpn/amneziawg-windows-client/version"
)
//go:linkname fastrandn runtime.fastrandn
func fastrandn(n uint32) uint32
type UpdateState uint32
const (
UpdateStateUnknown UpdateState = iota
UpdateStateFoundUpdate
UpdateStateUpdatesDisabledUnofficialBuild
)
var updateState = UpdateStateUnknown
func jitterSleep(min, max time.Duration) {
time.Sleep(min + time.Millisecond*time.Duration(fastrandn(uint32((max-min+1)/time.Millisecond))))
}
func checkForUpdates() {
if !version.IsRunningOfficialVersion() {
log.Println("Build is not official, so updates are disabled")
updateState = UpdateStateUpdatesDisabledUnofficialBuild
IPCServerNotifyUpdateFound(updateState)
return
}
if services.StartedAtBoot() {
jitterSleep(time.Minute*2, time.Minute*5)
}
noError, didNotify := true, false
for {
update, err := updater.CheckForUpdate()
if err == nil && update != nil && !didNotify {
log.Println("An update is available")
updateState = UpdateStateFoundUpdate
IPCServerNotifyUpdateFound(updateState)
didNotify = true
} else if err != nil && !didNotify {
log.Printf("Update checker: %v", err)
if noError {
jitterSleep(time.Minute*4, time.Minute*6)
noError = false
} else {
jitterSleep(time.Minute*25, time.Minute*30)
}
} else {
jitterSleep(time.Hour-time.Minute*3, time.Hour+time.Minute*3)
}
}
}