Skip to content

Commit c7cce20

Browse files
matheus23Frandorklaehn“ramfox”
authored
feat!: Switch from anyhow and thiserror to n0-error (#78)
- Switches all uses of `thiserror` in `irpc` and `irpc-iroh` to use `n0-error` - keeps `anyhow` dependency for examples - Adjusts to the new 0-RTT and `ProtocolHandler` apis --------- Co-authored-by: Frando <[email protected]> Co-authored-by: Ruediger Klaehn <[email protected]> Co-authored-by: “ramfox” <“[email protected]”>
1 parent 6f0dec7 commit c7cce20

File tree

10 files changed

+551
-520
lines changed

10 files changed

+551
-520
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ tokio = { workspace = true, features = ["sync", "macros"] }
2323
# for PollSender (which for some reason is not available in the main tokio api)
2424
tokio-util = { version = "0.7.14", default-features = false }
2525
# errors
26-
thiserror = "2.0.12"
26+
n0-error = { workspace = true }
2727

2828
# used in the endpoint handler code when using rpc
2929
tracing = { workspace = true, optional = true }
@@ -37,8 +37,6 @@ smallvec = { version = "1.14.0", features = ["write"], optional = true }
3737
rustls = { version = "0.23.5", default-features = false, features = ["std"], optional = true }
3838
# used in the test utils to generate quinn endpoints
3939
rcgen = { version = "0.14.5", optional = true }
40-
# used in the test utils to generate quinn endpoints
41-
anyhow = { workspace = true, optional = true }
4240
# used in the benches
4341
futures-buffered ={ version = "0.2.9", optional = true }
4442
# for AbortOnDropHandle
@@ -61,12 +59,14 @@ thousands = "0.2.0"
6159
# macro tests
6260
trybuild = "1.0.104"
6361
testresult = "0.4.1"
62+
# used in examples
63+
anyhow = { workspace = true }
6464

6565
[features]
6666
# enable the remote transport
67-
rpc = ["dep:quinn", "dep:postcard", "dep:anyhow", "dep:smallvec", "dep:tracing", "tokio/io-util"]
67+
rpc = ["dep:quinn", "dep:postcard", "dep:smallvec", "dep:tracing", "tokio/io-util"]
6868
# add test utilities
69-
quinn_endpoint_setup = ["rpc", "dep:rustls", "dep:rcgen", "dep:anyhow", "dep:futures-buffered", "quinn/rustls-ring"]
69+
quinn_endpoint_setup = ["rpc", "dep:rustls", "dep:rcgen", "dep:futures-buffered", "quinn/rustls-ring"]
7070
# pick up parent span when creating channel messages
7171
spans = ["dep:tracing"]
7272
stream = ["dep:futures-util"]
@@ -101,14 +101,15 @@ rustdoc-args = ["--cfg", "quicrpc_docsrs"]
101101
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(quicrpc_docsrs)"] }
102102

103103
[workspace.dependencies]
104-
anyhow = { version = "1.0.98" }
104+
anyhow = { version = "1" }
105105
tokio = { version = "1.44", default-features = false }
106106
postcard = { version = "1.1.1", default-features = false }
107107
serde = { version = "1", default-features = false, features = ["derive"] }
108108
tracing = { version = "0.1.41", default-features = false }
109109
n0-future = { version = "0.3", default-features = false }
110+
n0-error = { version = "0.1.0" }
110111
tracing-subscriber = { version = "0.3.20" }
111-
iroh = { version = "0.94" }
112-
iroh-base = { version = "0.94" }
112+
iroh = { version = "0.95" }
113+
iroh-base = { version = "0.95" }
113114
quinn = { package = "iroh-quinn", version = "0.14.0", default-features = false }
114115
futures-util = { version = "0.3", features = ["sink"] }

irpc-iroh/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ description = "Iroh transport for irpc"
1313
crate-type = ["cdylib", "rlib"]
1414

1515
[dependencies]
16-
anyhow = { workspace = true }
1716
iroh = { workspace = true }
1817
tokio = { workspace = true, features = ["sync"] }
1918
tracing = { workspace = true }
2019
serde = { workspace = true }
2120
postcard = { workspace = true, features = ["alloc", "use-std"] }
21+
n0-error = { workspace = true }
2222
n0-future = { workspace = true }
2323
irpc = { version = "0.10.0", path = ".." }
2424
iroh-base.workspace = true
@@ -34,3 +34,4 @@ clap = { version = "4.5.41", features = ["derive"] }
3434
futures-util.workspace = true
3535
hex = "0.4.3"
3636
rand = "0.9.2"
37+
anyhow = { workspace = true }

irpc-iroh/examples/0rtt.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ mod cli {
187187

188188
mod ping {
189189
use anyhow::{Context, Result};
190-
use futures_util::FutureExt;
191190
use iroh::Endpoint;
192191
use irpc::{channel::oneshot, rpc::RemoteService, rpc_requests, Client, WithChannels};
193-
use irpc_iroh::{Iroh0RttProtocol, IrohProtocol, IrohRemoteConnection};
194-
use n0_future::future;
192+
use irpc_iroh::{
193+
Iroh0RttProtocol, IrohProtocol, IrohRemoteConnection, IrohZrttRemoteConnection,
194+
};
195195
use serde::{Deserialize, Serialize};
196196
use tracing::info;
197197

@@ -205,7 +205,6 @@ mod ping {
205205

206206
pub struct EchoApi {
207207
inner: Client<EchoProtocol>,
208-
zero_rtt_accepted: futures_util::future::Shared<future::Boxed<bool>>,
209208
}
210209

211210
impl EchoApi {
@@ -216,9 +215,7 @@ mod ping {
216215
}
217216

218217
pub async fn echo_0rtt(&self, data: Vec<u8>) -> irpc::Result<Vec<u8>> {
219-
self.inner
220-
.rpc_0rtt(Echo { data }, self.zero_rtt_accepted.clone())
221-
.await
218+
self.inner.rpc_0rtt(Echo { data }).await
222219
}
223220

224221
pub fn expose_0rtt(self) -> Result<Iroh0RttProtocol<EchoProtocol>> {
@@ -245,10 +242,8 @@ mod ping {
245242
.connect(addr, Self::ALPN)
246243
.await
247244
.context("failed to connect to remote service")?;
248-
let fut: future::Boxed<bool> = Box::pin(async { true });
249245
Ok(EchoApi {
250246
inner: Client::boxed(IrohRemoteConnection::new(conn)),
251-
zero_rtt_accepted: fut.shared(),
252247
})
253248
}
254249

@@ -261,21 +256,17 @@ mod ping {
261256
.await
262257
.context("failed to connect to remote service")?;
263258
match connecting.into_0rtt() {
264-
Ok((conn, zero_rtt_accepted)) => {
259+
Ok(conn) => {
265260
info!("0-RTT possible from our side");
266-
let fut: future::Boxed<bool> = Box::pin(zero_rtt_accepted);
267261
Ok(EchoApi {
268-
inner: Client::boxed(IrohRemoteConnection::new(conn)),
269-
zero_rtt_accepted: fut.shared(),
262+
inner: Client::boxed(IrohZrttRemoteConnection::new(conn)),
270263
})
271264
}
272265
Err(connecting) => {
273266
info!("0-RTT not possible from our side");
274-
let fut: future::Boxed<bool> = Box::pin(async { true });
275267
let conn = connecting.await?;
276268
Ok(EchoApi {
277269
inner: Client::boxed(IrohRemoteConnection::new(conn)),
278-
zero_rtt_accepted: fut.shared(),
279270
})
280271
}
281272
}
@@ -295,10 +286,8 @@ mod ping {
295286
let (tx, rx) = tokio::sync::mpsc::channel(1);
296287
let actor = Self { recv: rx };
297288
n0_future::task::spawn(actor.run());
298-
let fut: future::Boxed<bool> = Box::pin(async { true });
299289
EchoApi {
300290
inner: Client::local(tx),
301-
zero_rtt_accepted: fut.shared(),
302291
}
303292
}
304293

0 commit comments

Comments
 (0)