Skip to content

Commit 16bc7fe

Browse files
refactor: extract ProtocolHandler impl into here
1 parent 6b2c973 commit 16bc7fe

File tree

5 files changed

+66
-12
lines changed

5 files changed

+66
-12
lines changed

Cargo.lock

+24-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+9-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ iroh-blobs = { version = "0.27.0", optional = true, features = ["downloader"] }
4040
iroh-gossip = { version = "0.27.0", optional = true }
4141
iroh-metrics = { version = "0.27.0", default-features = false }
4242
iroh-net = { version = "0.27.0", optional = true }
43+
iroh-router = { version = "0.27.0", optional = true }
4344
lru = "0.12"
4445
num_enum = "0.7"
4546
postcard = { version = "1", default-features = false, features = ["alloc", "use-std", "experimental-derive"] }
@@ -69,8 +70,15 @@ test-strategy = "0.3.1"
6970
default = ["net", "metrics", "engine"]
7071
net = ["dep:iroh-net", "tokio/io-util", "dep:tokio-stream", "dep:tokio-util"]
7172
metrics = ["iroh-metrics/metrics"]
72-
engine = ["net", "dep:iroh-gossip", "dep:iroh-blobs"]
73+
engine = ["net", "dep:iroh-gossip", "dep:iroh-blobs", "dep:iroh-router"]
7374

7475
[package.metadata.docs.rs]
7576
all-features = true
7677
rustdoc-args = ["--cfg", "iroh_docsrs"]
78+
79+
[patch.crates-io]
80+
iroh-router = { git = "https://github.com/n0-computer/iroh", branch = "main" }
81+
iroh-net = { git = "https://github.com/n0-computer/iroh", branch = "main" }
82+
iroh-metrics = { git = "https://github.com/n0-computer/iroh", branch = "main" }
83+
iroh-base = { git = "https://github.com/n0-computer/iroh", branch = "main" }
84+
iroh-blobs = { git = "https://github.com/n0-computer/iroh-blobs", branch = "main" }

deny.toml

+6
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@ license-files = [
3434
ignore = [
3535
"RUSTSEC-2024-0370", # unmaintained, no upgrade available
3636
]
37+
38+
[sources]
39+
allow-git = [
40+
"https://github.com/n0-computer/iroh.git",
41+
"https://github.com/n0-computer/iroh-blobs.git",
42+
]

src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ pub mod metrics;
3838
#[cfg(feature = "net")]
3939
#[cfg_attr(iroh_docsrs, doc(cfg(feature = "net")))]
4040
pub mod net;
41+
#[cfg(feature = "engine")]
42+
#[cfg_attr(iroh_docsrs, doc(cfg(feature = "engine")))]
43+
pub mod protocol;
4144
#[cfg(feature = "net")]
4245
#[cfg_attr(iroh_docsrs, doc(cfg(feature = "net")))]
4346
mod ticket;

src/protocol.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//! [`ProtocolHandler`] implementation for the docs [`Engine`].
2+
3+
use std::sync::Arc;
4+
5+
use anyhow::Result;
6+
use futures_lite::future::Boxed as BoxedFuture;
7+
use iroh_net::endpoint::Connecting;
8+
use iroh_router::ProtocolHandler;
9+
10+
use crate::engine::Engine;
11+
12+
impl ProtocolHandler for Engine {
13+
fn accept(self: Arc<Self>, conn: Connecting) -> BoxedFuture<Result<()>> {
14+
Box::pin(async move { self.handle_connection(conn).await })
15+
}
16+
17+
fn shutdown(self: Arc<Self>) -> BoxedFuture<()> {
18+
Box::pin(async move {
19+
if let Err(err) = (*self).shutdown().await {
20+
tracing::warn!("shutdown error: {:?}", err);
21+
}
22+
})
23+
}
24+
}

0 commit comments

Comments
 (0)