ws

package
v0.3.88 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentConn

type AgentConn struct {
	ServerID string
	SendCh   chan []byte
	// contains filtered or unexported fields
}

AgentConn represents an active agent WebSocket connection.

func (*AgentConn) HasCapability added in v0.3.87

func (ac *AgentConn) HasCapability(cap string) bool

HasCapability reports whether the agent advertised the given capability.

func (*AgentConn) LastHeartbeat

func (ac *AgentConn) LastHeartbeat() time.Time

LastHeartbeat returns the time of the last heartbeat.

func (*AgentConn) SetCapabilities added in v0.3.87

func (ac *AgentConn) SetCapabilities(caps []string)

SetCapabilities records the capabilities the agent reported in agent.info.

func (*AgentConn) UpdateHeartbeat

func (ac *AgentConn) UpdateHeartbeat()

UpdateHeartbeat records the latest heartbeat time.

type AgentHandler

type AgentHandler struct {
	// contains filtered or unexported fields
}

AgentHandler handles WebSocket connections from agents.

func NewAgentHandler

func NewAgentHandler(hub *Hub, serverStore *store.ServerStore, nodeStore *store.NodeStore, metricsStore *store.MetricsStore, versionStore *store.VersionHistoryStore, geoResolver *dashboard.GeoIPResolver) *AgentHandler

NewAgentHandler creates a new WebSocket handler for agent connections.

func (*AgentHandler) HandleUpgrade

func (h *AgentHandler) HandleUpgrade(w http.ResponseWriter, r *http.Request)

HandleUpgrade upgrades an HTTP connection to WebSocket and runs the agent message loop.

type BrowserConn

type BrowserConn struct {
	ID     string
	SendCh chan []byte
}

BrowserConn represents an active browser WebSocket connection.

type BrowserHandler

type BrowserHandler struct {
	// contains filtered or unexported fields
}

BrowserHandler handles WebSocket connections from browser clients.

func NewBrowserHandler

func NewBrowserHandler(hub *Hub) *BrowserHandler

NewBrowserHandler creates a new WebSocket handler for browser connections.

func (*BrowserHandler) HandleUpgrade

func (h *BrowserHandler) HandleUpgrade(w http.ResponseWriter, r *http.Request)

HandleUpgrade upgrades an HTTP connection to WebSocket for browser clients.

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

Hub manages all active agent connections.

func NewHub

func NewHub(serverStore *store.ServerStore, nodeStore *store.NodeStore) *Hub

NewHub creates a new connection hub.

func (*Hub) AgentHasCapability added in v0.3.87

func (h *Hub) AgentHasCapability(serverID, cap string) bool

AgentHasCapability reports whether the connected agent advertised the given capability. Returns false for an unknown/disconnected agent — so callers transparently fall back to the pre-capability behavior (backward compatible).

func (*Hub) Broadcast

func (h *Hub) Broadcast(msg *models.Message)

Broadcast sends a message to all connected agents.

func (*Hub) BroadcastToBrowsers

func (h *Hub) BroadcastToBrowsers(action string, payload any)

BroadcastToBrowsers sends a JSON event to all connected browser clients.

func (*Hub) ConnectedCount

func (h *Hub) ConnectedCount() int

ConnectedCount returns the number of connected agents.

func (*Hub) HandleResult

func (h *Hub) HandleResult(result *models.CommandResult)

HandleResult processes a command result from an agent. Matches the result to a pending command by command ID.

func (*Hub) IsConnected

func (h *Hub) IsConnected(serverID string) bool

IsConnected checks if an agent is currently connected.

func (*Hub) PendingCommandIDs

func (h *Hub) PendingCommandIDs() []string

PendingCommandIDs returns the IDs of all pending commands (for testing).

func (*Hub) PendingCount

func (h *Hub) PendingCount() int

PendingCount returns the number of commands awaiting responses.

func (*Hub) Register

func (h *Hub) Register(serverID string) *AgentConn

Register adds a new agent connection to the hub.

func (*Hub) RegisterBrowser

func (h *Hub) RegisterBrowser(clientID string) *BrowserConn

RegisterBrowser adds a browser client connection.

func (*Hub) Send

func (h *Hub) Send(serverID string, msg *models.Message) error

Send sends a message to a specific agent.

func (*Hub) SendCommand

func (h *Hub) SendCommand(serverID string, msg *models.Message, timeout time.Duration) (*models.CommandResult, error)

SendCommand sends a command to an agent and waits for the result. Returns the result or an error if the agent is offline or the command times out.

func (*Hub) SetAgentCapabilities added in v0.3.87

func (h *Hub) SetAgentCapabilities(serverID string, caps []string)

SetAgentCapabilities records the capabilities reported by a connected agent.

func (*Hub) StartHealthCheck

func (h *Hub) StartHealthCheck(timeoutFn func() time.Duration)

StartHealthCheck starts the background heartbeat monitor. Marks agents as offline if no heartbeat received within the timeout. timeoutFn is called on every tick so the timeout can be changed at runtime (e.g. from the Settings page) without restarting the dashboard.

func (*Hub) Stop

func (h *Hub) Stop()

Stop stops the health check goroutine.

func (*Hub) Unregister

func (h *Hub) Unregister(serverID string)

Unregister removes an agent connection from the hub.

func (*Hub) UnregisterBrowser

func (h *Hub) UnregisterBrowser(clientID string)

UnregisterBrowser removes a browser client connection.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL