Skip to content

Commit a9164c4

Browse files
committed
Delete the setup of a local quinn connection for tests
replace with the new tools in quic-rpc v0.17.3
1 parent dec9643 commit a9164c4

File tree

3 files changed

+21
-126
lines changed

3 files changed

+21
-126
lines changed

Cargo.lock

Lines changed: 5 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ postcard = { version = "1", default-features = false, features = [
5454
"use-std",
5555
"experimental-derive",
5656
] }
57-
quic-rpc = { version = "0.17.1", optional = true }
57+
quic-rpc = { version = "0.17.3", optional = true }
5858
quic-rpc-derive = { version = "0.17", optional = true }
5959
quinn = { package = "iroh-quinn", version = "0.12", features = ["ring"] }
6060
rand = "0.8"
@@ -119,7 +119,7 @@ example-iroh = [
119119
"dep:console",
120120
"iroh/discovery-local-network"
121121
]
122-
test = ["quic-rpc/quinn-transport"]
122+
test = ["quic-rpc/quinn-transport", "quic-rpc/test-utils"]
123123

124124
[package.metadata.docs.rs]
125125
all-features = true

tests/rpc.rs

Lines changed: 14 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,15 @@
11
#![cfg(feature = "test")]
2-
use std::{net::SocketAddr, path::PathBuf, sync::Arc};
2+
use std::{net::SocketAddr, path::PathBuf, vec};
33

44
use iroh_blobs::{net_protocol::Blobs, util::local_pool::LocalPool};
5-
use quic_rpc::transport::quinn::QuinnConnector;
6-
use quinn::{
7-
crypto::rustls::{QuicClientConfig, QuicServerConfig},
8-
rustls, ClientConfig, Endpoint, ServerConfig,
9-
};
10-
use rcgen::CertifiedKey;
5+
use quic_rpc::client::QuinnConnector;
116
use tempfile::TempDir;
127
use testresult::TestResult;
138
use tokio_util::task::AbortOnDropHandle;
149

15-
type QC = QuinnConnector<iroh_blobs::rpc::proto::Response, iroh_blobs::rpc::proto::Request>;
10+
type QC = QuinnConnector<iroh_blobs::rpc::proto::RpcService>;
1611
type BlobsClient = iroh_blobs::rpc::client::blobs::Client<QC>;
1712

18-
/// Builds default quinn client config and trusts given certificates.
19-
///
20-
/// ## Args
21-
///
22-
/// - server_certs: a list of trusted certificates in DER format.
23-
fn configure_client(server_certs: &[CertifiedKey]) -> anyhow::Result<ClientConfig> {
24-
let mut certs = rustls::RootCertStore::empty();
25-
for cert in server_certs {
26-
let cert = cert.cert.der().clone();
27-
certs.add(cert)?;
28-
}
29-
30-
let crypto_client_config = rustls::ClientConfig::builder_with_provider(Arc::new(
31-
rustls::crypto::ring::default_provider(),
32-
))
33-
.with_protocol_versions(&[&rustls::version::TLS13])
34-
.expect("valid versions")
35-
.with_root_certificates(certs)
36-
.with_no_client_auth();
37-
let quic_client_config = QuicClientConfig::try_from(crypto_client_config)?;
38-
39-
Ok(ClientConfig::new(Arc::new(quic_client_config)))
40-
}
41-
42-
/// Returns default server configuration along with its certificate.
43-
#[allow(clippy::field_reassign_with_default)] // https://github.com/rust-lang/rust-clippy/issues/6527
44-
fn configure_server() -> anyhow::Result<(ServerConfig, CertifiedKey)> {
45-
let cert = rcgen::generate_simple_self_signed(vec!["localhost".into()])?;
46-
let cert_der = cert.cert.der();
47-
let priv_key = rustls::pki_types::PrivatePkcs8KeyDer::from(cert.key_pair.serialize_der());
48-
let cert_chain = vec![cert_der.clone()];
49-
50-
let crypto_server_config = rustls::ServerConfig::builder_with_provider(Arc::new(
51-
rustls::crypto::ring::default_provider(),
52-
))
53-
.with_protocol_versions(&[&rustls::version::TLS13])
54-
.expect("valid versions")
55-
.with_no_client_auth()
56-
.with_single_cert(cert_chain, priv_key.into())?;
57-
let quic_server_config = QuicServerConfig::try_from(crypto_server_config)?;
58-
let mut server_config = ServerConfig::with_crypto(Arc::new(quic_server_config));
59-
60-
Arc::get_mut(&mut server_config.transport)
61-
.unwrap()
62-
.max_concurrent_uni_streams(0_u8.into());
63-
64-
Ok((server_config, cert))
65-
}
66-
67-
pub fn make_server_endpoint(bind_addr: SocketAddr) -> anyhow::Result<(Endpoint, CertifiedKey)> {
68-
let (server_config, server_cert) = configure_server()?;
69-
let endpoint = Endpoint::server(server_config, bind_addr)?;
70-
Ok((endpoint, server_cert))
71-
}
72-
73-
pub fn make_client_endpoint(
74-
bind_addr: SocketAddr,
75-
server_certs: &[CertifiedKey],
76-
) -> anyhow::Result<Endpoint> {
77-
let client_cfg = configure_client(server_certs)?;
78-
let mut endpoint = Endpoint::client(bind_addr)?;
79-
endpoint.set_default_client_config(client_cfg);
80-
Ok(endpoint)
81-
}
82-
8313
/// An iroh node that just has the blobs transport
8414
#[derive(Debug)]
8515
pub struct Node {
@@ -90,7 +20,7 @@ pub struct Node {
9020
}
9121

9222
impl Node {
93-
pub async fn new(path: PathBuf) -> anyhow::Result<(Self, SocketAddr, CertifiedKey)> {
23+
pub async fn new(path: PathBuf) -> anyhow::Result<(Self, SocketAddr, Vec<u8>)> {
9424
let store = iroh_blobs::store::fs::Store::load(path).await?;
9525
let local_pool = LocalPool::default();
9626
let endpoint = iroh::Endpoint::builder().bind().await?;
@@ -99,7 +29,7 @@ impl Node {
9929
.accept(iroh_blobs::ALPN, blobs.clone())
10030
.spawn()
10131
.await?;
102-
let (config, key) = configure_server()?;
32+
let (config, key) = quic_rpc::transport::quinn::configure_server()?;
10333
let endpoint = quinn::Endpoint::server(config, "127.0.0.1:0".parse().unwrap())?;
10434
let local_addr = endpoint.local_addr()?;
10535
let rpc_server = quic_rpc::transport::quinn::QuinnListener::new(endpoint)?;
@@ -121,8 +51,15 @@ impl Node {
12151
async fn node_and_client() -> TestResult<(Node, BlobsClient, TempDir)> {
12252
let testdir = tempfile::tempdir()?;
12353
let (node, addr, key) = Node::new(testdir.path().join("blobs")).await?;
124-
let client = make_client_endpoint("127.0.0.1:0".parse().unwrap(), &[key])?;
125-
let client = QuinnConnector::new(client, addr, "localhost".to_string());
54+
let client = quic_rpc::transport::quinn::make_client_endpoint(
55+
"127.0.0.1:0".parse().unwrap(),
56+
&[key.as_slice()],
57+
)?;
58+
let client = QuinnConnector::<iroh_blobs::rpc::proto::RpcService>::new(
59+
client,
60+
addr,
61+
"localhost".to_string(),
62+
);
12663
let client = quic_rpc::RpcClient::<iroh_blobs::rpc::proto::RpcService, _>::new(client);
12764
let client = iroh_blobs::rpc::client::blobs::Client::new(client);
12865
Ok((node, client, testdir))

0 commit comments

Comments
 (0)