quic_settings.rs

Overview

This file defines the ConfigFactory enum and its associated methods to create and configure QUIC connection settings and credentials for client and server configurations. It acts as a factory for producing Configuration objects used by the msquic library, encapsulating the creation of QUIC settings and TLS credential configurations.

The main responsibilities of this file include:

This file interacts primarily with the msquic crate for QUIC protocol abstractions and the crate::tls module for TLS certificate construction. It facilitates the initialization of secure QUIC connections by preparing the necessary configurations.


Entities

Enum: ConfigFactory

An enum with two variants representing the type of configuration to be created:

This enum drives the conditional logic for building appropriate settings and credentials.


Methods

build(&self, registration: &Registration, alpn: &[&str], credential: &NetCredential) -> anyhow::Result<Configuration>

Creates and returns a fully configured Configuration object based on the factory variant (client or server).

Parameters

Returns

Usage Example

let factory = ConfigFactory::Server;
let config = factory.build(&registration, &["h3"], &net_credential)?;

build_settings(&self) -> Settings

Constructs and returns a Settings instance with QUIC transport parameters pre-configured.

Behavior

This default settings profile is generic but optimized for server-like scenarios. The method is pub(crate) as it is intended for internal use.


build_credential(&self, credential: &NetCredential) -> anyhow::Result<CredentialConfig>

Creates a CredentialConfig object for TLS, including certificate and flags, customized based on whether the factory is a client or server.

Parameters

Returns

Implementation Details


Implementation Details and Interactions


Diagram

classDiagram
class ConfigFactory {
<<enum>>
+Client
+Server
+build()
+build_settings()
+build_credential()
}
class Registration
class Configuration
class Settings
class CredentialConfig
ConfigFactory --> Registration : uses
ConfigFactory --> Configuration : creates
ConfigFactory --> Settings : creates
ConfigFactory --> CredentialConfig : creates

This diagram illustrates that ConfigFactory is an enum providing three main methods. It depends on Registration to open configurations, produces Configuration objects, and internally creates Settings and CredentialConfig for configuration setup.