Ver Fonte

broadcast del ext client to the network

Abhishek Kondur há 2 anos atrás
pai
commit
41c06a72d8
2 ficheiros alterados com 34 adições e 6 exclusões
  1. 2 2
      controllers/ext_client.go
  2. 32 4
      mq/publishers.go

+ 2 - 2
controllers/ext_client.go

@@ -401,7 +401,7 @@ func createExtClient(w http.ResponseWriter, r *http.Request) {
 	logger.Log(0, r.Header.Get("user"), "created new ext client on network", networkName)
 	w.WriteHeader(http.StatusOK)
 	go func() {
-		go mq.BroadCastExtClient(host, &node)
+		go mq.BroadcastNewExtClient(host, &node)
 		// if err := mq.PublishPeerUpdate(); err != nil {
 		// 	logger.Log(1, "error setting ext peers on "+nodeid+": "+err.Error())
 		// }
@@ -582,7 +582,7 @@ func deleteExtClient(w http.ResponseWriter, r *http.Request) {
 	go func() {
 		ingressHost, err := logic.GetHost(ingressnode.HostID.String())
 		if err == nil {
-			go mq.BroadCastExtClient(ingressHost, &ingressnode)
+			go mq.BroadcastDelExtClient(ingressHost, &ingressnode, extclient)
 		}
 
 		if err = mq.PublishDeleteExtClientDNS(&extclient); err != nil {

+ 32 - 4
mq/publishers.go

@@ -275,15 +275,43 @@ func BroadcastAddOrUpdatePeer(host *models.Host, node *models.Node, update bool)
 	return nil
 }
 
-func BroadCastExtClient(ingressHost *models.Host, ingressNode *models.Node) error {
-	//1. flush peers to ingress
-	//2. broadcast update ingress peer msg to other hosts
+// BroadcastNewExtClient - adds ext client to peers in the network
+func BroadcastNewExtClient(ingressHost *models.Host, ingressNode *models.Node) error {
+
 	nodes, err := logic.GetNetworkNodes(ingressNode.Network)
 	if err != nil {
 		return err
 	}
+	//flush peers to ingress host
 	go FlushNetworkPeersToHost(ingressHost, ingressNode, nodes)
-	go BroadCastAddOrUpdatePeer(ingressHost, ingressNode, true)
+	// broadcast to update ingress peer to other hosts
+	go BroadcastAddOrUpdatePeer(ingressHost, ingressNode, true)
+	// TODO - send fw update
+	return nil
+}
+
+// BroadcastDelExtClient - removes ext client from network
+func BroadcastDelExtClient(ingressHost *models.Host, ingressNode *models.Node, extclient models.ExtClient) error {
+	// TODO - send fw update
+	go BroadcastAddOrUpdatePeer(ingressHost, ingressNode, true)
+	extPubKey, err := wgtypes.ParseKey(extclient.PublicKey)
+	if err != nil {
+		return err
+	}
+	p := models.PeerAction{
+		Action: models.RemovePeer,
+		Peers: []wgtypes.PeerConfig{
+			{
+				PublicKey: extPubKey,
+				Remove:    true,
+			},
+		},
+	}
+	data, err := json.Marshal(p)
+	if err != nil {
+		return err
+	}
+	publish(ingressHost, fmt.Sprintf("peer/host/%s/%s", ingressHost.ID.String(), servercfg.GetServer()), data)
 	return nil
 }