Skip to content

Commit

Permalink
Add MemClient type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
rklaehn committed Nov 14, 2024
1 parent 17aba72 commit 3cf208a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! Quic RPC implementation for docs.

use proto::{Request, Response, RpcService};
use proto::{Request, RpcService};
use quic_rpc::{
server::{ChannelTypes, RpcChannel},
transport::flume::FlumeConnector,
RpcClient, RpcServer,
};
use tokio_util::task::AbortOnDropHandle;
Expand All @@ -20,7 +19,7 @@ type RpcResult<T> = std::result::Result<T, RpcError>;

impl<D: iroh_blobs::store::Store> Engine<D> {
/// Get an in memory client to interact with the docs engine.
pub fn client(&self) -> &client::docs::Client<FlumeConnector<Response, Request>> {
pub fn client(&self) -> &client::docs::MemClient {
&self
.rpc_handler
.get_or_init(|| RpcHandler::new(self))
Expand Down Expand Up @@ -81,7 +80,7 @@ impl<D: iroh_blobs::store::Store> Engine<D> {
#[derive(Debug)]
pub(crate) struct RpcHandler {
/// Client to hand out
client: client::docs::Client<FlumeConnector<Response, Request>>,
client: client::docs::MemClient,
/// Handler task
_handler: AbortOnDropHandle<()>,
}
Expand All @@ -91,7 +90,7 @@ impl RpcHandler {
let engine = engine.clone();
let (listener, connector) = quic_rpc::transport::flume::channel(1);
let listener = RpcServer::new(listener);
let client = client::docs::Client::new(RpcClient::new(connector));
let client = client::docs::MemClient::new(RpcClient::new(connector));
let _handler = listener
.spawn_accept_loop(move |req, chan| engine.clone().handle_rpc_request(req, chan));
Self { client, _handler }
Expand Down
8 changes: 7 additions & 1 deletion src/rpc/client/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use iroh_base::node_addr::AddrInfoOptions;
use iroh_blobs::{export::ExportProgress, store::ExportMode, Hash};
use iroh_net::NodeAddr;
use portable_atomic::{AtomicBool, Ordering};
use quic_rpc::{client::BoxedConnector, message::RpcMsg, Connector};
use quic_rpc::{
client::BoxedConnector, message::RpcMsg, transport::flume::FlumeConnector, Connector,
};
use serde::{Deserialize, Serialize};

use super::{authors, flatten};
Expand All @@ -38,6 +40,10 @@ pub use crate::{
Entry,
};

/// Type alias for a memory-backed client.
pub type MemClient =
Client<FlumeConnector<crate::rpc::proto::Response, crate::rpc::proto::Request>>;

/// Iroh docs client.
#[derive(Debug, Clone)]
#[repr(transparent)]
Expand Down

0 comments on commit 3cf208a

Please sign in to comment.