|
1 |
| -use std::net::Ipv6Addr; |
| 1 | +use core::net::{Ipv4Addr, Ipv6Addr}; |
| 2 | + |
2 | 3 | use std::process::ExitStatus;
|
3 | 4 |
|
4 | 5 | use anyhow::Context;
|
@@ -79,28 +80,22 @@ where
|
79 | 80 |
|
80 | 81 | #[cfg(feature = "quic")]
|
81 | 82 | pub async fn with_quic_endpoints<T, Fut>(
|
82 |
| - f: impl FnOnce(std::net::SocketAddr, quinn::Endpoint, quinn::Endpoint) -> Fut, |
| 83 | + f: impl FnOnce(core::net::SocketAddr, quinn::Endpoint, quinn::Endpoint) -> Fut, |
83 | 84 | ) -> anyhow::Result<T>
|
84 | 85 | where
|
85 | 86 | Fut: core::future::Future<Output = anyhow::Result<T>>,
|
86 | 87 | {
|
87 | 88 | use std::sync::Arc;
|
88 | 89 |
|
89 | 90 | use quinn::crypto::rustls::QuicClientConfig;
|
90 |
| - use quinn::{ClientConfig, EndpointConfig, ServerConfig, TokioRuntime}; |
| 91 | + use quinn::{ClientConfig, ServerConfig}; |
91 | 92 | use rcgen::{generate_simple_self_signed, CertifiedKey};
|
92 | 93 | use rustls::pki_types::{CertificateDer, PrivatePkcs8KeyDer};
|
93 | 94 | use rustls::version::TLS13;
|
94 | 95 |
|
95 |
| - let mut clt_ep = quinn::Endpoint::client((Ipv6Addr::LOCALHOST, 0).into()) |
| 96 | + let mut clt_ep = quinn::Endpoint::client((Ipv4Addr::LOCALHOST, 0).into()) |
96 | 97 | .context("failed to create client endpoint")?;
|
97 | 98 |
|
98 |
| - let srv_sock = std::net::UdpSocket::bind((Ipv6Addr::LOCALHOST, 0)) |
99 |
| - .context("failed to open a UDP socket")?; |
100 |
| - let srv_addr = srv_sock |
101 |
| - .local_addr() |
102 |
| - .context("failed to query server address")?; |
103 |
| - |
104 | 99 | let CertifiedKey {
|
105 | 100 | cert: srv_crt,
|
106 | 101 | key_pair: srv_key,
|
@@ -132,13 +127,11 @@ where
|
132 | 127 | .expect("failed to create server config");
|
133 | 128 |
|
134 | 129 | clt_ep.set_default_client_config(ClientConfig::new(Arc::new(clt_cnf)));
|
135 |
| - let srv_ep = quinn::Endpoint::new( |
136 |
| - EndpointConfig::default(), |
137 |
| - Some(srv_cnf), |
138 |
| - srv_sock, |
139 |
| - Arc::new(TokioRuntime), |
140 |
| - ) |
141 |
| - .context("failed to create server endpoint")?; |
| 130 | + let srv_ep = quinn::Endpoint::server(srv_cnf, (Ipv4Addr::LOCALHOST, 0).into()) |
| 131 | + .context("failed to create server endpoint")?; |
| 132 | + let srv_addr = srv_ep |
| 133 | + .local_addr() |
| 134 | + .context("failed to query server address")?; |
142 | 135 |
|
143 | 136 | f(srv_addr, clt_ep, srv_ep).await.context("closure failed")
|
144 | 137 | }
|
@@ -180,7 +173,13 @@ where
|
180 | 173 | .context("failed to construct URL")?;
|
181 | 174 | let (clt, srv) = tokio::try_join!(
|
182 | 175 | async move {
|
183 |
| - web_transport_quinn::connect(&clt, &url) |
| 176 | + let conn = clt |
| 177 | + .connect(addr, "localhost") |
| 178 | + .context("failed to connect to server")?; |
| 179 | + let conn = conn |
| 180 | + .await |
| 181 | + .context("failed to establish client connection")?; |
| 182 | + web_transport_quinn::connect_with(conn, &url) |
184 | 183 | .await
|
185 | 184 | .context("failed to connect to server")
|
186 | 185 | },
|
|
0 commit comments