relay
Safe HaskellNone
LanguageGHC2024

Relay.Reliable.Outbox

Description

 
Synopsis

Documentation

data Outbox a Source #

Sender-local reliable state for one session. Collapses Monarch's Outbox (sequence assignment) and Unacked (in-flight buffer): in the ack-driven model a message is simply either acknowledged or still awaiting acknowledgement.

Constructors

Outbox 

Fields

  • outboxSession :: SessionId

    The session every frame is stamped with. One Outbox is one sending session.

  • nextSeq :: Nat

    Next sequence number to assign. Starts at 1.

  • unacked :: Map Nat a

    Frames sent but not yet acknowledged, keyed by sequence number. A Map (rather than a deque) is a deliberate modelling choice: it gives out-of-order insertion and a simple cumulative prune, and carries unchanged into the multi-stream development.

  • largestAcked :: Maybe Nat

    The sender's view of delivery progress: the highest sequence number the receiver has confirmed, as learned from acks arriving on the reverse channel. Nothing until the first ack arrives. This is the sender's (possibly lagging) copy of the receiver's frontier, not the receiver's own state.

Instances

Instances details
Eq a => Eq (Outbox a) Source # 
Instance details

Defined in Relay.Reliable.Outbox

Methods

(==) :: Outbox a -> Outbox a -> Bool #

(/=) :: Outbox a -> Outbox a -> Bool #

Show a => Show (Outbox a) Source # 
Instance details

Defined in Relay.Reliable.Outbox

Methods

showsPrec :: Int -> Outbox a -> ShowS #

show :: Outbox a -> String #

showList :: [Outbox a] -> ShowS #

emptyOutbox :: SessionId -> Outbox a Source #

Initial sender state for a session. The first assigned sequence number is 1; nothing is in flight or acknowledged.

send :: a -> Outbox a -> (Outbox a, Frame a) Source #

Assign the next sequence number to a payload, record it as in-flight, and return the frame to put on the wire.

ack :: Nat -> Outbox a -> (Outbox a, [a]) Source #

Process a cumulative acknowledgement: drop every in-flight frame with sequence number <= n and return their payloads in sequence order.

Total under impossible acks: the recorded watermark is clamped to min n (nextSeq - 1), so an ack for frames never sent (a dishonest n >= nextSeq) cannot push largestAcked past what exists. The watermark never decreases, so an ack at or below it is a no-op.

unackedFrames :: Outbox a -> [Frame a] Source #

The in-flight frames to retransmit, each carrying its original sequence number, in ascending sequence order. Retransmission never reassigns sequence numbers.