Browse Source

publish dns records on adding host to network from UI

Abhishek Kondur 1 year ago
parent
commit
34612733af
2 changed files with 3 additions and 2 deletions
  1. 1 0
      controllers/hosts.go
  2. 2 2
      mq/handlers.go

+ 1 - 0
controllers/hosts.go

@@ -286,6 +286,7 @@ func addHostToNetwork(w http.ResponseWriter, r *http.Request) {
 			Node:   *newNode,
 			Node:   *newNode,
 		})
 		})
 		mq.PublishPeerUpdate()
 		mq.PublishPeerUpdate()
+		mq.HandleNewNodeDNS(currHost, newNode)
 	}()
 	}()
 	logger.Log(2, r.Header.Get("user"), fmt.Sprintf("added host %s to network %s", currHost.Name, network))
 	logger.Log(2, r.Header.Get("user"), fmt.Sprintf("added host %s to network %s", currHost.Name, network))
 	w.WriteHeader(http.StatusOK)
 	w.WriteHeader(http.StatusOK)

+ 2 - 2
mq/handlers.go

@@ -116,7 +116,7 @@ func UpdateHost(client mqtt.Client, msg mqtt.Message) {
 					slog.Error("failed peers publish after join acknowledged", "name", hostUpdate.Host.Name, "id", currentHost.ID, "error", err)
 					slog.Error("failed peers publish after join acknowledged", "name", hostUpdate.Host.Name, "id", currentHost.ID, "error", err)
 					return
 					return
 				}
 				}
-				if err = handleNewNodeDNS(&hu.Host, &hu.Node); err != nil {
+				if err = HandleNewNodeDNS(&hu.Host, &hu.Node); err != nil {
 					slog.Error("failed to send dns update after node added to host", "name", hostUpdate.Host.Name, "id", currentHost.ID, "error", err)
 					slog.Error("failed to send dns update after node added to host", "name", hostUpdate.Host.Name, "id", currentHost.ID, "error", err)
 					return
 					return
 				}
 				}
@@ -217,7 +217,7 @@ func ClientPeerUpdate(client mqtt.Client, msg mqtt.Message) {
 	slog.Info("sent peer updates after signal received from", "id", id)
 	slog.Info("sent peer updates after signal received from", "id", id)
 }
 }
 
 
-func handleNewNodeDNS(host *models.Host, node *models.Node) error {
+func HandleNewNodeDNS(host *models.Host, node *models.Node) error {
 	dns := models.DNSUpdate{
 	dns := models.DNSUpdate{
 		Action: models.DNSInsert,
 		Action: models.DNSInsert,
 		Name:   host.Name + "." + node.Network,
 		Name:   host.Name + "." + node.Network,