Skip to content

Commit 9fe3af5

Browse files
committed
refactor: add rpc feature flag
1 parent f469e50 commit 9fe3af5

File tree

6 files changed

+28
-16
lines changed

6 files changed

+28
-16
lines changed

Cargo.lock

Lines changed: 1 addition & 5 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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ chrono = "0.4.39"
3636
nested_enum_utils = "0.2.1"
3737
ref-cast = "1.0.24"
3838
arrayvec = "0.7.6"
39-
iroh = "0.93"
39+
iroh = { version = "0.93", default-features = false }
4040
self_cell = "1.1.0"
4141
genawaiter = { version = "0.99.1", features = ["futures03"] }
4242
iroh-base = "0.93"
43-
irpc = { version = "0.9.0", features = ["rpc", "quinn_endpoint_setup", "spans", "stream", "derive"], default-features = false }
43+
irpc = { version = "0.9.0", features = ["spans", "stream", "derive", "varint-util"], default-features = false }
4444
iroh-metrics = { version = "0.36" }
4545
redb = { version = "2.6.3", optional = true }
4646
reflink-copy = { version = "0.1.24", optional = true }
@@ -62,9 +62,15 @@ atomic_refcell = "0.1.13"
6262
iroh = { version = "0.93", features = ["discovery-local-network"]}
6363
async-compression = { version = "0.4.30", features = ["lz4", "tokio"] }
6464
concat_const = "0.2.0"
65+
irpc = { version = "0.9.0", features = ["rpc", "quinn_endpoint_setup", "spans", "stream", "derive"], default-features = false }
6566

6667
[features]
6768
hide-proto-docs = []
6869
metrics = []
69-
default = ["hide-proto-docs", "fs-store"]
70+
default = ["hide-proto-docs", "fs-store", "rpc"]
7071
fs-store = ["dep:redb", "dep:reflink-copy"]
72+
rpc = ["irpc/rpc", "irpc/quinn_endpoint_setup"]
73+
74+
[patch.crates-io]
75+
# irpc = { git = "https://github.com/n0-computer/irpc", branch = "Frando/varint-feature" }
76+
irpc = { path = "../irpc" }

src/api.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
//!
1313
//! You can also [`connect`](Store::connect) to a remote store that is listening
1414
//! to rpc requests.
15-
use std::{io, net::SocketAddr, ops::Deref};
15+
use std::{io, ops::Deref};
1616

1717
use bao_tree::io::EncodeError;
1818
use iroh::Endpoint;
19-
use irpc::rpc::{listen, RemoteService};
2019
use n0_snafu::SpanTrace;
2120
use nested_enum_utils::common_fields;
22-
use proto::{Request, ShutdownRequest, SyncDbRequest};
21+
use proto::{ShutdownRequest, SyncDbRequest};
2322
use ref_cast::RefCast;
2423
use serde::{Deserialize, Serialize};
2524
use snafu::{Backtrace, IntoError, Snafu};
@@ -128,6 +127,7 @@ impl From<irpc::Error> for ExportBaoError {
128127
irpc::Error::OneshotRecv(e) => OneshotRecvSnafu.into_error(e),
129128
irpc::Error::Send(e) => SendSnafu.into_error(e),
130129
irpc::Error::Request(e) => RequestSnafu.into_error(e),
130+
#[cfg(feature = "rpc")]
131131
irpc::Error::Write(e) => ExportBaoIoSnafu.into_error(e.into()),
132132
}
133133
}
@@ -220,6 +220,7 @@ impl From<irpc::channel::mpsc::RecvError> for Error {
220220
}
221221
}
222222

223+
#[cfg(feature = "rpc")]
223224
impl From<irpc::rpc::WriteError> for Error {
224225
fn from(e: irpc::rpc::WriteError) -> Self {
225226
Self::Io(e.into())
@@ -298,16 +299,20 @@ impl Store {
298299
}
299300

300301
/// Connect to a remote store as a rpc client.
301-
pub fn connect(endpoint: quinn::Endpoint, addr: SocketAddr) -> Self {
302+
#[cfg(feature = "rpc")]
303+
pub fn connect(endpoint: quinn::Endpoint, addr: std::net::SocketAddr) -> Self {
302304
let sender = irpc::Client::quinn(endpoint, addr);
303305
Store::from_sender(sender)
304306
}
305307

306308
/// Listen on a quinn endpoint for incoming rpc connections.
309+
#[cfg(feature = "rpc")]
307310
pub async fn listen(self, endpoint: quinn::Endpoint) {
311+
use self::proto::Request;
312+
use irpc::rpc::RemoteService;
308313
let local = self.client.as_local().unwrap().clone();
309314
let handler = Request::remote_handler(local);
310-
listen::<Request>(endpoint, handler).await
315+
irpc::rpc::listen::<Request>(endpoint, handler).await
311316
}
312317

313318
pub async fn sync_db(&self) -> RequestResult<()> {

src/api/downloader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct Downloader {
3131
client: irpc::Client<SwarmProtocol>,
3232
}
3333

34-
#[rpc_requests(message = SwarmMsg, alias = "Msg")]
34+
#[rpc_requests(message = SwarmMsg, alias = "Msg", rpc_feature = "rpc")]
3535
#[derive(Debug, Serialize, Deserialize)]
3636
enum SwarmProtocol {
3737
#[rpc(tx = mpsc::Sender<DownloadProgressItem>)]

src/api/proto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl HashSpecific for CreateTagMsg {
8787
}
8888
}
8989

90-
#[rpc_requests(message = Command, alias = "Msg")]
90+
#[rpc_requests(message = Command, alias = "Msg", rpc_feature = "rpc")]
9191
#[derive(Debug, Serialize, Deserialize)]
9292
pub enum Request {
9393
#[rpc(tx = mpsc::Sender<super::Result<Hash>>)]

src/provider/events.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ impl EventSender {
531531
}
532532
}
533533

534-
#[rpc_requests(message = ProviderMessage)]
534+
#[rpc_requests(message = ProviderMessage, rpc_feature = "rpc")]
535535
#[derive(Debug, Serialize, Deserialize)]
536536
pub enum ProviderProto {
537537
/// A new client connected to the provider.
@@ -705,10 +705,15 @@ mod irpc_ext {
705705
.map_err(irpc::Error::from)?;
706706
Ok(req_tx)
707707
}
708+
#[cfg(feature = "rpc")]
708709
irpc::Request::Remote(remote) => {
709710
let (s, _) = remote.write(msg).await?;
710711
Ok(s.into())
711712
}
713+
#[cfg(not(feature = "rpc"))]
714+
irpc::Request::Remote(_) => {
715+
unreachable!()
716+
}
712717
}
713718
}
714719
}

0 commit comments

Comments
 (0)