Skip to content

Commit

Permalink
refator(iroh): rename Provider{Response|Request}
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed May 6, 2024
1 parent bde91d4 commit 2ce0277
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 26 deletions.
9 changes: 4 additions & 5 deletions iroh/src/client/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
use quic_rpc::transport::flume::FlumeConnection;

use crate::rpc_protocol::{ProviderRequest, ProviderResponse, RpcService};
use crate::rpc_protocol::{Request, Response, RpcService};

/// RPC client to an iroh node running in the same process.
pub type RpcClient =
quic_rpc::RpcClient<RpcService, FlumeConnection<ProviderResponse, ProviderRequest>>;
pub type RpcClient = quic_rpc::RpcClient<RpcService, FlumeConnection<Response, Request>>;

/// In-memory client to an iroh node running in the same process.
///
/// This is obtained from [`crate::node::Node::client`].
pub type Iroh = super::Iroh<FlumeConnection<ProviderResponse, ProviderRequest>>;
pub type Iroh = super::Iroh<FlumeConnection<Response, Request>>;

/// In-memory document client to an iroh node running in the same process.
pub type Doc = super::docs::Doc<FlumeConnection<ProviderResponse, ProviderRequest>>;
pub type Doc = super::docs::Doc<FlumeConnection<Response, Request>>;
9 changes: 4 additions & 5 deletions iroh/src/client/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,23 @@ use quic_rpc::transport::quinn::QuinnConnection;

use crate::{
node::RpcStatus,
rpc_protocol::{NodeStatusRequest, ProviderRequest, ProviderResponse, RpcService},
rpc_protocol::{NodeStatusRequest, Request, Response, RpcService},
};

/// ALPN used by irohs RPC mechanism.
// TODO: Change to "/iroh-rpc/1"
pub(crate) const RPC_ALPN: [u8; 17] = *b"n0/provider-rpc/1";

/// RPC client to an iroh node running in a separate process.
pub type RpcClient =
quic_rpc::RpcClient<RpcService, QuinnConnection<ProviderResponse, ProviderRequest>>;
pub type RpcClient = quic_rpc::RpcClient<RpcService, QuinnConnection<Response, Request>>;

/// Client to an iroh node running in a separate process.
///
/// This is obtained from [`Iroh::connect`].
pub type Iroh = super::Iroh<QuinnConnection<ProviderResponse, ProviderRequest>>;
pub type Iroh = super::Iroh<QuinnConnection<Response, Request>>;

/// RPC document client to an iroh node running in a separate process.
pub type Doc = super::docs::Doc<QuinnConnection<ProviderResponse, ProviderRequest>>;
pub type Doc = super::docs::Doc<QuinnConnection<Response, Request>>;

impl Iroh {
/// Connect to an iroh node running on the same computer, but in a different process.
Expand Down
4 changes: 2 additions & 2 deletions iroh/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use tokio_util::sync::CancellationToken;
use tokio_util::task::LocalPoolHandle;
use tracing::debug;

use crate::rpc_protocol::{ProviderRequest, ProviderResponse};
use crate::rpc_protocol::{Request, Response};
use crate::sync_engine::SyncEngine;

mod builder;
Expand Down Expand Up @@ -97,7 +97,7 @@ struct NodeInner<D> {
endpoint: MagicEndpoint,
secret_key: SecretKey,
cancel_token: CancellationToken,
controller: FlumeConnection<ProviderResponse, ProviderRequest>,
controller: FlumeConnection<Response, Request>,
#[debug("callbacks: Sender<Box<dyn Fn(Event)>>")]
cb_sender: mpsc::Sender<Box<dyn Fn(Event) -> BoxFuture<()> + Send + Sync + 'static>>,
callbacks: Callbacks,
Expand Down
11 changes: 4 additions & 7 deletions iroh/src/node/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use tracing::{debug, error, error_span, info, trace, warn, Instrument};
use crate::{
client::RPC_ALPN,
node::{Event, NodeInner},
rpc_protocol::{ProviderRequest, ProviderResponse, RpcService},
rpc_protocol::{Request, Response, RpcService},
sync_engine::SyncEngine,
util::{fs::load_secret_key, path::IrohPaths},
};
Expand Down Expand Up @@ -247,9 +247,7 @@ where
}

/// Configure the default iroh rpc endpoint.
pub async fn enable_rpc(
self,
) -> Result<Builder<D, QuinnServerEndpoint<ProviderRequest, ProviderResponse>>> {
pub async fn enable_rpc(self) -> Result<Builder<D, QuinnServerEndpoint<Request, Response>>> {
let (ep, actual_rpc_port) = make_rpc_endpoint(&self.secret_key, DEFAULT_RPC_PORT)?;
if let StorageConfig::Persistent(ref root) = self.storage {
// store rpc endpoint
Expand Down Expand Up @@ -739,7 +737,7 @@ const MAX_RPC_STREAMS: u32 = 1024;
fn make_rpc_endpoint(
secret_key: &SecretKey,
rpc_port: u16,
) -> Result<(QuinnServerEndpoint<ProviderRequest, ProviderResponse>, u16)> {
) -> Result<(QuinnServerEndpoint<Request, Response>, u16)> {
let rpc_addr = SocketAddrV4::new(Ipv4Addr::LOCALHOST, rpc_port);
let mut transport_config = quinn::TransportConfig::default();
transport_config
Expand Down Expand Up @@ -774,8 +772,7 @@ fn make_rpc_endpoint(
};

let actual_rpc_port = rpc_quinn_endpoint.local_addr()?.port();
let rpc_endpoint =
QuinnServerEndpoint::<ProviderRequest, ProviderResponse>::new(rpc_quinn_endpoint)?;
let rpc_endpoint = QuinnServerEndpoint::<Request, Response>::new(rpc_quinn_endpoint)?;

Ok((rpc_endpoint, actual_rpc_port))
}
6 changes: 3 additions & 3 deletions iroh/src/node/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use crate::rpc_protocol::{
DocSetHashRequest, ListTagsRequest, NodeConnectionInfoRequest, NodeConnectionInfoResponse,
NodeConnectionsRequest, NodeConnectionsResponse, NodeIdRequest, NodeShutdownRequest,
NodeStatsRequest, NodeStatsResponse, NodeStatusRequest, NodeWatchRequest, NodeWatchResponse,
ProviderRequest, RpcService, SetTagOption,
Request, RpcService, SetTagOption,
};

use super::{Event, NodeInner};
Expand All @@ -67,12 +67,12 @@ pub(crate) struct Handler<D> {
impl<D: BaoStore> Handler<D> {
pub(crate) fn handle_rpc_request<E: ServiceEndpoint<RpcService>>(
&self,
msg: ProviderRequest,
msg: Request,
chan: RpcChannel<RpcService, E>,
) {
let handler = self.clone();
tokio::task::spawn(async move {
use ProviderRequest::*;
use Request::*;
debug!("handling rpc request: {msg}");
match msg {
NodeWatch(msg) => chan.server_streaming(msg, handler, Self::node_watch).await,
Expand Down
8 changes: 4 additions & 4 deletions iroh/src/rpc_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ pub struct RpcService;
/// The request enum, listing all possible requests.
#[allow(missing_docs)]
#[derive(strum::Display, Debug, Serialize, Deserialize, From, TryInto)]
pub enum ProviderRequest {
pub enum Request {
NodeStatus(NodeStatusRequest),
NodeId(NodeIdRequest),
NodeStats(NodeStatsRequest),
Expand Down Expand Up @@ -1097,7 +1097,7 @@ pub enum ProviderRequest {
/// The response enum, listing all possible responses.
#[allow(missing_docs, clippy::large_enum_variant)]
#[derive(Debug, Serialize, Deserialize, From, TryInto)]
pub enum ProviderResponse {
pub enum Response {
NodeStatus(RpcResult<NodeStatus>),
NodeId(RpcResult<NodeId>),
NodeStats(RpcResult<NodeStatsResponse>),
Expand Down Expand Up @@ -1153,6 +1153,6 @@ pub enum ProviderResponse {
}

impl Service for RpcService {
type Req = ProviderRequest;
type Res = ProviderResponse;
type Req = Request;
type Res = Response;
}

0 comments on commit 2ce0277

Please sign in to comment.