Skip to content

Commit

Permalink
refactor(iroh): rename ProviderService to RpcService
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed May 3, 2024
1 parent d7dba22 commit 2f2c0e6
Show file tree
Hide file tree
Showing 18 changed files with 144 additions and 149 deletions.
4 changes: 2 additions & 2 deletions iroh-cli/src/commands/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use derive_more::FromStr;
use futures_lite::StreamExt;
use iroh::base::base32::fmt_short;

use iroh::client::{Iroh, ProviderService};
use iroh::client::{Iroh, RpcService};
use iroh::sync::{Author, AuthorId};
use quic_rpc::ServiceConnection;

Expand Down Expand Up @@ -34,7 +34,7 @@ pub enum AuthorCommands {
impl AuthorCommands {
pub async fn run<C>(self, iroh: &Iroh<C>, env: &ConsoleEnv) -> Result<()>
where
C: ServiceConnection<ProviderService>,
C: ServiceConnection<RpcService>,
{
match self {
Self::Switch { author } => {
Expand Down
16 changes: 8 additions & 8 deletions iroh-cli/src/commands/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use iroh::{
BlobInfo, BlobStatus, CollectionInfo, DownloadMode, DownloadOptions,
IncompleteBlobInfo, WrapOption,
},
Iroh, ProviderService,
Iroh, RpcService,
},
net::{key::PublicKey, relay::RelayUrl, NodeAddr},
};
Expand Down Expand Up @@ -184,7 +184,7 @@ impl std::str::FromStr for TicketOrHash {
impl BlobCommands {
pub async fn run<C>(self, iroh: &Iroh<C>) -> Result<()>
where
C: ServiceConnection<ProviderService>,
C: ServiceConnection<RpcService>,
{
match self {
Self::Get {
Expand Down Expand Up @@ -449,7 +449,7 @@ pub enum ListCommands {
impl ListCommands {
pub async fn run<C>(self, iroh: &Iroh<C>) -> Result<()>
where
C: ServiceConnection<ProviderService>,
C: ServiceConnection<RpcService>,
{
match self {
Self::Blobs => {
Expand Down Expand Up @@ -509,7 +509,7 @@ pub enum DeleteCommands {
impl DeleteCommands {
pub async fn run<C>(self, iroh: &Iroh<C>) -> Result<()>
where
C: ServiceConnection<ProviderService>,
C: ServiceConnection<RpcService>,
{
match self {
Self::Blob { hash } => {
Expand Down Expand Up @@ -542,7 +542,7 @@ fn apply_report_level(text: String, level: ReportLevel) -> console::StyledObject

pub async fn consistency_check<C>(iroh: &Iroh<C>, verbose: u8, repair: bool) -> Result<()>
where
C: ServiceConnection<ProviderService>,
C: ServiceConnection<RpcService>,
{
let mut response = iroh.blobs.consistency_check(repair).await?;
let verbosity = get_report_level(verbose);
Expand Down Expand Up @@ -586,7 +586,7 @@ where

pub async fn validate<C>(iroh: &Iroh<C>, verbose: u8, repair: bool) -> Result<()>
where
C: ServiceConnection<ProviderService>,
C: ServiceConnection<RpcService>,
{
let mut state = ValidateProgressState::new();
let mut response = iroh.blobs.validate(repair).await?;
Expand Down Expand Up @@ -807,7 +807,7 @@ pub enum TicketOption {
Print,
}

pub async fn add_with_opts<C: ServiceConnection<ProviderService>>(
pub async fn add_with_opts<C: ServiceConnection<RpcService>>(
client: &iroh::client::Iroh<C>,
source: BlobSource,
opts: BlobAddOptions,
Expand Down Expand Up @@ -840,7 +840,7 @@ pub async fn add_with_opts<C: ServiceConnection<ProviderService>>(
}

/// Add data to iroh, either from a path or, if path is `None`, from STDIN.
pub async fn add<C: ServiceConnection<ProviderService>>(
pub async fn add<C: ServiceConnection<RpcService>>(
client: &iroh::client::Iroh<C>,
source: BlobSourceIroh,
tag: SetTagOption,
Expand Down
4 changes: 2 additions & 2 deletions iroh-cli/src/commands/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Result;
use clap::{Parser, Subcommand};
use colored::Colorize;
use iroh::base::base32::fmt_short;
use iroh::client::{Iroh, ProviderService};
use iroh::client::{Iroh, RpcService};
use quic_rpc::ServiceConnection;
use rustyline::{error::ReadlineError, Config, DefaultEditor};
use tokio::sync::{mpsc, oneshot};
Expand All @@ -14,7 +14,7 @@ use crate::{

pub async fn run<C>(iroh: &Iroh<C>, env: &ConsoleEnv) -> Result<()>
where
C: ServiceConnection<ProviderService>,
C: ServiceConnection<RpcService>,
{
println!("{}", "Welcome to the Iroh console!".purple().bold());
println!("Type `{}` for a list of commands.", "help".bold());
Expand Down
12 changes: 6 additions & 6 deletions iroh-cli/src/commands/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use iroh::{
client::{
blobs::WrapOption,
docs::{Doc, Entry, LiveEvent, Origin, ShareMode},
Iroh, ProviderService,
Iroh, RpcService,
},
sync::{
store::{DownloadPolicy, FilterKind, Query, SortDirection},
Expand Down Expand Up @@ -305,7 +305,7 @@ impl From<Sorting> for iroh::sync::store::SortBy {
impl DocCommands {
pub async fn run<C>(self, iroh: &Iroh<C>, env: &ConsoleEnv) -> Result<()>
where
C: ServiceConnection<ProviderService>,
C: ServiceConnection<RpcService>,
{
match self {
Self::Switch { id: doc } => {
Expand Down Expand Up @@ -671,7 +671,7 @@ async fn get_doc<C>(
id: Option<NamespaceId>,
) -> anyhow::Result<Doc<C>>
where
C: ServiceConnection<ProviderService>,
C: ServiceConnection<RpcService>,
{
iroh.docs
.open(env.doc(id)?)
Expand All @@ -686,7 +686,7 @@ async fn fmt_content<C>(
mode: DisplayContentMode,
) -> Result<String, String>
where
C: ServiceConnection<ProviderService>,
C: ServiceConnection<RpcService>,
{
let read_failed = |err: anyhow::Error| format!("<failed to get content: {err}>");
let encode_hex = |err: std::string::FromUtf8Error| format!("0x{}", hex::encode(err.as_bytes()));
Expand Down Expand Up @@ -737,7 +737,7 @@ fn human_len(entry: &Entry) -> HumanBytes {
#[must_use = "this won't be printed, you need to print it yourself"]
async fn fmt_entry<C>(doc: &Doc<C>, entry: &Entry, mode: DisplayContentMode) -> String
where
C: ServiceConnection<ProviderService>,
C: ServiceConnection<RpcService>,
{
let key = std::str::from_utf8(entry.key())
.unwrap_or("<bad key>")
Expand Down Expand Up @@ -778,7 +778,7 @@ async fn import_coordinator<C>(
expected_entries: u64,
) -> Result<()>
where
C: ServiceConnection<ProviderService>,
C: ServiceConnection<RpcService>,
{
let imp = ImportProgressBar::new(
&root.display().to_string(),
Expand Down
4 changes: 2 additions & 2 deletions iroh-cli/src/commands/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use comfy_table::{presets::NOTHING, Cell};
use futures_lite::{Stream, StreamExt};
use human_time::ToHumanTimeString;
use iroh::client::Iroh;
use iroh::client::ProviderService;
use iroh::client::RpcService;
use iroh::net::{
key::PublicKey,
magic_endpoint::{ConnectionInfo, DirectAddrInfo},
Expand Down Expand Up @@ -40,7 +40,7 @@ pub enum NodeCommands {
impl NodeCommands {
pub async fn run<C>(self, iroh: &Iroh<C>) -> Result<()>
where
C: ServiceConnection<ProviderService>,
C: ServiceConnection<RpcService>,
{
match self {
Self::Connections => {
Expand Down
4 changes: 2 additions & 2 deletions iroh-cli/src/commands/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use clap::Subcommand;
use iroh::client::{Iroh, ProviderService};
use iroh::client::{Iroh, RpcService};
use quic_rpc::ServiceConnection;

use crate::config::ConsoleEnv;
Expand Down Expand Up @@ -60,7 +60,7 @@ pub enum RpcCommands {
impl RpcCommands {
pub async fn run<C>(self, iroh: &Iroh<C>, env: &ConsoleEnv) -> Result<()>
where
C: ServiceConnection<ProviderService>,
C: ServiceConnection<RpcService>,
{
match self {
Self::Node { command } => command.run(iroh).await,
Expand Down
4 changes: 2 additions & 2 deletions iroh-cli/src/commands/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bytes::Bytes;
use clap::Subcommand;
use futures_lite::StreamExt;
use iroh::bytes::Tag;
use iroh::client::{Iroh, ProviderService};
use iroh::client::{Iroh, RpcService};
use quic_rpc::ServiceConnection;

#[derive(Subcommand, Debug, Clone)]
Expand All @@ -22,7 +22,7 @@ pub enum TagCommands {
impl TagCommands {
pub async fn run<C>(self, iroh: &Iroh<C>) -> Result<()>
where
C: ServiceConnection<ProviderService>,
C: ServiceConnection<RpcService>,
{
match self {
Self::List => {
Expand Down
6 changes: 3 additions & 3 deletions iroh/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use futures_lite::{Stream, StreamExt};
use quic_rpc::{RpcClient, ServiceConnection};

#[doc(inline)]
pub use crate::rpc_protocol::ProviderService;
pub use crate::rpc_protocol::RpcService;

mod mem;
mod quic;
Expand Down Expand Up @@ -37,10 +37,10 @@ pub struct Iroh<C> {

impl<C> Iroh<C>
where
C: ServiceConnection<ProviderService>,
C: ServiceConnection<RpcService>,
{
/// Create a new high-level client to a Iroh node from the low-level RPC client.
pub fn new(rpc: RpcClient<ProviderService, C>) -> Self {
pub fn new(rpc: RpcClient<RpcService, C>) -> Self {
Self {
node: node::Client { rpc: rpc.clone() },
blobs: blobs::Client { rpc: rpc.clone() },
Expand Down
6 changes: 3 additions & 3 deletions iroh/src/client/authors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ use quic_rpc::{RpcClient, ServiceConnection};

use crate::rpc_protocol::{
AuthorCreateRequest, AuthorDeleteRequest, AuthorExportRequest, AuthorImportRequest,
AuthorListRequest, ProviderService,
AuthorListRequest, RpcService,
};

use super::flatten;

/// Iroh authors client.
#[derive(Debug, Clone)]
pub struct Client<C> {
pub(super) rpc: RpcClient<ProviderService, C>,
pub(super) rpc: RpcClient<RpcService, C>,
}

impl<C> Client<C>
where
C: ServiceConnection<ProviderService>,
C: ServiceConnection<RpcService>,
{
/// Create a new document author.
pub async fn create(&self) -> Result<AuthorId> {
Expand Down
21 changes: 9 additions & 12 deletions iroh/src/client/blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,26 @@ use crate::rpc_protocol::{
BlobDeleteBlobRequest, BlobDownloadRequest, BlobExportRequest, BlobGetCollectionRequest,
BlobGetCollectionResponse, BlobListCollectionsRequest, BlobListIncompleteRequest,
BlobListRequest, BlobReadAtRequest, BlobReadAtResponse, BlobValidateRequest,
CreateCollectionRequest, CreateCollectionResponse, NodeStatusRequest, ProviderService,
SetTagOption,
CreateCollectionRequest, CreateCollectionResponse, NodeStatusRequest, RpcService, SetTagOption,
};

use super::{flatten, Iroh};

/// Iroh blobs client.
#[derive(Debug, Clone)]
pub struct Client<C> {
pub(super) rpc: RpcClient<ProviderService, C>,
pub(super) rpc: RpcClient<RpcService, C>,
}

impl<'a, C: ServiceConnection<ProviderService>> From<&'a Iroh<C>>
for &'a RpcClient<ProviderService, C>
{
fn from(client: &'a Iroh<C>) -> &'a RpcClient<ProviderService, C> {
impl<'a, C: ServiceConnection<RpcService>> From<&'a Iroh<C>> for &'a RpcClient<RpcService, C> {
fn from(client: &'a Iroh<C>) -> &'a RpcClient<RpcService, C> {
&client.blobs.rpc
}
}

impl<C> Client<C>
where
C: ServiceConnection<ProviderService>,
C: ServiceConnection<RpcService>,
{
/// Stream the contents of a a single blob.
///
Expand Down Expand Up @@ -755,15 +752,15 @@ impl Reader {
}
}

pub(crate) async fn from_rpc_read<C: ServiceConnection<ProviderService>>(
rpc: &RpcClient<ProviderService, C>,
pub(crate) async fn from_rpc_read<C: ServiceConnection<RpcService>>(
rpc: &RpcClient<RpcService, C>,
hash: Hash,
) -> anyhow::Result<Self> {
Self::from_rpc_read_at(rpc, hash, 0, None).await
}

async fn from_rpc_read_at<C: ServiceConnection<ProviderService>>(
rpc: &RpcClient<ProviderService, C>,
async fn from_rpc_read_at<C: ServiceConnection<RpcService>>(
rpc: &RpcClient<RpcService, C>,
hash: Hash,
offset: u64,
len: Option<usize>,
Expand Down
Loading

0 comments on commit 2f2c0e6

Please sign in to comment.