Skip to content

Commit

Permalink
refactor: make iroh::rpc_protocol private
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed May 2, 2024
1 parent 21542e5 commit 99f1e25
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 83 deletions.
2 changes: 1 addition & 1 deletion iroh-cli/src/commands/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 8 additions & 10 deletions iroh-cli/src/commands/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion 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, rpc_protocol::ProviderService};
use iroh::client::{Iroh, ProviderService};
use quic_rpc::ServiceConnection;
use rustyline::{error::ReadlineError, Config, DefaultEditor};
use tokio::sync::{mpsc, oneshot};
Expand Down
30 changes: 6 additions & 24 deletions iroh-cli/src/commands/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<NamespaceId>,
/// The sharing mode.
mode: ShareMode,
/// Options to configure the address information in the generated ticket.
///
Expand Down Expand Up @@ -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<ShareMode> 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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion iroh-cli/src/commands/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion 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, rpc_protocol::ProviderService};
use iroh::client::{Iroh, ProviderService};
use quic_rpc::ServiceConnection;

use crate::config::ConsoleEnv;
Expand Down
2 changes: 1 addition & 1 deletion 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, rpc_protocol::ProviderService};
use iroh::client::{Iroh, ProviderService};
use quic_rpc::ServiceConnection;

#[derive(Subcommand, Debug, Clone)]
Expand Down
4 changes: 1 addition & 3 deletions iroh/examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions iroh/examples/collection-provide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion iroh/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 13 additions & 1 deletion iroh/src/client/blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<String>,
},
}

/// Status information about a blob.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BlobStatus {
Expand Down
12 changes: 11 additions & 1 deletion iroh/src/client/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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,
};
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion iroh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
4 changes: 2 additions & 2 deletions iroh/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
5 changes: 3 additions & 2 deletions iroh/src/node/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -648,7 +650,6 @@ impl<D: BaoStore> Handler<D> {
msg: BlobAddPathRequest,
progress: flume::Sender<AddProgress>,
) -> anyhow::Result<()> {
use crate::rpc_protocol::WrapOption;
use iroh_bytes::store::ImportMode;
use std::collections::BTreeMap;

Expand Down
27 changes: 2 additions & 25 deletions iroh/src/rpc_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,15 @@ 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,
},
sync_engine::LiveEvent,
};
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.
Expand All @@ -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<String>,
},
}

impl Msg<ProviderService> for BlobAddPathRequest {
type Pattern = ServerStreaming;
}
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion iroh/src/sync_engine/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion iroh/src/util/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
7 changes: 3 additions & 4 deletions iroh/tests/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down

0 comments on commit 99f1e25

Please sign in to comment.