Skip to content

Commit

Permalink
NET-1461:update peer info after extClient public key changed (#3088)
Browse files Browse the repository at this point in the history
* update peer info after extClient public key changed

* peerUpdate after the extClient public key change
  • Loading branch information
yabinma authored Sep 12, 2024
1 parent bb8e4e5 commit 32994f6
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions controllers/ext_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,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: ",
Expand Down Expand Up @@ -594,6 +595,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(
Expand Down Expand Up @@ -633,6 +639,11 @@ 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 {
Expand Down

0 comments on commit 32994f6

Please sign in to comment.