Skip to content

Commit 127a9fd

Browse files
committed
refactor: rename BlobsApi back to Request, remove unneeded code
1 parent df42ef5 commit 127a9fd

File tree

4 files changed

+12
-47
lines changed

4 files changed

+12
-47
lines changed

src/api.rs

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
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, sync::Arc};
15+
use std::{io, net::SocketAddr, ops::Deref};
1616

1717
use bao_tree::io::EncodeError;
1818
use iroh::Endpoint;
19-
use irpc::rpc::{listen, Handler};
19+
use irpc::rpc::{listen, RemoteService};
2020
use n0_snafu::SpanTrace;
2121
use nested_enum_utils::common_fields;
22-
use proto::{BlobsApi, ShutdownRequest, SyncDbRequest};
22+
use proto::{Request, ShutdownRequest, SyncDbRequest};
2323
use ref_cast::RefCast;
2424
use serde::{Deserialize, Serialize};
2525
use snafu::{Backtrace, IntoError, Snafu};
@@ -32,7 +32,7 @@ pub mod remote;
3232
pub mod tags;
3333
pub use crate::{store::util::Tag, util::temp_tag::TempTag};
3434

35-
pub(crate) type ApiClient = irpc::Client<proto::BlobsApi>;
35+
pub(crate) type ApiClient = irpc::Client<proto::Request>;
3636

3737
#[common_fields({
3838
backtrace: Option<Backtrace>,
@@ -282,42 +282,8 @@ impl Store {
282282
/// Listen on a quinn endpoint for incoming rpc connections.
283283
pub async fn listen(self, endpoint: quinn::Endpoint) {
284284
let local = self.client.as_local().unwrap().clone();
285-
let handler: Handler<BlobsApi> = Arc::new(move |req, rx, tx| {
286-
let local = local.clone();
287-
Box::pin({
288-
match req {
289-
BlobsApi::SetTag(msg) => local.send((msg, tx)),
290-
BlobsApi::CreateTag(msg) => local.send((msg, tx)),
291-
BlobsApi::DeleteTags(msg) => local.send((msg, tx)),
292-
BlobsApi::RenameTag(msg) => local.send((msg, tx)),
293-
BlobsApi::ListTags(msg) => local.send((msg, tx)),
294-
295-
BlobsApi::ListTempTags(msg) => local.send((msg, tx)),
296-
BlobsApi::CreateTempTag(msg) => local.send((msg, tx)),
297-
298-
BlobsApi::BlobStatus(msg) => local.send((msg, tx)),
299-
300-
BlobsApi::ImportBytes(msg) => local.send((msg, tx)),
301-
BlobsApi::ImportByteStream(msg) => local.send((msg, tx, rx)),
302-
BlobsApi::ImportBao(msg) => local.send((msg, tx, rx)),
303-
BlobsApi::ImportPath(msg) => local.send((msg, tx)),
304-
BlobsApi::ListBlobs(msg) => local.send((msg, tx)),
305-
BlobsApi::DeleteBlobs(msg) => local.send((msg, tx)),
306-
BlobsApi::Batch(msg) => local.send((msg, tx, rx)),
307-
308-
BlobsApi::ExportBao(msg) => local.send((msg, tx)),
309-
BlobsApi::ExportRanges(msg) => local.send((msg, tx)),
310-
BlobsApi::ExportPath(msg) => local.send((msg, tx)),
311-
312-
BlobsApi::Observe(msg) => local.send((msg, tx)),
313-
314-
BlobsApi::ClearProtected(msg) => local.send((msg, tx)),
315-
BlobsApi::SyncDb(msg) => local.send((msg, tx)),
316-
BlobsApi::Shutdown(msg) => local.send((msg, tx)),
317-
}
318-
})
319-
});
320-
listen::<BlobsApi>(endpoint, handler).await
285+
let handler = Request::remote_handler(local);
286+
listen::<Request>(endpoint, handler).await
321287
}
322288

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

src/api/proto.rs

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

8989
#[rpc_requests(message = Command, alias = "Msg")]
9090
#[derive(Debug, Serialize, Deserialize)]
91-
pub enum BlobsApi {
91+
pub enum Request {
9292
#[rpc(tx = mpsc::Sender<super::Result<Hash>>)]
9393
ListBlobs(ListRequest),
9494
#[rpc(tx = oneshot::Sender<Scope>, rx = mpsc::Receiver<BatchResponse>)]

src/store/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ impl AsRef<Store> for FsStore {
12591259

12601260
impl FsStore {
12611261
fn new(
1262-
sender: irpc::LocalSender<proto::BlobsApi>,
1262+
sender: irpc::LocalSender<proto::Request>,
12631263
db: tokio::sync::mpsc::Sender<InternalCommand>,
12641264
) -> Self {
12651265
Self {

src/store/fs/import.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ use crate::{
3838
api::{
3939
blobs::{AddProgressItem, ImportMode},
4040
proto::{
41-
BlobsApi, HashSpecific, ImportByteStreamMsg, ImportByteStreamRequest,
42-
ImportByteStreamUpdate, ImportBytesMsg, ImportBytesRequest, ImportPathMsg,
43-
ImportPathRequest, Scope,
41+
HashSpecific, ImportByteStreamMsg, ImportByteStreamRequest, ImportByteStreamUpdate,
42+
ImportBytesMsg, ImportBytesRequest, ImportPathMsg, ImportPathRequest, Request, Scope,
4443
},
4544
},
4645
store::{
@@ -136,12 +135,12 @@ impl std::fmt::Debug for ImportEntry {
136135
}
137136
}
138137

139-
impl Channels<BlobsApi> for ImportEntry {
138+
impl Channels<Request> for ImportEntry {
140139
type Tx = mpsc::Sender<AddProgressItem>;
141140
type Rx = NoReceiver;
142141
}
143142

144-
pub type ImportEntryMsg = WithChannels<ImportEntry, BlobsApi>;
143+
pub type ImportEntryMsg = WithChannels<ImportEntry, Request>;
145144

146145
impl HashSpecific for ImportEntryMsg {
147146
fn hash(&self) -> Hash {

0 commit comments

Comments
 (0)