From 55b35f4160c08323039842ec608e7a1b89c17c51 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Wed, 1 May 2024 17:06:42 +0200 Subject: [PATCH] fix issue preveting get node when disco is missing (#1919) Fixed #1816 Signed-off-by: Kristoffer Dalby --- hscontrol/types/node.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hscontrol/types/node.go b/hscontrol/types/node.go index 7f285924..b0afe99d 100644 --- a/hscontrol/types/node.go +++ b/hscontrol/types/node.go @@ -306,11 +306,15 @@ func (node *Node) AfterFind(tx *gorm.DB) error { } node.NodeKey = nodeKey - var discoKey key.DiscoPublic - if err := discoKey.UnmarshalText([]byte(node.DiscoKeyDatabaseField)); err != nil { - return fmt.Errorf("unmarshalling disco key from db: %w", err) + // DiscoKey might be empty if a node has not sent it to headscale. + // This means that this might fail if the disco key is empty. + if node.DiscoKeyDatabaseField != "" { + var discoKey key.DiscoPublic + if err := discoKey.UnmarshalText([]byte(node.DiscoKeyDatabaseField)); err != nil { + return fmt.Errorf("unmarshalling disco key from db: %w", err) + } + node.DiscoKey = discoKey } - node.DiscoKey = discoKey endpoints := make([]netip.AddrPort, len(node.EndpointsDatabaseField)) for idx, ep := range node.EndpointsDatabaseField {