Skip to content

Commit

Permalink
iroh-net transport (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
rklaehn authored Nov 11, 2024
2 parents 8e323b5 + 6672560 commit 4d23e36
Show file tree
Hide file tree
Showing 8 changed files with 4,462 additions and 423 deletions.
3,908 changes: 3,487 additions & 421 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ futures-lite = "2.3.0"
futures-sink = "0.3.30"
futures-util = { version = "0.3.30", features = ["sink"] }
hyper = { version = "0.14.16", features = ["full"], optional = true }
iroh-net = { version = "0.28.1", optional = true }
pin-project = "1"
quinn = { package = "iroh-quinn", version = "0.12", optional = true }
serde = { version = "1.0.183", features = ["derive"] }
Expand Down Expand Up @@ -56,6 +57,7 @@ nested_enum_utils = "0.1.0"
hyper-transport = ["dep:flume", "dep:hyper", "dep:bincode", "dep:bytes", "dep:tokio-serde", "dep:tokio-util"]
quinn-transport = ["dep:flume", "dep:quinn", "dep:bincode", "dep:tokio-serde", "dep:tokio-util"]
flume-transport = ["dep:flume"]
iroh-net-transport = ["dep:iroh-net", "dep:flume", "dep:quinn", "dep:bincode", "dep:tokio-serde", "dep:tokio-util"]
macros = []
default = ["flume-transport"]

Expand Down
44 changes: 44 additions & 0 deletions src/transport/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,50 @@ impl<In: RpcMessage, Out: RpcMessage> BoxableListener<In, Out>
}
}

#[cfg(feature = "iroh-net-transport")]
impl<In: RpcMessage, Out: RpcMessage> BoxableConnector<In, Out>
for super::iroh_net::IrohNetConnector<In, Out>
{
fn clone_box(&self) -> Box<dyn BoxableConnector<In, Out>> {
Box::new(self.clone())
}

fn open_boxed(&self) -> OpenFuture<In, Out> {
let f = Box::pin(async move {
let (send, recv) = super::Connector::open(self).await?;
// map the error types to anyhow
let send = send.sink_map_err(anyhow::Error::from);
let recv = recv.map_err(anyhow::Error::from);
// return the boxed streams
anyhow::Ok((SendSink::boxed(send), RecvStream::boxed(recv)))
});
OpenFuture::boxed(f)
}
}

#[cfg(feature = "iroh-net-transport")]
impl<In: RpcMessage, Out: RpcMessage> BoxableListener<In, Out>
for super::iroh_net::IrohNetListener<In, Out>
{
fn clone_box(&self) -> Box<dyn BoxableListener<In, Out>> {
Box::new(self.clone())
}

fn accept_bi_boxed(&self) -> AcceptFuture<In, Out> {
let f = async move {
let (send, recv) = super::Listener::accept(self).await?;
let send = send.sink_map_err(anyhow::Error::from);
let recv = recv.map_err(anyhow::Error::from);
anyhow::Ok((SendSink::boxed(send), RecvStream::boxed(recv)))
};
AcceptFuture::boxed(f)
}

fn local_addr(&self) -> &[super::LocalAddr] {
super::Listener::local_addr(self)
}
}

#[cfg(feature = "flume-transport")]
impl<In: RpcMessage, Out: RpcMessage> BoxableConnector<In, Out>
for super::flume::FlumeConnector<In, Out>
Expand Down
Loading

0 comments on commit 4d23e36

Please sign in to comment.