This commit is contained in:
ryan
2026-06-18 16:59:02 +08:00
parent e3bfd9ca6d
commit dfc480c73a
33 changed files with 3362 additions and 133 deletions
@@ -18,6 +18,7 @@ const (
AgentWSConnectedLastSeenValue = "__OPENFLARE_AGENT_WS_CONNECTED__"
agentMessageTypeForceSyncConfig = "force_sync_config"
agentMessageTypeWAFIPGroups = "waf_ip_groups"
)
type agentClient struct {
@@ -102,6 +103,28 @@ func IsAgentConnected(nodeID string) bool {
}
}
// BroadcastWAFIPGroups pushes changed WAF IP groups to all connected agents.
func BroadcastWAFIPGroups(payload any) int {
if payload == nil {
return 0
}
message := Message{Type: agentMessageTypeWAFIPGroups, Payload: payload}
defaultAgentHub.mu.RLock()
clients := make([]*agentClient, 0, len(defaultAgentHub.clients))
for _, client := range defaultAgentHub.clients {
clients = append(clients, client)
}
defaultAgentHub.mu.RUnlock()
success := 0
for _, client := range clients {
if client.enqueue(message) {
success++
}
}
return success
}
// SendForceSyncConfig notifies an agent to force sync configuration.
func SendForceSyncConfig(nodeID string, payload any) bool {
defaultAgentHub.mu.RLock()