Skip to content

Commit ad3985a

Browse files
Merge pull request #4504 from netbirdio/sub-feat/auto-upgrade/move-version-networkmap
Move autoUpdateVersion inside NetworkMap
2 parents 5042339 + 02afd4e commit ad3985a

File tree

7 files changed

+233
-238
lines changed

7 files changed

+233
-238
lines changed

client/internal/engine.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ const (
7676
PeerConnectionTimeoutMax = 45000 // ms
7777
PeerConnectionTimeoutMin = 30000 // ms
7878
connInitLimit = 200
79-
// skipAutoUpdateVersion used as a placeholder for autoUpdateVersion in proto responses to indicate response contains no new updates
80-
skipAutoUpdateVersion = "skip"
81-
disableAutoUpdate = "disabled"
79+
disableAutoUpdate = "disabled"
8280
)
8381

8482
var ErrResetConnection = fmt.Errorf("reset connection")
@@ -704,25 +702,25 @@ func (e *Engine) PopulateNetbirdConfig(netbirdConfig *mgmProto.NetbirdConfig, mg
704702
}
705703

706704
func (e *Engine) handleAutoUpdateVersion(autoUpdateVersion string) {
707-
if autoUpdateVersion != skipAutoUpdateVersion {
708-
if e.updateManager == nil && autoUpdateVersion != disableAutoUpdate {
709-
e.updateManager = updatemanager.NewUpdateManager(e.statusRecorder)
710-
e.updateManager.Start(e.ctx)
711-
} else if e.updateManager != nil && autoUpdateVersion == disableAutoUpdate {
712-
e.updateManager.Stop()
713-
e.updateManager = nil
714-
}
715-
if e.updateManager != nil {
716-
e.updateManager.SetVersion(autoUpdateVersion)
717-
}
705+
if e.updateManager == nil && autoUpdateVersion != disableAutoUpdate {
706+
e.updateManager = updatemanager.NewUpdateManager(e.statusRecorder)
707+
e.updateManager.Start(e.ctx)
708+
} else if e.updateManager != nil && autoUpdateVersion == disableAutoUpdate {
709+
e.updateManager.Stop()
710+
e.updateManager = nil
711+
}
712+
if e.updateManager != nil {
713+
e.updateManager.SetVersion(autoUpdateVersion)
718714
}
719715
}
720716

721717
func (e *Engine) handleSync(update *mgmProto.SyncResponse) error {
722718
e.syncMsgMux.Lock()
723719
defer e.syncMsgMux.Unlock()
724720

725-
e.handleAutoUpdateVersion(update.AutoUpdateVersion)
721+
if update.NetworkMap != nil && update.NetworkMap.PeerConfig != nil {
722+
e.handleAutoUpdateVersion(update.NetworkMap.PeerConfig.AutoUpdateVersion)
723+
}
726724
if update.GetNetbirdConfig() != nil {
727725
wCfg := update.GetNetbirdConfig()
728726
err := e.updateTURNs(wCfg.GetTurns())

management/server/account.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ const (
5252
peerSchedulerRetryInterval = 3 * time.Second
5353
emptyUserID = "empty user ID in claims"
5454
errorGettingDomainAccIDFmt = "error getting account ID by private domain: %v"
55-
// skipAutoUpdateVersion used as a placeholder for autoUpdateVersion in proto responses to indicate response contains no new updates
56-
skipAutoUpdateVersion = "skip"
5755
)
5856

5957
type userLoggedInOnce bool

management/server/grpcserver.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -710,19 +710,20 @@ func toPeerConfig(peer *nbpeer.Peer, network *types.Network, dnsName string, set
710710
Fqdn: fqdn,
711711
RoutingPeerDnsResolutionEnabled: settings.RoutingPeerDNSResolutionEnabled,
712712
LazyConnectionEnabled: settings.LazyConnectionEnabled,
713+
AutoUpdateVersion: settings.AutoUpdateVersion,
713714
}
714715
}
715716

716717
func toSyncResponse(ctx context.Context, config *nbconfig.Config, peer *nbpeer.Peer, turnCredentials *Token, relayCredentials *Token, networkMap *types.NetworkMap, dnsName string, checks []*posture.Checks, dnsCache *DNSConfigCache, settings *types.Settings, extraSettings *types.ExtraSettings, peerGroups []string) *proto.SyncResponse {
717718
response := &proto.SyncResponse{
718719
PeerConfig: toPeerConfig(peer, networkMap.Network, dnsName, settings),
719720
NetworkMap: &proto.NetworkMap{
720-
Serial: networkMap.Network.CurrentSerial(),
721-
Routes: toProtocolRoutes(networkMap.Routes),
722-
DNSConfig: toProtocolDNSConfig(networkMap.DNSConfig, dnsCache),
721+
Serial: networkMap.Network.CurrentSerial(),
722+
Routes: toProtocolRoutes(networkMap.Routes),
723+
DNSConfig: toProtocolDNSConfig(networkMap.DNSConfig, dnsCache),
724+
PeerConfig: toPeerConfig(peer, networkMap.Network, dnsName, settings),
723725
},
724-
Checks: toProtocolChecks(ctx, checks),
725-
AutoUpdateVersion: settings.AutoUpdateVersion,
726+
Checks: toProtocolChecks(ctx, checks),
726727
}
727728

728729
nbConfig := toNetbirdConfig(config, turnCredentials, relayCredentials, extraSettings)

management/server/peer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1554,8 +1554,8 @@ func deletePeers(ctx context.Context, am *DefaultAccountManager, transaction sto
15541554
RemotePeersIsEmpty: true,
15551555
FirewallRules: []*proto.FirewallRule{},
15561556
FirewallRulesIsEmpty: true,
1557+
PeerConfig: toPeerConfig(peer, network, dnsDomain, settings),
15571558
},
1558-
AutoUpdateVersion: settings.AutoUpdateVersion,
15591559
},
15601560
NetworkMap: &types.NetworkMap{},
15611561
})

management/server/token_mgr.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ func (m *TimeBasedAuthSecretsManager) pushNewTURNAndRelayTokens(ctx context.Cont
210210
NetbirdConfig: &proto.NetbirdConfig{
211211
Turns: turns,
212212
},
213-
AutoUpdateVersion: skipAutoUpdateVersion,
214213
}
215214

216215
// workaround for the case when client is unable to handle turn and relay updates at different time
@@ -247,7 +246,6 @@ func (m *TimeBasedAuthSecretsManager) pushNewRelayTokens(ctx context.Context, ac
247246
},
248247
// omit Turns to avoid updates there
249248
},
250-
AutoUpdateVersion: skipAutoUpdateVersion,
251249
}
252250

253251
m.extendNetbirdConfig(ctx, peerID, accountID, update)

0 commit comments

Comments
 (0)