mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 08:16:39 +00:00
Fix auto-update message handling
This commit is contained in:
@@ -273,7 +273,7 @@ func (c *ConnectClient) run(mobileDependency MobileDependency, runningChan chan
|
|||||||
c.engineMutex.Lock()
|
c.engineMutex.Lock()
|
||||||
c.engine = NewEngine(engineCtx, cancel, signalClient, mgmClient, relayManager, engineConfig, mobileDependency, c.statusRecorder, checks)
|
c.engine = NewEngine(engineCtx, cancel, signalClient, mgmClient, relayManager, engineConfig, mobileDependency, c.statusRecorder, checks)
|
||||||
if loginResp.PeerConfig != nil && loginResp.PeerConfig.AutoUpdate != nil {
|
if loginResp.PeerConfig != nil && loginResp.PeerConfig.AutoUpdate != nil {
|
||||||
c.engine.handleAutoUpdateVersion(loginResp.PeerConfig.AutoUpdate)
|
c.engine.InitialUpdateHandling(loginResp.PeerConfig.AutoUpdate)
|
||||||
}
|
}
|
||||||
c.engine.SetSyncResponsePersistence(c.persistSyncResponse)
|
c.engine.SetSyncResponsePersistence(c.persistSyncResponse)
|
||||||
c.engineMutex.Unlock()
|
c.engineMutex.Unlock()
|
||||||
|
|||||||
@@ -509,6 +509,12 @@ func (e *Engine) Start(netbirdConfig *mgmProto.NetbirdConfig, mgmtURL *url.URL)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *Engine) InitialUpdateHandling(autoUpdateSettings *mgmProto.AutoUpdateSettings) {
|
||||||
|
e.syncMsgMux.Lock()
|
||||||
|
defer e.syncMsgMux.Unlock()
|
||||||
|
e.handleAutoUpdateVersion(autoUpdateSettings, true)
|
||||||
|
}
|
||||||
|
|
||||||
func (e *Engine) createFirewall() error {
|
func (e *Engine) createFirewall() error {
|
||||||
if e.config.DisableFirewall {
|
if e.config.DisableFirewall {
|
||||||
log.Infof("firewall is disabled")
|
log.Infof("firewall is disabled")
|
||||||
@@ -721,20 +727,36 @@ func (e *Engine) PopulateNetbirdConfig(netbirdConfig *mgmProto.NetbirdConfig, mg
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Engine) handleAutoUpdateVersion(autoUpdateSettings *mgmProto.AutoUpdateSettings) {
|
func (e *Engine) handleAutoUpdateVersion(autoUpdateSettings *mgmProto.AutoUpdateSettings, initialCheck bool) {
|
||||||
if autoUpdateSettings == nil {
|
if autoUpdateSettings == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if e.updateManager == nil && autoUpdateSettings.Version != disableAutoUpdate && autoUpdateSettings.AlwaysUpdate {
|
|
||||||
e.updateManager = updatemanager.NewUpdateManager(e.statusRecorder, e.stateManager)
|
disabled := autoUpdateSettings.Version == disableAutoUpdate
|
||||||
e.updateManager.Start(e.ctx)
|
|
||||||
} else if e.updateManager != nil && autoUpdateSettings.Version == disableAutoUpdate {
|
// Stop and cleanup if disabled
|
||||||
|
if e.updateManager != nil && disabled {
|
||||||
|
log.Infof("auto-update is disabled, stopping update manager")
|
||||||
e.updateManager.Stop()
|
e.updateManager.Stop()
|
||||||
e.updateManager = nil
|
e.updateManager = nil
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if e.updateManager != nil && autoUpdateSettings.AlwaysUpdate {
|
|
||||||
e.updateManager.SetVersion(autoUpdateSettings.Version)
|
// Skip check unless AlwaysUpdate is enabled or this is the initial check at startup
|
||||||
|
if !autoUpdateSettings.AlwaysUpdate && !initialCheck {
|
||||||
|
log.Debugf("skipping auto-update check, AlwaysUpdate is false and this is not the initial check")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start manager if needed
|
||||||
|
if e.updateManager == nil {
|
||||||
|
log.Infof("starting auto-update manager")
|
||||||
|
e.updateManager = updatemanager.NewUpdateManager(e.statusRecorder, e.stateManager)
|
||||||
|
e.updateManager.Start(e.ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Infof("handling auto-update version: %s", autoUpdateSettings.Version)
|
||||||
|
e.updateManager.SetVersion(autoUpdateSettings.Version)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Engine) handleSync(update *mgmProto.SyncResponse) error {
|
func (e *Engine) handleSync(update *mgmProto.SyncResponse) error {
|
||||||
@@ -742,7 +764,7 @@ func (e *Engine) handleSync(update *mgmProto.SyncResponse) error {
|
|||||||
defer e.syncMsgMux.Unlock()
|
defer e.syncMsgMux.Unlock()
|
||||||
|
|
||||||
if update.NetworkMap != nil && update.NetworkMap.PeerConfig != nil {
|
if update.NetworkMap != nil && update.NetworkMap.PeerConfig != nil {
|
||||||
e.handleAutoUpdateVersion(update.NetworkMap.PeerConfig.AutoUpdate)
|
e.handleAutoUpdateVersion(update.NetworkMap.PeerConfig.AutoUpdate, false)
|
||||||
}
|
}
|
||||||
if update.GetNetbirdConfig() != nil {
|
if update.GetNetbirdConfig() != nil {
|
||||||
wCfg := update.GetNetbirdConfig()
|
wCfg := update.GetNetbirdConfig()
|
||||||
|
|||||||
@@ -273,7 +273,10 @@ message PeerConfig {
|
|||||||
|
|
||||||
message AutoUpdateSettings {
|
message AutoUpdateSettings {
|
||||||
string version = 1;
|
string version = 1;
|
||||||
// When false, only update if the connection started < 1 minute ago
|
/*
|
||||||
|
alwaysUpdate = true → Updates happen automatically in the background
|
||||||
|
alwaysUpdate = false → Updates only happen when triggered by a peer connection
|
||||||
|
*/
|
||||||
bool alwaysUpdate = 2;
|
bool alwaysUpdate = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user