Skip to main content
Version: v0.0.4

Function: ltpReduce()

ltpReduce(state, event): LtpTransition

Advance the LTP session by one inbound event - a pure function, no I/O.

Behaviour by phase:

  • neutral - enq accepts establishment (sendAck, enter transfer); eot is a benign line reset (no-op); ack/nak are unexpected at a receiver (surfaced, never read as acceptance); a frame before establishment is tolerated (Postel's Law) - the session auto-establishes and processes it, with a warning.
  • transfer - a frame is accepted (sendAck, appended, sequence advanced) only when it is trusted and carries the expected number; a duplicate of the last accepted frame is idempotently re-ACKed without re-appending; a bad or out-of-sequence frame is NAKed and dropped. eot terminates the transfer and returns to neutral (a record left open on an ETB is not delivered). enq restarts establishment. ack/nak are unexpected.

Parameters

state

LtpState

The current session state.

event

LtpEvent

The inbound event.

Returns

LtpTransition

The next state, the actions to take, and any warnings.

Example

import { ltpInitialState, ltpReduce } from "@cosyte/astm";
// A bad-checksum frame is NAKed, never ACKed, and never appended.
const est = ltpReduce(ltpInitialState(), { type: "enq" }).state;
const bad = { trusted: false } as never;
ltpReduce(est, { type: "frame", frame: bad }).actions; // [{ type: "sendNak" }]