mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-26 17:03:06 +00:00
Use helper methods in Machine
This commit is contained in:
parent
3da872bb30
commit
940dbc7706
1 changed files with 13 additions and 4 deletions
17
machine.go
17
machine.go
|
@ -138,6 +138,17 @@ func (machine Machine) isExpired() bool {
|
||||||
return time.Now().UTC().After(*machine.Expiry)
|
return time.Now().UTC().After(*machine.Expiry)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isOnline returns if the machine is connected to Headscale.
|
||||||
|
// This is really a naive implementation, as we don't really see
|
||||||
|
// if there is a working connection between the client and the server.
|
||||||
|
func (machine *Machine) isOnline() bool {
|
||||||
|
if machine.LastSeen == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return machine.LastSeen.After(time.Now().Add(-keepAliveInterval))
|
||||||
|
}
|
||||||
|
|
||||||
func containsAddresses(inputs []string, addrs []string) bool {
|
func containsAddresses(inputs []string, addrs []string) bool {
|
||||||
for _, addr := range addrs {
|
for _, addr := range addrs {
|
||||||
if contains(inputs, addr) {
|
if contains(inputs, addr) {
|
||||||
|
@ -708,9 +719,7 @@ func (h *Headscale) toNode(
|
||||||
|
|
||||||
hostInfo := machine.GetHostInfo()
|
hostInfo := machine.GetHostInfo()
|
||||||
|
|
||||||
// A node is Online if it is connected to the control server,
|
online := machine.isOnline()
|
||||||
// and we now we update LastSeen every keepAliveInterval duration at least.
|
|
||||||
online := machine.LastSeen.After(time.Now().Add(-keepAliveInterval))
|
|
||||||
|
|
||||||
node := tailcfg.Node{
|
node := tailcfg.Node{
|
||||||
ID: tailcfg.NodeID(machine.ID), // this is the actual ID
|
ID: tailcfg.NodeID(machine.ID), // this is the actual ID
|
||||||
|
@ -1023,7 +1032,7 @@ func (h *Headscale) EnableRoutes(machine *Machine, routeStrs ...string) error {
|
||||||
|
|
||||||
// Mark already as primary if there is only this node offering this subnet
|
// Mark already as primary if there is only this node offering this subnet
|
||||||
// (and is not an exit route)
|
// (and is not an exit route)
|
||||||
if prefix != ExitRouteV4 && prefix != ExitRouteV6 {
|
if !route.isExitRoute() {
|
||||||
route.IsPrimary = h.isUniquePrefix(route)
|
route.IsPrimary = h.isUniquePrefix(route)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue