From 08efea73ac7a823e40502a883fd9e78fc800aab8 Mon Sep 17 00:00:00 2001 From: Aceix Date: Thu, 11 Apr 2024 12:44:15 +0000 Subject: [PATCH] fix(NET-1055): fix auto-relay with enrollment key (#2887) --- auth/host_session.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/auth/host_session.go b/auth/host_session.go index 90ae2ff12..829516619 100644 --- a/auth/host_session.go +++ b/auth/host_session.go @@ -248,12 +248,20 @@ func CheckNetRegAndHostUpdate(networks []string, h *models.Host, relayNodeId uui // check if relay node exists and acting as relay relaynode, err := logic.GetNodeByID(relayNodeId.String()) if err == nil && relaynode.IsRelay { + slog.Info(fmt.Sprintf("adding relayed node %s to relay %s on network %s", newNode.ID.String(), relayNodeId.String(), network)) newNode.IsRelayed = true newNode.RelayedBy = relayNodeId.String() - slog.Info(fmt.Sprintf("adding relayed node %s to relay %s on network %s", newNode.ID.String(), relayNodeId.String(), network)) + updatedRelayNode := relaynode + updatedRelayNode.RelayedNodes = append(updatedRelayNode.RelayedNodes, newNode.ID.String()) + logic.UpdateRelayed(&relaynode, &updatedRelayNode) + if err := logic.UpsertNode(&updatedRelayNode); err != nil { + slog.Error("failed to update node", "nodeid", relayNodeId.String()) + } if err := logic.UpsertNode(newNode); err != nil { slog.Error("failed to update node", "nodeid", relayNodeId.String()) } + } else { + slog.Error("failed to relay node. maybe specified relay node is actually not a relay?", "err", err) } } logger.Log(1, "added new node", newNode.ID.String(), "to host", h.Name)