quic_listener (quic v1.3.0)

View Source

QUIC server listener for accepting connections.

This module handles: - UDP socket management - Initial packet routing to connections - Connection ID management - Stateless retry (optional)

Connection Handler Callback

The connection_handler option allows custom handling of new connections:

   Opts = #{
       cert => Cert,
       key => Key,
       connection_handler => fun(Conn) ->
           %% Conn is the connection pid
           %% Spawn your handler and return its pid
           HandlerPid = spawn(fun() -> my_handler(Conn) end),
           %% Ownership will be transferred to HandlerPid
           {ok, HandlerPid}
       end
   }

Summary

Functions

Get list of active connections.

Get the port the listener is bound to.

false Handle incoming UDP packets (gen_udp backend)

false

Start a QUIC listener (without linking to caller).

Start a QUIC listener on the given port. Options: - cert: Server certificate (DER binary) - cert_chain: Certificate chain [binary()] - key: Private key - alpn: List of supported ALPN protocols - active_n: Number of packets before socket goes passive (default 100) - reuseport: Enable SO_REUSEPORT for multiple listeners (default false) - connections_table: Shared ETS table for connection tracking (pool mode) - preferred_ipv4: {IP, Port} for preferred IPv4 address (RFC 9000 Section 9.6) - preferred_ipv6: {IP, Port} for preferred IPv6 address (RFC 9000 Section 9.6)

Stop the listener.

Types

state/0

-type state() ::
          #listener_state{socket :: gen_udp:socket() | socket:socket(),
                          socket_state :: quic_socket:socket_state() | undefined,
                          socket_backend :: gen_udp | socket,
                          gro_receiver :: pid() | undefined,
                          port :: inet:port_number(),
                          cert :: binary(),
                          cert_chain :: [binary()],
                          private_key :: term(),
                          alpn_list :: [binary()],
                          connections :: ets:tid(),
                          tickets_table :: ets:tid(),
                          owns_tables :: boolean(),
                          reset_secret :: binary(),
                          address_validation :: never | always,
                          token_max_age_ms :: non_neg_integer(),
                          connection_handler ::
                              fun((pid()) -> {ok, pid()} | {error, term()}) |
                              fun((pid(), binary()) -> {ok, pid()} | {error, term()}) |
                              undefined,
                          cid_config ::
                              #cid_config{lb_config ::
                                              #lb_config{config_rotation :: 0..6,
                                                         algorithm ::
                                                             plaintext | stream_cipher | block_cipher,
                                                         server_id :: binary(),
                                                         server_id_len :: 1..15,
                                                         nonce_len :: 4..18,
                                                         key :: binary() | undefined} |
                                              undefined,
                                          cid_len :: 1..20,
                                          reset_secret :: binary() | undefined} |
                              undefined,
                          dcid_len :: pos_integer(),
                          opts :: map()}.

Functions

code_change(OldVsn, State, Extra)

false

get_connections(Listener)

-spec get_connections(pid()) -> [pid()].

Get list of active connections.

get_port(Listener)

-spec get_port(pid()) -> inet:port_number().

Get the port the listener is bound to.

handle_call(Request, From, Listener_state)

-spec handle_call(term(), gen_server:from(), state()) -> {reply, term(), state()}.

false

handle_cast(Msg, State)

-spec handle_cast(term(), state()) -> {noreply, state()}.

false

handle_continue(_, _)

false

handle_info(Info, Listener_state)

false Handle incoming UDP packets (gen_udp backend)

init(_)

-spec init({inet:port_number(), map()}) -> term().

false

start(Port, Opts)

-spec start(inet:port_number(), map()) -> {ok, pid()} | {error, term()}.

Start a QUIC listener (without linking to caller).

start_link(Port, Opts)

-spec start_link(inet:port_number(), map()) -> {ok, pid()} | {error, term()}.

Start a QUIC listener on the given port. Options: - cert: Server certificate (DER binary) - cert_chain: Certificate chain [binary()] - key: Private key - alpn: List of supported ALPN protocols - active_n: Number of packets before socket goes passive (default 100) - reuseport: Enable SO_REUSEPORT for multiple listeners (default false) - connections_table: Shared ETS table for connection tracking (pool mode) - preferred_ipv4: {IP, Port} for preferred IPv4 address (RFC 9000 Section 9.6) - preferred_ipv6: {IP, Port} for preferred IPv6 address (RFC 9000 Section 9.6)

stop(Listener)

-spec stop(pid()) -> ok.

Stop the listener.

terminate(Reason, Listener_state)

false