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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
MaxFrameBytes is the largest frame this peer sends or receives.
func (*Peer) Subprotocol ¶
Subprotocol is what the handshake beneath this peer selected, and "" when it selected none. bitwire/1 reads nothing into it.