quic_listener (quic v1.6.4)

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.

Get the address the listener is bound to. Resolves the actual bound address from the socket, so it reflects the real value even when the listener was opened with inet6, {ip, Addr} or {ifaddr, Addr}.

false Handle incoming UDP packets (gen_udp backend)

false

Add a connection ID to the routing table. Called by a connection when it issues a new CID (NEW_CONNECTION_ID) so packets the peer sends to the rotated/migrated CID reach the connection (the routing ETS is owned by the listener).

Remove a connection ID from the routing table (CID retired).

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() | undefined,
                          cert_chain :: [binary()],
                          private_key :: term() | undefined,
                          psks :: #{binary() => binary()} | undefined,
                          psk_callback :: fun((binary()) -> {ok, binary()} | not_found) | undefined,
                          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.

get_sockname(Listener)

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

Get the address the listener is bound to. Resolves the actual bound address from the socket, so it reflects the real value even when the listener was opened with inet6, {ip, Addr} or {ifaddr, Addr}.

handle_call(Request, From, Listener_state)

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

false

handle_cast(Msg, Listener_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

register_cid(Listener, CID, ConnPid)

-spec register_cid(pid(), binary(), pid()) -> ok.

Add a connection ID to the routing table. Called by a connection when it issues a new CID (NEW_CONNECTION_ID) so packets the peer sends to the rotated/migrated CID reach the connection (the routing ETS is owned by the listener).

retire_cid(Listener, CID)

-spec retire_cid(pid(), binary()) -> ok.

Remove a connection ID from the routing table (CID retired).

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