diff --git a/quinn/examples/client.rs b/quinn/examples/client.rs index 0ace61f95..80fc3562d 100644 --- a/quinn/examples/client.rs +++ b/quinn/examples/client.rs @@ -13,7 +13,7 @@ use std::{ use anyhow::{anyhow, Result}; use clap::Parser; -use proto::crypto::rustls::QuicClientConfig; +use proto::{crypto::rustls::QuicClientConfig, TransportConfig}; use rustls::pki_types::CertificateDer; use tracing::{error, info}; use url::Url; @@ -101,8 +101,13 @@ async fn run(options: Opt) -> Result<()> { client_crypto.key_log = Arc::new(rustls::KeyLogFile::new()); } - let client_config = + let mut transport = TransportConfig::default(); + transport + .send_observed_address_reports(true) + .receive_observed_address_reports(true); + let mut client_config = quinn::ClientConfig::new(Arc::new(QuicClientConfig::try_from(client_crypto)?)); + client_config.transport_config(Arc::new(transport)); let mut endpoint = quinn::Endpoint::client(options.bind)?; endpoint.set_default_client_config(client_config); @@ -117,6 +122,18 @@ async fn run(options: Opt) -> Result<()> { .await .map_err(|e| anyhow!("failed to connect: {}", e))?; eprintln!("connected at {:?}", start.elapsed()); + let mut external_addresses = conn.observed_external_addr(); + tokio::spawn(async move { + loop { + if let Some(new_addr) = *external_addresses.borrow_and_update() { + info!(%new_addr, "new external address report"); + } + if external_addresses.changed().await.is_err() { + break; + } + } + }); + let (mut send, mut recv) = conn .open_bi() .await diff --git a/quinn/examples/server.rs b/quinn/examples/server.rs index b6f63160e..b65d739be 100644 --- a/quinn/examples/server.rs +++ b/quinn/examples/server.rs @@ -127,7 +127,10 @@ async fn run(options: Opt) -> Result<()> { let mut server_config = quinn::ServerConfig::with_crypto(Arc::new(QuicServerConfig::try_from(server_crypto)?)); let transport_config = Arc::get_mut(&mut server_config.transport).unwrap(); - transport_config.max_concurrent_uni_streams(0_u8.into()); + transport_config + .max_concurrent_uni_streams(0_u8.into()) + .send_observed_address_reports(true) + .receive_observed_address_reports(true); let root = Arc::::from(options.root.clone()); if !root.exists() { @@ -176,6 +179,21 @@ async fn handle_connection(root: Arc, conn: quinn::Incoming) -> Result<()> .protocol .map_or_else(|| "".into(), |x| String::from_utf8_lossy(&x).into_owned()) ); + + let mut external_addresses = connection.observed_external_addr(); + tokio::spawn( + async move { + loop { + if let Some(new_addr) = *external_addresses.borrow_and_update() { + info!(%new_addr, "new external address report"); + } + if external_addresses.changed().await.is_err() { + break; + } + } + } + .instrument(span.clone()), + ); async { info!("established");