Skip to content

Commit

Permalink
refactor: move ProtocolHandler docs to iroh-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Oct 29, 2024
1 parent 30f3e03 commit 3a73ff7
Show file tree
Hide file tree
Showing 9 changed files with 440 additions and 529 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ iroh-router = { path = "./iroh-router" }

iroh-blobs = { git = "https://github.com/n0-computer/iroh-blobs", branch = "main" }
iroh-gossip = { git = "https://github.com/n0-computer/iroh-gossip", branch = "main" }
iroh-docs = { git = "https://github.com/n0-computer/iroh-docs", branch = "refactor-protocol-handler" }
1 change: 1 addition & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ ignore = [
allow-git = [
"https://github.com/n0-computer/iroh-blobs.git",
"https://github.com/n0-computer/iroh-gossip.git",
"https://github.com/n0-computer/iroh-docs.git",
]
7 changes: 3 additions & 4 deletions iroh/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use iroh_blobs::{
store::Store as BaoStore,
util::local_pool::{LocalPool, LocalPoolHandle},
};
use iroh_docs::net::DOCS_ALPN;
use iroh_docs::{engine::Engine, net::DOCS_ALPN};
use iroh_net::{
endpoint::{DirectAddrsStream, RemoteInfo},
AddrInfo, Endpoint, NodeAddr,
Expand All @@ -65,11 +65,10 @@ use tokio::task::{JoinError, JoinSet};
use tokio_util::{sync::CancellationToken, task::AbortOnDropHandle};
use tracing::{debug, error, info, info_span, trace, warn, Instrument};

use crate::node::{nodes_storage::store_node_addrs, protocol::docs::DocsProtocol};
use crate::node::nodes_storage::store_node_addrs;

mod builder;
mod nodes_storage;
mod protocol;
mod rpc;
mod rpc_status;

Expand Down Expand Up @@ -294,7 +293,7 @@ impl<D: iroh_blobs::store::Store> NodeInner<D> {
if let GcPolicy::Interval(gc_period) = gc_policy {
let router = router.clone();
let handle = local_pool.spawn(move || async move {
let docs_engine = router.get_protocol::<DocsProtocol>(DOCS_ALPN);
let docs_engine = router.get_protocol::<Engine>(DOCS_ALPN);
let blobs = router
.get_protocol::<BlobsProtocol<D>>(iroh_blobs::protocol::ALPN)
.expect("missing blobs");
Expand Down
37 changes: 33 additions & 4 deletions iroh/src/node/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ use iroh_blobs::{
store::{Map, Store as BaoStore},
util::local_pool::{self, LocalPool, LocalPoolHandle, PanicMode},
};
use iroh_docs::{engine::DefaultAuthorStorage, net::DOCS_ALPN};
use iroh_docs::{
engine::{DefaultAuthorStorage, Engine},
net::DOCS_ALPN,
};
use iroh_gossip::net::{Gossip, GOSSIP_ALPN};
#[cfg(not(test))]
use iroh_net::discovery::local_swarm_discovery::LocalSwarmDiscovery;
Expand All @@ -37,7 +40,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::docs::DocsProtocol},
node::nodes_storage::load_node_addrs,
rpc_protocol::RpcService,
util::{fs::load_secret_key, path::IrohPaths},
};
Expand Down Expand Up @@ -71,6 +74,32 @@ pub enum DocsStorage {
Persistent(PathBuf),
}

/// Start the engine, and prepare the selected storage version.
async fn spawn_docs<S: iroh_blobs::store::Store>(
storage: DocsStorage,
blobs_store: S,
default_author_storage: DefaultAuthorStorage,
endpoint: Endpoint,
gossip: Gossip,
downloader: Downloader,
) -> anyhow::Result<Option<Engine>> {
let docs_store = match storage {
DocsStorage::Disabled => return Ok(None),
DocsStorage::Memory => iroh_docs::store::fs::Store::memory(),
DocsStorage::Persistent(path) => iroh_docs::store::fs::Store::persistent(path)?,
};
let engine = Engine::spawn(
endpoint,
gossip,
docs_store,
blobs_store,
downloader,
default_author_storage,
)
.await?;
Ok(Some(engine))
}

/// Builder for the [`Node`].
///
/// You must supply a blob store and a document store.
Expand Down Expand Up @@ -651,7 +680,7 @@ where

// Spawn the docs engine, if enabled.
// This returns None for DocsStorage::Disabled, otherwise Some(DocsProtocol).
let docs = DocsProtocol::spawn(
let docs = spawn_docs(
self.docs_storage,
self.blobs_store.clone(),
self.storage.default_author_storage(),
Expand Down Expand Up @@ -809,7 +838,7 @@ impl<D: iroh_blobs::store::Store> ProtocolBuilder<D> {
store: D,
gossip: Gossip,
downloader: Downloader,
docs: Option<DocsProtocol>,
docs: Option<Engine>,
) -> Self {
// Register blobs.
let blobs_proto = BlobsProtocol::new_with_events(
Expand Down
1 change: 0 additions & 1 deletion iroh/src/node/protocol.rs

This file was deleted.

64 changes: 0 additions & 64 deletions iroh/src/node/protocol/docs.rs

This file was deleted.

Loading

0 comments on commit 3a73ff7

Please sign in to comment.