Skip to content
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

refactor: extract ProtocolHandler impl into here #3

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
35 changes: 24 additions & 11 deletions Cargo.lock

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

10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down Expand Up @@ -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" }
6 changes: 6 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions src/protocol.rs
Original file line number Diff line number Diff line change
@@ -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<Self>, conn: Connecting) -> BoxedFuture<Result<()>> {
Box::pin(async move { self.handle_connection(conn).await })
}

fn shutdown(self: Arc<Self>) -> BoxedFuture<()> {
Box::pin(async move {
if let Err(err) = (*self).shutdown().await {
tracing::warn!("shutdown error: {:?}", err);
}
})
}
}
Loading