From 41ca8790a36c05334df12eca8e749aceb1c31a29 Mon Sep 17 00:00:00 2001 From: Max Ma Date: Fri, 30 Aug 2024 14:21:12 +0200 Subject: [PATCH 1/2] update peer info after extClient public key changed --- controllers/ext_client.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/controllers/ext_client.go b/controllers/ext_client.go index b98256927..55b614a74 100644 --- a/controllers/ext_client.go +++ b/controllers/ext_client.go @@ -531,6 +531,7 @@ func updateExtClient(w http.ResponseWriter, r *http.Request) { var update models.CustomExtClient //var oldExtClient models.ExtClient var sendPeerUpdate bool + var replacePeers bool err := json.NewDecoder(r.Body).Decode(&update) if err != nil { logger.Log(0, r.Header.Get("user"), "error decoding request body: ", @@ -588,6 +589,11 @@ func updateExtClient(w http.ResponseWriter, r *http.Request) { if update.Enabled != oldExtClient.Enabled { sendPeerUpdate = true } + if update.PublicKey != oldExtClient.PublicKey { + //remove old peer entry + sendPeerUpdate = true + replacePeers = true + } newclient := logic.UpdateExtClient(&oldExtClient, &update) if err := logic.DeleteExtClient(oldExtClient.Network, oldExtClient.ClientID); err != nil { slog.Error( @@ -630,7 +636,7 @@ func updateExtClient(w http.ResponseWriter, r *http.Request) { if sendPeerUpdate { // need to send a peer update to the ingress node as enablement of one of it's clients has changed ingressNode, err := logic.GetNodeByID(newclient.IngressGatewayID) if err == nil { - if err = mq.PublishPeerUpdate(false); err != nil { + if err = mq.PublishPeerUpdate(replacePeers); err != nil { logger.Log( 1, "error setting ext peers on", @@ -657,7 +663,7 @@ func updateExtClient(w http.ResponseWriter, r *http.Request) { slog.Error("Failed to get nodes", "error", err) return } - go mq.PublishSingleHostPeerUpdate(ingressHost, nodes, nil, []models.ExtClient{oldExtClient}, false, nil) + go mq.PublishSingleHostPeerUpdate(ingressHost, nodes, nil, []models.ExtClient{oldExtClient}, replacePeers, nil) } } From 461f125ed152b2c7a52a5b8fe0b911b79a4dc942 Mon Sep 17 00:00:00 2001 From: Max Ma Date: Wed, 4 Sep 2024 17:04:23 +0200 Subject: [PATCH 2/2] peerUpdate after the extClient public key change --- controllers/ext_client.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/controllers/ext_client.go b/controllers/ext_client.go index 55b614a74..9ffb970d7 100644 --- a/controllers/ext_client.go +++ b/controllers/ext_client.go @@ -633,10 +633,15 @@ func updateExtClient(w http.ResponseWriter, r *http.Request) { if changedID && servercfg.IsDNSMode() { logic.SetDNS() } + if replacePeers { + if err := mq.PublishDeletedClientPeerUpdate(&oldExtClient); err != nil { + slog.Error("error deleting old ext peers", "error", err.Error()) + } + } if sendPeerUpdate { // need to send a peer update to the ingress node as enablement of one of it's clients has changed ingressNode, err := logic.GetNodeByID(newclient.IngressGatewayID) if err == nil { - if err = mq.PublishPeerUpdate(replacePeers); err != nil { + if err = mq.PublishPeerUpdate(false); err != nil { logger.Log( 1, "error setting ext peers on", @@ -663,7 +668,7 @@ func updateExtClient(w http.ResponseWriter, r *http.Request) { slog.Error("Failed to get nodes", "error", err) return } - go mq.PublishSingleHostPeerUpdate(ingressHost, nodes, nil, []models.ExtClient{oldExtClient}, replacePeers, nil) + go mq.PublishSingleHostPeerUpdate(ingressHost, nodes, nil, []models.ExtClient{oldExtClient}, false, nil) } }