From 4de49f5f4934f6f9b05abb0b49ccd1e0f3468005 Mon Sep 17 00:00:00 2001 From: Juan Font Date: Tue, 27 Dec 2022 11:30:59 +0000 Subject: [PATCH] Add isEphemeral() method to Machine --- app.go | 3 +-- machine.go | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app.go b/app.go index 64907572..9eb52d81 100644 --- a/app.go +++ b/app.go @@ -257,8 +257,7 @@ func (h *Headscale) expireEphemeralNodesWorker() { expiredFound := false for _, machine := range machines { - if machine.AuthKey != nil && machine.LastSeen != nil && - machine.AuthKey.Ephemeral && + if machine.isEphemeral() && machine.LastSeen != nil && time.Now(). After(machine.LastSeen.Add(h.cfg.EphemeralNodeInactivityTimeout)) { expiredFound = true diff --git a/machine.go b/machine.go index 79485f7d..a77d2227 100644 --- a/machine.go +++ b/machine.go @@ -153,6 +153,12 @@ func (machine *Machine) isOnline() bool { return machine.LastSeen.After(time.Now().Add(-keepAliveInterval)) } +// isEphemeral returns if the machine is registered as an Ephemeral node. +// https://tailscale.com/kb/1111/ephemeral-nodes/ +func (machine *Machine) isEphemeral() bool { + return machine.AuthKey != nil && machine.AuthKey.Ephemeral +} + func containsAddresses(inputs []string, addrs []string) bool { for _, addr := range addrs { if containsStr(inputs, addr) {