nquic_stream_manager (nquic v1.0.0)

View Source

Stream ID allocation and validation per RFC 9000 Section 2.

Manages stream creation with limit checking. Stream IDs encode the initiator (client/server) and type (bidi/uni) in the low 2 bits, and increment by 4 for each new stream of the same type.

Summary

Functions

Return the first stream ID initiated by the peer for the given type.

Retrieve an existing stream or create a new one with no limit checking.

Retrieve an existing stream or create a new one, validating against concurrency limits.

Return the stream type (bidi or uni) based on the low 2 bits of the stream ID.

Functions

first_peer_stream_id/2

-spec first_peer_stream_id(client | server, bidi | uni) -> nquic:stream_id().

Return the first stream ID initiated by the peer for the given type.

get_or_create(StreamID, Streams, Role)

-spec get_or_create(nquic:stream_id(), map(), client | server) ->
                       {ok,
                        #stream_state{stream_id :: nquic:stream_id(),
                                      type :: bidi | uni,
                                      send_state ::
                                          ready | send | data_sent | data_recvd | reset_sent |
                                          reset_recvd,
                                      send_offset :: non_neg_integer(),
                                      send_max_data :: non_neg_integer(),
                                      last_stream_data_blocked :: non_neg_integer(),
                                      pending_send_data :: [binary()],
                                      pending_send_size :: non_neg_integer(),
                                      pending_send_fin :: boolean(),
                                      recv_state ::
                                          recv | size_known | data_recvd | reset_recvd | data_read |
                                          reset_read,
                                      recv_offset :: non_neg_integer(),
                                      recv_max_offset :: non_neg_integer(),
                                      recv_window :: non_neg_integer(),
                                      recv_buffer ::
                                          gb_trees:tree(non_neg_integer(), {binary(), boolean()}),
                                      app_buffer :: iodata(),
                                      app_buffer_size :: non_neg_integer()},
                        map()} |
                       {error, term()}.

Retrieve an existing stream or create a new one with no limit checking.

get_or_create(StreamID, Streams, Role, Limits)

-spec get_or_create(nquic:stream_id(), map(), client | server, map()) ->
                       {ok,
                        #stream_state{stream_id :: nquic:stream_id(),
                                      type :: bidi | uni,
                                      send_state ::
                                          ready | send | data_sent | data_recvd | reset_sent |
                                          reset_recvd,
                                      send_offset :: non_neg_integer(),
                                      send_max_data :: non_neg_integer(),
                                      last_stream_data_blocked :: non_neg_integer(),
                                      pending_send_data :: [binary()],
                                      pending_send_size :: non_neg_integer(),
                                      pending_send_fin :: boolean(),
                                      recv_state ::
                                          recv | size_known | data_recvd | reset_recvd | data_read |
                                          reset_read,
                                      recv_offset :: non_neg_integer(),
                                      recv_max_offset :: non_neg_integer(),
                                      recv_window :: non_neg_integer(),
                                      recv_buffer ::
                                          gb_trees:tree(non_neg_integer(), {binary(), boolean()}),
                                      app_buffer :: iodata(),
                                      app_buffer_size :: non_neg_integer()},
                        map()} |
                       {error, term()}.

Retrieve an existing stream or create a new one, validating against concurrency limits.

type(StreamID)

-spec type(nquic:stream_id()) -> bidi | uni.

Return the stream type (bidi or uni) based on the low 2 bits of the stream ID.