link

package
v0.3.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package link keeps the agent's connection to the panel: WebSocket over mTLS, hello handshake, and reconnects with backoff (docs/agent-protocol.md in the panel repo).

Index

Constants

View Source
const Protocol = 1

Protocol is the protocol version this agent speaks.

Variables

View Source
var ErrDisconnected = errors.New("not connected to the panel")

ErrDisconnected is returned by Request while there is no panel connection.

View Source
var ErrRevoked = errors.New("the panel rejected this node's certificate (node deleted or re-joined elsewhere); join again")

ErrRevoked means the panel no longer accepts this node's certificate.

Functions

This section is empty.

Types

type Hello

type Hello struct {
	Protocol      int    `json:"protocol"`
	AgentVersion  string `json:"agent_version"`
	Hostname      string `json:"hostname"`
	OS            string `json:"os"`
	Kernel        string `json:"kernel"`
	Arch          string `json:"arch"`
	CPUs          int    `json:"cpus"`
	MemoryBytes   uint64 `json:"memory_bytes"`
	DiskBytes     uint64 `json:"disk_bytes"`
	DiskFreeBytes uint64 `json:"disk_free_bytes"`
	DockerVersion string `json:"docker_version"`
	// Services lists every service on this node and its state.
	Services []proto.ServiceState `json:"services"`
	// SFTPPort is where the built-in SFTP server listens (0 = disabled).
	SFTPPort int `json:"sftp_port"`
	// Web is the node's web hosting stack (nil when Caddy is not installed).
	Web *proto.WebCapabilities `json:"web,omitempty"`
	// Websites lists the websites this node knows.
	Websites []string `json:"websites,omitempty"`
}

Hello is sent first on every connection.

type Link struct {
	URL    string
	TLS    *tls.Config
	Hello  func(ctx context.Context) Hello // called before every connection
	Logger *slog.Logger

	// Backoff bounds; zero values use 1s and 60s.
	MinBackoff, MaxBackoff time.Duration
	// OnConnected is called after each successful handshake (optional, for tests).
	OnConnected func()
	// Handle answers a panel request; the result becomes the "ok" reply's data. Optional.
	Handle func(ctx context.Context, msg Message) (any, error)
	// contains filtered or unexported fields
}

Link is a reconnecting connection to the panel.

func (*Link) Notify

func (l *Link) Notify(typ string, data any)

Notify sends an event to the panel if connected. Events sent while disconnected are dropped: the next hello carries the current state of everything.

func (*Link) Request

func (l *Link) Request(ctx context.Context, typ string, data any) (Message, error)

Request sends a message to the panel and waits for its reply (e.g. to check SFTP credentials). An error reply from the panel is returned as an error.

func (*Link) Run

func (l *Link) Run(ctx context.Context) error

Run connects and reconnects until ctx is cancelled or the certificate is revoked.

type Message

type Message struct {
	ID      string          `json:"id,omitempty"`
	Type    string          `json:"type"`
	ReplyTo string          `json:"reply_to,omitempty"`
	Error   string          `json:"error,omitempty"`
	Data    json.RawMessage `json:"data,omitempty"`
}

Message is the envelope for every frame (mirrors panel internal/agentlink).

Jump to

Keyboard shortcuts

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