Skip to main content

tokio_quiche/quic/
hooks.rs

1// Copyright (C) 2025, Cloudflare, Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8//     * Redistributions of source code must retain the above copyright notice,
9//       this list of conditions and the following disclaimer.
10//
11//     * Redistributions in binary form must reproduce the above copyright
12//       notice, this list of conditions and the following disclaimer in the
13//       documentation and/or other materials provided with the distribution.
14//
15// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
19// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27use boring::ssl::SslContextBuilder;
28
29use crate::quic::QuicheConnection;
30use crate::settings::TlsCertificatePaths;
31
32/// A set of hooks executed at the level of a [quiche::Connection].
33pub trait ConnectionHook {
34    /// Constructs an optional [`SslContextBuilder`].
35    ///
36    /// This method allows full customization of quiche's SSL context, for
37    /// example to specify async callbacks during the QUIC handshake. It is
38    /// called once per socket during initial setup, and then reused across
39    /// all connections on that socket.
40    ///
41    /// Only called if both the hook and [`TlsCertificatePaths`] are set in
42    /// [`ConnectionParams`](crate::ConnectionParams).
43    fn create_custom_ssl_context_builder(
44        &self, settings: TlsCertificatePaths<'_>,
45    ) -> Option<SslContextBuilder>;
46
47    /// Called when the QUIC connection reports a path-specific event.
48    ///
49    /// This runs synchronously on the connection's I/O worker and must not
50    /// block. Applications that need asynchronous processing should copy the
51    /// event into a non-blocking channel.
52    fn on_path_event(
53        &self, _qconn: &mut QuicheConnection, _event: &quiche::PathEvent,
54    ) {
55    }
56}