From bc872ce17fe84c477f68f482a03f7cb17103fcfb Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Thu, 2 May 2024 21:20:35 +0200 Subject: [PATCH] refactor: make `iroh::rpc_protocol` private --- iroh-cli/src/commands/author.rs | 2 +- iroh-cli/src/commands/blob.rs | 18 ++++++++--------- iroh-cli/src/commands/console.rs | 2 +- iroh-cli/src/commands/doc.rs | 30 ++++++----------------------- iroh-cli/src/commands/node.rs | 2 +- iroh-cli/src/commands/rpc.rs | 2 +- iroh-cli/src/commands/tag.rs | 2 +- iroh/examples/client.rs | 4 +--- iroh/examples/collection-provide.rs | 3 +-- iroh/src/client.rs | 3 ++- iroh/src/client/blobs.rs | 14 +++++++++++++- iroh/src/client/docs.rs | 12 +++++++++++- iroh/src/lib.rs | 2 +- iroh/src/node.rs | 4 ++-- iroh/src/node/rpc.rs | 5 +++-- iroh/src/rpc_protocol.rs | 27 ++------------------------ iroh/src/sync_engine/rpc.rs | 3 ++- iroh/src/util/fs.rs | 2 +- iroh/tests/sync.rs | 7 +++---- 19 files changed, 61 insertions(+), 83 deletions(-) diff --git a/iroh-cli/src/commands/author.rs b/iroh-cli/src/commands/author.rs index 64a02dd603c..c60e02b6b7c 100644 --- a/iroh-cli/src/commands/author.rs +++ b/iroh-cli/src/commands/author.rs @@ -4,8 +4,8 @@ use derive_more::FromStr; use futures_lite::StreamExt; use iroh::base::base32::fmt_short; +use iroh::client::{Iroh, ProviderService}; use iroh::sync::{Author, AuthorId}; -use iroh::{client::Iroh, rpc_protocol::ProviderService}; use quic_rpc::ServiceConnection; use crate::config::ConsoleEnv; diff --git a/iroh-cli/src/commands/blob.rs b/iroh-cli/src/commands/blob.rs index 863656d672d..234374ac3c6 100644 --- a/iroh-cli/src/commands/blob.rs +++ b/iroh-cli/src/commands/blob.rs @@ -15,26 +15,24 @@ use indicatif::{ }; use iroh::{ base::node_addr::AddrInfoOptions, + base::ticket::BlobTicket, bytes::{ get::{db::DownloadProgress, progress::BlobProgress, Stats}, provider::AddProgress, store::{ ConsistencyCheckProgress, ExportFormat, ExportMode, ReportLevel, ValidateProgress, }, + util::SetTagOption, BlobFormat, Hash, HashAndFormat, Tag, }, -}; -use iroh::{ - base::ticket::BlobTicket, - client::Iroh, - rpc_protocol::{ProviderService, WrapOption}, -}; -use iroh::{ - client::blobs::{ - BlobInfo, BlobStatus, CollectionInfo, DownloadMode, DownloadOptions, IncompleteBlobInfo, + client::{ + blobs::{ + BlobInfo, BlobStatus, CollectionInfo, DownloadMode, DownloadOptions, + IncompleteBlobInfo, WrapOption, + }, + Iroh, ProviderService, }, net::{key::PublicKey, relay::RelayUrl, NodeAddr}, - rpc_protocol::SetTagOption, }; use quic_rpc::ServiceConnection; use tokio::io::AsyncWriteExt; diff --git a/iroh-cli/src/commands/console.rs b/iroh-cli/src/commands/console.rs index b7f9178ce1a..a0516bfb88a 100644 --- a/iroh-cli/src/commands/console.rs +++ b/iroh-cli/src/commands/console.rs @@ -2,7 +2,7 @@ use anyhow::Result; use clap::{Parser, Subcommand}; use colored::Colorize; use iroh::base::base32::fmt_short; -use iroh::{client::Iroh, rpc_protocol::ProviderService}; +use iroh::client::{Iroh, ProviderService}; use quic_rpc::ServiceConnection; use rustyline::{error::ReadlineError, Config, DefaultEditor}; use tokio::sync::{mpsc, oneshot}; diff --git a/iroh-cli/src/commands/doc.rs b/iroh-cli/src/commands/doc.rs index a75f9131169..691be31a585 100644 --- a/iroh-cli/src/commands/doc.rs +++ b/iroh-cli/src/commands/doc.rs @@ -14,17 +14,16 @@ use futures_buffered::BufferedStreamExt; use futures_lite::{Stream, StreamExt}; use indicatif::{HumanBytes, HumanDuration, MultiProgress, ProgressBar, ProgressStyle}; use quic_rpc::ServiceConnection; -use serde::{Deserialize, Serialize}; use tokio::io::AsyncReadExt; use iroh::{ base::{base32::fmt_short, node_addr::AddrInfoOptions}, - bytes::{provider::AddProgress, Hash, Tag}, + bytes::{provider::AddProgress, util::SetTagOption, Hash, Tag}, client::{ - docs::{Doc, Entry, LiveEvent}, - Iroh, + blobs::WrapOption, + docs::{Doc, Entry, LiveEvent, ShareMode}, + Iroh, ProviderService, }, - rpc_protocol::{ProviderService, SetTagOption, WrapOption}, sync::{ store::{DownloadPolicy, FilterKind, Query, SortDirection}, AuthorId, DocTicket, NamespaceId, @@ -115,6 +114,7 @@ pub enum DocCommands { /// Within the Iroh console, the active document can also set with `doc switch`. #[clap(short, long)] doc: Option, + /// The sharing mode. mode: ShareMode, /// Options to configure the address information in the generated ticket. /// @@ -285,24 +285,6 @@ pub enum DocCommands { }, } -/// Intended capability for document share tickets -#[derive(Serialize, Deserialize, Debug, Clone, clap::ValueEnum)] -pub enum ShareMode { - /// Read-only access - Read, - /// Write access - Write, -} - -impl From for iroh::rpc_protocol::ShareMode { - fn from(value: ShareMode) -> Self { - match value { - ShareMode::Read => iroh::rpc_protocol::ShareMode::Read, - ShareMode::Write => iroh::rpc_protocol::ShareMode::Write, - } - } -} - #[derive(clap::ValueEnum, Clone, Debug, Default, strum::Display)] #[strum(serialize_all = "kebab-case")] pub enum Sorting { @@ -369,7 +351,7 @@ impl DocCommands { addr_options, } => { let doc = get_doc(iroh, env, doc).await?; - let ticket = doc.share(mode.into(), addr_options).await?; + let ticket = doc.share(mode, addr_options).await?; println!("{}", ticket); } Self::Set { diff --git a/iroh-cli/src/commands/node.rs b/iroh-cli/src/commands/node.rs index d8f6bd499ff..e9d1a6b2e14 100644 --- a/iroh-cli/src/commands/node.rs +++ b/iroh-cli/src/commands/node.rs @@ -8,11 +8,11 @@ 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::net::{ key::PublicKey, magic_endpoint::{ConnectionInfo, DirectAddrInfo}, }; -use iroh::rpc_protocol::ProviderService; use quic_rpc::ServiceConnection; #[derive(Subcommand, Debug, Clone)] diff --git a/iroh-cli/src/commands/rpc.rs b/iroh-cli/src/commands/rpc.rs index 036ecf08c7b..da3f1cb292c 100644 --- a/iroh-cli/src/commands/rpc.rs +++ b/iroh-cli/src/commands/rpc.rs @@ -1,6 +1,6 @@ use anyhow::Result; use clap::Subcommand; -use iroh::{client::Iroh, rpc_protocol::ProviderService}; +use iroh::client::{Iroh, ProviderService}; use quic_rpc::ServiceConnection; use crate::config::ConsoleEnv; diff --git a/iroh-cli/src/commands/tag.rs b/iroh-cli/src/commands/tag.rs index f337f87c32b..fdf90fc17bd 100644 --- a/iroh-cli/src/commands/tag.rs +++ b/iroh-cli/src/commands/tag.rs @@ -3,7 +3,7 @@ use bytes::Bytes; use clap::Subcommand; use futures_lite::StreamExt; use iroh::bytes::Tag; -use iroh::{client::Iroh, rpc_protocol::ProviderService}; +use iroh::client::{Iroh, ProviderService}; use quic_rpc::ServiceConnection; #[derive(Subcommand, Debug, Clone)] diff --git a/iroh/examples/client.rs b/iroh/examples/client.rs index 7688ac0bdcc..0d488c42c2c 100644 --- a/iroh/examples/client.rs +++ b/iroh/examples/client.rs @@ -6,9 +6,7 @@ //! run this example from the project root: //! $ cargo run --example client use indicatif::HumanBytes; -use iroh::{client::Entry, node::Node}; -use iroh_base::base32; -use iroh_sync::store::Query; +use iroh::{base::base32, client::docs::Entry, node::Node, sync::store::Query}; use tokio_stream::StreamExt; #[tokio::main] diff --git a/iroh/examples/collection-provide.rs b/iroh/examples/collection-provide.rs index 3269ced626a..5f12a7b6c95 100644 --- a/iroh/examples/collection-provide.rs +++ b/iroh/examples/collection-provide.rs @@ -6,8 +6,7 @@ //! This is using an in memory database and a random node id. //! run this example from the project root: //! $ cargo run --example collection-provide -use iroh::rpc_protocol::SetTagOption; -use iroh_bytes::{format::collection::Collection, BlobFormat}; +use iroh::bytes::{format::collection::Collection, util::SetTagOption, BlobFormat}; use tracing_subscriber::{prelude::*, EnvFilter}; // set the RUST_LOG env var to one of {debug,info,warn} to see logging info diff --git a/iroh/src/client.rs b/iroh/src/client.rs index 936837134ca..19206c1af9f 100644 --- a/iroh/src/client.rs +++ b/iroh/src/client.rs @@ -5,7 +5,8 @@ use futures_lite::{Stream, StreamExt}; use quic_rpc::{RpcClient, ServiceConnection}; -use crate::rpc_protocol::ProviderService; +#[doc(inline)] +pub use crate::rpc_protocol::ProviderService; pub mod mem; pub mod quic; diff --git a/iroh/src/client/blobs.rs b/iroh/src/client/blobs.rs index 08afb37ae5a..ab36411f544 100644 --- a/iroh/src/client/blobs.rs +++ b/iroh/src/client/blobs.rs @@ -36,7 +36,7 @@ use crate::rpc_protocol::{ BlobGetCollectionResponse, BlobListCollectionsRequest, BlobListIncompleteRequest, BlobListRequest, BlobReadAtRequest, BlobReadAtResponse, BlobValidateRequest, CreateCollectionRequest, CreateCollectionResponse, NodeStatusRequest, ProviderService, - SetTagOption, WrapOption, + SetTagOption, }; use super::{flatten, Iroh}; @@ -376,6 +376,18 @@ where } } +/// Whether to wrap the added data in a collection. +#[derive(Debug, Serialize, Deserialize)] +pub enum WrapOption { + /// Do not wrap the file or directory. + NoWrap, + /// Wrap the file or directory in a collection. + Wrap { + /// Override the filename in the wrapping collection. + name: Option, + }, +} + /// Status information about a blob. #[derive(Debug, Clone, PartialEq, Eq)] pub enum BlobStatus { diff --git a/iroh/src/client/docs.rs b/iroh/src/client/docs.rs index f938dd9cd6f..a7a8cad2787 100644 --- a/iroh/src/client/docs.rs +++ b/iroh/src/client/docs.rs @@ -9,6 +9,7 @@ use std::{ use anyhow::{anyhow, Context as _, Result}; use bytes::Bytes; +use derive_more::{Display, FromStr}; use futures_lite::{Stream, StreamExt}; use iroh_base::{key::PublicKey, node_addr::AddrInfoOptions}; use iroh_bytes::{export::ExportProgress, store::ExportMode, Hash}; @@ -29,7 +30,7 @@ use crate::{ DocGetSyncPeersRequest, DocImportFileRequest, DocImportProgress, DocImportRequest, DocLeaveRequest, DocListRequest, DocOpenRequest, DocSetDownloadPolicyRequest, DocSetHashRequest, DocSetRequest, DocShareRequest, DocStartSyncRequest, DocStatusRequest, - DocSubscribeRequest, ProviderService, ShareMode, + DocSubscribeRequest, ProviderService, }, sync_engine::SyncEvent, }; @@ -471,6 +472,15 @@ impl Entry { } } +/// Intended capability for document share tickets +#[derive(Serialize, Deserialize, Debug, Clone, Display, FromStr)] +pub enum ShareMode { + /// Read-only access + Read, + /// Write access + Write, +} + /// Events informing about actions of the live sync progress. #[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq, strum::Display)] pub enum LiveEvent { diff --git a/iroh/src/lib.rs b/iroh/src/lib.rs index 90df5ad2e0b..7133e67380e 100644 --- a/iroh/src/lib.rs +++ b/iroh/src/lib.rs @@ -17,7 +17,7 @@ pub mod node; pub mod sync_engine; pub mod util; -pub mod rpc_protocol; +mod rpc_protocol; /// Expose metrics module #[cfg(feature = "metrics")] diff --git a/iroh/src/node.rs b/iroh/src/node.rs index 3d861f15cdd..90e89283919 100644 --- a/iroh/src/node.rs +++ b/iroh/src/node.rs @@ -283,8 +283,8 @@ mod tests { use iroh_net::relay::RelayMode; use crate::{ - client::blobs::BlobAddOutcome, - rpc_protocol::{BlobAddPathRequest, BlobAddPathResponse, SetTagOption, WrapOption}, + client::blobs::{BlobAddOutcome, WrapOption}, + rpc_protocol::{BlobAddPathRequest, BlobAddPathResponse, SetTagOption}, }; use super::*; diff --git a/iroh/src/node/rpc.rs b/iroh/src/node/rpc.rs index e616fdbd8a5..5cb2842dcf4 100644 --- a/iroh/src/node/rpc.rs +++ b/iroh/src/node/rpc.rs @@ -32,7 +32,9 @@ use quic_rpc::{ use tokio_util::task::LocalPoolHandle; use tracing::{debug, info}; -use crate::client::blobs::{BlobInfo, CollectionInfo, DownloadMode, IncompleteBlobInfo}; +use crate::client::blobs::{ + BlobInfo, CollectionInfo, DownloadMode, IncompleteBlobInfo, WrapOption, +}; use crate::client::node::NodeStatus; use crate::client::tags::TagInfo; use crate::rpc_protocol::{ @@ -648,7 +650,6 @@ impl Handler { msg: BlobAddPathRequest, progress: flume::Sender, ) -> anyhow::Result<()> { - use crate::rpc_protocol::WrapOption; use iroh_bytes::store::ImportMode; use std::collections::BTreeMap; diff --git a/iroh/src/rpc_protocol.rs b/iroh/src/rpc_protocol.rs index 08c7a0ad012..e451edc050f 100644 --- a/iroh/src/rpc_protocol.rs +++ b/iroh/src/rpc_protocol.rs @@ -42,7 +42,8 @@ pub use iroh_bytes::{provider::AddProgress, store::ValidateProgress}; use crate::{ client::{ - blobs::{BlobInfo, CollectionInfo, DownloadMode, IncompleteBlobInfo}, + blobs::{BlobInfo, CollectionInfo, DownloadMode, IncompleteBlobInfo, WrapOption}, + docs::ShareMode, node::NodeStatus, tags::TagInfo, }, @@ -50,9 +51,6 @@ use crate::{ }; pub use iroh_bytes::util::SetTagOption; -/// A 32-byte key or token -pub type KeyBytes = [u8; 32]; - /// A request to the node to provide the data at the given path /// /// Will produce a stream of [`AddProgress`] messages. @@ -73,18 +71,6 @@ pub struct BlobAddPathRequest { pub wrap: WrapOption, } -/// Whether to wrap the added data in a collection. -#[derive(Debug, Serialize, Deserialize)] -pub enum WrapOption { - /// Do not wrap the file or directory. - NoWrap, - /// Wrap the file or directory in a collection. - Wrap { - /// Override the filename in the wrapping collection. - name: Option, - }, -} - impl Msg for BlobAddPathRequest { type Pattern = ServerStreaming; } @@ -487,15 +473,6 @@ pub struct AuthorImportResponse { pub author_id: AuthorId, } -/// Intended capability for document share tickets -#[derive(Serialize, Deserialize, Debug, Clone)] -pub enum ShareMode { - /// Read-only access - Read, - /// Write access - Write, -} - /// Subscribe to events for a document. #[derive(Serialize, Deserialize, Debug)] pub struct DocSubscribeRequest { diff --git a/iroh/src/sync_engine/rpc.rs b/iroh/src/sync_engine/rpc.rs index 88f1ba9a5ed..6749d715b07 100644 --- a/iroh/src/sync_engine/rpc.rs +++ b/iroh/src/sync_engine/rpc.rs @@ -6,6 +6,7 @@ use iroh_bytes::{store::Store as BaoStore, BlobFormat}; use iroh_sync::{Author, DocTicket, NamespaceSecret}; use tokio_stream::StreamExt; +use crate::client::docs::ShareMode; use crate::rpc_protocol::{ AuthorDeleteRequest, AuthorDeleteResponse, AuthorExportRequest, AuthorExportResponse, AuthorImportRequest, AuthorImportResponse, DocGetSyncPeersRequest, DocGetSyncPeersResponse, @@ -21,7 +22,7 @@ use crate::{ DocSetDownloadPolicyRequest, DocSetDownloadPolicyResponse, DocSetHashRequest, DocSetHashResponse, DocSetRequest, DocSetResponse, DocShareRequest, DocShareResponse, DocStartSyncRequest, DocStartSyncResponse, DocStatusRequest, DocStatusResponse, - DocSubscribeRequest, DocSubscribeResponse, RpcResult, ShareMode, + DocSubscribeRequest, DocSubscribeResponse, RpcResult, }, sync_engine::SyncEngine, }; diff --git a/iroh/src/util/fs.rs b/iroh/src/util/fs.rs index 0eefe33bc1f..d1af9650b09 100644 --- a/iroh/src/util/fs.rs +++ b/iroh/src/util/fs.rs @@ -11,7 +11,7 @@ use iroh_net::key::SecretKey; use tokio::io::AsyncWriteExt; use walkdir::WalkDir; -use crate::rpc_protocol::WrapOption; +use crate::client::blobs::WrapOption; /// A data source #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)] diff --git a/iroh/tests/sync.rs b/iroh/tests/sync.rs index 37b5f4daae8..cc80ae7164e 100644 --- a/iroh/tests/sync.rs +++ b/iroh/tests/sync.rs @@ -10,15 +10,14 @@ use bytes::Bytes; use futures_lite::Stream; use futures_util::{FutureExt, StreamExt, TryStreamExt}; use iroh::{ + base::node_addr::AddrInfoOptions, client::{ - docs::{Entry, LiveEvent}, + docs::{Entry, LiveEvent, ShareMode}, mem::Doc, }, + net::key::{PublicKey, SecretKey}, node::{Builder, Node}, - rpc_protocol::ShareMode, }; -use iroh_base::node_addr::AddrInfoOptions; -use iroh_net::key::{PublicKey, SecretKey}; use quic_rpc::transport::misc::DummyServerEndpoint; use rand::{CryptoRng, Rng, SeedableRng}; use tracing::{debug, error_span, info, Instrument};