### Start Client Session with QuicClientConfig Source: https://docs.rs/quinn/latest/quinn/crypto/rustls/struct.QuicClientConfig.html Starts a client session using the QuicClientConfig. This method is part of the ClientConfig trait implementation for QuicClientConfig. ```rust fn start_session( self: Arc, version: u32, server_name: &str, params: &TransportParameters, ) -> Result, ConnectError> ``` -------------------------------- ### Start Server Session Source: https://docs.rs/quinn/latest/quinn/crypto/rustls/struct.QuicServerConfig.html Starts a server session with the given configuration, version, and transport parameters. This method is part of the ServerConfig trait implementation for QuicServerConfig. ```rust fn start_session( self: Arc, version: u32, params: &TransportParameters, ) -> Box ``` -------------------------------- ### starts_with Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Checks if the slice starts with a specific prefix. ```APIDOC ## starts_with ### Description Returns true if needle is a prefix of the slice or equal to the slice. ### Parameters - **needle** (&[T]) - Required - The prefix to check for. ### Response - **bool** - Returns true if the slice starts with the needle. ``` -------------------------------- ### Trait: ClientConfig Source: https://docs.rs/quinn/latest/quinn/crypto/trait.ClientConfig.html Defines the required method for starting a client session within the quinn crypto protocol. ```APIDOC ## Trait: ClientConfig ### Description Client-side configuration for the crypto protocol. ### Required Methods #### start_session Starts a client session with the provided configuration. - **self** (Arc) - Required - The client configuration instance. - **version** (u32) - Required - The protocol version. - **server_name** (&str) - Required - The name of the server to connect to. - **params** (&TransportParameters) - Required - The transport parameters for the session. ### Returns - **Result, ConnectError>** - Returns a session object on success or a ConnectError on failure. ``` -------------------------------- ### Construct Endpoint with Custom Configuration Source: https://docs.rs/quinn/latest/quinn/struct.Endpoint.html Construct an endpoint with arbitrary configuration, an optional server configuration, a UDP socket, and a runtime. Useful for advanced setups. ```rust pub fn new( config: EndpointConfig, server_config: Option, socket: UdpSocket, runtime: Arc, ) -> Result ``` -------------------------------- ### Get Header Key Sample Size Source: https://docs.rs/quinn/latest/quinn/crypto/trait.HeaderKey.html Returns the sample size used by this key's algorithm. This is typically the size of the authentication tag. ```rust fn sample_size(&self) -> usize; ``` -------------------------------- ### Get Element Offset in Slice Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Use `element_offset` to find the index of an element reference within a slice. This method uses pointer arithmetic and does not compare elements. It returns `None` if the element reference is not aligned with the start of an element. ```rust let nums: &[u32] = &[1, 7, 1, 1]; let num = &nums[2]; assert_eq!(num, &1); assert_eq!(nums.element_offset(num), Some(2)); ``` ```rust let arr: &[[u32; 2]] = &[[0, 1], [2, 3]]; let flat_arr: &[u32] = arr.as_flattened(); let ok_elm: &[u32; 2] = flat_arr[0..2].try_into().unwrap(); let weird_elm: &[u32; 2] = flat_arr[1..3].try_into().unwrap(); assert_eq!(ok_elm, &[0, 1]); assert_eq!(weird_elm, &[1, 2]); assert_eq!(arr.element_offset(ok_elm), Some(0)); // Points to element 0 assert_eq!(arr.element_offset(weird_elm), None); // Points between element 0 and 1 ``` -------------------------------- ### Create Initial Keys Source: https://docs.rs/quinn/latest/quinn/crypto/rustls/struct.QuicServerConfig.html Creates the initial set of keys for a server session, given the client's initial destination ConnectionId and the QUIC version. This is part of the ServerConfig trait. ```rust fn initial_keys( &self, version: u32, dst_cid: &ConnectionId, ) -> Result ``` -------------------------------- ### Start Work Cycle Source: https://docs.rs/quinn/latest/src/quinn/work_limiter.rs.html Resets the completed work count for the current cycle. If in measurement mode, it records the start time. ```rust pub(crate) fn start_cycle(&mut self, now: impl Fn() -> Instant) { self.completed = 0; if let Mode::Measure = self.mode { self.start_time = Some(now()); } } ``` -------------------------------- ### ServerConfig Initialization Source: https://docs.rs/quinn/latest/quinn/struct.ServerConfig.html Methods for creating a new ServerConfig instance. ```APIDOC ## POST /serverconfig/with_single_cert ### Description Creates a server config with the given certificate chain to be presented to clients. Uses a randomized handshake token key. ### Method POST ### Endpoint /serverconfig/with_single_cert ### Parameters #### Request Body - **cert_chain** (Vec>) - Required - The certificate chain to present to clients. - **key** (PrivateKeyDer<'static>) - Required - The private key associated with the certificate. ### Response #### Success Response (200) - **ServerConfig** (object) - The created server configuration. ### Response Example ```json { "server_config": { "certificate_chain": [...], "private_key": "..." } } ``` ``` ```APIDOC ## POST /serverconfig/with_crypto ### Description Creates a server config with the given `crypto::ServerConfig`. Uses a randomized handshake token key. ### Method POST ### Endpoint /serverconfig/with_crypto ### Parameters #### Request Body - **crypto** (Arc) - Required - The crypto server configuration to use. ### Response #### Success Response (200) - **ServerConfig** (object) - The created server configuration. ### Response Example ```json { "server_config": { "crypto_config": "..." } } ``` ``` -------------------------------- ### ServerConfig Struct and Methods Source: https://docs.rs/quinn/latest/quinn/struct.ServerConfig.html Configuration settings and builder methods for initializing and customizing a Quinn server instance. ```APIDOC ## ServerConfig ### Description Parameters governing incoming connections. Default values are suitable for most internet applications. ### Fields - **transport** (Arc) - Transport configuration to use for incoming connections. - **crypto** (Arc) - TLS configuration used for incoming connections (must be TLS 1.3). - **validation_token** (ValidationTokenConfig) - Configuration for sending and handling validation tokens. ### Methods - **new(crypto, token_key)**: Create a default config with a particular handshake token key. - **transport_config(transport)**: Set a custom TransportConfig. - **validation_token_config(validation_token)**: Set a custom ValidationTokenConfig. - **token_key(value)**: Set the private key used to authenticate data in handshake tokens. - **retry_token_lifetime(value)**: Set duration for which a retry token is considered valid (default 15s). - **migration(value)**: Enable/disable client migration to new addresses (default true). - **preferred_address_v4(address)**: Set preferred IPv4 address for handshaking. - **preferred_address_v6(address)**: Set preferred IPv6 address for handshaking. - **max_incoming(max_incoming)**: Set maximum number of concurrent Incoming connection attempts (default 65536). - **incoming_buffer_size(incoming_buffer_size)**: Set max bytes to buffer per Incoming connection (default 10 MiB). - **incoming_buffer_size_total(incoming_buffer_size_total)**: Set max bytes to buffer for all Incoming connections collectively (default 100 MiB). - **time_source(time_source)**: Set the object used to retrieve current SystemTime. ``` -------------------------------- ### Get Last Element of a Slice Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Use `last` to get an immutable reference to the last element. Returns `None` if the slice is empty. ```rust let v = [10, 40, 30]; assert_eq!(Some(&30), v.last()); let w: &[i32] = &[]; assert_eq!(None, w.last()); ``` -------------------------------- ### Get Open Connections Count Source: https://docs.rs/quinn/latest/quinn/struct.Endpoint.html Get the number of connections that are currently open on this endpoint. This can be used for monitoring or managing endpoint load. ```rust pub fn open_connections(&self) -> usize ``` -------------------------------- ### QuicServerConfig::with_initial Source: https://docs.rs/quinn/latest/quinn/crypto/rustls/struct.QuicServerConfig.html Initializes a QUIC-compatible TLS client configuration with a separate initial cipher suite. ```APIDOC ## pub fn with_initial(inner: Arc, initial: Suite) -> Result ### Description Initialize a QUIC-compatible TLS client configuration with a separate initial cipher suite. This is useful if you want to avoid the initial cipher suite for traffic encryption. ### Parameters - **inner** (Arc) - Required - The underlying rustls server configuration. - **initial** (Suite) - Required - The initial cipher suite to use. ### Response - **Result** - Returns a new QuicServerConfig or an error if the initial cipher suite is invalid. ``` -------------------------------- ### Initialize a Connecting instance Source: https://docs.rs/quinn/latest/src/quinn/connection.rs.html Creates a new Connecting instance and spawns the connection driver task on the provided runtime. ```rust impl Connecting { pub(crate) fn new( handle: ConnectionHandle, conn: proto::Connection, endpoint_events: mpsc::UnboundedSender<(ConnectionHandle, EndpointEvent)>, conn_events: mpsc::UnboundedReceiver, socket: Arc, runtime: Arc, ) -> Self { let (on_handshake_data_send, on_handshake_data_recv) = oneshot::channel(); let (on_connected_send, on_connected_recv) = oneshot::channel(); let conn = ConnectionRef::new( handle, conn, endpoint_events, conn_events, on_handshake_data_send, on_connected_send, socket, runtime.clone(), ); let driver = ConnectionDriver(conn.clone()); runtime.spawn(Box::pin( async { if let Err(e) = driver.await { tracing::error!("I/O error: {e}"); } } .instrument(Span::current()), )); Self { conn: Some(conn), connected: on_connected_recv, handshake_data_ready: Some(on_handshake_data_recv), } } ``` -------------------------------- ### Get Mutable Reference to Last Element of a Slice Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Use `last_mut` to get a mutable reference to the last element. Returns `None` if the slice is empty. ```rust let x = &mut [0, 1, 2]; if let Some(last) = x.last_mut() { *last = 10; } assert_eq!(x, &[0, 1, 10]); let y: &mut [i32] = &mut []; assert_eq!(None, y.last_mut()); ``` -------------------------------- ### Accept Incoming Connections Source: https://docs.rs/quinn/latest/quinn/struct.Endpoint.html Get the next incoming connection attempt from a client. Yields `Incoming`s, or `None` if the endpoint is closed. `Incoming` can be awaited to obtain the final `Connection`. ```rust pub fn accept(&self) -> Accept<'_> ``` -------------------------------- ### Get Local Socket Address Source: https://docs.rs/quinn/latest/quinn/struct.Endpoint.html Get the local `SocketAddr` the underlying socket is bound to. This is useful for determining the endpoint's network interface and port. ```rust pub fn local_addr(&self) -> Result ``` -------------------------------- ### NewReno Controller - initial_window Source: https://docs.rs/quinn/latest/quinn/congestion/struct.NewReno.html Returns the initial congestion window size. ```rust fn initial_window(&self) -> u64 ``` -------------------------------- ### Get First N Elements as an Array Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Use `first_chunk` to get the first `N` elements as an array reference. Returns `None` if the slice is shorter than `N`. ```rust let u = [10, 40, 30]; assert_eq!(Some(&[10, 40]), u.first_chunk::<2>()); let v: &[i32] = &[10]; assert_eq!(None, v.first_chunk::<2>()); let w: &[i32] = &[]; assert_eq!(Some(&[]), w.first_chunk::<0>()); ``` -------------------------------- ### Build Controller from BbrConfig Source: https://docs.rs/quinn/latest/quinn/congestion/struct.BbrConfig.html Constructs a fresh Controller instance using BbrConfig, current time, and MTU. ```rust fn build( self: Arc, _now: Instant, current_mtu: u16, ) -> Box ``` -------------------------------- ### Initialize QuicClientConfig Source: https://docs.rs/quinn/latest/quinn/crypto/rustls/struct.QuicClientConfig.html Creates a new QuicClientConfig with a specific initial cipher suite. ```APIDOC ## fn with_initial ### Description Initialize a QUIC-compatible TLS client configuration with a separate initial cipher suite. This is useful if you want to avoid the initial cipher suite for traffic encryption. ### Parameters - **inner** (Arc) - Required - The underlying rustls configuration. - **initial** (Suite) - Required - The initial cipher suite to use. ### Response - **Result** - Returns the configured QuicClientConfig or an error if the cipher suite is invalid. ``` -------------------------------- ### Split Off Slice Starting from Third Element Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Use `split_off` with a range like `2..` to remove and return a subslice starting from a specific index. The original slice is modified. ```rust let mut slice: &[_] = &['a', 'b', 'c', 'd']; let mut tail = slice.split_off(2..).unwrap(); assert_eq!(slice, &['a', 'b']); assert_eq!(tail, &['c', 'd']); ``` -------------------------------- ### Endpoint Initialization Source: https://docs.rs/quinn/latest/quinn The Endpoint is the primary entry point for the quinn crate, representing a local QUIC node that can act as a client, server, or both. ```APIDOC ## Endpoint ### Description The `Endpoint` is the central structure in the quinn crate. It manages the lifecycle of QUIC connections, handles incoming packets, and facilitates the creation of client or server instances. ### Usage - **Client**: Initiates connections to a remote server. - **Server**: Accepts incoming connections from clients. - **Peer-to-Peer**: Functions as both client and server simultaneously. ``` -------------------------------- ### Get First N Elements Mutably as an Array Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Use `first_chunk_mut` to get the first `N` elements as a mutable array reference. Returns `None` if the slice is shorter than `N`. ```rust let x = &mut [0, 1, 2]; if let Some(first) = x.first_chunk_mut::<2>() { first[0] = 5; first[1] = 4; } assert_eq!(x, &[5, 4, 2]); assert_eq!(None, x.first_chunk_mut::<4>()); ``` -------------------------------- ### Split Off Slice Starting from Third Element (Mutable) Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Use `split_off_mut` with a range like `2..` to remove and return a mutable reference to a subslice starting from a specific index. The original mutable slice is modified. ```rust let mut slice: &mut [_] = &mut ['a', 'b', 'c', 'd']; let mut tail = slice.split_off_mut(2..).unwrap(); assert_eq!(slice, &mut ['a', 'b']); assert_eq!(tail, &mut ['c', 'd']); ``` -------------------------------- ### Connect with custom configuration Source: https://docs.rs/quinn/latest/src/quinn/endpoint.rs.html Initiates a connection using a specific ClientConfig, validating address compatibility and endpoint state. ```rust pub fn connect_with( &self, config: ClientConfig, addr: SocketAddr, server_name: &str, ) -> Result { let mut endpoint = self.inner.state.lock().unwrap(); if endpoint.driver_lost || endpoint.recv_state.connections.close.is_some() { return Err(ConnectError::EndpointStopping); } if addr.is_ipv6() && !endpoint.ipv6 { return Err(ConnectError::InvalidRemoteAddress(addr)); } let addr = if endpoint.ipv6 { SocketAddr::V6(ensure_ipv6(addr)) } else { addr }; let (ch, conn) = endpoint .inner .connect(self.runtime.now(), config, addr, server_name)?; let socket = endpoint.socket.clone(); endpoint.stats.outgoing_handshakes += 1; Ok(endpoint .recv_state .connections .insert(ch, conn, socket, self.runtime.clone())) } ``` -------------------------------- ### initial_window Method Source: https://docs.rs/quinn/latest/quinn/congestion/trait.Controller.html Returns the initial congestion window size. ```rust fn initial_window(&self) -> u64; ``` -------------------------------- ### Accept Incoming Connection with Custom Server Configuration Source: https://docs.rs/quinn/latest/src/quinn/incoming.rs.html Accepts an incoming connection using a provided `ServerConfig`. Use this when specific server configurations are required for a connection. ```rust pub fn accept_with( mut self, server_config: Arc, ) -> Result { let state = self.0.take().unwrap(); state.endpoint.accept(state.inner, Some(server_config)) } ``` -------------------------------- ### rchunks Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Returns an iterator over chunks of the slice starting from the end. ```APIDOC ## fn rchunks(&self, chunk_size: usize) -> RChunks<'_, T> ### Description Returns an iterator over chunk_size elements of the slice at a time, starting at the end of the slice. The chunks are slices and do not overlap. ### Parameters #### Query Parameters - **chunk_size** (usize) - Required - The size of each chunk. ### Panics - Panics if chunk_size is zero. ``` -------------------------------- ### GET /endpoint/stats Source: https://docs.rs/quinn/latest/src/quinn/endpoint.rs.html Retrieves statistics regarding the activity of the endpoint. ```APIDOC ## GET /endpoint/stats ### Description Returns cumulative statistics on endpoint activity including handshakes. ### Response #### Success Response (200) - **accepted_handshakes** (u64) - Cumulative number of QUIC handshakes accepted. - **outgoing_handshakes** (u64) - Cumulative number of QUIC handshakes sent. - **refused_handshakes** (u64) - Cumulative number of QUIC handshakes refused. - **ignored_handshakes** (u64) - Cumulative number of QUIC handshakes ignored. ``` -------------------------------- ### Initialize QuicServerConfig with Initial Cipher Suite Source: https://docs.rs/quinn/latest/quinn/crypto/rustls/struct.QuicServerConfig.html Initializes a QUIC-compatible TLS server configuration with a separate initial cipher suite. This is useful for avoiding the initial cipher suite for traffic encryption. ```rust pub fn with_initial( inner: Arc, initial: Suite, ) -> Result ``` -------------------------------- ### Get Stream ID Source: https://docs.rs/quinn/latest/quinn/struct.RecvStream.html Retrieves the unique identifier for this stream. ```APIDOC ## pub fn id(&self) -> StreamId ### Description Get the identity of this stream. ### Method GET ### Endpoint /recvstream/id ### Response #### Success Response (200) - **StreamId** - The unique identifier of the stream. ### Response Example ```json { "stream_id": 123 } ``` ``` -------------------------------- ### Endpoint::new Source: https://docs.rs/quinn/latest/src/quinn/endpoint.rs.html Constructs a QUIC endpoint with arbitrary configuration and a provided UDP socket. ```APIDOC ## Endpoint::new ### Description Constructs an endpoint with arbitrary configuration and socket. This is a lower-level constructor that allows for more control over the endpoint's setup. ### Method `pub fn new(config: EndpointConfig, server_config: Option, socket: std::net::UdpSocket) -> io::Result` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let endpoint_config = quinn::EndpointConfig::default(); let server_config = Some(quinn::ServerConfig::default()); let socket = std::net::UdpSocket::bind("0.0.0.0:0")?; let endpoint = quinn::Endpoint::new(endpoint_config, server_config, socket); ``` ### Response #### Success Response (200) An initialized `Endpoint` instance. #### Response Example ```rust // Success is indicated by the function returning Ok(Endpoint) ``` ### Error Handling Returns `io::Error` if the endpoint cannot be initialized with the given configuration and socket. ``` -------------------------------- ### ClientConfig Constructors Source: https://docs.rs/quinn/latest/quinn/struct.ClientConfig.html Provides methods for creating and configuring a ClientConfig. ```APIDOC ## ClientConfig Configuration for outgoing connections. ### `new(crypto: Arc) -> ClientConfig` Create a default config with a particular cryptographic config. ### `with_platform_verifier() -> ClientConfig` Deprecated since 0.11.13: use `try_with_platform_verifier()` instead. Create a client configuration that trusts the platform’s native roots. ### `try_with_platform_verifier() -> Result` Create a client configuration that trusts the platform’s native roots. ### `with_root_certificates(roots: Arc) -> Result` Create a client configuration that trusts specified trust anchors. ``` -------------------------------- ### Get stream identity Source: https://docs.rs/quinn/latest/quinn/struct.RecvStream.html Retrieves the unique identifier for the stream. ```rust pub fn id(&self) -> StreamId ``` -------------------------------- ### Get Endpoint Statistics Source: https://docs.rs/quinn/latest/quinn/struct.Endpoint.html Returns relevant statistics from this Endpoint. ```rust pub fn stats(&self) -> EndpointStats ``` -------------------------------- ### TryFrom> for QuicServerConfig Source: https://docs.rs/quinn/latest/quinn/crypto/rustls/struct.QuicServerConfig.html Converts a standard rustls::ServerConfig into a QuicServerConfig. ```APIDOC ## fn try_from(inner: Arc) -> Result ### Description Performs the conversion from a standard rustls::ServerConfig to a QuicServerConfig. Note that the rustls::ServerConfig must have TLS 1.3 support enabled for conversion to succeed. ### Parameters - **inner** (Arc) - Required - The rustls server configuration to convert. ### Response - **Result** - Returns the converted configuration or a NoInitialCipherSuite error. ``` -------------------------------- ### metrics Method (Provided) Source: https://docs.rs/quinn/latest/quinn/congestion/trait.Controller.html Retrieves implementation-specific metrics for qlog traces. This is a provided default implementation. ```rust fn metrics(&self) -> ControllerMetrics { ... } ``` -------------------------------- ### as_rchunks_mut Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Splits a slice into a slice of N-element arrays starting from the end. ```APIDOC ## fn as_rchunks_mut(&mut self) -> (&mut [T], &mut [[T; N]]) ### Description Splits the slice into a slice of N-element arrays, starting at the end of the slice, and a remainder slice with length strictly less than N. ### Parameters #### Path Parameters - **N** (usize) - Required - The size of the chunks. ### Panics - Panics if N is zero. ``` -------------------------------- ### get Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Returns a reference to an element or subslice based on the provided index or range. ```APIDOC ## pub fn get(&self, index: I) -> Option<&>::Output> ### Description Returns a reference to an element or subslice depending on the type of index. If given a position, returns a reference to the element at that position or None if out of bounds. If given a range, returns the subslice corresponding to that range, or None if out of bounds. ### Parameters #### Path Parameters - **index** (I) - Required - The index or range to access. ### Response - **Option<&Output>** - The element or subslice at the specified index. ``` -------------------------------- ### Configure Stream Limits and Windows Source: https://docs.rs/quinn/latest/src/quinn/connection.rs.html Methods to adjust concurrent stream limits and transport window sizes. ```rust pub fn set_max_concurrent_uni_streams(&self, count: VarInt) { let mut conn = self.0.state.lock("set_max_concurrent_uni_streams"); conn.inner.set_max_concurrent_streams(Dir::Uni, count); // May need to send MAX_STREAMS to make progress conn.wake(); } ``` ```rust pub fn set_send_window(&self, send_window: u64) { let mut conn = self.0.state.lock("set_send_window"); conn.inner.set_send_window(send_window); conn.wake(); } ``` ```rust pub fn set_receive_window(&self, receive_window: VarInt) { let mut conn = self.0.state.lock("set_receive_window"); conn.inner.set_receive_window(receive_window); conn.wake(); } ``` ```rust pub fn set_max_concurrent_bi_streams(&self, count: VarInt) { let mut conn = self.0.state.lock("set_max_concurrent_bi_streams"); conn.inner.set_max_concurrent_streams(Dir::Bi, count); // May need to send MAX_STREAMS to make progress conn.wake(); } ``` -------------------------------- ### Get Local Address Source: https://docs.rs/quinn/latest/src/quinn/endpoint.rs.html Retrieves the local SocketAddr bound to the underlying socket. ```rust pub fn local_addr(&self) -> io::Result { self.inner.state.lock().unwrap().socket.local_addr() } ``` -------------------------------- ### AckFrequencyConfig Configuration Methods Source: https://docs.rs/quinn/latest/quinn/struct.AckFrequencyConfig.html Methods to configure acknowledgement thresholds and delays for the QUIC connection. ```APIDOC ## AckFrequencyConfig Configuration ### Description Configures parameters for controlling the peer's acknowledgement frequency, sent at the beginning of a connection. ### Methods #### ack_eliciting_threshold(value: VarInt) -> &mut AckFrequencyConfig - **value** (VarInt) - Required - The number of ack-eliciting packets an endpoint may receive without immediately sending an ACK. Defaults to 1. #### max_ack_delay(value: Option) -> &mut AckFrequencyConfig - **value** (Option) - Required - The maximum time an endpoint waits before sending an ACK when the threshold is not reached. Defaults to None. #### reordering_threshold(value: VarInt) -> &mut AckFrequencyConfig - **value** (VarInt) - Required - The number of out-of-order packets that trigger an immediate ACK. Defaults to 2. ``` -------------------------------- ### Get Send Stream ID Source: https://docs.rs/quinn/latest/src/quinn/send_stream.rs.html Returns the unique identifier for this send stream. ```rust pub fn id(&self) -> StreamId { self.stream } ``` -------------------------------- ### Get Slice Length Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Returns the number of elements in the slice. This is a standard slice operation. ```rust pub fn len(&self) -> usize ``` ```rust let a = [1, 2, 3]; assert_eq!(a.len(), 3); ``` -------------------------------- ### Get Stable Connection ID Source: https://docs.rs/quinn/latest/src/quinn/connection.rs.html Returns a stable identifier for the connection that persists for its lifetime. ```rust pub fn stable_id(&self) -> usize { self.0.stable_id() } ``` -------------------------------- ### Struct QuicServerConfig Source: https://docs.rs/quinn/latest/quinn/crypto/rustls/struct.QuicServerConfig.html Represents a QUIC-compatible TLS server configuration. Quinn often uses reasonable defaults, but custom configurations require attention to early data and TLS version support. ```rust pub struct QuicServerConfig { /* private fields */ } ``` -------------------------------- ### Implement State Methods Source: https://docs.rs/quinn/latest/src/quinn/endpoint.rs.html Internal methods for driving packet reception. ```rust impl State { fn drive_recv(&mut self, cx: &mut Context, now: Instant) -> Result { let get_time = || self.runtime.now(); ``` -------------------------------- ### Get Remote Address Source: https://docs.rs/quinn/latest/src/quinn/incoming.rs.html Retrieves the UDP socket address of the peer initiating the connection. ```rust pub fn remote_address(&self) -> SocketAddr { self.0.as_ref().unwrap().inner.remote_address() } ``` -------------------------------- ### MtuDiscoveryConfig Configuration Methods Source: https://docs.rs/quinn/latest/quinn/struct.MtuDiscoveryConfig.html Methods to configure the MTU discovery behavior, including intervals, upper bounds, and black hole detection settings. ```APIDOC ## MtuDiscoveryConfig Configuration ### Description Methods to configure the parameters governing MTU discovery in Quinn. ### Methods - **interval(value: Duration)**: Specifies the time to wait after completing MTU discovery before starting a new run. Defaults to 600 seconds. - **upper_bound(value: u16)**: Specifies the upper bound to the max UDP payload size that MTU discovery will search for. Defaults to 1452. - **black_hole_cooldown(value: Duration)**: Specifies the amount of time to wait after a black hole is detected before running MTU discovery again. Defaults to one minute. - **minimum_change(value: u16)**: Specifies the minimum MTU change to stop the MTU discovery phase. Defaults to 20. ``` -------------------------------- ### Validate slice prefixes Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Checks if a slice starts with a specific sequence. Empty slices always return true. ```rust let v = [10, 40, 30]; assert!(v.starts_with(&[10])); assert!(v.starts_with(&[10, 40])); assert!(v.starts_with(&v)); assert!(!v.starts_with(&[50])); assert!(!v.starts_with(&[10, 50])); ``` ```rust let v = &[10, 40, 30]; assert!(v.starts_with(&[])); let v: &[u8] = &[]; assert!(v.starts_with(&[])); ``` -------------------------------- ### Split slice from the end into at most n parts using rsplitn Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Splits a slice into at most n subslices starting from the end. ```rust let v = [10, 40, 30, 20, 60, 50]; for group in v.rsplitn(2, |num| *num % 3 == 0) { println!("{group:?}"); } ``` -------------------------------- ### NewReno Controller - metrics Source: https://docs.rs/quinn/latest/quinn/congestion/struct.NewReno.html Retrieves implementation-specific metrics for qlog tracing. ```rust fn metrics(&self) -> ControllerMetrics ``` -------------------------------- ### Endpoint Implementation Methods Source: https://docs.rs/quinn/latest/src/quinn/endpoint.rs.html Methods for creating client and server endpoints, and retrieving endpoint statistics. ```rust #[cfg(all(not(wasm_browser), any(feature = "aws-lc-rs", feature = "ring")))] // `EndpointConfig::default()` is only available with these pub fn client(addr: SocketAddr) -> io::Result { let socket = Socket::new(Domain::for_address(addr), Type::DGRAM, Some(Protocol::UDP))?; if addr.is_ipv6() { if let Err(e) = socket.set_only_v6(false) { tracing::debug!(%e, "unable to make socket dual-stack"); } } socket.bind(&addr.into())?; let runtime = default_runtime().ok_or_else(|| io::Error::other("no async runtime found"))?; Self::new_with_abstract_socket( EndpointConfig::default(), None, runtime.wrap_udp_socket(socket.into())?, runtime, ) } /// Returns relevant stats from this Endpoint pub fn stats(&self) -> EndpointStats { self.inner.state.lock().unwrap().stats } /// Helper to construct an endpoint for use with both incoming and outgoing connections /// /// Platform defaults for dual-stack sockets vary. For example, any socket bound to a wildcard /// IPv6 address on Windows will not by default be able to communicate with IPv4 /// addresses. Portable applications should bind an address that matches the family they wish to /// communicate within. #[cfg(all(not(wasm_browser), any(feature = "aws-lc-rs", feature = "ring")))] // `EndpointConfig::default()` is only available with these pub fn server(config: ServerConfig, addr: SocketAddr) -> io::Result { let socket = std::net::UdpSocket::bind(addr)?; let runtime = default_runtime().ok_or_else(|| io::Error::other("no async runtime found"))?; Self::new_with_abstract_socket( EndpointConfig::default(), Some(config), runtime.wrap_udp_socket(socket)?, runtime, ) } ``` -------------------------------- ### Mutate slice chunks in reverse Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Uses rchunks_mut to modify elements in chunks of a specified size, starting from the end. ```rust let v = &mut [0, 0, 0, 0, 0]; let mut count = 1; for chunk in v.rchunks_mut(2) { for elem in chunk.iter_mut() { *elem += count; } count += 1; } assert_eq!(v, &[3, 2, 2, 1, 1]); ``` -------------------------------- ### Initialize QuicClientConfig with Initial Cipher Suite Source: https://docs.rs/quinn/latest/quinn/crypto/rustls/struct.QuicClientConfig.html Initializes a QuicClientConfig with a separate initial cipher suite, useful for avoiding the initial cipher suite for traffic encryption. Requires an Arc and a Suite. ```rust pub fn with_initial( inner: Arc, initial: Suite, ) -> Result ``` -------------------------------- ### Iterate over slice chunks in reverse Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Uses rchunks to iterate over a slice in chunks of a specified size, starting from the end. ```rust let slice = ['l', 'o', 'r', 'e', 'm']; let mut iter = slice.rchunks(2); assert_eq!(iter.next().unwrap(), &['e', 'm']); assert_eq!(iter.next().unwrap(), &['o', 'r']); assert_eq!(iter.next().unwrap(), &['l']); assert!(iter.next().is_none()); ``` -------------------------------- ### Accept Incoming Connection Source: https://docs.rs/quinn/latest/src/quinn/incoming.rs.html Accepts an incoming connection with default settings. This is the primary method for establishing a new connection. ```rust pub fn accept(mut self) -> Result { let state = self.0.take().unwrap(); state.endpoint.accept(state.inner, None) } ``` -------------------------------- ### Get a raw pointer to the slice buffer Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Returns a constant raw pointer to the slice's underlying memory. ```rust let x = &[1, 2, 4]; let x_ptr = x.as_ptr(); unsafe { for i in 0..x.len() { assert_eq!(x.get_unchecked(i), &*x_ptr.add(i)); } } ``` -------------------------------- ### Get Send Stream Priority Source: https://docs.rs/quinn/latest/src/quinn/send_stream.rs.html Retrieves the priority of the send stream. Requires holding a lock on the connection state. ```rust pub fn priority(&self) -> Result { let mut conn = self.conn.state.lock("SendStream::priority"); conn.inner.send_stream(self.stream).priority() } ``` -------------------------------- ### Endpoint Construction Methods Source: https://docs.rs/quinn/latest/quinn/struct.Endpoint.html Methods for initializing a QUIC endpoint for client or server operations. ```APIDOC ## Endpoint::client ### Description Helper to construct an endpoint for use with outgoing connections only. ### Parameters #### Request Body - **addr** (SocketAddr) - Required - The local address to bind to. ## Endpoint::server ### Description Helper to construct an endpoint for use with both incoming and outgoing connections. ### Parameters #### Request Body - **config** (ServerConfig) - Required - Configuration for the server. - **addr** (SocketAddr) - Required - The local address to bind to. ``` -------------------------------- ### Create a Server Endpoint Source: https://docs.rs/quinn/latest/quinn/struct.Endpoint.html Helper to construct an endpoint for both incoming and outgoing connections. Platform defaults for dual-stack sockets vary; bind to an address matching the desired communication family. ```rust pub fn server(config: ServerConfig, addr: SocketAddr) -> Result ``` -------------------------------- ### Get Original Destination CID Source: https://docs.rs/quinn/latest/src/quinn/incoming.rs.html Retrieves the original destination Connection ID (CID) used when initiating the connection. ```rust pub fn orig_dst_cid(&self) -> ConnectionId { *self.0.as_ref().unwrap().inner.orig_dst_cid() } ``` -------------------------------- ### Get a mutable raw pointer to the slice buffer Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Returns a mutable raw pointer to the slice's underlying memory. ```rust let x = &mut [1, 2, 4]; let x_ptr = x.as_mut_ptr(); unsafe { for i in 0..x.len() { *x_ptr.add(i) += 2; } } assert_eq!(x, &[3, 4, 6]); ``` -------------------------------- ### Incoming Connection Management Source: https://docs.rs/quinn/latest/quinn/struct.Incoming.html Methods for handling incoming connection attempts in the Quinn library. ```APIDOC ## accept ### Description Attempt to accept this incoming connection. ### Method Rust Method ### Response - **Result** - Returns a Connecting future or a ConnectionError. ## accept_with ### Description Accept this incoming connection using a custom server configuration. ### Parameters - **server_config** (Arc) - Required - The custom configuration to apply. ### Response - **Result** - Returns a Connecting future or a ConnectionError. ## refuse ### Description Reject this incoming connection attempt. ## retry ### Description Respond with a retry packet, requiring the client to retry with address validation. ### Response - **Result<(), RetryError>** - Returns success or a RetryError if retrying is not permitted. ## ignore ### Description Ignore this incoming connection attempt without sending any response packet. ## local_ip ### Description Returns the local IP address used when the peer established the connection. ### Response - **Option** - The local IP address if available. ## remote_address ### Description Returns the peer's UDP address. ### Response - **SocketAddr** - The remote socket address. ## remote_address_validated ### Description Checks if the initiating socket address has been validated. ### Response - **bool** - True if validated, false otherwise. ## may_retry ### Description Checks if it is legal to respond with a retry packet. ### Response - **bool** - True if a retry is permitted. ## orig_dst_cid ### Description Returns the original destination Connection ID. ### Response - **ConnectionId** - The original destination CID. ``` -------------------------------- ### TryFrom ClientConfig for QuicClientConfig Source: https://docs.rs/quinn/latest/quinn/crypto/rustls/struct.QuicClientConfig.html Attempts to convert a ClientConfig into a QuicClientConfig. Similar to the Arc conversion, this may fail if TLS 1.3 is not enabled in the inner configuration. ```rust type Error = NoInitialCipherSuite fn try_from( inner: ClientConfig, ) -> Result>::Error> ``` -------------------------------- ### Get Remote Peer Address Source: https://docs.rs/quinn/latest/src/quinn/connection.rs.html Retrieves the UDP address of the connected peer. Panics if called after `poll` has returned `Ready`. ```rust pub fn remote_address(&self) -> SocketAddr { let conn_ref: &ConnectionRef = self.conn.as_ref().expect("used after yielding Ready"); conn_ref.state.lock("remote_address").inner.remote_address() } ``` -------------------------------- ### TryFrom ServerConfig for QuicServerConfig Source: https://docs.rs/quinn/latest/quinn/crypto/rustls/struct.QuicServerConfig.html Attempts to convert a ServerConfig into a QuicServerConfig. Similar to the Arc version, this conversion requires the ServerConfig to have TLS 1.3 support enabled. ```rust type Error = NoInitialCipherSuite ``` ```rust fn try_from( inner: ServerConfig, ) -> Result>::Error> ``` -------------------------------- ### Get Connection Close Reason Source: https://docs.rs/quinn/latest/quinn/struct.Connection.html Returns the reason why the connection was closed, if it is closed. Returns None if the connection is still open. ```rust pub fn close_reason(&self) -> Option ``` -------------------------------- ### pub fn rchunks_mut Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Returns an iterator over chunk_size elements of the slice at a time, starting at the end of the slice, providing mutable access. ```APIDOC ## rchunks_mut ### Description Returns an iterator over `chunk_size` elements of the slice at a time, starting at the end of the slice. The chunks are mutable slices and do not overlap. ### Parameters - **chunk_size** (usize) - Required - The size of each chunk. Panics if zero. ``` -------------------------------- ### TokenStore take Method Source: https://docs.rs/quinn/latest/quinn/trait.TokenStore.html Try to find and take a token that was stored with the given server name. The same token must never be returned from `take` twice. Called when trying to connect to a server. ```rust fn take(&self, server_name: &str) -> Option; ``` -------------------------------- ### NewRenoConfig Configuration Methods Source: https://docs.rs/quinn/latest/quinn/congestion/struct.NewRenoConfig.html Methods available for configuring the NewReno congestion controller settings. ```APIDOC ## NewRenoConfig Configuration ### Description Methods to configure the NewReno congestion controller instance. ### Methods - **initial_window(&mut self, value: u64) -> &mut NewRenoConfig** - Sets the default limit on the amount of outstanding data in bytes. - **loss_reduction_factor(&mut self, value: f32) -> &mut NewRenoConfig** - Sets the reduction in congestion window when a new loss event is detected. ``` -------------------------------- ### Iterate and Mutate Slice Elements Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Returns an iterator that yields mutable references to each element, allowing modification. Iterates from start to end. ```rust let x = &mut [1, 2, 4]; for elem in x.iter_mut() { *elem += 2; } assert_eq!(x, &[3, 4, 6]); ``` -------------------------------- ### TryFrom Arc for QuicServerConfig Source: https://docs.rs/quinn/latest/quinn/crypto/rustls/struct.QuicServerConfig.html Attempts to convert an Arc into a QuicServerConfig. This conversion may fail if the inner ServerConfig does not meet QUIC requirements, such as TLS 1.3 support. ```rust type Error = NoInitialCipherSuite ``` ```rust fn try_from( inner: Arc, ) -> Result>>::Error> ``` -------------------------------- ### Iterate Over Slice Elements Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Returns an iterator that yields immutable references to each element in the slice from start to end. Useful for reading elements. ```rust let x = &[1, 2, 4]; let mut iterator = x.iter(); assert_eq!(iterator.next(), Some(&1)); assert_eq!(iterator.next(), Some(&2)); assert_eq!(iterator.next(), Some(&4)); assert_eq!(iterator.next(), None); ``` -------------------------------- ### CloneToUninit Trait Implementation Source: https://docs.rs/quinn/latest/quinn/struct.ValidationTokenConfig.html Nightly-only experimental implementation of `CloneToUninit`. ```APIDOC ## impl CloneToUninit for T where T: Clone, ### Description 🔬This is a nightly-only experimental API. (`clone_to_uninit`) Performs copy-assignment from `self` to `dest`. ### Methods #### unsafe fn clone_to_uninit(&self, dest: *mut u8) Performs copy-assignment from `self` to `dest`. ``` -------------------------------- ### Pointer Range Access Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Provides methods to get raw pointer ranges for interacting with foreign interfaces or checking element containment. ```APIDOC ## GET /slice/as_ptr_range ### Description Returns the two raw pointers spanning the slice. The returned range is half-open, meaning the end pointer points one past the last element. This is useful for interacting with foreign interfaces that use two pointers to refer to a range of elements. ### Method GET ### Endpoint /slice/as_ptr_range ### Parameters None ### Response #### Success Response (200) - **Range<*const T>** (object) - A range object containing two raw pointers. - **start** (*const T) - The starting raw pointer. - **end** (*const T) - The ending raw pointer (one past the last element). ### Response Example ```json { "start": "0x1234567890ab", "end": "0x1234567890ad" } ``` ## GET /slice/as_mut_ptr_range ### Description Returns the two unsafe mutable pointers spanning the slice. Similar to `as_ptr_range`, but provides mutable pointers. ### Method GET ### Endpoint /slice/as_mut_ptr_range ### Parameters None ### Response #### Success Response (200) - **Range<*mut T>** (object) - A range object containing two mutable raw pointers. - **start** (*mut T) - The starting mutable raw pointer. - **end** (*mut T) - The ending mutable raw pointer (one past the last element). ### Response Example ```json { "start": "0x1234567890ab", "end": "0x1234567890ad" } ``` ``` -------------------------------- ### ClientConfig Configuration Methods Source: https://docs.rs/quinn/latest/quinn/struct.ClientConfig.html Methods to customize the ClientConfig for specific connection behaviors. ```APIDOC ## ClientConfig Configuration ### `initial_dst_cid_provider(&mut self, initial_dst_cid_provider: Arc ConnectionId + Sync + Send>) -> &mut ClientConfig` Configure how to populate the destination CID of the initial packet when attempting to establish a new connection. By default, it’s populated with random bytes with reasonable length, so unless you have a good reason, you do not need to change it. When prefer to override the default, please note that the generated connection ID MUST be at least 8 bytes long and unpredictable, as per section 7.2 of RFC 9000. ### `transport_config(&mut self, transport: Arc) -> &mut ClientConfig` Set a custom `TransportConfig`. ### `token_store(&mut self, store: Arc) -> &mut ClientConfig` Set a custom `TokenStore`. Defaults to `TokenMemoryCache`, which is suitable for most internet applications. ### `version(&mut self, version: u32) -> &mut ClientConfig` Set the QUIC version to use. ``` -------------------------------- ### Get Connection Close Reason Source: https://docs.rs/quinn/latest/src/quinn/connection.rs.html Retrieves the reason why the QUIC connection was closed, if it has been closed. Returns `None` if the connection is still open. ```rust pub fn close_reason(&self) -> Option { self.0.state.lock("close_reason").error.clone() } ``` -------------------------------- ### Set Initial Window for BbrConfig Source: https://docs.rs/quinn/latest/quinn/congestion/struct.BbrConfig.html Sets the default limit for outstanding data in bytes for the BbrConfig. A recommended value is provided. ```rust pub fn initial_window(&mut self, value: u64) -> &mut BbrConfig ``` -------------------------------- ### Get AEAD Tag Length Source: https://docs.rs/quinn/latest/quinn/crypto/trait.PacketKey.html Returns the length of the AEAD tag that is appended to packets during encryption. This is crucial for buffer management during decryption. ```rust fn tag_len(&self) -> usize; ``` -------------------------------- ### Mutable reverse chunking with as_rchunks_mut Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Splits a slice into N-element arrays starting from the end, returning a remainder slice. Panics if N is zero. ```rust let v = &mut [0, 0, 0, 0, 0]; let mut count = 1; let (remainder, chunks) = v.as_rchunks_mut(); remainder[0] = 9; for chunk in chunks { *chunk = [count; 2]; count += 1; } assert_eq!(v, &[9, 1, 1, 2, 2]); ``` -------------------------------- ### Set Default Client Configuration Source: https://docs.rs/quinn/latest/quinn/struct.Endpoint.html Set the client configuration used by the `connect` method. This configuration will be applied to all subsequent connection attempts unless overridden. ```rust pub fn set_default_client_config(&mut self, config: ClientConfig) ``` -------------------------------- ### Split Slice into Last Element and Remainder Source: https://docs.rs/quinn/latest/quinn/struct.ConnectionId.html Use `split_last` to get the last element and the rest of the slice. Returns `None` if the slice is empty. ```rust let x = &[0, 1, 2]; if let Some((last, elements)) = x.split_last() { assert_eq!(last, &2); assert_eq!(elements, &[0, 1]); } ```