Skip to content

feat: update to [email protected] #3274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 31 additions & 41 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ unexpected_cfgs = { level = "warn", check-cfg = ["cfg(iroh_docsrs)", "cfg(iroh_l

[workspace.lints.clippy]
unused-async = "warn"

[patch.crates-io]
tokio-rustls-acme = { git = "https://github.com/n0-computer/tokio-rustls-acme", branch = "feat-axum-8" }
8 changes: 4 additions & 4 deletions iroh-dns-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ readme = "README.md"
[dependencies]
anyhow = "1.0.80"
async-trait = "0.1.77"
axum = { version = "0.7", features = ["macros"] }
axum = { version = "0.8", features = ["macros"] }
axum-server = { version = "0.7", features = ["tls-rustls-no-provider"] }
base64-url = "3.0"
bytes = "1.7"
Expand All @@ -24,7 +24,7 @@ derive_more = { version = "1.0.0", features = [
"from",
] }
dirs-next = "2.0.0"
governor = "0.6.3" #needs new release of tower_governor for 0.7.0
governor = "0.8"
hickory-server = { version = "0.25.1", features = ["https-ring"] }
http = "1.0.0"
humantime-serde = "1.1.1"
Expand All @@ -45,12 +45,12 @@ tokio-rustls = { version = "0.26", default-features = false, features = [
"logging",
"ring",
] }
tokio-rustls-acme = { version = "0.6", features = ["axum"] }
tokio-rustls-acme = { version = "0.7", features = ["axum"] }
tokio-stream = "0.1.14"
tokio-util = "0.7"
toml = "0.8.10"
tower-http = { version = "0.6.1", features = ["cors", "trace"] }
tower_governor = "0.4"
tower_governor = "0.7"
tracing = "0.1"
tracing-subscriber = "0.3.18"
ttl_cache = "0.5.1"
Expand Down
2 changes: 1 addition & 1 deletion iroh-dns-server/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub(crate) fn create_app(state: AppState, rate_limit_config: &RateLimitConfig) -
let router = Router::new()
.route("/dns-query", get(doh::get).post(doh::post))
.route(
"/pkarr/:key",
"/pkarr/{key}",
if let Some(rate_limit) = rate_limit {
get(pkarr::get).put(pkarr::put.layer(rate_limit))
} else {
Expand Down
63 changes: 37 additions & 26 deletions iroh-dns-server/src/http/doh/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

use std::{
fmt::{self, Display, Formatter},
future::Future,
net::SocketAddr,
str::FromStr,
};

use async_trait::async_trait;
use axum::{
body::Body,
extract::{ConnectInfo, FromRequest, FromRequestParts, Query},
http::Request,
};
Expand Down Expand Up @@ -98,53 +99,63 @@ pub struct DnsRequestQuery(pub(crate) DNSRequest, pub(crate) DnsMimeType);
#[derive(Debug)]
pub struct DnsRequestBody(pub(crate) DNSRequest);

#[async_trait]
impl<S> FromRequestParts<S> for DnsRequestQuery
where
S: Send + Sync,
{
type Rejection = AppError;

async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
let ConnectInfo(src_addr) = ConnectInfo::from_request_parts(parts, state).await?;

match parts.headers.get(header::ACCEPT) {
Some(content_type) if content_type == "application/dns-message" => {
handle_dns_message_query(parts, state, src_addr).await
}
Some(content_type) if content_type == "application/dns-json" => {
handle_dns_json_query(parts, state, src_addr).await
#[allow(clippy::manual_async_fn)]
fn from_request_parts(
parts: &mut Parts,
state: &S,
) -> impl Future<Output = Result<Self, Self::Rejection>> + Send {
async move {
let ConnectInfo(src_addr) = ConnectInfo::from_request_parts(parts, state).await?;

match parts.headers.get(header::ACCEPT) {
Some(content_type) if content_type == "application/dns-message" => {
handle_dns_message_query(parts, state, src_addr).await
}
Some(content_type) if content_type == "application/dns-json" => {
handle_dns_json_query(parts, state, src_addr).await
}
Some(content_type) if content_type == "application/x-javascript" => {
handle_dns_json_query(parts, state, src_addr).await
}
None => handle_dns_message_query(parts, state, src_addr).await,
_ => Err(AppError::with_status(StatusCode::NOT_ACCEPTABLE)),
}
Some(content_type) if content_type == "application/x-javascript" => {
handle_dns_json_query(parts, state, src_addr).await
}
None => handle_dns_message_query(parts, state, src_addr).await,
_ => Err(AppError::with_status(StatusCode::NOT_ACCEPTABLE)),
}
}
}

#[async_trait]
impl<S> FromRequest<S> for DnsRequestBody
where
S: Send + Sync,
{
type Rejection = AppError;

async fn from_request(req: axum::extract::Request, state: &S) -> Result<Self, Self::Rejection> {
let (mut parts, body) = req.into_parts();
#[allow(clippy::manual_async_fn)]
fn from_request(
req: Request<Body>,
state: &S,
) -> impl Future<Output = Result<Self, Self::Rejection>> + Send {
async move {
let (mut parts, body) = req.into_parts();

let ConnectInfo(src_addr) = ConnectInfo::from_request_parts(&mut parts, state).await?;
let ConnectInfo(src_addr) = ConnectInfo::from_request_parts(&mut parts, state).await?;

let req = Request::from_parts(parts, body);
let req = Request::from_parts(parts, body);

let body = Bytes::from_request(req, state)
.await
.map_err(|_| AppError::with_status(StatusCode::INTERNAL_SERVER_ERROR))?;
let body = Bytes::from_request(req, state)
.await
.map_err(|_| AppError::with_status(StatusCode::INTERNAL_SERVER_ERROR))?;

let request = decode_request(&body, src_addr)?;
let request = decode_request(&body, src_addr)?;

Ok(DnsRequestBody(request))
Ok(DnsRequestBody(request))
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion iroh-relay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ rustls-cert-reloadable-resolver = { version = "0.7.1", optional = true }
rustls-cert-file-reader = { version = "0.4.1", optional = true }
rustls-pemfile = { version = "2.1", optional = true }
time = { version = "0.3.37", optional = true }
tokio-rustls-acme = { version = "0.6", optional = true }
tokio-rustls-acme = { version = "0.7", optional = true }
tokio-websockets = { version = "0.11.3", features = ["rustls-bring-your-own-connector", "ring", "getrandom", "rand", "server"], optional = true } # server-side websocket implementation
toml = { version = "0.8", optional = true }
tracing-subscriber = { version = "0.3", features = [
Expand Down
4 changes: 2 additions & 2 deletions iroh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ swarm-discovery = { version = "0.3.1", optional = true }
futures-util = "0.3"

# test_utils
axum = { version = "0.7", optional = true }
axum = { version = "0.8", optional = true }

# Examples
clap = { version = "4", features = ["derive"], optional = true }
Expand Down Expand Up @@ -132,7 +132,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }

# *non*-wasm-in-browser test/dev dependencies
[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dev-dependencies]
axum = { version = "0.7" }
axum = { version = "0.8" }
clap = { version = "4", features = ["derive"] }
futures-lite = "2.6"
pretty_assertions = "1.4"
Expand Down
2 changes: 1 addition & 1 deletion iroh/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ pub(crate) mod pkarr_relay {
pub async fn run_pkarr_relay(state: AppState) -> Result<(Url, CleanupDropGuard)> {
let bind_addr = SocketAddr::from((Ipv4Addr::LOCALHOST, 0));
let app = Router::new()
.route("/pkarr/:key", put(pkarr_put))
.route("/pkarr/{key}", put(pkarr_put))
.with_state(state);
let listener = tokio::net::TcpListener::bind(bind_addr).await?;
let bound_addr = listener.local_addr()?;
Expand Down
Loading