moonbitstack/moonquic/stream does not have a README file

    Refused

    pub(all) suberror Refused {
    Illegal(String)
    Exceeded(limit~ : UInt64, got~ : UInt64)
    Conflict(String)
    } derive(Eq)

    Why a stream operation was refused.

    Illegal is a transition §3.1 or §3.2 does not allow — a bug on this side. Exceeded is the peer sending past a limit we advertised, or this side being asked to send past one the peer advertised (§4.1, §4.6). Conflict is a retransmission that disagrees with what arrived before, or a final size contradicting one already known (§2.2, §4.5) — which RFC 9000 makes a connection error.
    impl Show for Refused

    Refused::equal

    fn Refused::equal(Refused, Refused) -> Bool

    Refused::not_equal

    fn Refused::not_equal(x : Refused, y : Refused) -> Bool

    Refused::output

    fn Refused::output(self : Refused, logger : &Logger) -> Unit

    Refused::to_string

    fn Refused::to_string(self : Refused) -> String

    Assembler

    pub struct Assembler {
    consumed : UInt64
    runs : Array[(UInt64, Bytes)]
    final_size : UInt64?
    limit : UInt64
    }

    A stream's reassembly buffer. consumed is the next offset the reader has not taken; the runs beyond it are sorted, non-overlapping, and each starts at or after it.

    Assembler::buffered

    fn Assembler::buffered(self : Assembler) -> UInt64

    How many bytes are buffered ahead of the cursor.

    Assembler::complete

    fn Assembler::complete(self : Assembler) -> Bool

    Whether the whole stream has arrived and been read.

    Assembler::consumed

    fn Assembler::consumed(self : Assembler) -> UInt64

    The next contiguous offset the reader has taken.

    Assembler::final_size

    fn Assembler::final_size(self : Assembler) -> UInt64?

    The stream's final size, once a fin has fixed it.

    Assembler::insert

    fn Assembler::insert(self : Assembler, offset : UInt64, data : Bytes, fin~ : Bool) -> Unit raise Refused

    Take a fragment at offset, with fin marking it the last.

    A fragment wholly behind the cursor is dropped; one that overlaps buffered bytes with different values, or contradicts a known final size, is refused — §2.2 requires a retransmission to carry the same bytes, so disagreement is the peer misbehaving.

    Assembler::new

    fn Assembler::new(limit? : UInt64) -> Assembler

    A fresh assembler at the start of a stream.

    Assembler::read

    fn Assembler::read(self : Assembler) -> Bytes

    Take the contiguous run from the cursor, moving it past what comes back. Empty when the next expected offset has not arrived.

    Budget

    pub struct Budget {
    connection : Credit
    streams : Map[UInt64, Credit]
    initial : UInt64
    }

    A connection's send windows: the connection-wide one and one per stream, each opened at the peer's initial per-stream maximum when the stream is first written to.

    Budget::available

    fn Budget::available(self : Budget, id : UInt64) -> UInt64

    How much may go out on stream id right now: the smaller of the connection's window and the stream's (§4.1).

    Budget::connection

    fn Budget::connection(self : Budget) -> UInt64

    What may still go out across all streams together.

    Budget::new

    fn Budget::new(data : UInt64, stream_data : UInt64) -> Budget

    A budget at the peer's initial connection-wide and per-stream maxima, which come from its transport parameters (RFC 9000 §18.2).

    Budget::on_max_data

    fn Budget::on_max_data(self : Budget, limit : UInt64) -> Unit

    Raise the connection-wide limit from a MAX_DATA frame.

    Budget::on_max_stream_data

    fn Budget::on_max_stream_data(self : Budget, id : UInt64, limit : UInt64) -> Unit

    Raise stream id's limit from a MAX_STREAM_DATA frame.

    Budget::spend

    fn Budget::spend(self : Budget, id : UInt64, n : UInt64) -> Unit raise Refused

    Account for n bytes on stream id, against both windows. Both are checked before either is charged, so a refusal leaves neither half spent.

    Budget::stream

    fn Budget::stream(self : Budget, id : UInt64) -> Credit

    Stream id's window, opened at the initial maximum on first use.

    Chunk

    pub(all) struct Chunk {
    stream : UInt64
    offset : UInt64
    length : UInt64
    fin : Bool
    } derive(Eq,
    Debug
    )

    A scheduling decision: send length bytes of stream at offset, ending it when fin.

    Chunk::equal

    fn Chunk::equal(Chunk, Chunk) -> Bool

    Chunk::not_equal

    fn Chunk::not_equal(x : Chunk, y : Chunk) -> Bool

    Chunk::to_repr

    Credit

    pub struct Credit {
    spent : UInt64
    limit : UInt64
    }

    The send side of one window: how much has gone out against the limit the peer gave.

    Credit::available

    fn Credit::available(self : Credit) -> UInt64

    How much more may go out right now — zero when blocked.

    Credit::blocked

    fn Credit::blocked(self : Credit) -> Bool

    Whether the window is spent, which is the STREAM_DATA_BLOCKED and DATA_BLOCKED condition.

    Credit::grant

    fn Credit::grant(self : Credit, limit : UInt64) -> Unit

    Adopt a limit from a MAX_DATA or MAX_STREAM_DATA frame. A limit only ever rises, so an old frame arriving late is ignored rather than shrinking the window (§4.1).

    Credit::new

    fn Credit::new(limit : UInt64) -> Credit

    A send window at the peer's initial maximum.

    Credit::sent

    fn Credit::sent(self : Credit) -> UInt64

    How much has gone out in total.

    Credit::spend

    fn Credit::spend(self : Credit, n : UInt64) -> Unit raise Refused

    Account for n bytes going out. Refused when that would pass the peer's limit, and nothing is charged when it is.

    Direction

    pub(all) enum Direction {
    Bidi
    Uni
    } derive(Eq,
    Debug
    )

    Whether a stream carries data one way or both.

    Direction::equal

    fn Direction::equal(Direction, Direction) -> Bool

    Direction::not_equal

    fn Direction::not_equal(x : Direction, y : Direction) -> Bool

    Incoming

    type Incoming

    One receiving stream: its assembler, its own window, and the highest offset seen, which is what the connection-wide window is charged against.

    Initiator

    pub(all) enum Initiator {
    Client
    Server
    } derive(Eq,
    Debug
    )

    Which endpoint opened a stream.

    Initiator::equal

    fn Initiator::equal(Initiator, Initiator) -> Bool

    Initiator::not_equal

    fn Initiator::not_equal(x : Initiator, y : Initiator) -> Bool

    Out

    pub(all) struct Out {
    pending : UInt64
    offset : UInt64
    fin_queued : Bool
    fin_sent : Bool
    } derive(Eq,
    Debug
    )

    What one stream still has to send: how much is queued, where its next frame starts, and whether a FIN is queued and whether it has gone out.

    Out::equal

    fn Out::equal(Out, Out) -> Bool

    Out::not_equal

    fn Out::not_equal(x : Out, y : Out) -> Bool

    Out::to_repr

    Quota

    pub struct Quota {
    limit : UInt64
    opened : UInt64
    }

    How many streams of one kind the peer may still open (RFC 9000 §4.6), and how many it has. A peer that opens past the limit is a connection error, and without this an endpoint would let one hold open as many as it liked.

    Quota::available

    fn Quota::available(self : Quota) -> UInt64

    How many more may be opened.

    Quota::grant

    fn Quota::grant(self : Quota, limit : UInt64) -> Unit

    Adopt a limit from a MAX_STREAMS frame; as with data, a limit only rises.

    Quota::new

    fn Quota::new(limit : UInt64) -> Quota

    A quota of limit streams, none opened.

    Quota::open

    fn Quota::open(self : Quota, id : UInt64) -> Unit raise Refused

    Record stream id as opened, by its sequence number. Refused when it is past the limit; opening one already counted changes nothing, because a stream is opened by whichever frame mentions it first and several may.

    Receiving

    pub(all) enum Receiving {
    Recv
    SizeKnown
    DataReceived
    DataRead
    ResetReceived
    ResetRead
    } derive(Eq,
    Debug
    )

    The receiving part's state (§3.2).

    Receiving::equal

    fn Receiving::equal(Receiving, Receiving) -> Bool

    Receiving::next

    fn Receiving::next(self : Receiving, event : RecvEvent) -> Receiving raise Refused

    The state after event (§3.2). A stream may be reset from any state short of a terminal one; the read events apply only once the data or the reset has arrived.

    Receiving::not_equal

    fn Receiving::not_equal(x : Receiving, y : Receiving) -> Bool

    RecvEvent

    pub(all) enum RecvEvent {
    Receive(fin~ : Bool)
    AllReceived
    AppRead
    ReceiveReset
    AppReadReset
    } derive(Eq,
    Debug
    )

    What reached the receiving part: a STREAM frame, with fin fixing the final size; all the data up to that size; the application reading it all; a RESET_STREAM; the application being told of that reset.

    RecvEvent::equal

    fn RecvEvent::equal(RecvEvent, RecvEvent) -> Bool

    RecvEvent::not_equal

    fn RecvEvent::not_equal(x : RecvEvent, y : RecvEvent) -> Bool

    Scheduler

    pub struct Scheduler {
    budget : Budget
    streams : Map[UInt64, Out]
    order : Array[UInt64]
    cursor : Int
    frame : UInt64
    }

    A round-robin scheduler over a connection's sending streams, bounded by the send budget and by how much one frame carries.

    Scheduler::new

    fn Scheduler::new(budget : Budget, frame? : UInt64) -> Scheduler

    A scheduler over budget, with frames capped at frame bytes.

    Scheduler::next

    fn Scheduler::next(self : Scheduler) -> Chunk? raise Refused

    The next decision, or None when no stream can send — all drained, or every one of them blocked by flow control.

    Streams take turns: whichever sent last goes to the back, so one stream with a great deal queued cannot starve the rest.

    Scheduler::on_max_data

    fn Scheduler::on_max_data(self : Scheduler, limit : UInt64) -> Unit

    Raise the connection-wide send limit from a MAX_DATA frame.

    Scheduler::on_max_stream_data

    fn Scheduler::on_max_stream_data(self : Scheduler, id : UInt64, limit : UInt64) -> Unit

    Raise stream id's send limit from a MAX_STREAM_DATA frame.

    Scheduler::queue

    fn Scheduler::queue(self : Scheduler, id : UInt64, n : UInt64) -> Unit

    Queue n more bytes to send on stream id.

    Scheduler::queue_fin

    fn Scheduler::queue_fin(self : Scheduler, id : UInt64) -> Unit

    Mark stream id finished: the FIN rides the frame that drains it, or goes alone.

    SendEvent

    pub(all) enum SendEvent {
    Write(fin~ : Bool)
    AllAcked
    ResetStream
    ResetAcked
    } derive(Eq,
    Debug
    )

    What the sending part did: wrote a STREAM frame, with fin on the last one; had all its data acknowledged; sent a RESET_STREAM; had that reset acknowledged.

    SendEvent::equal

    fn SendEvent::equal(SendEvent, SendEvent) -> Bool

    SendEvent::not_equal

    fn SendEvent::not_equal(x : SendEvent, y : SendEvent) -> Bool

    Sending

    pub(all) enum Sending {
    Ready
    Send
    DataSent
    DataRecvd
    ResetSent
    ResetRecvd
    } derive(Eq,
    Debug
    )

    The sending part's state (§3.1).

    Sending::equal

    fn Sending::equal(Sending, Sending) -> Bool

    Sending::next

    fn Sending::next(self : Sending, event : SendEvent) -> Sending raise Refused

    The state after event (§3.1). A stream may be reset from any state short of a terminal one; writing after a terminal or reset state is refused.

    Sending::not_equal

    fn Sending::not_equal(x : Sending, y : Sending) -> Bool

    Sending::to_repr

    Streams

    pub struct Streams {
    streams : Map[UInt64, Incoming]
    connection : Window
    charged : UInt64
    size : UInt64
    bidi : Quota
    uni : Quota
    server : Bool
    }

    A connection's receiving streams and its connection-wide window.

    Streams::count

    fn Streams::count(self : Streams) -> Int

    How many streams are being tracked.

    Streams::max_data

    fn Streams::max_data(self : Streams) -> UInt64?

    The new MAX_DATA to advertise, or None when the gain would not be worth the frame (RFC 9000 §4.1).

    Streams::max_stream_data

    fn Streams::max_stream_data(self : Streams, id : UInt64) -> UInt64?

    The new MAX_STREAM_DATA to advertise on id, or None.

    Streams::new

    fn Streams::new(data : UInt64, stream_data : UInt64, server~ : Bool, bidi? : Quota, uni? : Quota) -> Streams

    Streams advertising data of connection-wide credit and stream_data per stream, admitting bidi and uni peer-opened streams of each kind (RFC 9000 §4.6).

    server says which side this is, so a peer's stream is told from our own. The stream quotas default to a hundred each, which is what quic-go and quiche both start at; leave them out and they apply, or pass a Quota to set them from the transport parameters that were actually negotiated.

    Streams::on_stream

    fn Streams::on_stream(self : Streams, id : UInt64, offset : UInt64, data : Bytes, fin~ : Bool) -> Bytes raise Refused

    Take a STREAM frame for id carrying data at offset, fin on the last fragment.

    Enforces the stream quota, then both flow-control windows, then reassembles, and answers with the bytes now readable — charged against both windows as they go out, because from the connection's point of view delivered is consumed.

    Streams::read

    fn Streams::read(self : Streams, id : UInt64) -> Bytes

    Any further contiguous bytes readable on id, empty when the stream is unknown or nothing new is contiguous.

    Streams::window

    fn Streams::window(self : Streams, id : UInt64) -> Window

    Stream id's receive window, for the MAX_STREAM_DATA a reader's progress earns.

    Window

    pub struct Window {
    received : UInt64
    consumed : UInt64
    limit : UInt64
    size : UInt64
    ratio : Double
    }

    The receive side of one window: the peer may send up to the limit we advertised, and the limit moves up as the application consumes what arrived.

    Window::arrived

    fn Window::arrived(self : Window, offset : UInt64) -> Unit raise Refused

    Record that data up to absolute offset offset has arrived. Refused when the peer passed the limit we advertised, which §4.1 makes a connection error.

    Window::consume

    fn Window::consume(self : Window, n : UInt64) -> Unit

    Account for the application taking n more bytes, which frees window space.

    Window::consumed

    fn Window::consumed(self : Window) -> UInt64

    How much the application has taken.

    Window::grant

    fn Window::grant(self : Window) -> UInt64

    Issue a new limit — what has been consumed plus a window — and answer with it: the MAX_DATA or MAX_STREAM_DATA value to send. The mirror of Credit::grant, which is how the other end takes it.

    Window::limit

    fn Window::limit(self : Window) -> UInt64

    The limit currently advertised.

    Window::new

    fn Window::new(size : UInt64, ratio? : Double) -> Window

    A receive window of size bytes, which is also the initial advertised limit.

    Window::should_grant

    fn Window::should_grant(self : Window) -> Bool

    Whether a new limit is worth advertising: what we could offer is at least ratio of a window beyond what we have.

    direction

    fn direction(id : UInt64) -> Direction

    Which way stream id carries data — bit 1.

    frame

    let frame : UInt64

    How many bytes of stream data one frame carries at most.

    A QUIC packet must fit the path, and 1200 is the datagram every path is required to carry (RFC 9000 §14); the rest of that goes to the header and the AEAD tag, so a kilobyte of payload leaves room without needing to know the header's exact shape.

    id_of

    fn id_of(initiator : Initiator, direction : Direction, seq : UInt64) -> UInt64

    The ID of the seq-th stream of that kind, counting from zero.

    initiator

    fn initiator(id : UInt64) -> Initiator

    The endpoint that opened stream id — bit 0.

    is_bidi

    fn is_bidi(id : UInt64) -> Bool

    Whether stream id carries data both ways.

    is_client

    fn is_client(id : UInt64) -> Bool

    Whether the client opened stream id.

    is_local

    fn is_local(id : UInt64, server~ : Bool) -> Bool

    Whether this endpoint opened stream id.

    is_writable

    fn is_writable(id : UInt64, server~ : Bool) -> Bool

    Whether this endpoint may send on stream id: one it opened, or a bidirectional one the peer opened. A peer's unidirectional stream is receive-only (§2.1, §3).

    limit

    let limit : UInt64

    How many bytes an assembler will hold ahead of the read cursor before refusing more.

    A connection's receive window already bounds this, and a megabyte is what quiche advertises per stream by default; the limit is here so an assembler used on its own is bounded too.

    ratio

    let ratio : Double

    How much of a window must become reclaimable before advertising a new limit is worth a frame. Half a window is what quiche uses; RFC 9000 §4.1 leaves it open, saying only that an endpoint should avoid a frame per byte.

    sequence

    fn sequence(id : UInt64) -> UInt64

    The stream's sequence number within its kind — the ID with its low two bits dropped.

    Source Files