Struct QuicListeners

Source
pub struct QuicListeners { /* private fields */ }
Expand description

A QUIC listener that can serve multiple virtual servers, accepting incoming connections.

§Creating Listeners

Use QuicListenersBuilder to configure the listener, then call QuicListenersBuilder::listen to start accepting connections.

Note: Only one QuicListeners instance can run at a time globally. To stop the listeners, call QuicListeners::shutdown or drop all references to the Arc<QuicListeners>.

§Managing Servers

Add multiple virtual servers by calling QuicListeners::add_server multiple times. Each server is identified by its server name (SNI) and handles connections independently.

  • Servers can share the same network interfaces
  • Servers can be added without initially binding to any interface

§Connection Handling

Call QuicListeners::accept to receive incoming connections. The listener automatically:

  • Routes connections to the appropriate server based on SNI (Server Name Indication)
  • Rejects connections if the target server isn’t listening on the receiving interface
  • Returns connections that may still be completing their QUIC handshake

Implementations§

Source§

impl QuicListeners

Source

pub fn builder() -> Result<QuicListenersBuilder<ConfigBuilder<ServerConfig, WantsVerifier>>, BuildServerError>

Start to build a QuicListeners.

Source

pub fn builder_with_crypto_provieder( provider: Arc<CryptoProvider>, ) -> Result<QuicListenersBuilder<ConfigBuilder<ServerConfig, WantsVerifier>>, BuildServerError>

Start to build a QuicServer with the given tls crypto provider.

Source

pub fn builder_with_tls<T>( tls_config: T, ) -> Result<QuicListenersBuilder<T>, BuildServerError>

Start to build a QuicListeners with the given TLS configuration.

This is useful when you want to customize the TLS configuration, or integrate qm-quic with other crates.

Source

pub fn add_server( &self, server_name: impl Into<String>, cert_chain: impl ToCertificate, private_key: impl ToPrivateKey, bind_uris: impl IntoIterator<Item = impl Into<BindUri>>, ocsp: impl Into<Option<Vec<u8>>>, ) -> Result<(), ServerError>

Add a virtual server with its certificate chain and private key.

Creates a new virtual host identified by its server name (SNI). The server will use the certificate chain and private key that matches the SNI in the client’s ClientHello message. If no matching server is found, the connection will be rejected.

A server can be added without binding to any interface initially, but will not accept connections until interfaces are added via bind_interfaces. This allows flexible server configuration and hot-swapping of network bindings.

Source

pub fn remove_server(&self, server_name: &str) -> bool

Remove a virtual server and all its associated interfaces.

Completely removes a server from the listeners, including all network interfaces it was bound to (if the interface is not used by other servers). This is the inverse operation of add_server and provides a clean way to decommission a virtual host.

Returns true if the server existed and was removed, false if no server with the specified name was found. You must remove an existing server before adding a new one with the same name.

Source

pub fn bind_interfaces( &self, server_name: impl Into<String>, bind_uris: impl IntoIterator<Item = impl Into<BindUri>>, ) -> Result<(), ServerError>

Add additional network interfaces to an existing virtual server.

Extends an existing server to listen on additional network interfaces, enabling horizontal scaling and multi-homed server configurations. Interfaces that are already bound to the server will be silently ignored, allowing for idempotent operations.

The server must have been created with add_server first. Added interfaces can later be removed selectively with unbind_interface, supporting hot-swapping and zero-downtime updates.

Source

pub fn get_server<'l>( &'l self, server_name: &str, ) -> Option<impl Deref<Target = Server> + 'l>

Get the server by its name.

Source

pub fn unbind_interface<'s>( &self, server_names: Option<impl IntoIterator<Item = &'s str>>, bind_uri: BindUri, )

Remove a specific network interface from one or more servers.

Provides fine-grained control over interface management, allowing selective removal of interfaces without affecting the server’s core configuration or other interfaces. This is the counterpart to bind_interfaces for flexible network topology management.

The server_names parameter controls the scope:

  • Some(server_names) - Remove the interface only from specified servers
  • None - Remove the interface from ALL servers currently using it

Operations are graceful: non-existent servers or unbound interfaces are silently ignored, enabling safe cleanup and idempotent scripts.

Source

pub async fn accept(&self) -> Result<(Arc<Connection>, String, Pathway, Link)>

Accept an incoming QUIC connection from the queue.

Returns the connection, connected server name, and network path information. Connections are automatically routed based on SNI (Server Name Indication).

The connection queue size is limited by the backlog parameter in QuicListenersBuilder::listen. When the queue is full, new incoming packets may be dropped at the network level.

Source

pub fn shutdown(&self)

Close the QuicListeners, stops accepting new connections.

Unaccepted connections will be closed

Trait Implementations§

Source§

impl Drop for QuicListeners

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more