pluginclient

package
v2.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package pluginclient owns the agent-side WebSocket command loop that dhcp, dns, proxy (and future) plugins share with alpacon-server.

The flow each plugin used to copy-paste:

  1. Connect via the shared runner.WebsocketClient.
  2. Enforce a 10 MiB read limit + the standard read deadline.
  3. Decode each frame, reject anything outside the whitelist of stock queries (ping, config_updated, reconfigure, quit, reconnect, restart).
  4. Dispatch config_updated to configreceiver.Receiver (modern pull-based path), dispatch the plugin-private reconfigure payload to a plugin-supplied callback (legacy push, kept for the dual-emit rollout window), and handle ping / quit / reconnect / restart inline against the shared WsClient.

All of that lives here so each plugin only needs to bring an Applier and (during the rollout window) a small reconfigure callback that decodes its own Command.Config-bearing payload.

Index

Constants

View Source
const MaxMessageSize = 10 * 1024 * 1024

MaxMessageSize is the maximum allowed WebSocket message size (10 MiB) enforced both at the gorilla connection layer (SetReadLimit) and as a secondary guard inside the handler.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// WsClient is the persistent WebSocket to alpacon-server, owned
	// by the plugin SDK host runtime.
	WsClient *runner.WebsocketClient

	// Receiver handles the modern pull-based config flow.
	Receiver *configreceiver.Receiver

	// PluginName is logged when handling “restart“ (e.g.
	// "alpamon-dhcp-plugin will restart in 1 second.").
	PluginName string

	// OnReconfigure, if non-nil, is called with the raw WS message
	// when a legacy “reconfigure“ query arrives. Plugins decode
	// their own Config-bearing payload from the bytes. Nil means
	// the legacy path is disabled — the message is logged and
	// discarded.
	OnReconfigure func(rawMessage []byte)
	// contains filtered or unexported fields
}

Client is the shared dispatcher. Plugins construct one via New and run it for the lifetime of the plugin process.

func New

func New(
	ws *runner.WebsocketClient,
	session *scheduler.Session,
	applier configreceiver.Applier,
	pluginName string,
	onReconfigure func(rawMessage []byte),
) *Client

New wires a Client with the standard configreceiver.Receiver around the supplied Applier. “onReconfigure“ may be nil if the plugin does not (or no longer) supports the legacy push path.

func (*Client) HandleMessage

func (c *Client) HandleMessage(ctx context.Context, message []byte)

HandleMessage runs the shared dispatch for one inbound frame. It never panics for arbitrary inputs — the readers above feed it whatever the WebSocket produces.

func (*Client) RunForever

func (c *Client) RunForever(ctx context.Context)

RunForever maintains the WebSocket connection and dispatches every inbound frame through HandleMessage until ctx is cancelled or the remote sends “quit“.

Cancellation caveat: “ctx“ interrupts the read loop and post-connect reconnect (CloseAndReconnect honours ctx), but the *initial* WsClient.Connect call below uses its own internal retry timeout and does not honour ctx. A caller cancelling during the very first connect attempt should expect the call to return only after that attempt completes (or the underlying connect times out). This matches the existing runner.WebsocketClient.Connect semantics in alpamon and is preserved here for behavioural compatibility.

Jump to

Keyboard shortcuts

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