diff --git a/hscontrol/db/node.go b/hscontrol/db/node.go index da4836c76f..dc4b75dd61 100644 --- a/hscontrol/db/node.go +++ b/hscontrol/db/node.go @@ -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) { @@ -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. diff --git a/hscontrol/mapper/mapper.go b/hscontrol/mapper/mapper.go index c971f56436..0fead909bd 100644 --- a/hscontrol/mapper/mapper.go +++ b/hscontrol/mapper/mapper.go @@ -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" @@ -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, @@ -618,5 +614,7 @@ func appendPeerChanges( resp.UserProfiles = profiles resp.SSHPolicy = sshPolicy + resp.OnlineChange = peers.OnlineNodeMap() + return nil } diff --git a/hscontrol/types/node.go b/hscontrol/types/node.go index f8af2338e7..f2b193c7dc 100644 --- a/hscontrol/types/node.go +++ b/hscontrol/types/node.go @@ -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() {