diff --git a/Cargo.lock b/Cargo.lock index 1e88159..10ac6b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1609,8 +1609,7 @@ checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" [[package]] name = "iroh-base" version = "0.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28a777d7e0b3e2fdab4ad1b21b64be87a43ac3ceb2a2ccef905e480ad3317396" +source = "git+https://github.com/n0-computer/iroh?branch=main#30f3e03cde8a58af3b84a5f11134fb970ec3efa1" dependencies = [ "aead", "anyhow", @@ -1627,7 +1626,6 @@ dependencies = [ "rand_core", "redb 2.1.4", "serde", - "serde-error", "ssh-key", "thiserror", "ttl_cache", @@ -1651,8 +1649,7 @@ dependencies = [ [[package]] name = "iroh-blobs" version = "0.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69e83475d6c8cc312a224d4c6bdf287f862d30d2b176768ef71f188a0d8aa7cd" +source = "git+https://github.com/n0-computer/iroh-blobs?branch=main#378fc0fd8257c0beeb3a655a8378226a630b2d73" dependencies = [ "anyhow", "async-channel", @@ -1670,6 +1667,7 @@ dependencies = [ "iroh-metrics", "iroh-net", "iroh-quinn", + "iroh-router", "num_cpus", "oneshot", "parking_lot", @@ -1682,6 +1680,7 @@ dependencies = [ "reflink-copy", "self_cell", "serde", + "serde-error", "smallvec", "tempfile", "thiserror", @@ -1710,6 +1709,7 @@ dependencies = [ "iroh-gossip", "iroh-metrics", "iroh-net", + "iroh-router", "iroh-test", "lru", "num_enum", @@ -1776,8 +1776,7 @@ dependencies = [ [[package]] name = "iroh-metrics" version = "0.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c78cf30022e1c7a10fc0ae0a6ba83f131b7c3b92d4876f6c97aba93fe534be6" +source = "git+https://github.com/n0-computer/iroh?branch=main#30f3e03cde8a58af3b84a5f11134fb970ec3efa1" dependencies = [ "anyhow", "erased_set", @@ -1797,8 +1796,7 @@ dependencies = [ [[package]] name = "iroh-net" version = "0.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34192d8846fc59d6669fb80a485b430215ecc1bf3c2b9df4f8a92370fe37e13a" +source = "git+https://github.com/n0-computer/iroh?branch=main#30f3e03cde8a58af3b84a5f11134fb970ec3efa1" dependencies = [ "anyhow", "backoff", @@ -1920,6 +1918,21 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "iroh-router" +version = "0.27.0" +source = "git+https://github.com/n0-computer/iroh?branch=main#30f3e03cde8a58af3b84a5f11134fb970ec3efa1" +dependencies = [ + "anyhow", + "futures-buffered", + "futures-lite 2.3.0", + "futures-util", + "iroh-net", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "iroh-test" version = "0.27.0" @@ -3535,9 +3548,9 @@ dependencies = [ [[package]] name = "serde-error" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e988182713aeed6a619a88bca186f6d6407483485ffe44c869ee264f8eabd13f" +checksum = "342110fb7a5d801060c885da03bf91bfa7c7ca936deafcc64bb6706375605d47" dependencies = [ "serde", ] diff --git a/Cargo.toml b/Cargo.toml index 544d40d..b6e8315 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,7 @@ iroh-blobs = { version = "0.27.0", optional = true, features = ["downloader"] } iroh-gossip = { version = "0.27.0", optional = true } iroh-metrics = { version = "0.27.0", default-features = false } iroh-net = { version = "0.27.0", optional = true } +iroh-router = { version = "0.27.0", optional = true } lru = "0.12" num_enum = "0.7" postcard = { version = "1", default-features = false, features = ["alloc", "use-std", "experimental-derive"] } @@ -69,8 +70,15 @@ test-strategy = "0.3.1" default = ["net", "metrics", "engine"] net = ["dep:iroh-net", "tokio/io-util", "dep:tokio-stream", "dep:tokio-util"] metrics = ["iroh-metrics/metrics"] -engine = ["net", "dep:iroh-gossip", "dep:iroh-blobs"] +engine = ["net", "dep:iroh-gossip", "dep:iroh-blobs", "dep:iroh-router"] [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "iroh_docsrs"] + +[patch.crates-io] +iroh-router = { git = "https://github.com/n0-computer/iroh", branch = "main" } +iroh-net = { git = "https://github.com/n0-computer/iroh", branch = "main" } +iroh-metrics = { git = "https://github.com/n0-computer/iroh", branch = "main" } +iroh-base = { git = "https://github.com/n0-computer/iroh", branch = "main" } +iroh-blobs = { git = "https://github.com/n0-computer/iroh-blobs", branch = "main" } diff --git a/deny.toml b/deny.toml index 7db03d1..310d8bd 100644 --- a/deny.toml +++ b/deny.toml @@ -34,3 +34,9 @@ license-files = [ ignore = [ "RUSTSEC-2024-0370", # unmaintained, no upgrade available ] + +[sources] +allow-git = [ + "https://github.com/n0-computer/iroh.git", + "https://github.com/n0-computer/iroh-blobs.git", +] diff --git a/src/lib.rs b/src/lib.rs index b7bac5f..63702b3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,6 +38,9 @@ pub mod metrics; #[cfg(feature = "net")] #[cfg_attr(iroh_docsrs, doc(cfg(feature = "net")))] pub mod net; +#[cfg(feature = "engine")] +#[cfg_attr(iroh_docsrs, doc(cfg(feature = "engine")))] +pub mod protocol; #[cfg(feature = "net")] #[cfg_attr(iroh_docsrs, doc(cfg(feature = "net")))] mod ticket; diff --git a/src/protocol.rs b/src/protocol.rs new file mode 100644 index 0000000..18bccc5 --- /dev/null +++ b/src/protocol.rs @@ -0,0 +1,24 @@ +//! [`ProtocolHandler`] implementation for the docs [`Engine`]. + +use std::sync::Arc; + +use anyhow::Result; +use futures_lite::future::Boxed as BoxedFuture; +use iroh_net::endpoint::Connecting; +use iroh_router::ProtocolHandler; + +use crate::engine::Engine; + +impl ProtocolHandler for Engine { + fn accept(self: Arc, conn: Connecting) -> BoxedFuture> { + Box::pin(async move { self.handle_connection(conn).await }) + } + + fn shutdown(self: Arc) -> BoxedFuture<()> { + Box::pin(async move { + if let Err(err) = (*self).shutdown().await { + tracing::warn!("shutdown error: {:?}", err); + } + }) + } +}