Skip to content

Commit

Permalink
refactor: Remove use of MemIroh/QuicIroh type aliases
Browse files Browse the repository at this point in the history
They are no longer needed and will be removed soon.
  • Loading branch information
rklaehn committed Jun 20, 2024
1 parent 21daa0d commit 4bada75
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 50 deletions.
6 changes: 3 additions & 3 deletions iroh-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
use anyhow::{ensure, Context, Result};
use clap::Parser;
use derive_more::FromStr;
use iroh::client::QuicIroh;
use iroh::client::Iroh;

use crate::config::{ConsoleEnv, NodeConfig};

Expand Down Expand Up @@ -130,7 +130,7 @@ impl Cli {
.await
} else {
crate::logging::init_terminal_logging()?;
let iroh = QuicIroh::connect(data_dir).await.context("rpc connect")?;
let iroh = Iroh::connect(data_dir).await.context("rpc connect")?;
let env = ConsoleEnv::for_console(data_dir_owned, &iroh).await?;
console::run(&iroh, &env).await
}
Expand All @@ -151,7 +151,7 @@ impl Cli {
.await
} else {
crate::logging::init_terminal_logging()?;
let iroh = QuicIroh::connect(data_dir).await.context("rpc connect")?;
let iroh = Iroh::connect(data_dir).await.context("rpc connect")?;
let env = ConsoleEnv::for_cli(data_dir_owned, &iroh).await?;
command.run(&iroh, &env).await
}
Expand Down
2 changes: 1 addition & 1 deletion iroh-cli/src/commands/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ mod tests {
let cli = ConsoleEnv::for_console(data_dir.path().to_owned(), &node)
.await
.context("ConsoleEnv")?;
let iroh = iroh::client::QuicIroh::connect(data_dir.path())
let iroh = iroh::client::Iroh::connect(data_dir.path())
.await
.context("rpc connect")?;

Expand Down
4 changes: 2 additions & 2 deletions iroh-cli/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub async fn run_with_command<F, T>(
command: F,
) -> Result<()>
where
F: FnOnce(iroh::client::MemIroh) -> T + Send + 'static,
F: FnOnce(iroh::client::Iroh) -> T + Send + 'static,
T: Future<Output = Result<()>> + 'static,
{
let _guard = crate::logging::init_terminal_and_file_logging(&config.file_logs, iroh_data_root)?;
Expand Down Expand Up @@ -68,7 +68,7 @@ async fn run_with_command_inner<F, T>(
command: F,
) -> Result<()>
where
F: FnOnce(iroh::client::MemIroh) -> T + Send + 'static,
F: FnOnce(iroh::client::Iroh) -> T + Send + 'static,
T: Future<Output = Result<()>> + 'static,
{
let relay_map = config.relay_map()?;
Expand Down
6 changes: 3 additions & 3 deletions iroh/examples/custom-protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::Result;
use clap::Parser;
use futures_lite::future::Boxed as BoxedFuture;
use iroh::{
client::MemIroh,
client::Iroh,
net::{
endpoint::{get_remote_node_id, Connecting},
Endpoint, NodeId,
Expand Down Expand Up @@ -59,7 +59,7 @@ const EXAMPLE_ALPN: &[u8] = b"example-proto/0";

#[derive(Debug, Clone)]
struct ExampleProto {
client: MemIroh,
client: Iroh,
endpoint: Endpoint,
}

Expand Down Expand Up @@ -89,7 +89,7 @@ impl ProtocolHandler for ExampleProto {
}

impl ExampleProto {
pub fn new(client: MemIroh, endpoint: Endpoint) -> Self {
pub fn new(client: Iroh, endpoint: Endpoint) -> Self {
Self { client, endpoint }
}

Expand Down
12 changes: 9 additions & 3 deletions iroh/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ use ref_cast::RefCast;
#[doc(inline)]
pub use crate::rpc_protocol::RpcService;

mod mem;
mod quic;

pub use self::mem::{Doc as MemDoc, Iroh as MemIroh, RpcClient as MemRpcClient};
// #[deprecated]
// pub use self::docs::Doc as MemDoc;
// #[deprecated]
// pub use self::Iroh as MemIroh;
// #[deprecated]
// pub use self::docs::Doc as QuicDoc;
// #[deprecated]
// pub use self::Iroh as QuicIroh;
pub use self::docs::Doc;
pub use self::node::NodeStatus;
pub use self::quic::{Doc as QuicDoc, Iroh as QuicIroh, RpcClient as QuicRpcClient};

pub(crate) use self::quic::{connect_raw as quic_connect_raw, RPC_ALPN};

Expand Down
18 changes: 0 additions & 18 deletions iroh/src/client/mem.rs

This file was deleted.

9 changes: 1 addition & 8 deletions iroh/src/client/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{
use anyhow::{bail, Context};
use quic_rpc::transport::{boxed::Connection as BoxedConnection, quinn::QuinnConnection};

use super::Iroh;
use crate::{
node::RpcStatus,
rpc_protocol::{NodeStatusRequest, RpcService},
Expand All @@ -22,14 +23,6 @@ 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, BoxedConnection<RpcService>>;

/// Client to an iroh node running in a separate process.
///
/// This is obtained from [`Iroh::connect`].
pub type Iroh = super::Iroh;

/// RPC document client to an iroh node running in a separate process.
pub type Doc = super::docs::Doc;

impl Iroh {
/// Connect to an iroh node running on the same computer, but in a different process.
pub async fn connect(root: impl AsRef<Path>) -> anyhow::Result<Self> {
Expand Down
6 changes: 3 additions & 3 deletions iroh/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct NodeInner<D> {
gossip: Gossip,
secret_key: SecretKey,
cancel_token: CancellationToken,
client: crate::client::MemIroh,
client: crate::client::Iroh,
#[debug("rt")]
rt: LocalPoolHandle,
downloader: Downloader,
Expand Down Expand Up @@ -133,7 +133,7 @@ impl<D: BaoStore> Node<D> {
}

/// Return a client to control this node over an in-memory channel.
pub fn client(&self) -> &crate::client::MemIroh {
pub fn client(&self) -> &crate::client::Iroh {
&self.inner.client
}

Expand Down Expand Up @@ -180,7 +180,7 @@ impl<D: BaoStore> Node<D> {
}

impl<D> std::ops::Deref for Node<D> {
type Target = crate::client::MemIroh;
type Target = crate::client::Iroh;

fn deref(&self) -> &Self::Target {
&self.inner.client
Expand Down
2 changes: 1 addition & 1 deletion iroh/src/node/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ impl<D: iroh_blobs::store::Store, E: ServiceEndpoint<RpcService>> ProtocolBuilde
///
/// Note that RPC calls performed with the client will not complete until the node is
/// spawned.
pub fn client(&self) -> &crate::client::MemIroh {
pub fn client(&self) -> &crate::client::Iroh {
&self.inner.client
}

Expand Down
2 changes: 1 addition & 1 deletion iroh/src/node/rpc_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub enum RpcStatus {
/// The port we are connected on.
port: u16,
/// Actual connected RPC client.
client: crate::client::QuicRpcClient,
client: crate::client::IrohRpcClient,
},
}

Expand Down
14 changes: 7 additions & 7 deletions iroh/tests/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use iroh::{
base::node_addr::AddrInfoOptions,
client::{
docs::{Entry, LiveEvent, ShareMode},
MemDoc,
Doc,
},
net::key::{PublicKey, SecretKey},
node::{Builder, Node},
Expand Down Expand Up @@ -1012,14 +1012,14 @@ async fn test_list_docs_stream() -> Result<()> {
}

/// Get all entries of a document.
async fn get_all(doc: &MemDoc) -> anyhow::Result<Vec<Entry>> {
async fn get_all(doc: &Doc) -> anyhow::Result<Vec<Entry>> {
let entries = doc.get_many(Query::all()).await?;
let entries = entries.collect::<Vec<_>>().await;
entries.into_iter().collect()
}

/// Get all entries of a document with the blob content.
async fn get_all_with_content(doc: &MemDoc) -> anyhow::Result<Vec<(Entry, Bytes)>> {
async fn get_all_with_content(doc: &Doc) -> anyhow::Result<Vec<(Entry, Bytes)>> {
let entries = doc.get_many(Query::all()).await?;
let entries = entries.and_then(|entry| async {
let content = entry.content_bytes(doc).await;
Expand All @@ -1031,7 +1031,7 @@ async fn get_all_with_content(doc: &MemDoc) -> anyhow::Result<Vec<(Entry, Bytes)
}

async fn publish(
docs: &[MemDoc],
docs: &[Doc],
expected: &mut Vec<ExpectedEntry>,
n: usize,
cb: impl Fn(usize, usize) -> (AuthorId, String, String),
Expand Down Expand Up @@ -1090,7 +1090,7 @@ async fn wait_for_events(
}

async fn assert_all_docs(
docs: &[MemDoc],
docs: &[Doc],
node_ids: &[PublicKey],
expected: &Vec<ExpectedEntry>,
label: &str,
Expand Down Expand Up @@ -1203,12 +1203,12 @@ async fn sync_drop_doc() -> Result<()> {
Ok(())
}

async fn assert_latest(doc: &MemDoc, key: &[u8], value: &[u8]) {
async fn assert_latest(doc: &Doc, key: &[u8], value: &[u8]) {
let content = get_latest(doc, key).await.unwrap();
assert_eq!(content, value.to_vec());
}

async fn get_latest(doc: &MemDoc, key: &[u8]) -> anyhow::Result<Vec<u8>> {
async fn get_latest(doc: &Doc, key: &[u8]) -> anyhow::Result<Vec<u8>> {
let query = Query::single_latest_per_key().key_exact(key);
let entry = doc
.get_many(query)
Expand Down

0 comments on commit 4bada75

Please sign in to comment.