nquic_conn (nquic v1.0.0)
View SourceQUIC Connection Management API.
This module provides functions to query connection state, statistics,
and to close connections. Use nquic for establishing connections
and stream operations.
Connection Information
The info/1 function returns a map containing:
state- Connection state (initial, handshake, established)role- client or serverscid- Source connection IDdcid- Destination connection IDrtt- RTT statistics (smoothed, variance, min, latest)cwnd- Congestion window size in bytesbytes_in_flight- Unacknowledged bytesstreams_open- Number of active streams
Summary
Functions
Close the connection gracefully with no error.
Close the connection with an error code and reason. Sends a CONNECTION_CLOSE frame with the specified error code and reason phrase, then terminates the connection. Common error codes (RFC 9000 Section 20)
Get connection information and statistics. Returns detailed information about the connection including RTT measurements, congestion control state, and transport parameters.
Migrate the connection to a new local address (RFC 9000 Section 9).
Initiates active connection migration by rebinding the client socket to the
new local address and sending a PATH_CHALLENGE to validate the new path.
Returns {error, migration_disabled} if the peer set disable_active_migration.
Only works in the established state.
Get path-level statistics for the connection.
Returns a flat map suitable for routing decisions (srtt_us, cwnd,
bytes_in_flight, ssthresh, ...) and for operational dashboards
(lifetime packets_sent, packets_lost, packets_acked, ECN
counters, pto_count).
Reads cached state inside the gen_statem; no protocol I/O.
Get the peer's TLS certificate in DER format.
Get the peer's address and port.
Get the local address and port.
List active stream IDs on the connection.
Types
-type conn_info() :: #{state := atom(), role := client | server, scid := nquic:connection_id(), dcid := nquic:connection_id(), rtt := #{smoothed := non_neg_integer(), variance := non_neg_integer(), min := non_neg_integer(), latest := non_neg_integer()}, cwnd := non_neg_integer(), bytes_in_flight := non_neg_integer(), streams_open := non_neg_integer(), local_params := #transport_params{original_destination_connection_id :: nquic:connection_id() | undefined, max_idle_timeout :: non_neg_integer(), stateless_reset_token :: binary() | undefined, max_udp_payload_size :: pos_integer(), initial_max_data :: non_neg_integer(), initial_max_stream_data_bidi_local :: non_neg_integer(), initial_max_stream_data_bidi_remote :: non_neg_integer(), initial_max_stream_data_uni :: non_neg_integer(), initial_max_streams_bidi :: non_neg_integer(), initial_max_streams_uni :: non_neg_integer(), ack_delay_exponent :: 0..20, max_ack_delay :: non_neg_integer(), disable_active_migration :: boolean(), preferred_address :: nquic_transport:preferred_address() | undefined, active_connection_id_limit :: non_neg_integer(), initial_source_connection_id :: nquic:connection_id() | undefined, retry_source_connection_id :: nquic:connection_id() | undefined, version_information :: nquic_transport:version_information() | undefined, max_datagram_frame_size :: non_neg_integer() | undefined}, remote_params := #transport_params{original_destination_connection_id :: nquic:connection_id() | undefined, max_idle_timeout :: non_neg_integer(), stateless_reset_token :: binary() | undefined, max_udp_payload_size :: pos_integer(), initial_max_data :: non_neg_integer(), initial_max_stream_data_bidi_local :: non_neg_integer(), initial_max_stream_data_bidi_remote :: non_neg_integer(), initial_max_stream_data_uni :: non_neg_integer(), initial_max_streams_bidi :: non_neg_integer(), initial_max_streams_uni :: non_neg_integer(), ack_delay_exponent :: 0..20, max_ack_delay :: non_neg_integer(), disable_active_migration :: boolean(), preferred_address :: nquic_transport:preferred_address() | undefined, active_connection_id_limit :: non_neg_integer(), initial_source_connection_id :: nquic:connection_id() | undefined, retry_source_connection_id :: nquic:connection_id() | undefined, version_information :: nquic_transport:version_information() | undefined, max_datagram_frame_size :: non_neg_integer() | undefined} | undefined}.
Functions
-spec close(pid()) -> ok.
Close the connection gracefully with no error.
-spec close(pid(), non_neg_integer(), binary()) -> ok.
Close the connection with an error code and reason. Sends a CONNECTION_CLOSE frame with the specified error code and reason phrase, then terminates the connection. Common error codes (RFC 9000 Section 20):
0- NO_ERROR (graceful close)1- INTERNAL_ERROR2- CONNECTION_REFUSED3- FLOW_CONTROL_ERROR10- APPLICATION_ERROR (generic application error)
-spec info(pid()) -> {ok, conn_info()} | {error, nquic_error:any_reason()}.
Get connection information and statistics. Returns detailed information about the connection including RTT measurements, congestion control state, and transport parameters.
-spec migrate(pid(), nquic_socket:sockaddr()) -> ok | {error, nquic_error:any_reason()}.
Migrate the connection to a new local address (RFC 9000 Section 9).
Initiates active connection migration by rebinding the client socket to the
new local address and sending a PATH_CHALLENGE to validate the new path.
Returns {error, migration_disabled} if the peer set disable_active_migration.
Only works in the established state.
-spec path_stats(pid()) -> {ok, nquic_loss:path_stats()} | {error, nquic_error:any_reason()}.
Get path-level statistics for the connection.
Returns a flat map suitable for routing decisions (srtt_us, cwnd,
bytes_in_flight, ssthresh, ...) and for operational dashboards
(lifetime packets_sent, packets_lost, packets_acked, ECN
counters, pto_count).
Reads cached state inside the gen_statem; no protocol I/O.
Get the peer's TLS certificate in DER format.
-spec peername(pid()) -> {ok, {inet:ip_address(), inet:port_number()}} | {error, nquic_error:any_reason()}.
Get the peer's address and port.
-spec sockname(pid()) -> {ok, {inet:ip_address(), inet:port_number()}} | {error, nquic_error:any_reason()}.
Get the local address and port.
-spec streams(pid()) -> {ok, [nquic:stream_id()]} | {error, nquic_error:any_reason()}.
List active stream IDs on the connection.