Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions h3-iroh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ license = "MIT"

[dependencies]
anyhow = { version = "1", optional = true }
axum = { version = "0.7", optional = true }
axum = { version = "0.8", optional = true }
bytes = "1"
futures = "0.3"
h3 = { version = "0.0.6", features = ["tracing"] }
h3 = { version = "0.0.8", features = ["tracing"] }
http = { version = "1.1", optional = true }
http-body = { version = "1", optional = true }
http-body-util = { version = "0.1", optional = true }
hyper = { version = "1.5", optional = true }
hyper-util = { version = "0.1", optional = true }
iroh = "0.93"
iroh-base = { version = "0.93", features = ["ticket"] }
iroh = "0.94"
iroh-tickets = "0.1"
tokio = { version = "1", features = ["io-util"], default-features = false}
tokio-util = "0.7"
tower = { version = "0.5", optional = true }
Expand Down
21 changes: 15 additions & 6 deletions h3-iroh/examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::{future, str::FromStr};

use anyhow::{bail, Context, Result};
use clap::Parser;
use iroh::NodeAddr;
use iroh_base::ticket::NodeTicket;
use iroh::EndpointAddr;
use iroh_tickets::endpoint::EndpointTicket;
use tokio::io::AsyncWriteExt;
use tracing::info;

Expand All @@ -27,8 +27,8 @@ async fn main() -> Result<()> {
bail!("URI scheme must be iroh+h3");
}
let ticket = uri.host().context("missing hostname in URI")?;
let ticket = NodeTicket::from_str(ticket)?;
let addr: NodeAddr = ticket.into();
let ticket = EndpointTicket::from_str(ticket)?;
let addr: EndpointAddr = ticket.into();

let ep = iroh::Endpoint::builder()
.keylog(args.keylogfile)
Expand All @@ -41,8 +41,17 @@ async fn main() -> Result<()> {
let (mut driver, mut send_request) = h3::client::new(conn).await?;

let drive_fut = async move {
future::poll_fn(|cx| driver.poll_close(cx)).await?;
Ok::<(), anyhow::Error>(())
let err = future::poll_fn(|cx| driver.poll_close(cx)).await;
match err {
h3::error::ConnectionError::Local { ref error, .. } => {
if matches!(error, h3::error::LocalError::Closing { .. }) {
Ok(())
} else {
Err(err)
}
}
_ => Err(err),
}
};

let req_fut = async move {
Expand Down
33 changes: 19 additions & 14 deletions h3-iroh/examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use std::{path::PathBuf, sync::Arc};
use anyhow::{bail, Result};
use bytes::{Bytes, BytesMut};
use clap::Parser;
use h3::{error::ErrorLevel, quic::BidiStream, server::RequestStream};
use h3::{quic::BidiStream, server::RequestStream};
use http::{Request, StatusCode};
use iroh::endpoint::Incoming;
use iroh_base::ticket::NodeTicket;
use iroh_tickets::endpoint::EndpointTicket;
use tokio::{fs::File, io::AsyncReadExt};
use tracing::{debug, error, field, info, info_span, Instrument, Span};

Expand Down Expand Up @@ -47,12 +47,12 @@ async fn main() -> Result<()> {
.alpns(vec![b"iroh+h3".to_vec()])
.bind()
.await?;
info!("accepting connections on node: {}", ep.node_id());
info!("accepting connections on endpoint: {}", ep.id());

// Wait for direct addresses and a RelayUrl before printing a NodeTicket.
// Wait for direct addresses and a RelayUrl before printing a EndpointTicket.
ep.online().await;
let ticket = NodeTicket::new(ep.node_addr());
info!("node ticket: {ticket}");
let ticket = EndpointTicket::new(ep.addr());
info!("endpoint ticket: {ticket}");
info!("run e.g.: cargo run --example client -- iroh+h3://{ticket}/Cargo.toml");

// Handle incoming connections
Expand All @@ -64,7 +64,7 @@ async fn main() -> Result<()> {
error!("failed connection: {err:#}");
}
}
.instrument(info_span!("conn", remote_node_id = field::Empty))
.instrument(info_span!("conn", remote_endpoint_id = field::Empty))
});
}
ep.close().await;
Expand All @@ -74,15 +74,19 @@ async fn main() -> Result<()> {

async fn handle_connection(incoming: Incoming, root: Arc<Option<PathBuf>>) -> Result<()> {
let conn = incoming.accept()?.await?;
let remote_node_id = conn.remote_node_id()?;
let remote_endpoint_id = conn.remote_id()?;
let span = Span::current();
span.record("remote_node_id", remote_node_id.fmt_short().to_string());
span.record(
"remote_endpoint_id",
remote_endpoint_id.fmt_short().to_string(),
);
info!("new connection");

let mut h3_conn = h3::server::Connection::new(h3_iroh::Connection::new(conn)).await?;
loop {
match h3_conn.accept().await {
Ok(Some((req, stream))) => {
Ok(Some(req_resolver)) => {
let (req, stream) = req_resolver.resolve_request().await?;
info!(?req, "new request");
tokio::spawn({
let root = root.clone();
Expand All @@ -99,10 +103,11 @@ async fn handle_connection(incoming: Incoming, root: Arc<Option<PathBuf>>) -> Re
}
Err(err) => {
error!("accept error: {err:#}");
match err.get_error_level() {
ErrorLevel::ConnectionError => break,
ErrorLevel::StreamError => continue,
}
// TODO:
// match err {
// ErrorLevel::ConnectionError => break,
// ErrorLevel::StreamError => continue,
// }
}
}
}
Expand Down
Loading
Loading