mirror of
https://github.com/juanfont/headscale.git
synced 2026-11-24 22:26:29 +09:00
types: add Node.KeyExpiryDisabled
Switch beside Expiry, as on Tailscale. Views regenerated in the same commit: the clone check does not compile without them.
This commit is contained in:
1 parent
fe98ddab90
commit
3d8472c4ef
3 files changed
+27
-4
No files matched your search
+20
-4
@@ -186,6 +186,11 @@ type Node struct {
|
||||
|
||||
Expiry *time.Time
|
||||
|
||||
// KeyExpiryDisabled keeps the node from expiring while it is set; Expiry
|
||||
// is kept, and counts again once it is cleared. Tailscale stores the two
|
||||
// apart the same way.
|
||||
KeyExpiryDisabled bool `gorm:"default:false"`
|
||||
|
||||
// LastSeen is when the node was last in contact with
|
||||
// headscale. It is best effort and not persisted.
|
||||
LastSeen *time.Time `gorm:"column:last_seen"`
|
||||
@@ -262,6 +267,10 @@ func (node *Node) IsExpired() bool {
|
||||
|
||||
// IsExpiredAt reports whether the node registration has expired at now.
|
||||
func (node *Node) IsExpiredAt(now time.Time) bool {
|
||||
if node.KeyExpiryDisabled {
|
||||
return false
|
||||
}
|
||||
|
||||
// If Expiry is not set, the client has not indicated that
|
||||
// it wants an expiry time, it is therefore considered
|
||||
// to mean "not expired"
|
||||
@@ -1142,6 +1151,16 @@ func (nv NodeView) IsExpiredAt(now time.Time) bool {
|
||||
return nv.ж.IsExpiredAt(now)
|
||||
}
|
||||
|
||||
// KeyExpiry is the expiry clients are sent: none while expiry is disabled,
|
||||
// whatever time is kept for when it is enabled again.
|
||||
func (nv NodeView) KeyExpiry() (time.Time, bool) {
|
||||
if !nv.Valid() || nv.KeyExpiryDisabled() {
|
||||
return time.Time{}, false
|
||||
}
|
||||
|
||||
return nv.Expiry().GetOk()
|
||||
}
|
||||
|
||||
// Online reports the node's last known connectivity.
|
||||
func (nv NodeView) Online() bool {
|
||||
if !nv.Valid() {
|
||||
@@ -1375,10 +1394,7 @@ func (nv NodeView) TailNode(
|
||||
derp = nv.Hostinfo().NetInfo().PreferredDERP()
|
||||
}
|
||||
|
||||
var keyExpiry time.Time
|
||||
if nv.Expiry().Valid() {
|
||||
keyExpiry = nv.Expiry().Get()
|
||||
}
|
||||
keyExpiry, _ := nv.KeyExpiry()
|
||||
|
||||
// Fail here, where the mapper drops just this peer, rather than in
|
||||
// json.Marshal, which fails the whole response.
|
||||
|
||||
@@ -105,6 +105,7 @@ var _NodeCloneNeedsRegeneration = Node(struct {
|
||||
AuthKey *Credential
|
||||
Ephemeral bool
|
||||
Expiry *time.Time
|
||||
KeyExpiryDisabled bool
|
||||
LastSeen *time.Time
|
||||
ApprovedRoutes Prefixes
|
||||
AutoApprovedRoutes Prefixes
|
||||
|
||||
@@ -250,6 +250,11 @@ func (v NodeView) AuthKey() CredentialView { return v.ж.AuthKey.View() }
|
||||
func (v NodeView) Ephemeral() bool { return v.ж.Ephemeral }
|
||||
func (v NodeView) Expiry() views.ValuePointer[time.Time] { return views.ValuePointerOf(v.ж.Expiry) }
|
||||
|
||||
// KeyExpiryDisabled keeps the node from expiring while it is set; Expiry
|
||||
// is kept, and counts again once it is cleared. Tailscale stores the two
|
||||
// apart the same way.
|
||||
func (v NodeView) KeyExpiryDisabled() bool { return v.ж.KeyExpiryDisabled }
|
||||
|
||||
// LastSeen is when the node was last in contact with
|
||||
// headscale. It is best effort and not persisted.
|
||||
func (v NodeView) LastSeen() views.ValuePointer[time.Time] {
|
||||
@@ -336,6 +341,7 @@ var _NodeViewNeedsRegeneration = Node(struct {
|
||||
AuthKey *Credential
|
||||
Ephemeral bool
|
||||
Expiry *time.Time
|
||||
KeyExpiryDisabled bool
|
||||
LastSeen *time.Time
|
||||
ApprovedRoutes Prefixes
|
||||
AutoApprovedRoutes Prefixes
|
||||
|
||||
Reference in new issue
Block a user