remote

package
v0.0.0-...-9759625 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package remote implements wrongtop's read-only remote monitoring protocol: a token-authenticated TCP handshake followed by a stream of length-prefixed JSON collector snapshots. Clients only ever receive data — the protocol carries no commands by design.

Index

Constants

View Source
const DefaultPort = 61234

DefaultPort is used by serve and connect when none is specified.

View Source
const MaxFrame = 16 << 20

MaxFrame caps one frame's payload; snapshots stay orders of magnitude below this even on busy machines.

View Source
const Protocol = "WRONGTOP/1"

Protocol is the protocol identifier verified in the handshake.

Variables

This section is empty.

Functions

func Authorize

func Authorize(provided, expected string) bool

Authorize reports whether the provided token matches the expected one, comparing in constant time. An empty expected token never matches, so a misconfigured server refuses everyone instead of anyone.

func ReadFrame

func ReadFrame(r io.Reader, max int, v any) error

ReadFrame reads one length-prefixed JSON frame into v. Payloads above max bytes are rejected before allocation.

func Serve

func Serve(ctx context.Context, opts Options) error

Serve runs the monitoring server until ctx is done: one shared collector feeds every authenticated client. The protocol is read-only by construction — client input is limited to the auth handshake.

func WriteFrame

func WriteFrame(w io.Writer, v any) error

WriteFrame writes v as one 4-byte big-endian length-prefixed JSON frame.

Types

type Auth

type Auth struct {
	Token string `json:"token"`
}

Auth is the first frame a client sends after connecting.

type Client

type Client struct {
	Hello Hello
	// contains filtered or unexported fields
}

Client is the TUI side of the protocol: dial, authenticate, then pull snapshots one by one.

func Dial

func Dial(ctx context.Context, addr, token, version string) (*Client, error)

Dial connects to addr, performs the token handshake and returns a client ready to stream snapshots.

func (*Client) Close

func (c *Client) Close()

Close tears down the connection.

func (*Client) Next

func (c *Client) Next() (collector.Snapshot, error)

Next blocks until the next snapshot arrives. It unblocks with an error when Close cancels the connection.

type Hello

type Hello struct {
	Protocol  string `json:"protocol"`
	Version   string `json:"version,omitempty"`
	Hostname  string `json:"hostname,omitempty"`
	RefreshMS int    `json:"refresh_ms"`
}

Hello is the first frame the server sends after successful auth.

type Options

type Options struct {
	// Listen is the TCP address to bind, e.g. ":61234".
	Listen string
	// Token clients must present; Serve refuses to start without one.
	Token string
	// Refresh is the snapshot cadence (floored at 250ms).
	Refresh time.Duration
	// Version is reported in the Hello frame.
	Version string
}

Options configures Serve.

Jump to

Keyboard shortcuts

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