Skip to content

Commit

Permalink
set online status in lite requests
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Sep 24, 2023
1 parent 0030af3 commit f22cdac
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
12 changes: 1 addition & 11 deletions hscontrol/db/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,16 +635,6 @@ func (hsdb *HSDatabase) IsRoutesEnabled(node *types.Node, routeStr string) bool
return false
}

func OnlineNodeMap(peers types.Nodes) map[tailcfg.NodeID]bool {
ret := make(map[tailcfg.NodeID]bool)

for _, peer := range peers {
ret[tailcfg.NodeID(peer.ID)] = peer.IsOnline()
}

return ret
}

func (hsdb *HSDatabase) ListOnlineNodes(
node *types.Node,
) (map[tailcfg.NodeID]bool, error) {
Expand All @@ -656,7 +646,7 @@ func (hsdb *HSDatabase) ListOnlineNodes(
return nil, err
}

return OnlineNodeMap(peers), nil
return peers.OnlineNodeMap(), nil
}

// enableRoutes enables new routes based on a list of new routes.
Expand Down
6 changes: 2 additions & 4 deletions hscontrol/mapper/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"time"

mapset "github.com/deckarep/golang-set/v2"
"github.com/juanfont/headscale/hscontrol/db"
"github.com/juanfont/headscale/hscontrol/policy"
"github.com/juanfont/headscale/hscontrol/types"
"github.com/juanfont/headscale/hscontrol/util"
Expand Down Expand Up @@ -218,9 +217,6 @@ func (m *Mapper) fullMapResponse(
return nil, err
}

// TODO(kradalby): Move this into appendPeerChanges?
resp.OnlineChange = db.OnlineNodeMap(peers)

err = appendPeerChanges(
resp,
pol,
Expand Down Expand Up @@ -618,5 +614,7 @@ func appendPeerChanges(
resp.UserProfiles = profiles
resp.SSHPolicy = sshPolicy

resp.OnlineChange = peers.OnlineNodeMap()

return nil
}
10 changes: 10 additions & 0 deletions hscontrol/types/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ type (
Nodes []*Node
)

func (nodes Nodes) OnlineNodeMap() map[tailcfg.NodeID]bool {
ret := make(map[tailcfg.NodeID]bool)

for _, node := range nodes {
ret[tailcfg.NodeID(node.ID)] = node.IsOnline()
}

return ret
}

type NodeAddresses []netip.Addr

func (na NodeAddresses) Sort() {
Expand Down

0 comments on commit f22cdac

Please sign in to comment.