pub struct QuicClient { /* private fields */ }
Expand description
A quic client that can initiates connections to servers.
Implementations§
Source§impl QuicClient
impl QuicClient
Sourcepub fn builder() -> QuicClientBuilder<ConfigBuilder<ClientConfig, WantsVerifier>>
pub fn builder() -> QuicClientBuilder<ConfigBuilder<ClientConfig, WantsVerifier>>
Start to build a QuicClient.
Make sure that you have installed the rustls crypto provider before calling this method. If you dont want to use
the default crypto provider, you can use QuicClient::builder_with_crypto_provieder
to specify the crypto provider.
You can also use QuicClient::builder_with_tls
to specify the TLS configuration.
§Examples
use gm_quic::QuicClient;
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr};
rustls::crypto::ring::default_provider()
.install_default()
.expect("Failed to install rustls crypto provider");
let client_builder = QuicClient::builder()
.reuse_connection()
.prefer_versions([0x00000001u32]);
Sourcepub fn builder_with_crypto_provieder(
provider: Arc<CryptoProvider>,
) -> QuicClientBuilder<ConfigBuilder<ClientConfig, WantsVerifier>>
pub fn builder_with_crypto_provieder( provider: Arc<CryptoProvider>, ) -> QuicClientBuilder<ConfigBuilder<ClientConfig, WantsVerifier>>
Start to build a QuicClient with the given tls crypto provider.
Sourcepub fn builder_with_tls(
tls_config: TlsClientConfig,
) -> QuicClientBuilder<TlsClientConfig>
pub fn builder_with_tls( tls_config: TlsClientConfig, ) -> QuicClientBuilder<TlsClientConfig>
Start to build a QuicClient with the given TLS configuration.
This is useful when you want to customize the TLS configuration, or integrate qm-quic with other crates.
Sourcepub fn connect(
&self,
server_name: impl Into<String>,
server_ep: impl ToEndpointAddr,
) -> Result<Arc<Connection>>
pub fn connect( &self, server_name: impl Into<String>, server_ep: impl ToEndpointAddr, ) -> Result<Arc<Connection>>
Returns the connection to the specified server.
server_name
is the name of the server, it will be included in the ClientHello
message.
server_addr
is the address of the server, packets will be sent to this address.
Note that the returned connection may not yet be connected to the server, but you can use it to do anything you want, such as sending data, receiving data… operations will be pending until the connection is connected or failed to connect.
§Select an interface
First, the client will select an interface to communicate with the server.
If the client has already bound a set of addresses, The client will select the interface whose IP family of the first address matches the server addr from the bound and not closed interfaces.
If reuse_address
is not enabled; the client will not select an interface that is in use.
§Connecte to server
If connection reuse is enabled, the client will give priority to returning the existing connection to the
server_name
and server_addr
.
If the client does not bind any interface, the client will bind the interface on the address/port randomly assigned
by the system (i.e. xxx) through quic_iface_factory
every time it establishes a connection. When no interface is
bound, the reuse interface option will have no effect.
If reuse connection
is not enabled or there is no connection that can be reused, the client will initiates
a new connection to the server.