quicer_connection behaviour (quicer v0.4.3)

View Source

Quic Connection Behavior

Best practice for 1. server side connection acceptor

1. server side connection initiator

Summary

Types

active_n/0

-type active_n() :: boolean() | once | integer().

cb_ret/0

-type cb_ret() :: quicer_lib:cb_ret().

cb_state/0

-type cb_state() :: quicer_lib:cb_state().

conf_handle/0

-type conf_handle() :: reference().

conn_opts/0

-type conn_opts() ::
          #{alpn := [string()],
            conn_callback => module(),
            custom_verify => boolean(),
            handle => connection_handle(),
            nst => binary(),
            handshake_idle_timeout_ms => non_neg_integer(),
            quic_event_mask => uint32(),
            disable_1rtt_encryption => boolean(),
            local_address => string(),
            local_bidi_stream_count => uint16(),
            local_peer_unidi_stream_count => uint16(),
            cert => file:filename(),
            certfile => file:filename(),
            key => file:filename(),
            keyfile => file:filename(),
            password => string(),
            verify => none | peer | verify_peer | verify_none,
            cacertfile => file:filename(),
            sslkeylogfile => file:filename(),
            max_bytes_per_key => uint64(),
            handshake_idle_timeout_ms => uint64(),
            idle_timeout_ms => uint64(),
            tls_client_max_send_buffer => uint32(),
            tls_server_max_send_buffer => uint32(),
            stream_recv_window_default => uint32(),
            stream_recv_buffer_default => uint32(),
            conn_flow_control_window => uint32(),
            max_stateless_operations => uint32(),
            initial_window_packets => uint32(),
            send_idle_timeout_ms => uint32(),
            initial_rtt_ms => uint32(),
            max_ack_delay_ms => uint32(),
            disconnect_timeout_ms => uint32(),
            keep_alive_interval_ms => uint32(),
            congestion_control_algorithm => uint16(),
            peer_bidi_stream_count => uint16(),
            peer_unidi_stream_count => uint16(),
            retry_memory_limit => uint16(),
            load_balancing_mode => uint16(),
            max_operations_per_drain => uint8(),
            send_buffering_enabled => uint8(),
            pacing_enabled => uint8(),
            migration_enabled => uint8(),
            datagram_receive_enabled => uint8(),
            server_resumption_level => uint8(),
            minimum_mtu => uint16(),
            maximum_mtu => uint16(),
            mtu_discovery_search_complete_timeout_us => uint64(),
            mtu_discovery_missing_probe_count => uint8(),
            max_binding_stateless_operations => uint16(),
            stateless_operation_expiration_ms => uint16(),
            dynamic() => dynamic()}.

connection_handle/0

-type connection_handle() :: reference().

csend_flags/0

-type csend_flags() :: 0 | 1 | 2 | 4 | 8 | 16.

global_handle/0

-type global_handle() :: quic_global.

handle/0

hostname/0

-type hostname() :: string().

listener_handle/0

-type listener_handle() :: reference().

reg_handle/0

-type reg_handle() :: reference().

send_flags/0

-type send_flags() :: csend_flags() | 4096.

state/0

-type state() ::
          #{listener := listener_handle(),
            conn := connection_handle(),
            callback := atom(),
            callback_state := term(),
            sup := undefined | pid(),
            conn_opts := map(),
            stream_opts := map(),
            is_resumed := boolean()}.

stream_handle/0

-type stream_handle() :: reference().

stream_open_flags/0

-type stream_open_flags() :: 0 | 1 | 2.

stream_opts/0

-type stream_opts() ::
          #{active := active_n(),
            open_flag => stream_open_flags(),
            start_flag => stream_start_flags(),
            event_mask => uint32(),
            disable_fpbuffer => boolean(),
            stream_id => uint62(),
            priority => uint16(),
            ideal_send_buffer_size => uint64(),
            '0rtt_length' => uint64(),
            dynamic() => dynamic()}.

stream_start_flags/0

-type stream_start_flags() :: 0 | 1 | 2 | 4 | 8.

uint8/0

-type uint8() :: 0..1 bsl 8 - 1.

uint16/0

-type uint16() :: 0..1 bsl 16 - 1.

uint32/0

-type uint32() :: 0..1 bsl 32 - 1.

uint62/0

-type uint62() :: 0..1 bsl 62 - 1.

uint64/0

-type uint64() :: 0..1 bsl 64 - 1.

Callbacks

closed/3

-callback closed(connection_handle(), conn_closed_props(), cb_state()) -> cb_ret().
Handle connection closed. We don't have to terminate this process since connection could be resumed.

connected/3

-callback connected(connection_handle(), connected_props(), cb_state()) -> cb_ret().
Handle connection handshake done callback is suggested to accept new streams @see quicer:accept_stream/3

dgram_recv/4

(optional)
-callback dgram_recv(connection_handle(), DataBin :: binary(), Flags :: non_neg_integer(), cb_state()) ->
                        cb_ret().
Handle Unreliable Datagram of RFC 9221.

dgram_state_changed/3

(optional)
-callback dgram_state_changed(connection_handle(), dgram_state(), cb_state()) -> cb_ret().
Handle Datagram State Changed event.

handle_call/3

(optional)
-callback handle_call(Req :: term(), From :: gen_server:from(), cb_state()) -> cb_ret().

handle_cast/2

(optional)
-callback handle_cast(Req :: term(), cb_state()) -> cb_ret().
Handle cast with callback state.

handle_continue/2

(optional)
-callback handle_continue(Cont :: term(), cb_state()) -> cb_ret().
Handle continue from other callbacks with callback state.

handle_info/2

(optional)
-callback handle_info(Info :: term(), cb_state()) -> cb_ret().
handle unhandled info with callback state.

init/1

-callback init(cb_init_args()) -> {ok, cb_state()} | {error, app_error(), cb_state()}.
Init Callback, after return should expect for recv new connection

local_address_changed/3

-callback local_address_changed(connection_handle(), quicer_addr(), cb_state()) -> cb_ret().
Handle Local Addr Changed, currently not in use.

new_conn/3

-callback new_conn(connection_handle(), new_conn_props(), cb_state()) -> cb_ret().
Handle new incoming connection request return {ok, cb_state()} to complete handshakereturn {error, Reason, cb_state()} to reject the new connection, this process will be terminatedNOTE: 1. If acceptor is supervised,new new acceptor will be spawned. 2. Connection maybe rejected in the stack earlier before this Callback.

new_stream/3

-callback new_stream(stream_handle(), new_stream_props(), cb_state()) -> cb_ret().
Handle new stream from peer which has no owner assigned, or stream acceptor didn't accept the stream on time NOTE: The connection could start stream handoff procedure

nst_received/3

(optional)
-callback nst_received(connection_handle(), TicketBin :: binary(), cb_state()) -> cb_ret().
Client only, New session ticket received,

peer_address_changed/3

-callback peer_address_changed(connection_handle(), quicer_addr(), cb_state()) -> cb_ret().
Handle Peer Addr Changed

peer_cert_received/3

(optional)
-callback peer_cert_received(connection_handle(), cert_and_chain(), cb_state()) -> cb_ret().
Handle certifcate received from peer for custom cert/certchain verification.

peer_needs_streams/3

(optional)
-callback peer_needs_streams(connection_handle(), unidi_streams | bidi_streams, cb_state()) -> cb_ret().
Handle Peer needs streams that peer could not start new stream due to local flow control.

resumed/3

-callback resumed(connection_handle(), SessionData :: binary() | false, cb_state()) -> cb_ret().
Handle connection is resumed with 0-RTT SessionData contains session data was sent in 0-RTT

shutdown/3

-callback shutdown(connection_handle(), error_code(), cb_state()) -> cb_ret().
Handle connection shutdown initiated by peer

streams_available/3

-callback streams_available(connection_handle(),
                            {BidirStreams :: non_neg_integer(), UnidirStreams :: non_neg_integer()},
                            cb_state()) ->
                               cb_ret().
Handle Stream Available, reflect number of streams flow control at peer.

transport_shutdown/3

-callback transport_shutdown(connection_handle(), transport_shutdown_props(), cb_state()) -> cb_ret().
Handle connection shutdown due to transport error with error reason.NOTE: Cleanup is prefered to be handled in @see closed/3

Functions

get_cb_state(ConnPid)

-spec get_cb_state(ConnPid :: pid()) -> cb_state() | {error, any()}.

get_handle(ConnPid)

-spec get_handle(pid()) -> undefined | connection_handle().

get connection handle from quic connection process

handle_continue(Cont, State)

-spec handle_continue(Cont :: term(), State :: term()) ->
                         {noreply, NewState :: term()} |
                         {noreply, NewState :: term(), Timeout :: timeout()} |
                         {noreply, NewState :: term(), hibernate} |
                         {stop, Reason :: normal | term(), NewState :: term()}.

merge_cb_state(ConnPid, New)

-spec merge_cb_state(ConnPid :: pid(), New :: map()) -> cb_state() | {error, any()}.

start_acceptor(ListenHandle, Tab, Sup)

-spec start_acceptor(listener_handle(), ets:tid(), pid()) -> {ok, pid()} | {error, any()}.

start acceptor with shared Listener confs

start_link(CallbackModule, Peer, Opts)

-spec start_link(atom(), {hostname(), inet:port_number()}, {conn_opts(), stream_opts()}) ->
                    gen_server:start_ret().

Spawn Client connection or Start connection acceptor at server side

start_link(CallbackModule, Listener, ConnOpts, Sup)

-spec start_link(CallbackModule :: undefined | module(),
                 Listener :: quicer:listener_handle(),
                 ConnOpts :: term(),
                 Sup :: pid()) ->
                    {ok, Pid :: pid()} |
                    {error, Error :: {already_started, pid()}} |
                    {error, Error :: term()} |
                    ignore.

stream_send(ConnPid, Callback, Data, SendFlag, StreamOpts, Timeout)

-spec stream_send(ConnPid :: pid(),
                  Callback :: atom(),
                  Data :: iodata(),
                  SendFlag :: send_flags(),
                  StreamOpts :: stream_opts(),
                  timeout()) ->
                     ok | {error, any()}.