wire

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 9 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 wire is the internal bridge-to-server format described in docs/wire.md: ACP messages in numbered envelopes over a WebSocket, with cumulative acks, heartbeats, a send window and replay after a reconnect.

Index

Constants

View Source
const (
	HeaderLinkID        = "Actp-Link-Id"
	HeaderLastSeq       = "Actp-Last-Seq"
	HeaderClientName    = "Actp-Client-Name"
	HeaderPromptTimeout = "Actp-Prompt-Timeout"
)

Headers on the link upgrade request and response.

View Source
const (
	CloseReplaced      websocket.StatusCode = 4001
	CloseLinkEnded     websocket.StatusCode = 4002
	CloseProtocolError websocket.StatusCode = 4003
	CloseDead          websocket.StatusCode = 4004
)

WebSocket close codes.

View Source
const (
	TMsg   = "msg"
	TAck   = "ack"
	TPing  = "ping"
	TPong  = "pong"
	TBye   = "bye"
	TError = "error"
)

Frame types.

View Source
const (
	ErrAgentExited    = "agent_exited"
	ErrSpoolFull      = "spool_full"
	ErrServerShutdown = "server_shutdown"
	ErrEndedByAdmin   = "ended_by_admin"
	ErrLinkEnded      = "link_ended"
	ErrSequenceGap    = "sequence_gap"
	ErrProtocol       = "protocol_error"
)

Error codes sent in error frames.

Variables

View Source
var (
	// ErrBye means the peer said its client has left.
	ErrBye = errors.New("peer said bye")
	// ErrDead means nothing arrived from the peer for too long.
	ErrDead = errors.New("peer went silent")
	// ErrReplaced means a newer socket took over the link.
	ErrReplaced = errors.New("replaced by a newer connection")
	// ErrDetached means the socket was closed on purpose by this side.
	ErrDetached = errors.New("detached")
)
View Source
var Versions = []string{"actp.v1"}

Wire versions, newest first. A server and bridge pick the newest they share.

Functions

This section is empty.

Types

type Endpoint

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

Endpoint is one side of a link. It outlives sockets: messages sent while no socket is attached wait in the outbox and go out after the next Serve.

func NewEndpoint

func NewEndpoint(opts Options, deliver func(json.RawMessage) error) *Endpoint

NewEndpoint creates an endpoint. deliver is called once per peer message, in order; the message counts as processed when it returns nil.

func (*Endpoint) Attached

func (e *Endpoint) Attached() bool

Attached reports whether a socket is being served.

func (*Endpoint) Close

func (e *Endpoint) Close()

Close deletes the spool file. The endpoint must not be used afterwards.

func (*Endpoint) Detach

func (e *Endpoint) Detach(code websocket.StatusCode, reason string)

Detach closes the current socket, if any, with the given code.

func (*Endpoint) LastReceived

func (e *Endpoint) LastReceived() int64

LastReceived is the highest peer sequence number processed.

func (*Endpoint) OutboxBytes

func (e *Endpoint) OutboxBytes() int64

OutboxBytes is the size of messages waiting for an ack.

func (*Endpoint) Send

func (e *Endpoint) Send(raw json.RawMessage)

Send queues an ACP message for the peer.

func (*Endpoint) SendControl

func (e *Endpoint) SendControl(f Frame)

SendControl queues a control frame (bye, error) on the current socket.

func (*Endpoint) Serve

func (e *Endpoint) Serve(ctx context.Context, conn *websocket.Conn, peerLastSeq int64) error

Serve runs the link over conn until the socket ends. peerLastSeq is the highest of our messages the peer has processed; everything after it is resent.

func (*Endpoint) SetDiscard

func (e *Endpoint) SetDiscard(on bool)

SetDiscard drops queued and future outgoing messages. Used once nobody will read them.

func (*Endpoint) SpoolError

func (e *Endpoint) SpoolError() error

SpoolError reports a failure to use the spool file, if any.

type Frame

type Frame struct {
	T       string          `json:"t"`
	Seq     int64           `json:"seq,omitempty"`
	Ack     int64           `json:"ack,omitempty"`
	Msg     json.RawMessage `json:"msg,omitempty"`
	Code    string          `json:"code,omitempty"`
	Message string          `json:"message,omitempty"`
	Data    json.RawMessage `json:"data,omitempty"`
}

Frame is one WebSocket text frame.

type Options

type Options struct {
	HeartbeatEvery time.Duration // send something at least this often (10 s)
	DeadAfter      time.Duration // peer silent this long → socket is dead (25 s)
	AckDelay       time.Duration // ack received messages within this delay (1 s)
	AckEvery       int64         // or after this many messages (50)
	WindowMsgs     int64         // stop sending with this many unacked (1000)
	WindowBytes    int64         // or this many bytes unacked (4 MB)
	HeartbeatPing  bool          // heartbeat with ping instead of ack
	Tick           time.Duration // writer housekeeping interval (100 ms)
	// SpoolPath, when set, is a file that unacked messages spill into once
	// MemoryLimit bytes are held in memory (8 MB). The file is private to the user.
	SpoolPath   string
	MemoryLimit int64
}

Options tune liveness and flow control. Zero values use the defaults from docs/wire.md.

type RemoteError

type RemoteError struct {
	Code    string
	Message string
	Data    json.RawMessage
}

RemoteError is an error frame received from the other side.

func (*RemoteError) Error

func (e *RemoteError) Error() string

func (*RemoteError) Fatal

func (e *RemoteError) Fatal() bool

Fatal reports whether the link has ended, as opposed to only this socket.

Jump to

Keyboard shortcuts

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