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

@ -93,15 +93,9 @@ func (h *Headscale) handleExistingNode(
}
ctx := types.NotifyCtx(context.Background(), "logout-ephemeral", "na")
h.nodeNotifier.NotifyAll(ctx, types.StateUpdate{
Type: types.StatePeerRemoved,
Removed: []types.NodeID{node.ID},
})
h.nodeNotifier.NotifyAll(ctx, types.UpdatePeerRemoved(node.ID))
if changedNodes != nil {
h.nodeNotifier.NotifyAll(ctx, types.StateUpdate{
Type: types.StatePeerChanged,
ChangeNodes: changedNodes,
})
h.nodeNotifier.NotifyAll(ctx, types.UpdatePeerChanged(changedNodes...))
}
}
@ -114,7 +108,7 @@ func (h *Headscale) handleExistingNode(
}
ctx := types.NotifyCtx(context.Background(), "logout-expiry", "na")
h.nodeNotifier.NotifyWithIgnore(ctx, types.StateUpdateExpire(node.ID, requestExpiry), node.ID)
h.nodeNotifier.NotifyWithIgnore(ctx, types.UpdateExpire(node.ID, requestExpiry), node.ID)
}
return &tailcfg.RegisterResponse{
@ -249,7 +243,7 @@ func (h *Headscale) handleRegisterWithAuthKey(
if !updateSent {
ctx := types.NotifyCtx(context.Background(), "node updated", node.Hostname)
h.nodeNotifier.NotifyAll(ctx, types.StateUpdatePeerAdded(node.ID))
h.nodeNotifier.NotifyAll(ctx, types.UpdatePeerChanged(node.ID))
}
return &tailcfg.RegisterResponse{