use helper function for constructing state updates (#2410)

This helps preventing messages being sent with the wrong update type
and payload combination, and it is shorter/neater.

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
Kristoffer Dalby 2025-02-07 13:49:59 +01:00 committed by GitHub
parent b92bd3d27e
commit 1f0110fe06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 56 additions and 107 deletions

View file

@ -17,6 +17,7 @@ import (
"gorm.io/gorm"
"tailscale.com/tailcfg"
"tailscale.com/types/key"
"tailscale.com/types/ptr"
)
const (
@ -626,11 +627,7 @@ func enableRoutes(tx *gorm.DB,
node.Routes = nRoutes
return &types.StateUpdate{
Type: types.StatePeerChanged,
ChangeNodes: []types.NodeID{node.ID},
Message: "created in db.enableRoutes",
}, nil
return ptr.To(types.UpdatePeerChanged(node.ID)), nil
}
func generateGivenName(suppliedName string, randomSuffix bool) (string, error) {
@ -717,10 +714,7 @@ func ExpireExpiredNodes(tx *gorm.DB,
}
if len(expired) > 0 {
return started, types.StateUpdate{
Type: types.StatePeerChangedPatch,
ChangePatches: expired,
}, true
return started, types.UpdatePeerPatch(expired...), true
}
return started, types.StateUpdate{}, false