mapper: send change instead of full update (#2775)

This commit is contained in:
Kristoffer Dalby
2025-09-17 14:23:21 +02:00
committed by GitHub
parent 4de56c40d8
commit ed3a9c8d6d
8 changed files with 96 additions and 69 deletions

View File

@@ -3,6 +3,7 @@ package change
import (
"errors"
"time"
"github.com/juanfont/headscale/hscontrol/types"
)
@@ -68,6 +69,9 @@ type ChangeSet struct {
// IsSubnetRouter indicates whether the node is a subnet router.
IsSubnetRouter bool
// NodeExpiry is set if the change is NodeKeyExpiry.
NodeExpiry *time.Time
}
func (c *ChangeSet) Validate() error {
@@ -126,6 +130,11 @@ func RemoveUpdatesForSelf(id types.NodeID, cs []ChangeSet) (ret []ChangeSet) {
return ret
}
// IsSelfUpdate reports whether this ChangeSet represents an update to the given node itself.
func (c ChangeSet) IsSelfUpdate(nodeID types.NodeID) bool {
return c.NodeID == nodeID
}
func (c ChangeSet) AlsoSelf() bool {
// If NodeID is 0, it means this ChangeSet is not related to a specific node,
// so we consider it as a change that should be sent to all nodes.
@@ -179,10 +188,11 @@ func NodeOffline(id types.NodeID) ChangeSet {
}
}
func KeyExpiry(id types.NodeID) ChangeSet {
func KeyExpiry(id types.NodeID, expiry time.Time) ChangeSet {
return ChangeSet{
Change: NodeKeyExpiry,
NodeID: id,
Change: NodeKeyExpiry,
NodeID: id,
NodeExpiry: &expiry,
}
}