mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-26 08:53:05 +00:00
Update neighbours if node is expired or refreshed
In addition, only pass the map of registered and not expired nodes to clients.
This commit is contained in:
parent
caf1b1cabc
commit
68dc2a70db
2 changed files with 23 additions and 1 deletions
2
api.go
2
api.go
|
@ -186,7 +186,7 @@ func (h *Headscale) getMapResponse(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
peers, err := h.getPeers(machine)
|
||||
peers, err := h.getValidPeers(machine)
|
||||
if err != nil {
|
||||
log.Error().
|
||||
Str("func", "getMapResponse").
|
||||
|
|
22
machine.go
22
machine.go
|
@ -207,6 +207,23 @@ func (h *Headscale) getPeers(machine *Machine) (Machines, error) {
|
|||
return peers, nil
|
||||
}
|
||||
|
||||
func (h *Headscale) getValidPeers(machine *Machine) (Machines, error) {
|
||||
validPeers := make(Machines, 0)
|
||||
|
||||
peers, err := h.getPeers(machine)
|
||||
if err != nil {
|
||||
return Machines{}, err
|
||||
}
|
||||
|
||||
for _, peer := range peers {
|
||||
if peer.isRegistered() && !peer.isExpired() {
|
||||
validPeers = append(validPeers, peer)
|
||||
}
|
||||
}
|
||||
|
||||
return validPeers, nil
|
||||
}
|
||||
|
||||
func (h *Headscale) ListMachines() ([]Machine, error) {
|
||||
machines := []Machine{}
|
||||
if err := h.db.Preload("AuthKey").Preload("AuthKey.Namespace").Preload("Namespace").Find(&machines).Error; err != nil {
|
||||
|
@ -267,6 +284,8 @@ func (h *Headscale) ExpireMachine(machine *Machine) {
|
|||
now := time.Now()
|
||||
machine.Expiry = &now
|
||||
|
||||
h.setLastStateChangeToNow(machine.Namespace.Name)
|
||||
|
||||
h.db.Save(machine)
|
||||
}
|
||||
|
||||
|
@ -276,6 +295,9 @@ func (h *Headscale) RefreshMachine(machine *Machine, expiry time.Time) {
|
|||
|
||||
machine.LastSuccessfulUpdate = &now
|
||||
machine.Expiry = &expiry
|
||||
|
||||
h.setLastStateChangeToNow(machine.Namespace.Name)
|
||||
|
||||
h.db.Save(machine)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue