refactor: introduce func ContainsNodeKey

This commit is contained in:
ArcticLampyrid 2024-11-15 02:32:03 +08:00
parent b6adc84dc6
commit b3beb73f3f
No known key found for this signature in database
GPG key ID: DC72A2519E77D6CF
2 changed files with 11 additions and 12 deletions

View file

@ -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,

View file

@ -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),