Skip to content

Commit be7c5b0

Browse files
committed
Eliminate the tls crate.
It is a dependency of iroh-mainline-content-discovery, yet I don't want to publish it. So I can't publish iroh-mainline-content-discovery itself. I moved all the stuff into iroh-mainline-content-discovery under the feature flag
1 parent bfe4a47 commit be7c5b0

File tree

12 files changed

+71
-60
lines changed

12 files changed

+71
-60
lines changed

content-discovery/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ members = [
33
"iroh-mainline-content-discovery",
44
"iroh-mainline-content-discovery-cli",
55
"iroh-mainline-tracker",
6-
"tls",
76
]
87
resolver = "2"
98

content-discovery/iroh-mainline-content-discovery/Cargo.toml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ hex = "0.4.3"
2222

2323
# Optional features for the client functionality
2424
tracing = { version = "0.1", optional = true }
25-
iroh-quinn = { version = "0.13", optional = true }
25+
quinn = { package = "iroh-quinn", version = "0.13", optional = true }
2626
mainline = { version = "2.0.0", optional = true, features = ["async"] }
2727
anyhow = { version = "1", features = ["backtrace"], optional = true }
2828
postcard = { version = "1", default-features = false, features = ["alloc", "use-std"], optional = true }
@@ -32,8 +32,33 @@ rustls = { version = "0.23", default-features = false, features = ["ring"], opti
3232
genawaiter = { version = "0.99.1", features = ["futures03"], optional = true }
3333
tokio = { workspace = true, optional = true }
3434
flume = "0.11.0"
35-
tls = { path = "../tls", optional = true }
35+
36+
# dependencies for the tls utils
37+
der = { version = "0.7", features = ["alloc", "derive"], optional = true }
38+
webpki = { package = "rustls-webpki", version = "0.102", optional = true }
39+
x509-parser = { version = "0.16", optional = true }
40+
thiserror = { version = "2", optional = true }
41+
ring = { version = "0.17", optional = true }
3642

3743
[features]
38-
client = ["mainline", "iroh-quinn", "tracing", "anyhow", "rcgen", "genawaiter", "rustls", "futures", "postcard", "tokio", "tls"]
44+
client = [
45+
"dep:mainline",
46+
"dep:quinn",
47+
"dep:tracing",
48+
"dep:anyhow",
49+
"dep:rcgen",
50+
"dep:genawaiter",
51+
"dep:rustls",
52+
"dep:futures",
53+
"dep:postcard",
54+
"dep:tokio",
55+
"tls-utils",
56+
]
57+
tls-utils = [
58+
"dep:der",
59+
"dep:webpki",
60+
"dep:x509-parser",
61+
"dep:thiserror",
62+
"dep:ring",
63+
]
3964
default = ["client"]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Protocol and client for iroh mainline content discovery
2+
3+
This provides a very minimal protocol for content discovery as well as a
4+
client library for the protocol.
5+
6+
## Features
7+
8+
- client: the client that allows querying content discovery
9+
- tls-utils: utilities to set of quinn connections, used by client

content-discovery/iroh-mainline-content-discovery/src/client.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ use iroh::{
2020
};
2121
use iroh_blobs::HashAndFormat;
2222

23-
use crate::protocol::{
23+
use crate::{protocol::{
2424
AnnounceKind, Query, QueryResponse, Request, Response, SignedAnnounce, ALPN, REQUEST_SIZE_LIMIT,
25-
};
25+
}, tls_utils};
2626

2727
/// Announce to a tracker.
2828
///
@@ -33,7 +33,7 @@ use crate::protocol::{
3333
/// `content` is the content to announce.
3434
/// `kind` is the kind of the announcement. We can claim to have the complete data or only some of it.
3535
pub async fn announce_quinn(
36-
connection: iroh_quinn::Connection,
36+
connection: quinn::Connection,
3737
signed_announce: SignedAnnounce,
3838
) -> anyhow::Result<()> {
3939
let (mut send, mut recv) = connection.open_bi().await?;
@@ -119,14 +119,14 @@ async fn query_iroh_one(
119119

120120
/// A connection provider that can be used to connect to a tracker.
121121
///
122-
/// This can either be a [`iroh_quinn::Endpoint`] where connections are created on demand,
122+
/// This can either be a [`quinn::Endpoint`] where connections are created on demand,
123123
/// or some sort of connection pool.
124124
pub trait QuinnConnectionProvider<Addr>: Clone {
125-
fn connect(&self, addr: Addr) -> BoxFuture<anyhow::Result<iroh_quinn::Connection>>;
125+
fn connect(&self, addr: Addr) -> BoxFuture<anyhow::Result<quinn::Connection>>;
126126
}
127127

128-
impl QuinnConnectionProvider<SocketAddr> for iroh_quinn::Endpoint {
129-
fn connect(&self, addr: SocketAddr) -> BoxFuture<anyhow::Result<iroh_quinn::Connection>> {
128+
impl QuinnConnectionProvider<SocketAddr> for quinn::Endpoint {
129+
fn connect(&self, addr: SocketAddr) -> BoxFuture<anyhow::Result<quinn::Connection>> {
130130
async move { Ok(self.connect(addr, "localhost")?.await?) }.boxed()
131131
}
132132
}
@@ -229,7 +229,7 @@ pub async fn query_iroh(
229229

230230
/// Assume an existing connection to a tracker and query it for peers for some content.
231231
pub async fn query_quinn(
232-
connection: iroh_quinn::Connection,
232+
connection: quinn::Connection,
233233
args: Query,
234234
) -> anyhow::Result<QueryResponse> {
235235
tracing::info!("connected to {:?}", connection.remote_address());
@@ -252,12 +252,12 @@ pub fn create_quinn_client(
252252
bind_addr: SocketAddr,
253253
alpn_protocols: Vec<Vec<u8>>,
254254
keylog: bool,
255-
) -> anyhow::Result<iroh_quinn::Endpoint> {
255+
) -> anyhow::Result<quinn::Endpoint> {
256256
let secret_key = iroh::SecretKey::generate(rand::thread_rng());
257-
let tls_client_config = tls::make_client_config(&secret_key, None, alpn_protocols, keylog)?;
258-
let mut client_config = iroh_quinn::ClientConfig::new(Arc::new(tls_client_config));
259-
let mut endpoint = iroh_quinn::Endpoint::client(bind_addr)?;
260-
let mut transport_config = iroh_quinn::TransportConfig::default();
257+
let tls_client_config = tls_utils::make_client_config(&secret_key, None, alpn_protocols, keylog)?;
258+
let mut client_config = quinn::ClientConfig::new(Arc::new(tls_client_config));
259+
let mut endpoint = quinn::Endpoint::client(bind_addr)?;
260+
let mut transport_config = quinn::TransportConfig::default();
261261
transport_config.keep_alive_interval(Some(Duration::from_secs(1)));
262262
client_config.transport_config(Arc::new(transport_config));
263263
endpoint.set_default_client_config(client_config);
@@ -340,7 +340,7 @@ pub async fn connect(
340340

341341
pub enum Connection {
342342
Iroh(iroh::endpoint::Connection),
343-
Quinn(iroh_quinn::Connection),
343+
Quinn(quinn::Connection),
344344
}
345345

346346
/// Create a iroh endpoint and connect to a tracker using the [crate::protocol::ALPN] protocol.
@@ -363,7 +363,7 @@ async fn connect_iroh(
363363
async fn connect_socket(
364364
tracker: SocketAddr,
365365
local_addr: SocketAddr,
366-
) -> anyhow::Result<iroh_quinn::Connection> {
366+
) -> anyhow::Result<quinn::Connection> {
367367
let endpoint = create_quinn_client(local_addr, vec![ALPN.to_vec()], false)?;
368368
tracing::info!("trying t?o )connect to tracker at {:?}", tracker);
369369
let connection = endpoint.connect(tracker, "localhost")?.await?;

content-discovery/iroh-mainline-content-discovery/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ mod client;
88
pub mod protocol;
99
#[cfg(feature = "client")]
1010
pub use client::*;
11+
#[cfg(feature = "tls-utils")]
12+
pub mod tls_utils;

content-discovery/iroh-mainline-tracker/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ iroh-blobs = { workspace = true }
2323
mainline = { version = "2.0.0", features = ["async"] }
2424
pkarr = { version = "2.0.1", features = ["async"] }
2525
postcard = { version = "1", default-features = false, features = ["alloc", "use-std"] }
26-
iroh-quinn = "0.13"
2726
rand = "0.8"
2827
rcgen = "0.12.0"
2928
redb = "1.5.0"
@@ -42,7 +41,7 @@ url = "2.5.0"
4241
flume = "0.11.0"
4342
genawaiter = { version = "0.99.1", features = ["futures03"] }
4443
iroh-mainline-content-discovery = { path = "../iroh-mainline-content-discovery", features = ["client"] }
45-
tls = { path = "../tls" }
44+
quinn = { package = "iroh-quinn", version = "0.13" }
4645

4746
clap = { version = "4", features = ["derive"], optional = true }
4847
serde-big-array = "0.5.1"

content-discovery/iroh-mainline-tracker/src/main.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::{
1212
use clap::Parser;
1313
use iroh::{discovery::pkarr::dht::DhtDiscovery, Endpoint, NodeId};
1414
use iroh_blobs::util::fs::load_secret_key;
15-
use iroh_mainline_content_discovery::protocol::ALPN;
15+
use iroh_mainline_content_discovery::{protocol::ALPN, tls_utils};
1616
use iroh_mainline_tracker::{
1717
io::{
1818
self, load_from_file, setup_logging, tracker_home, tracker_path, CONFIG_DEBUG_FILE,
@@ -130,7 +130,7 @@ async fn server(args: Args) -> anyhow::Result<()> {
130130
let udp_socket = tokio::net::UdpSocket::bind(udp_bind_addr).await?;
131131
let quinn_bind_addr =
132132
SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, options.quinn_port));
133-
let quinn_endpoint = iroh_quinn::Endpoint::server(server_config, quinn_bind_addr)?;
133+
let quinn_endpoint = quinn::Endpoint::server(server_config, quinn_bind_addr)?;
134134
// set the quinn port to the actual port we bound to so the DHT will announce it correctly
135135
options.quinn_port = quinn_endpoint.local_addr()?.port();
136136
let iroh_endpoint = create_endpoint(key.clone(), options.iroh_ipv4_addr, true).await?;
@@ -185,7 +185,7 @@ async fn main() -> anyhow::Result<()> {
185185

186186
/// Returns default server configuration along with its certificate.
187187
#[allow(clippy::field_reassign_with_default)] // https://github.com/rust-lang/rust-clippy/issues/6527
188-
fn configure_server(secret_key: &iroh::SecretKey) -> anyhow::Result<iroh_quinn::ServerConfig> {
188+
fn configure_server(secret_key: &iroh::SecretKey) -> anyhow::Result<quinn::ServerConfig> {
189189
make_server_config(secret_key, 8, 1024, vec![ALPN.to_vec()])
190190
}
191191

@@ -195,10 +195,10 @@ pub fn make_server_config(
195195
max_streams: u64,
196196
max_connections: u32,
197197
alpn_protocols: Vec<Vec<u8>>,
198-
) -> anyhow::Result<iroh_quinn::ServerConfig> {
199-
let tls_server_config = tls::make_server_config(secret_key, alpn_protocols, false)?;
200-
let mut server_config = iroh_quinn::ServerConfig::with_crypto(Arc::new(tls_server_config));
201-
let mut transport_config = iroh_quinn::TransportConfig::default();
198+
) -> anyhow::Result<quinn::ServerConfig> {
199+
let tls_server_config = tls_utils::make_server_config(secret_key, alpn_protocols, false)?;
200+
let mut server_config = quinn::ServerConfig::with_crypto(Arc::new(tls_server_config));
201+
let mut transport_config = quinn::TransportConfig::default();
202202
transport_config
203203
.max_concurrent_bidi_streams(max_streams.try_into()?)
204204
.max_concurrent_uni_streams(0u32.into());

content-discovery/iroh-mainline-tracker/src/tracker.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ use iroh_mainline_content_discovery::{
1717
protocol::{
1818
AbsoluteTime, Announce, AnnounceKind, Query, QueryResponse, Request, Response,
1919
SignedAnnounce, REQUEST_SIZE_LIMIT,
20-
},
21-
to_infohash,
20+
}, tls_utils, to_infohash
2221
};
2322
use rand::Rng;
2423
use redb::{ReadableTable, RedbValue};
@@ -883,7 +882,7 @@ impl Tracker {
883882
Ok(())
884883
}
885884

886-
pub async fn quinn_accept_loop(self, endpoint: iroh_quinn::Endpoint) -> std::io::Result<()> {
885+
pub async fn quinn_accept_loop(self, endpoint: quinn::Endpoint) -> std::io::Result<()> {
887886
let local_addr = endpoint.local_addr()?;
888887
println!("quinn listening on {local_addr:?}");
889888
while let Some(incoming) = endpoint.accept().await {
@@ -948,7 +947,7 @@ impl Tracker {
948947
/// Handle a single incoming connection on the tracker ALPN.
949948
pub async fn handle_quinn_connection(
950949
&self,
951-
connection: iroh_quinn::Connection,
950+
connection: quinn::Connection,
952951
) -> anyhow::Result<()> {
953952
tracing::debug!("calling accept_bi");
954953
let (mut send, mut recv) = connection.accept_bi().await?;
@@ -1269,18 +1268,18 @@ impl Tracker {
12691268

12701269
/// Accept an incoming connection and extract the client-provided [`NodeId`] and ALPN protocol.
12711270
async fn accept_conn(
1272-
mut conn: iroh_quinn::Connecting,
1273-
) -> anyhow::Result<(NodeId, String, iroh_quinn::Connection)> {
1271+
mut conn: quinn::Connecting,
1272+
) -> anyhow::Result<(NodeId, String, quinn::Connection)> {
12741273
let alpn = get_alpn(&mut conn).await?;
12751274
let conn = conn.await?;
12761275
let node_id = get_remote_node_id(&conn)?;
12771276
Ok((node_id, alpn, conn))
12781277
}
12791278

12801279
/// Extract the ALPN protocol from the peer's TLS certificate.
1281-
pub async fn get_alpn(connecting: &mut iroh_quinn::Connecting) -> anyhow::Result<String> {
1280+
pub async fn get_alpn(connecting: &mut quinn::Connecting) -> anyhow::Result<String> {
12821281
let data = connecting.handshake_data().await?;
1283-
match data.downcast::<iroh_quinn::crypto::rustls::HandshakeData>() {
1282+
match data.downcast::<quinn::crypto::rustls::HandshakeData>() {
12841283
Ok(data) => match data.protocol {
12851284
Some(protocol) => std::string::String::from_utf8(protocol).map_err(Into::into),
12861285
None => anyhow::bail!("no ALPN protocol available"),
@@ -1289,7 +1288,7 @@ pub async fn get_alpn(connecting: &mut iroh_quinn::Connecting) -> anyhow::Result
12891288
}
12901289
}
12911290

1292-
pub fn get_remote_node_id(connection: &iroh_quinn::Connection) -> anyhow::Result<iroh::NodeId> {
1291+
pub fn get_remote_node_id(connection: &quinn::Connection) -> anyhow::Result<iroh::NodeId> {
12931292
let data = connection.peer_identity();
12941293
match data {
12951294
None => anyhow::bail!("no peer certificate found"),
@@ -1301,7 +1300,7 @@ pub fn get_remote_node_id(connection: &iroh_quinn::Connection) -> anyhow::Result
13011300
certs.len()
13021301
);
13031302
}
1304-
let cert = tls::certificate::parse(&certs[0])?;
1303+
let cert = tls_utils::certificate::parse(&certs[0])?;
13051304
Ok(cert.peer_id())
13061305
}
13071306
Err(_) => anyhow::bail!("invalid peer certificate"),

content-discovery/tls/Cargo.toml

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)