engine

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: Apache-2.0 Imports: 16 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 engine implements the bitwire/1 protocol over a frames duplex connection: JSON text frames carrying requests, responses, events and cancellations, correlated by serial request identifiers. A Peer realizes an Endpoint over any transport of the seam; the addressed path of a request or event travels as its canonical encoding in the frame's method or event name. It has no application authorization, replay, retries or persistence policy.

bitwire/1 is the behavior of nightseam v0.6.0's nightseam.duplex/1 profile (bitwire decision 0008). This engine accepts, refuses and sends what that release does; it presents the protocol only through its root Endpoint.

Index

Constants

View Source
const Protocol = "bitwire/1"

Protocol names the protocol revision this engine speaks. The name never travels on a connection: bitwire/1 agrees on its revision out of band.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Prepare runs on the peer once it is built and before it reads its
	// first frame: a receiver it attaches to the peer's Wire is there before
	// anything can arrive, so the other side's first request cannot be
	// refused method_not_found while the receiver is on its way. An error
	// fails the construction: the peer never runs and the constructor answers
	// with it.
	Prepare func(*Peer) error
	// MaxConcurrentHandlers bounds the incoming requests running at once; the
	// one past it is refused busy. Default 64.
	MaxConcurrentHandlers int
	// MaxPendingRequests bounds the calls this peer may have outstanding at
	// once; the one past it is refused busy without reaching the wire. It
	// also bounds the outgoing requests its root holds admitted. Default 128.
	MaxPendingRequests int
	// QueueCapacity bounds the outgoing frame queue, the incoming event queue
	// and the root's own queue, in frames. Default 128.
	QueueCapacity int
	// MaxFrameBytes is the largest frame the peer sends or receives. Default
	// 1 MiB.
	MaxFrameBytes int64
	// RequestTimeout bounds an outgoing call and an incoming request's
	// handler. Default 30 seconds.
	RequestTimeout time.Duration
	// WriteTimeout bounds a stalled write and a stalled consumer before the
	// connection ends. Default 10 seconds.
	WriteTimeout time.Duration
	// Propagator moves a trace between a frame and a handler's context.
	Propagator core.Propagator
}

Options limits are per connection. Zero values select the defaults. Handlers may run concurrently; event deliveries run serially in receive order.

func (Options) Normalized

func (o Options) Normalized() (Options, error)

Normalized returns the options with every default applied, or an error for a negative limit.

type Peer

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

Peer owns a frames duplex connection until Close or transport failure. Never send on or receive from the connection after handing it to NewPeer. The connection's receive limit is its maker's to set to MaxFrameBytes; the peer refuses a larger frame it is nonetheless handed.

func NewPeer

func NewPeer(ctx context.Context, conn transports.Conn, role Role, options Options) (*Peer, error)

NewPeer speaks bitwire/1 over any connection of the seam — a pipe, a socket already accepted, a tunnel channel — as the given role. The peer owns the connection from here and closes it when it ends; ctx ending ends the peer. If the connection reports a Subprotocol, the peer reports it too.

func (*Peer) Close

func (p *Peer) Close() error

Close ends the peer, closing the connection with 1000 and failing every pending call. It is safe to call more than once.

func (*Peer) Context

func (p *Peer) Context() context.Context

Context is the peer's own, cancelled when it ends: what a handler or a caller derives its own from to be released with the connection. It carries the values of the context the peer was made with, such as an authenticated identity.

func (*Peer) Done

func (p *Peer) Done() <-chan struct{}

Done is closed when the peer has ended, for whatever reason; Err says which.

func (*Peer) Err

func (p *Peer) Err() error

Err is why the peer ended, or nil while it runs. An ended peer's error is a closed carrier — errors.Is(err, transports.ErrClosed) — and also matches its cause: core.ErrBackpressure, the context's error, or the connection's own.

func (*Peer) MaxFrameBytes

func (p *Peer) MaxFrameBytes() int64

MaxFrameBytes is the largest frame this peer sends or receives.

func (*Peer) Role

func (p *Peer) Role() Role

Role is the side of the connection this peer is.

func (*Peer) Subprotocol

func (p *Peer) Subprotocol() string

Subprotocol is what the handshake beneath this peer selected, and "" when it selected none. bitwire/1 reads nothing into it.

func (*Peer) Wire

func (p *Peer) Wire() wire.Endpoint

Wire is the peer's root origin: send access to the remote side's paths, receive attachment for the requests and events the remote side sends, and the connection's closure. Repeated calls return the same endpoint.

type Role

type Role string

Role is the side of a connection a peer takes. It decides the prefix of the request identifiers the peer mints — c: for a client, s: for a server — so the two sides never mint the same one.

const (
	// ClientRole dials and mints request identifiers under the c: prefix.
	ClientRole Role = "client"
	// ServerRole accepts and mints request identifiers under the s: prefix.
	ServerRole Role = "server"
)

Jump to

Keyboard shortcuts

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