Skip to content

Commit 4d23e36

Browse files
authored
iroh-net transport (#105)
2 parents 8e323b5 + 6672560 commit 4d23e36

File tree

8 files changed

+4462
-423
lines changed

8 files changed

+4462
-423
lines changed

Cargo.lock

Lines changed: 3487 additions & 421 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ futures-lite = "2.3.0"
2121
futures-sink = "0.3.30"
2222
futures-util = { version = "0.3.30", features = ["sink"] }
2323
hyper = { version = "0.14.16", features = ["full"], optional = true }
24+
iroh-net = { version = "0.28.1", optional = true }
2425
pin-project = "1"
2526
quinn = { package = "iroh-quinn", version = "0.12", optional = true }
2627
serde = { version = "1.0.183", features = ["derive"] }
@@ -56,6 +57,7 @@ nested_enum_utils = "0.1.0"
5657
hyper-transport = ["dep:flume", "dep:hyper", "dep:bincode", "dep:bytes", "dep:tokio-serde", "dep:tokio-util"]
5758
quinn-transport = ["dep:flume", "dep:quinn", "dep:bincode", "dep:tokio-serde", "dep:tokio-util"]
5859
flume-transport = ["dep:flume"]
60+
iroh-net-transport = ["dep:iroh-net", "dep:flume", "dep:quinn", "dep:bincode", "dep:tokio-serde", "dep:tokio-util"]
5961
macros = []
6062
default = ["flume-transport"]
6163

src/transport/boxed.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,50 @@ impl<In: RpcMessage, Out: RpcMessage> BoxableListener<In, Out>
398398
}
399399
}
400400

401+
#[cfg(feature = "iroh-net-transport")]
402+
impl<In: RpcMessage, Out: RpcMessage> BoxableConnector<In, Out>
403+
for super::iroh_net::IrohNetConnector<In, Out>
404+
{
405+
fn clone_box(&self) -> Box<dyn BoxableConnector<In, Out>> {
406+
Box::new(self.clone())
407+
}
408+
409+
fn open_boxed(&self) -> OpenFuture<In, Out> {
410+
let f = Box::pin(async move {
411+
let (send, recv) = super::Connector::open(self).await?;
412+
// map the error types to anyhow
413+
let send = send.sink_map_err(anyhow::Error::from);
414+
let recv = recv.map_err(anyhow::Error::from);
415+
// return the boxed streams
416+
anyhow::Ok((SendSink::boxed(send), RecvStream::boxed(recv)))
417+
});
418+
OpenFuture::boxed(f)
419+
}
420+
}
421+
422+
#[cfg(feature = "iroh-net-transport")]
423+
impl<In: RpcMessage, Out: RpcMessage> BoxableListener<In, Out>
424+
for super::iroh_net::IrohNetListener<In, Out>
425+
{
426+
fn clone_box(&self) -> Box<dyn BoxableListener<In, Out>> {
427+
Box::new(self.clone())
428+
}
429+
430+
fn accept_bi_boxed(&self) -> AcceptFuture<In, Out> {
431+
let f = async move {
432+
let (send, recv) = super::Listener::accept(self).await?;
433+
let send = send.sink_map_err(anyhow::Error::from);
434+
let recv = recv.map_err(anyhow::Error::from);
435+
anyhow::Ok((SendSink::boxed(send), RecvStream::boxed(recv)))
436+
};
437+
AcceptFuture::boxed(f)
438+
}
439+
440+
fn local_addr(&self) -> &[super::LocalAddr] {
441+
super::Listener::local_addr(self)
442+
}
443+
}
444+
401445
#[cfg(feature = "flume-transport")]
402446
impl<In: RpcMessage, Out: RpcMessage> BoxableConnector<In, Out>
403447
for super::flume::FlumeConnector<In, Out>

0 commit comments

Comments
 (0)