Browse Source

send peer update after request + fix pass update issue

0xdcarns 2 years ago
parent
commit
977c9c8c19
3 changed files with 13 additions and 1 deletions
  1. 3 0
      controllers/enrollmentkeys.go
  2. 5 0
      logic/hosts.go
  3. 5 1
      mq/handlers.go

+ 3 - 0
controllers/enrollmentkeys.go

@@ -231,5 +231,8 @@ func checkNetRegAndHostUpdate(networks []string, h *models.Host) {
 			Action: models.RequestAck,
 			Action: models.RequestAck,
 			Host:   *h,
 			Host:   *h,
 		})
 		})
+		if err := mq.PublishPeerUpdate(); err != nil {
+			logger.Log(0, "failed to publish peer update during registration -", err.Error())
+		}
 	}
 	}
 }
 }

+ 5 - 0
logic/hosts.go

@@ -237,6 +237,11 @@ func AssociateNodeToHost(n *models.Node, h *models.Host) error {
 		return err
 		return err
 	}
 	}
 	h.Nodes = append(h.Nodes, n.ID.String())
 	h.Nodes = append(h.Nodes, n.ID.String())
+	currentHost, err := GetHost(h.ID.String())
+	if err != nil {
+		return err
+	}
+	h.HostPass = currentHost.HostPass
 	return UpsertHost(h)
 	return UpsertHost(h)
 }
 }
 
 

+ 5 - 1
mq/handlers.go

@@ -151,8 +151,12 @@ func UpdateHost(client mqtt.Client, msg mqtt.Message) {
 				if err = HostUpdate(hu); err != nil {
 				if err = HostUpdate(hu); err != nil {
 					logger.Log(0, "failed to send new node to host", hostUpdate.Host.Name, currentHost.ID.String(), err.Error())
 					logger.Log(0, "failed to send new node to host", hostUpdate.Host.Name, currentHost.ID.String(), err.Error())
 					return
 					return
+				} else {
+					if err = PublishSingleHostPeerUpdate(currentHost, nil); err != nil {
+						logger.Log(0, "failed peers publish after join acknowledged", hostUpdate.Host.Name, currentHost.ID.String(), err.Error())
+						return
+					}
 				}
 				}
-				sendPeerUpdate = true
 			}
 			}
 		case models.UpdateHost:
 		case models.UpdateHost:
 			sendPeerUpdate = logic.UpdateHostFromClient(&hostUpdate.Host, currentHost)
 			sendPeerUpdate = logic.UpdateHostFromClient(&hostUpdate.Host, currentHost)