ws

package
v0.21.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetUpgrader

func GetUpgrader() *gws.Upgrader

GetUpgrader returns a singleton WebSocket upgrader instance.

Types

type BaseHandler added in v0.14.0

type BaseHandler struct{}

BaseHandler provides a default implementation that can be embedded to make HandleLegacy optional

func (*BaseHandler) HandleLegacy added in v0.14.0

func (h *BaseHandler) HandleLegacy(rawData []byte) error

type FingerprintRecord

type FingerprintRecord struct {
	Id          string `db:"id"`
	SystemId    string `db:"system"`
	Fingerprint string `db:"fingerprint"`
	Token       string `db:"token"`
}

FingerprintRecord is fingerprints collection record data in the hub

type Handler

type Handler struct {
	gws.BuiltinEventHandler
}

Handler implements the WebSocket event handler for agent connections.

func (*Handler) OnClose

func (h *Handler) OnClose(conn *gws.Conn, err error)

OnClose handles WebSocket connection closures and triggers system down status after delay.

func (*Handler) OnMessage

func (h *Handler) OnMessage(conn *gws.Conn, message *gws.Message)

OnMessage routes incoming WebSocket messages to the request manager.

func (*Handler) OnOpen

func (h *Handler) OnOpen(conn *gws.Conn)

OnOpen sets a deadline for the WebSocket connection and extracts agent version.

type PendingRequest added in v0.13.0

type PendingRequest struct {
	ID         RequestID
	ResponseCh chan *gws.Message
	Context    context.Context
	Cancel     context.CancelFunc
	CreatedAt  time.Time
}

PendingRequest tracks an in-flight request

type RequestID added in v0.13.0

type RequestID uint32

RequestID uniquely identifies a request

type RequestManager added in v0.13.0

type RequestManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

RequestManager handles concurrent requests to an agent

func NewRequestManager added in v0.13.0

func NewRequestManager(conn *gws.Conn) *RequestManager

NewRequestManager creates a new request manager for a WebSocket connection

func (*RequestManager) Close added in v0.13.0

func (rm *RequestManager) Close()

Close shuts down the request manager

func (*RequestManager) SendRequest added in v0.13.0

func (rm *RequestManager) SendRequest(ctx context.Context, action common.WebSocketAction, data any) (*PendingRequest, error)

SendRequest sends a request and returns a channel for the response

type ResponseHandler added in v0.13.0

type ResponseHandler interface {
	Handle(agentResponse common.AgentResponse) error
	HandleLegacy(rawData []byte) error
}

ResponseHandler defines interface for handling agent responses. This is used by handleAgentRequest for legacy response handling.

type WsConn

type WsConn struct {
	DownChan chan struct{}
	// contains filtered or unexported fields
}

WsConn represents a WebSocket connection to an agent.

func NewWsConnection

func NewWsConnection(conn *gws.Conn, agentVersion semver.Version) *WsConn

NewWsConnection creates a new WebSocket connection wrapper with agent version.

func (*WsConn) AgentVersion added in v0.18.0

func (ws *WsConn) AgentVersion() semver.Version

AgentVersion returns the connected agent's version (as reported during handshake).

func (*WsConn) Close

func (ws *WsConn) Close(msg []byte)

Close terminates the WebSocket connection gracefully.

func (*WsConn) GetFingerprint

func (ws *WsConn) GetFingerprint(ctx context.Context, token string, signer ssh.Signer, needSysInfo bool) (common.FingerprintResponse, error)

GetFingerprint authenticates with the agent using SSH signature and returns the agent's fingerprint.

func (*WsConn) IsConnected

func (ws *WsConn) IsConnected() bool

IsConnected returns true if the WebSocket connection is active.

func (*WsConn) Ping

func (ws *WsConn) Ping() error

Ping sends a ping frame to keep the connection alive.

func (*WsConn) SendRequest added in v0.18.0

func (ws *WsConn) SendRequest(ctx context.Context, action common.WebSocketAction, data any) (*PendingRequest, error)

SendRequest sends a request to the agent and returns a pending request handle. This is used by the transport layer to send requests.

func (*WsConn) TimeSinceLastMessage added in v0.21.1

func (ws *WsConn) TimeSinceLastMessage() time.Duration

TimeSinceLastMessage returns how long it has been since the agent last sent a message.

Jump to

Keyboard shortcuts

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