Skip to content

Commit

Permalink
refactor(iroh): move blobs protocol to iroh-blobs (#2853)
Browse files Browse the repository at this point in the history
This moves the implementation of `iroh_router::ProtocolHandler` for
`iroh-blobs` into the `iroh-blobs` crate

Depends on n0-computer/iroh-blobs#6
  • Loading branch information
dignifiedquire authored Oct 29, 2024
1 parent 86b494a commit 30f3e03
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 332 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 6 additions & 17 deletions iroh/src/client/blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ use futures_lite::{Stream, StreamExt};
use futures_util::SinkExt;
use genawaiter::sync::{Co, Gen};
use iroh_base::{node_addr::AddrInfoOptions, ticket::BlobTicket};
pub use iroh_blobs::net_protocol::DownloadMode;
use iroh_blobs::{
export::ExportProgress as BytesExportProgress,
format::collection::{Collection, SimpleStore},
get::db::DownloadProgress as BytesDownloadProgress,
net_protocol::BlobDownloadRequest,
store::{BaoBlobSize, ConsistencyCheckProgress, ExportFormat, ExportMode, ValidateProgress},
util::SetTagOption,
BlobFormat, Hash, Tag,
Expand All @@ -90,6 +92,7 @@ use serde::{Deserialize, Serialize};
use tokio::io::{AsyncRead, AsyncReadExt, ReadBuf};
use tokio_util::io::{ReaderStream, StreamReader};
use tracing::warn;

mod batch;
pub use batch::{AddDirOpts, AddFileOpts, AddReaderOpts, Batch};

Expand All @@ -98,8 +101,8 @@ use crate::rpc_protocol::{
blobs::{
AddPathRequest, AddStreamRequest, AddStreamUpdate, BatchCreateRequest, BatchCreateResponse,
BlobStatusRequest, ConsistencyCheckRequest, CreateCollectionRequest,
CreateCollectionResponse, DeleteRequest, DownloadRequest, ExportRequest,
ListIncompleteRequest, ListRequest, ReadAtRequest, ReadAtResponse, ValidateRequest,
CreateCollectionResponse, DeleteRequest, ExportRequest, ListIncompleteRequest, ListRequest,
ReadAtRequest, ReadAtResponse, ValidateRequest,
},
node::StatusRequest,
};
Expand Down Expand Up @@ -357,7 +360,7 @@ impl Client {
} = opts;
let stream = self
.rpc
.server_streaming(DownloadRequest {
.server_streaming(BlobDownloadRequest {
hash,
format,
nodes,
Expand Down Expand Up @@ -980,20 +983,6 @@ pub struct DownloadOptions {
pub mode: DownloadMode,
}

/// Set the mode for whether to directly start the download or add it to the download queue.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum DownloadMode {
/// Start the download right away.
///
/// No concurrency limits or queuing will be applied. It is up to the user to manage download
/// concurrency.
Direct,
/// Queue the download.
///
/// The download queue will be processed in-order, while respecting the downloader concurrency limits.
Queued,
}

#[cfg(test)]
mod tests {
use iroh_blobs::hashseq::HashSeq;
Expand Down
3 changes: 2 additions & 1 deletion iroh/src/client/blobs/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use futures_lite::StreamExt;
use futures_util::{sink::Buffer, FutureExt, SinkExt, Stream};
use iroh_blobs::{
format::collection::Collection,
net_protocol::BatchId,
provider::BatchAddPathProgress,
store::ImportMode,
util::{SetTagOption, TagDrop},
Expand All @@ -27,7 +28,7 @@ use crate::{
rpc_protocol::{
blobs::{
BatchAddPathRequest, BatchAddStreamRequest, BatchAddStreamResponse,
BatchAddStreamUpdate, BatchCreateTempTagRequest, BatchId, BatchUpdate,
BatchAddStreamUpdate, BatchCreateTempTagRequest, BatchUpdate,
},
tags::{self, SyncMode},
},
Expand Down
2 changes: 1 addition & 1 deletion iroh/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ use futures_lite::StreamExt;
use futures_util::future::{MapErr, Shared};
use iroh_base::key::PublicKey;
use iroh_blobs::{
net_protocol::Blobs as BlobsProtocol,
store::Store as BaoStore,
util::local_pool::{LocalPool, LocalPoolHandle},
};
Expand All @@ -59,7 +60,6 @@ use iroh_net::{
AddrInfo, Endpoint, NodeAddr,
};
use iroh_router::{ProtocolHandler, Router};
use protocol::blobs::BlobsProtocol;
use quic_rpc::{transport::ServerEndpoint as _, RpcServer};
use tokio::task::{JoinError, JoinSet};
use tokio_util::{sync::CancellationToken, task::AbortOnDropHandle};
Expand Down
6 changes: 2 additions & 4 deletions iroh/src/node/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use futures_util::{FutureExt as _, TryFutureExt as _};
use iroh_base::key::SecretKey;
use iroh_blobs::{
downloader::Downloader,
net_protocol::Blobs as BlobsProtocol,
provider::EventSender,
store::{Map, Store as BaoStore},
util::local_pool::{self, LocalPool, LocalPoolHandle, PanicMode},
Expand All @@ -36,10 +37,7 @@ use tracing::{debug, error_span, trace, Instrument};
use super::{rpc_status::RpcStatus, IrohServerEndpoint, JoinErrToStr, Node, NodeInner};
use crate::{
client::RPC_ALPN,
node::{
nodes_storage::load_node_addrs,
protocol::{blobs::BlobsProtocol, docs::DocsProtocol},
},
node::{nodes_storage::load_node_addrs, protocol::docs::DocsProtocol},
rpc_protocol::RpcService,
util::{fs::load_secret_key, path::IrohPaths},
};
Expand Down
1 change: 0 additions & 1 deletion iroh/src/node/protocol.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pub(crate) mod blobs;
pub(crate) mod docs;
Loading

0 comments on commit 30f3e03

Please sign in to comment.