Skip to content

Commit

Permalink
use in example
Browse files Browse the repository at this point in the history
  • Loading branch information
divagant-martian committed Nov 21, 2024
1 parent e695df6 commit 5c0e633
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
21 changes: 19 additions & 2 deletions quinn/examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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
Expand Down
20 changes: 19 additions & 1 deletion quinn/examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Path>::from(options.root.clone());
if !root.exists() {
Expand Down Expand Up @@ -176,6 +179,21 @@ async fn handle_connection(root: Arc<Path>, conn: quinn::Incoming) -> Result<()>
.protocol
.map_or_else(|| "<none>".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");

Expand Down

0 comments on commit 5c0e633

Please sign in to comment.