moqtap_proxy/listener.rs
1//! Unified listener — one UDP endpoint that accepts both raw-QUIC MoQT
2//! and WebTransport clients, dispatching per connection based on the
3//! ALPN the client negotiated during the TLS handshake.
4
5use std::net::SocketAddr;
6use std::sync::Arc;
7
8use moqtap_codec::version::DraftVersion;
9use rustls::pki_types::{CertificateDer, PrivateKeyDer};
10
11use crate::error::ProxyError;
12use crate::transport::{self, TransportInstaller, TransportProfile};
13use crate::types::Leg;
14
15/// WebTransport ALPN identifier.
16const H3_ALPN: &[u8] = b"h3";
17
18/// Configuration for the proxy's listener.
19pub struct ListenerConfig {
20 /// Address to bind to (e.g., `"0.0.0.0:4443"`).
21 pub bind_addr: SocketAddr,
22 /// TLS certificate chain (DER-encoded).
23 pub cert_chain: Vec<CertificateDer<'static>>,
24 /// TLS private key (DER-encoded).
25 pub key_der: PrivateKeyDer<'static>,
26 /// Optional QUIC transport parameters — flow-control windows, MTU,
27 /// keep-alive, congestion control — applied to every client
28 /// connection this listener accepts.
29 ///
30 /// `None` installs no parameters of its own: the leg then takes
31 /// [`ListenerConfig::transport_profile`] if it names one, and quinn's
32 /// defaults otherwise.
33 ///
34 /// Setting this **and** [`ListenerConfig::transport_profile`] is
35 /// refused by [`Listener::bind`] rather than merged, with
36 /// [`ProxyError::TransportConfigAndProfile`] naming
37 /// [`Leg::Client`] — see that variant for why no merge is possible.
38 pub transport_config: Option<Arc<quinn::TransportConfig>>,
39 /// The same parameters as [`ListenerConfig::transport_config`], as a
40 /// value that can be written down, checked and stored.
41 ///
42 /// `Some(_)` builds the client leg's `quinn::TransportConfig` from this
43 /// profile — through [`ListenerConfig::installer`], or through
44 /// [`transport::DefaultInstaller`] when there is none — and installs it
45 /// before the endpoint exists. A profile the installer refuses is
46 /// [`ProxyError::TransportProfile`], and nothing is bound.
47 ///
48 /// `None` installs no profile: the leg then takes
49 /// [`ListenerConfig::transport_config`] if it names one, and quinn's
50 /// defaults otherwise. It is the *only* alternative to
51 /// `transport_config`, never a companion to it: a leg naming both is
52 /// refused at bind time.
53 pub transport_profile: Option<TransportProfile>,
54 /// How [`ListenerConfig::transport_profile`] becomes the config this
55 /// leg installs.
56 ///
57 /// `None` uses [`transport::DefaultInstaller`], which applies the
58 /// profile over a fresh `quinn::TransportConfig::default()`. Supply one
59 /// to start from a base of your own instead — the trait exists because
60 /// a `quinn::TransportConfig` cannot be cloned, so the only way to have
61 /// a base *and* a profile is to build the base again for each leg.
62 ///
63 /// **Inert without a profile.** [`TransportInstaller::build`] takes a
64 /// profile, so an installer set beside an empty
65 /// [`ListenerConfig::transport_profile`] is never called and the leg
66 /// installs nothing. It is said here because a setting that is quietly
67 /// ignored is the failure this crate is least willing to hide.
68 ///
69 /// **It composes with a `qlog` spec** — named in plain code font
70 /// because that field exists only under the `qlog` feature, so a link
71 /// from this always-compiled one would not resolve. A leg carrying a
72 /// profile, a spec and an installer builds its config here, once, and
73 /// the capture sink is attached to what came back;
74 /// [`TransportInstaller::build`] returns an owned
75 /// `quinn::TransportConfig` precisely so that the two can stack.
76 pub installer: Option<Arc<dyn TransportInstaller>>,
77 /// Where this leg's QUIC-level capture is written, if it is captured at
78 /// all.
79 ///
80 /// `Some(_)` builds the client leg's `quinn::TransportConfig`, installs
81 /// the sink built from this spec on it, and hands that to the endpoint
82 /// — all before the endpoint exists, because quinn accepts a sink in
83 /// exactly one place and that place is a method which mutates a
84 /// `quinn::TransportConfig`. It composes with
85 /// [`ListenerConfig::transport_profile`], which is applied to the same
86 /// config first, and **not** with
87 /// [`ListenerConfig::transport_config`]: a leg naming a raw config and
88 /// a spec is refused at bind time with
89 /// [`ProxyError::TransportConfigAndQlog`] naming [`Leg::Client`], for
90 /// the reason written out on that variant.
91 ///
92 /// A spec on its own, with neither of the other two fields set, is
93 /// enough: the leg builds a `quinn::TransportConfig::default()` for the
94 /// sink to go on and installs it, rather than installing nothing and
95 /// leaving the capture attached to a config no connection uses.
96 ///
97 /// `None` is how a leg says it does not want a capture. A spec that
98 /// names no writer is not that: it is refused with
99 /// [`ProxyError::Qlog`], because a spec is how a caller *asks* for a
100 /// capture.
101 ///
102 /// # Single-use, and therefore refused on a proxy template
103 ///
104 /// A [`QlogSpec`] owns its writer and is consumed when it becomes a
105 /// sink, so it has no `Clone`. [`TransparentProxy`] copies its
106 /// [`ListenerConfig`] template to build the listener it binds, and a
107 /// copy has nothing it could hand over — so a spec set on a
108 /// `ProxyConfig` could only be taken, counted as configured and
109 /// delivered nowhere. `TransparentProxy::run` therefore **refuses** such
110 /// a template with [`ProxyError::QlogOnProxyTemplate`], before it binds,
111 /// rather than dropping the field and coming up: a proxy that ran anyway
112 /// would report success and leave the caller's file uncreated, which
113 /// reads as a run that produced no events.
114 ///
115 /// Capture a client leg by building the [`ListenerConfig`] here and
116 /// calling [`Listener::bind`] yourself, which is also the only shape in
117 /// which one capture per connection is expressible: one sink shared by
118 /// an endpoint's connections writes all of them into one file, behind
119 /// one preamble, with no record saying where one ends.
120 ///
121 /// [`ProxyError::TransportConfigAndQlog`]: crate::error::ProxyError::TransportConfigAndQlog
122 /// [`ProxyError::Qlog`]: crate::error::ProxyError::Qlog
123 /// [`ProxyError::QlogOnProxyTemplate`]: crate::error::ProxyError::QlogOnProxyTemplate
124 /// [`QlogSpec`]: crate::qlog::QlogSpec
125 /// [`TransparentProxy`]: crate::proxy::TransparentProxy
126 #[cfg(feature = "qlog")]
127 pub qlog: Option<crate::qlog::QlogSpec>,
128}
129
130/// A client connection that has completed its handshake and is ready
131/// for MoQT session handling.
132///
133/// Produced by [`Listener::accept`]. Each variant corresponds to a
134/// distinct client-facing transport that MoQT can run over.
135pub enum AcceptedConn {
136 /// Raw QUIC connection speaking MoQT directly. The negotiated ALPN
137 /// (`moq-00`, `moqt-15`, `moqt-16`, `moqt-17`, …) is returned so
138 /// callers can resolve the draft version.
139 Quic {
140 /// The accepted QUIC connection.
141 conn: quinn::Connection,
142 /// The ALPN negotiated with the client.
143 alpn: Vec<u8>,
144 },
145 /// WebTransport session, with the H3 + extended-CONNECT dance
146 /// already completed by the listener.
147 #[cfg(feature = "webtransport")]
148 WebTransport(wtransport::Connection),
149}
150
151/// Build the ALPN list the server advertises to clients — every MoQT
152/// QUIC ALPN we support, plus `h3` when the WebTransport feature is on.
153///
154/// Each ALPN string comes from [`DraftVersion::quic_alpn`] and the set of
155/// drafts is [`DraftVersion::ALL`], so a draft joining the series is
156/// advertised without an edit here. That matters more than it looks: a draft
157/// missing from this list fails a client of that draft at the TLS handshake
158/// ("peer doesn't support any known protocol"), before it sends a single MoQT
159/// frame. `tests/control_plane_uni.rs` has a per-draft row that catches it.
160fn advertised_alpns() -> Vec<Vec<u8>> {
161 // Dedup: drafts 07–14 all map to `moq-00`, so iterate every draft
162 // and keep unique ALPNs.
163 let mut out: Vec<Vec<u8>> = Vec::new();
164 for d in DraftVersion::ALL {
165 let alpn = d.quic_alpn().to_vec();
166 if !out.iter().any(|existing| existing == &alpn) {
167 out.push(alpn);
168 }
169 }
170 #[cfg(feature = "webtransport")]
171 out.push(H3_ALPN.to_vec());
172 out
173}
174
175/// A transport-agnostic MoQT listener that accepts both raw-QUIC and
176/// WebTransport clients on the same UDP port.
177pub struct Listener {
178 endpoint: quinn::Endpoint,
179 /// The server configuration this endpoint was built with, kept so that
180 /// [`Listener::set_transport`] can replace one field of it without
181 /// rebuilding the rest.
182 ///
183 /// A clone of the value handed to quinn rather than a fresh build, and
184 /// the difference is not an optimisation. Rebuilding would re-parse the
185 /// certificate — which means retaining the private key here, and
186 /// `PrivateKeyDer` is not `Clone` — and `quinn::ServerConfig::with_crypto`
187 /// draws a fresh random handshake-token master key each time it is
188 /// called, which would invalidate every retry token already outstanding.
189 /// Keeping the built value costs one `Arc` per field and none of that.
190 server_config: quinn::ServerConfig,
191}
192
193impl Listener {
194 /// Bind to the configured address and start listening.
195 ///
196 /// The listener advertises every supported MoQT ALPN (`moq-00` and
197 /// `moqt-<N>` for all known drafts) plus `h3` for WebTransport. The
198 /// client picks which one to speak; the proxy forwards whatever
199 /// arrives.
200 ///
201 /// This binds an ordinary UDP socket at [`ListenerConfig::bind_addr`],
202 /// wraps it with quinn's default runtime adapter and hands it to
203 /// [`Listener::bind_with_socket`]. Must therefore be called from
204 /// inside a tokio runtime context — as it always had to be, because
205 /// quinn reaches for the same runtime when it binds a socket itself.
206 pub fn bind(config: ListenerConfig) -> Result<Self, ProxyError> {
207 let runtime = quinn::default_runtime()
208 .ok_or_else(|| ProxyError::Listener("no async runtime found".to_string()))?;
209 let socket = std::net::UdpSocket::bind(config.bind_addr)
210 .map_err(|e| ProxyError::Listener(e.to_string()))?;
211 let socket =
212 runtime.wrap_udp_socket(socket).map_err(|e| ProxyError::Listener(e.to_string()))?;
213
214 Self::bind_with_socket(config, socket)
215 }
216
217 /// Bind the listener over a caller-supplied abstract socket.
218 ///
219 /// Every datagram this listener sends to, or receives from, a client
220 /// passes through `socket`, so a caller that supplies a decorating
221 /// implementation — a tap, a counter, a network-impairment shim —
222 /// observes and can alter the whole client-facing leg. Ownership is
223 /// shared, so the caller keeps its handle on the socket after the
224 /// endpoint is running.
225 ///
226 /// [`ListenerConfig::bind_addr`] is ignored here: `socket` is already
227 /// bound, and its address is the one [`Listener::local_addr`] reports.
228 /// The rest of the configuration — the certificate, the advertised
229 /// ALPN list, the transport parameters — applies exactly as it does to
230 /// [`Listener::bind`], which is a thin wrapper around this function.
231 ///
232 /// # One socket covers WebTransport clients too
233 ///
234 /// This single seam reaches raw-QUIC and WebTransport clients alike,
235 /// because on the client-facing side the proxy never builds a
236 /// WebTransport endpoint of its own. It builds the QUIC endpoint here,
237 /// reads the negotiated ALPN off the handshake, and for `h3` clients
238 /// hands the still-connecting QUIC connection to the WebTransport
239 /// library to finish. The library adopts a connection that already
240 /// lives on this endpoint rather than binding a socket for it, so
241 /// there is no second datagram path to intercept.
242 ///
243 /// The relay leg to the upstream relay is a separate endpoint and is
244 /// not affected by this socket.
245 pub fn bind_with_socket(
246 config: ListenerConfig,
247 socket: Arc<dyn quinn::AsyncUdpSocket>,
248 ) -> Result<Self, ProxyError> {
249 // First, before the certificate is parsed and long before the
250 // endpoint is built. Every refusal this can produce is a fault in
251 // what the caller wrote rather than in the world, so a caller must
252 // not have to get a working certificate before hearing about one,
253 // and none of them must ever arrive attached to a live endpoint
254 // that then has to be torn down. It is also where a capture's sink
255 // is built, which writes the file's preamble — so a leg whose spec
256 // was refused has written nothing anywhere.
257 let transport = transport::resolve(
258 Leg::Client,
259 config.transport_config,
260 config.transport_profile.as_ref(),
261 config.installer.as_ref(),
262 // Moved out of the config rather than borrowed: a spec owns its
263 // writer and is consumed when it becomes a sink, so there is
264 // nothing here a second bind could use.
265 #[cfg(feature = "qlog")]
266 config.qlog,
267 )?;
268
269 let mut server_tls = rustls::ServerConfig::builder()
270 .with_no_client_auth()
271 .with_single_cert(config.cert_chain, config.key_der)
272 .map_err(|e| ProxyError::TlsConfig(format!("server cert config: {e}")))?;
273
274 server_tls.alpn_protocols = advertised_alpns();
275 server_tls.max_early_data_size = u32::MAX;
276
277 let quic_server_config: quinn::crypto::rustls::QuicServerConfig =
278 server_tls.try_into().map_err(|e| ProxyError::TlsConfig(format!("{e}")))?;
279
280 let mut server_config = quinn::ServerConfig::with_crypto(Arc::new(quic_server_config));
281 if let Some(transport) = transport {
282 server_config.transport_config(transport);
283 }
284
285 let runtime = quinn::default_runtime()
286 .ok_or_else(|| ProxyError::Listener("no async runtime found".to_string()))?;
287
288 let endpoint = quinn::Endpoint::new_with_abstract_socket(
289 quinn::EndpointConfig::default(),
290 Some(server_config.clone()),
291 socket,
292 runtime,
293 )
294 .map_err(|e| ProxyError::Listener(e.to_string()))?;
295
296 Ok(Self { endpoint, server_config })
297 }
298
299 /// Install `transport` as the QUIC transport parameters this listener
300 /// gives to the connections it accepts **from now on**.
301 ///
302 /// # It cannot reach a connection that already exists
303 ///
304 /// A quinn connection takes its `TransportConfig` once, out of the
305 /// server configuration in force when its handshake began, and keeps
306 /// that `Arc` for as long as it lives. There is no way to hand a live
307 /// connection a different one — quinn exposes four setters on an
308 /// accepted connection (the two stream-count limits and the two
309 /// windows) and nothing else. So this changes what the *next* accepted
310 /// connection gets and leaves every connection already running exactly
311 /// as it was.
312 ///
313 /// That is worth stating rather than glossing, because the failure it
314 /// produces is silent: on a proxy nobody is connecting to any more,
315 /// this call succeeds, changes the endpoint, and never reaches a single
316 /// packet.
317 ///
318 /// Everything else about the endpoint — the certificate, the advertised
319 /// ALPN list, the handshake token key — is carried over from the
320 /// configuration the listener bound with, so a client's view of this
321 /// server is unchanged apart from the transport parameters.
322 pub(crate) fn set_transport(&self, transport: std::sync::Arc<quinn::TransportConfig>) {
323 let mut config = self.server_config.clone();
324 config.transport_config(transport);
325 self.endpoint.set_server_config(Some(config));
326 }
327
328 /// Accept the next incoming connection and dispatch based on the
329 /// ALPN negotiated during the TLS handshake.
330 ///
331 /// Raw-QUIC connections are returned immediately with the negotiated
332 /// ALPN so the caller can pick the MoQT draft. For `h3` clients the
333 /// listener drives the HTTP/3 + extended-CONNECT handshake to
334 /// completion before returning a ready `wtransport::Connection`.
335 pub async fn accept(&self) -> Result<AcceptedConn, ProxyError> {
336 let incoming = self
337 .endpoint
338 .accept()
339 .await
340 .ok_or_else(|| ProxyError::Listener("endpoint closed".to_string()))?;
341
342 let mut connecting = incoming.accept().map_err(|e| ProxyError::Listener(e.to_string()))?;
343
344 // Peeking at handshake_data resolves as soon as the server has
345 // processed the ClientHello, so the ALPN is known before the
346 // full handshake completes — and the Connecting is still live.
347 let hs_data = connecting
348 .handshake_data()
349 .await
350 .map_err(|e| ProxyError::Listener(format!("handshake data: {e}")))?;
351
352 let alpn = hs_data
353 .downcast::<quinn::crypto::rustls::HandshakeData>()
354 .ok()
355 .and_then(|hd| hd.protocol)
356 .map(|p| p.to_vec())
357 .unwrap_or_default();
358
359 if alpn == H3_ALPN {
360 #[cfg(feature = "webtransport")]
361 {
362 let session_fut =
363 wtransport::endpoint::IncomingSessionFuture::with_quic_connecting(connecting);
364 let session_request = session_fut
365 .await
366 .map_err(|e| ProxyError::Listener(format!("webtransport handshake: {e}")))?;
367 let conn = session_request
368 .accept()
369 .await
370 .map_err(|e| ProxyError::Listener(format!("webtransport accept: {e}")))?;
371 Ok(AcceptedConn::WebTransport(conn))
372 }
373 #[cfg(not(feature = "webtransport"))]
374 {
375 drop(connecting);
376 Err(ProxyError::Listener(
377 "client negotiated h3 but webtransport feature is not enabled".to_string(),
378 ))
379 }
380 } else {
381 let conn = connecting.await.map_err(|e| ProxyError::Listener(e.to_string()))?;
382 Ok(AcceptedConn::Quic { conn, alpn })
383 }
384 }
385
386 /// Get the local address this listener is bound to.
387 pub fn local_addr(&self) -> Result<SocketAddr, ProxyError> {
388 self.endpoint.local_addr().map_err(|e| ProxyError::Listener(e.to_string()))
389 }
390
391 /// Stop accepting new connections.
392 pub fn close(&self) {
393 self.endpoint.close(0u32.into(), b"proxy shutting down");
394 }
395}
396
397#[cfg(test)]
398mod tests {
399 use std::sync::atomic::{AtomicUsize, Ordering};
400
401 use rustls::pki_types::PrivatePkcs8KeyDer;
402
403 use super::*;
404 use crate::transport::TransportProfileError;
405
406 /// A certificate this listener will never get as far as parsing.
407 ///
408 /// Every refusal tested below has to be reported *before* the TLS
409 /// build, so the tests hand over ten bytes of nothing. If one of them
410 /// ever fails with a `TlsConfig` error, the check has drifted later
411 /// than the certificate and a caller now has to hold a valid identity
412 /// before they can be told their two transport fields contradict.
413 fn unusable_identity() -> (Vec<CertificateDer<'static>>, PrivateKeyDer<'static>) {
414 (
415 vec![CertificateDer::from(vec![0u8; 10])],
416 PrivateKeyDer::Pkcs8(PrivatePkcs8KeyDer::from(vec![0u8; 10])),
417 )
418 }
419
420 /// A real self-signed `localhost` pair, for the one test that has to
421 /// bind successfully.
422 fn usable_identity() -> (Vec<CertificateDer<'static>>, PrivateKeyDer<'static>) {
423 let key_pair = rcgen::KeyPair::generate_for(&rcgen::PKCS_ECDSA_P256_SHA256)
424 .expect("a key pair for a test certificate");
425 let params =
426 rcgen::CertificateParams::new(vec!["localhost".into()]).expect("certificate params");
427 let cert = params.self_signed(&key_pair).expect("self-sign");
428 (
429 vec![CertificateDer::from(cert.der().to_vec())],
430 PrivateKeyDer::Pkcs8(PrivatePkcs8KeyDer::from(key_pair.serialize_der())),
431 )
432 }
433
434 fn config(identity: (Vec<CertificateDer<'static>>, PrivateKeyDer<'static>)) -> ListenerConfig {
435 let (cert_chain, key_der) = identity;
436 ListenerConfig {
437 bind_addr: "127.0.0.1:0".parse().expect("a literal address"),
438 cert_chain,
439 key_der,
440 transport_config: None,
441 transport_profile: None,
442 installer: None,
443 #[cfg(feature = "qlog")]
444 qlog: None,
445 }
446 }
447
448 /// Counts the builds and returns a config built the default way.
449 struct CountingInstaller(Arc<AtomicUsize>);
450
451 impl TransportInstaller for CountingInstaller {
452 fn build(
453 &self,
454 profile: &TransportProfile,
455 ) -> Result<quinn::TransportConfig, TransportProfileError> {
456 self.0.fetch_add(1, Ordering::Relaxed);
457 profile.into_config()
458 }
459 }
460
461 #[tokio::test]
462 async fn a_client_leg_naming_both_a_config_and_a_profile_is_refused_at_bind() {
463 let mut config = config(unusable_identity());
464 config.transport_config = Some(Arc::new(quinn::TransportConfig::default()));
465 config.transport_profile = Some(TransportProfile::default());
466
467 let err = Listener::bind(config).err().expect("a contradiction is not a listener");
468 assert!(
469 matches!(err, ProxyError::TransportConfigAndProfile { leg: Leg::Client }),
470 "the client leg's contradiction has to be reported as the client leg's: {err}"
471 );
472 }
473
474 /// The client leg's other contradiction, refused as its own thing and
475 /// with nothing written anywhere.
476 ///
477 /// Two halves. The first is that the refusal is
478 /// `TransportConfigAndQlog` and not `TransportConfigAndProfile`: the
479 /// two pairs have different fixes, and a caller told the wrong one goes
480 /// looking at the wrong half of their configuration. The second is what
481 /// makes this more than a claim about a return value — the sink writes
482 /// its preamble the instant it is built, so a writer that is still
483 /// empty afterwards is proof that no sink was built and no capture was
484 /// quietly begun on a leg that then refused to bind.
485 #[cfg(feature = "qlog")]
486 #[tokio::test]
487 async fn a_client_leg_naming_both_a_config_and_a_spec_is_refused_as_that() {
488 /// Everything written to it, readable while the writer is alive.
489 #[derive(Clone)]
490 struct Captured(Arc<std::sync::Mutex<Vec<u8>>>);
491
492 impl std::io::Write for Captured {
493 fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
494 self.0.lock().expect("no test holds this across a panic").extend_from_slice(buf);
495 Ok(buf.len())
496 }
497
498 fn flush(&mut self) -> std::io::Result<()> {
499 Ok(())
500 }
501 }
502
503 let sink = Arc::new(std::sync::Mutex::new(Vec::new()));
504 let mut config = config(unusable_identity());
505 config.transport_config = Some(Arc::new(quinn::TransportConfig::default()));
506 config.qlog = Some(crate::qlog::QlogSpec {
507 writer: Some(Box::new(Captured(Arc::clone(&sink)))),
508 title: Some("client leg".to_string()),
509 description: None,
510 });
511
512 let err = Listener::bind(config).err().expect("a contradiction is not a listener");
513 assert!(
514 matches!(err, ProxyError::TransportConfigAndQlog { leg: Leg::Client }),
515 "a raw config and a spec is a different fault from a raw config and a profile, with a \
516 different fix, and one refusal covering both would send the caller to the wrong half \
517 of their configuration: {err}"
518 );
519 assert!(
520 sink.lock().expect("uncontended").is_empty(),
521 "the preamble is written the moment a sink is built, so anything here means the \
522 refused leg began a capture on its way to refusing"
523 );
524 }
525
526 #[tokio::test]
527 async fn a_client_leg_whose_profile_cannot_be_honoured_does_not_bind() {
528 let mut config = config(unusable_identity());
529 // quinn raises anything under 1200 to 1200 without a word, so a
530 // listener that came up here would be running at an MTU nobody
531 // asked for.
532 config.transport_profile =
533 Some(TransportProfile { initial_mtu: Some(900), ..Default::default() });
534
535 let err = Listener::bind(config).err().expect("an unhonourable profile is not a listener");
536 assert!(
537 matches!(
538 err,
539 ProxyError::TransportProfile {
540 leg: Leg::Client,
541 source: TransportProfileError::MtuBelowFloor { .. },
542 }
543 ),
544 "{err}"
545 );
546 }
547
548 #[tokio::test]
549 async fn a_profile_carrying_client_leg_installs_and_binds() {
550 let _ = rustls::crypto::ring::default_provider().install_default();
551
552 let builds = Arc::new(AtomicUsize::new(0));
553 let mut config = config(usable_identity());
554 config.transport_profile = Some(TransportProfile {
555 initial_mtu: Some(1350),
556 receive_window: Some(4 * 1024 * 1024),
557 ..Default::default()
558 });
559 config.installer = Some(Arc::new(CountingInstaller(Arc::clone(&builds))));
560
561 let listener = Listener::bind(config).expect("a valid profile binds a listener");
562 assert!(listener.local_addr().is_ok(), "the endpoint is live");
563 assert_eq!(
564 builds.load(Ordering::Relaxed),
565 1,
566 "the leg has to build its config through the installer, once, before the endpoint \
567 exists — a leg that bound without consulting it would be running on quinn's \
568 defaults and reporting success"
569 );
570 listener.close();
571 }
572}