Skip to content

Commit

Permalink
populate online
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Nov 24, 2023
1 parent dc91927 commit 99d76a2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
17 changes: 6 additions & 11 deletions hscontrol/mapper/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
16 changes: 15 additions & 1 deletion hscontrol/poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion integration/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 99d76a2

Please sign in to comment.