From 99d76a202c3428403ce2eebb91427f08f765862c Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Thu, 23 Nov 2023 17:18:24 +0000 Subject: [PATCH] populate online Signed-off-by: Kristoffer Dalby --- hscontrol/mapper/mapper.go | 17 ++++++----------- hscontrol/poll.go | 16 +++++++++++++++- integration/run.sh | 2 +- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/hscontrol/mapper/mapper.go b/hscontrol/mapper/mapper.go index 17e6262c8f8..faed56bd6a2 100644 --- a/hscontrol/mapper/mapper.go +++ b/hscontrol/mapper/mapper.go @@ -419,21 +419,16 @@ func (m *Mapper) marshalMapResponse( "MapResponse": resp, } - responseType := "unknown" + responseType := "keepalive" - if resp.Peers != nil && len(resp.Peers) > 0 { + switch { + case resp.Peers != nil && len(resp.Peers) > 0: responseType = "full" - } - - if resp.PeersChanged != nil && len(resp.PeersChanged) > 0 { + case resp.PeersChanged != nil && len(resp.PeersChanged) > 0: responseType = "changed" - } - - if resp.PeersChangedPatch != nil && len(resp.PeersChangedPatch) > 0 { + case resp.PeersChangedPatch != nil && len(resp.PeersChangedPatch) > 0: responseType = "patch" - } - - if resp.PeersRemoved != nil && len(resp.PeersRemoved) > 0 { + case resp.PeersRemoved != nil && len(resp.PeersRemoved) > 0: responseType = "removed" } diff --git a/hscontrol/poll.go b/hscontrol/poll.go index 1f25bc2fd31..4e7f3489401 100644 --- a/hscontrol/poll.go +++ b/hscontrol/poll.go @@ -62,7 +62,7 @@ func (h *Headscale) handlePoll( ) { logInfo, logErr := logPollFunc(mapRequest, node) - // This is the mechanism where the node gives us inforamtion about its + // This is the mechanism where the node gives us information about its // current configuration. // // If OmitPeers is true, Stream is false, and ReadOnly is false, @@ -83,6 +83,10 @@ func (h *Headscale) handlePoll( Msg("Received endpoint update") change := node.PeerChangeFromMapRequest(mapRequest) + + online := h.nodeNotifier.IsConnected(node.MachineKey) + change.Online = &online + node.ApplyPeerChange(&change) // Check if the Hostinfo of the node has changed. @@ -171,6 +175,11 @@ func (h *Headscale) handlePoll( } change := node.PeerChangeFromMapRequest(mapRequest) + + // A stream is being set up, the node is Online + online := true + change.Online = &online + node.ApplyPeerChange(&change) // Only save HostInfo if changed, update routes if changed @@ -211,6 +220,11 @@ func (h *Headscale) handlePoll( return } + for _, peer := range peers { + online := h.nodeNotifier.IsConnected(peer.MachineKey) + peer.IsOnline = &online + } + mapp := mapper.NewMapper( node, peers, diff --git a/integration/run.sh b/integration/run.sh index b03338a5c10..8c1fb0161c0 100755 --- a/integration/run.sh +++ b/integration/run.sh @@ -29,7 +29,7 @@ run_tests() { -failfast \ -timeout 120m \ -parallel 1 \ - -run "^$test_name\$" >/dev/null 2>&1 + -run "^$test_name\$" >./control_logs/"$test_name"_"$i".log 2>&1 status=$? end=$(date +%s)