Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move ProtocolHandler docs to iroh-docs #2859

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = "main" }
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",
]
2 changes: 1 addition & 1 deletion iroh-router/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use iroh_net::endpoint::Connecting;
///
/// Implement this trait on a struct that should handle incoming connections.
/// The protocol handler must then be registered on the node for an ALPN protocol with
/// [`crate::node::builder::ProtocolBuilder::accept`].
/// [`crate::RouterBuilder::accept`].
pub trait ProtocolHandler: Send + Sync + IntoArcAny + std::fmt::Debug + 'static {
/// Handle an incoming connection.
///
Expand Down
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
Loading