diff --git a/hscontrol/handlers.go b/hscontrol/handlers.go index c97866d3..7a44aa27 100644 --- a/hscontrol/handlers.go +++ b/hscontrol/handlers.go @@ -99,18 +99,7 @@ func (h *Headscale) VerifyHandler( http.Error(writer, "Internal error", http.StatusInternalServerError) } - for _, node := range nodes { - log.Debug().Str("node", node.NodeKey.String()).Msg("Node") - } - - allow := false - // Check if the node is in the list of nodes - for _, node := range nodes { - if node.NodeKey == derpAdmitClientRequest.NodePublic { - allow = true - break - } - } + allow := nodes.ContainsNodeKey(derpAdmitClientRequest.NodePublic) resp := tailcfg.DERPAdmitClientResponse{ Allow: allow, diff --git a/hscontrol/types/node.go b/hscontrol/types/node.go index 9d632bd8..36a65062 100644 --- a/hscontrol/types/node.go +++ b/hscontrol/types/node.go @@ -223,6 +223,16 @@ func (nodes Nodes) FilterByIP(ip netip.Addr) Nodes { return found } +func (nodes Nodes) ContainsNodeKey(nodeKey key.NodePublic) bool { + for _, node := range nodes { + if node.NodeKey == nodeKey { + return true + } + } + + return false +} + func (node *Node) Proto() *v1.Node { nodeProto := &v1.Node{ Id: uint64(node.ID),