node: return observable metrics for ip change broadcast/reconnect
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/openp2p-cn/inp2p/pkg/protocol"
|
||||
)
|
||||
|
||||
func (s *Server) HandleNodeMeta(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -51,7 +53,38 @@ func (s *Server) HandleNodeMeta(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusBadRequest, `{"error":1,"message":"`+err.Error()+`"}`)
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, `{"error":0,"message":"ok"}`)
|
||||
|
||||
nodes := s.GetOnlineNodesByTenant(ac.TenantID)
|
||||
affectedNode := ""
|
||||
reconnectTriggered := false
|
||||
broadcastCount := 0
|
||||
for _, n := range nodes {
|
||||
nc, err := s.store.GetNodeCredentialByName(ac.TenantID, n.Name)
|
||||
if err != nil || nc == nil {
|
||||
continue
|
||||
}
|
||||
peer := map[string]any{"node": n.Name, "ip": nc.VirtualIP, "online": n.IsOnline()}
|
||||
if nc.NodeUUID == req.NodeUUID {
|
||||
affectedNode = n.Name
|
||||
_ = n.Conn.Write(protocol.MsgPush, protocol.SubPushSDWANDel, peer)
|
||||
n.Conn.Close()
|
||||
reconnectTriggered = true
|
||||
continue
|
||||
}
|
||||
_ = n.Conn.Write(protocol.MsgPush, protocol.SubPushSDWANPeer, peer)
|
||||
broadcastCount++
|
||||
}
|
||||
|
||||
resp, _ := json.Marshal(map[string]any{
|
||||
"error": 0,
|
||||
"message": "ok",
|
||||
"affected_node": affectedNode,
|
||||
"target_node_uuid": req.NodeUUID,
|
||||
"new_virtual_ip": req.VirtualIP,
|
||||
"broadcast_count": broadcastCount,
|
||||
"reconnect_triggered": reconnectTriggered,
|
||||
})
|
||||
writeJSON(w, http.StatusOK, string(resp))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user