Skip to content

Commit 61acd96

Browse files
refactor: move ProtocolHandler docs to iroh-docs (#2859)
Depends on n0-computer/iroh-docs#3
1 parent 9495c21 commit 61acd96

File tree

10 files changed

+442
-531
lines changed

10 files changed

+442
-531
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@ iroh-router = { path = "./iroh-router" }
5454

5555
iroh-blobs = { git = "https://github.com/n0-computer/iroh-blobs", branch = "main" }
5656
iroh-gossip = { git = "https://github.com/n0-computer/iroh-gossip", branch = "main" }
57+
iroh-docs = { git = "https://github.com/n0-computer/iroh-docs", branch = "main" }

deny.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ ignore = [
3939
allow-git = [
4040
"https://github.com/n0-computer/iroh-blobs.git",
4141
"https://github.com/n0-computer/iroh-gossip.git",
42+
"https://github.com/n0-computer/iroh-docs.git",
4243
]

iroh-router/src/protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use iroh_net::endpoint::Connecting;
1313
///
1414
/// Implement this trait on a struct that should handle incoming connections.
1515
/// The protocol handler must then be registered on the node for an ALPN protocol with
16-
/// [`crate::node::builder::ProtocolBuilder::accept`].
16+
/// [`crate::RouterBuilder::accept`].
1717
pub trait ProtocolHandler: Send + Sync + IntoArcAny + std::fmt::Debug + 'static {
1818
/// Handle an incoming connection.
1919
///

iroh/src/node.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use iroh_blobs::{
5454
store::Store as BaoStore,
5555
util::local_pool::{LocalPool, LocalPoolHandle},
5656
};
57-
use iroh_docs::net::DOCS_ALPN;
57+
use iroh_docs::{engine::Engine, net::DOCS_ALPN};
5858
use iroh_net::{
5959
endpoint::{DirectAddrsStream, RemoteInfo},
6060
AddrInfo, Endpoint, NodeAddr,
@@ -65,11 +65,10 @@ use tokio::task::{JoinError, JoinSet};
6565
use tokio_util::{sync::CancellationToken, task::AbortOnDropHandle};
6666
use tracing::{debug, error, info, info_span, trace, warn, Instrument};
6767

68-
use crate::node::{nodes_storage::store_node_addrs, protocol::docs::DocsProtocol};
68+
use crate::node::nodes_storage::store_node_addrs;
6969

7070
mod builder;
7171
mod nodes_storage;
72-
mod protocol;
7372
mod rpc;
7473
mod rpc_status;
7574

@@ -294,7 +293,7 @@ impl<D: iroh_blobs::store::Store> NodeInner<D> {
294293
if let GcPolicy::Interval(gc_period) = gc_policy {
295294
let router = router.clone();
296295
let handle = local_pool.spawn(move || async move {
297-
let docs_engine = router.get_protocol::<DocsProtocol>(DOCS_ALPN);
296+
let docs_engine = router.get_protocol::<Engine>(DOCS_ALPN);
298297
let blobs = router
299298
.get_protocol::<BlobsProtocol<D>>(iroh_blobs::protocol::ALPN)
300299
.expect("missing blobs");

iroh/src/node/builder.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ use iroh_blobs::{
1616
store::{Map, Store as BaoStore},
1717
util::local_pool::{self, LocalPool, LocalPoolHandle, PanicMode},
1818
};
19-
use iroh_docs::{engine::DefaultAuthorStorage, net::DOCS_ALPN};
19+
use iroh_docs::{
20+
engine::{DefaultAuthorStorage, Engine},
21+
net::DOCS_ALPN,
22+
};
2023
use iroh_gossip::net::{Gossip, GOSSIP_ALPN};
2124
#[cfg(not(test))]
2225
use iroh_net::discovery::local_swarm_discovery::LocalSwarmDiscovery;
@@ -37,7 +40,7 @@ use tracing::{debug, error_span, trace, Instrument};
3740
use super::{rpc_status::RpcStatus, IrohServerEndpoint, JoinErrToStr, Node, NodeInner};
3841
use crate::{
3942
client::RPC_ALPN,
40-
node::{nodes_storage::load_node_addrs, protocol::docs::DocsProtocol},
43+
node::nodes_storage::load_node_addrs,
4144
rpc_protocol::RpcService,
4245
util::{fs::load_secret_key, path::IrohPaths},
4346
};
@@ -71,6 +74,32 @@ pub enum DocsStorage {
7174
Persistent(PathBuf),
7275
}
7376

77+
/// Start the engine, and prepare the selected storage version.
78+
async fn spawn_docs<S: iroh_blobs::store::Store>(
79+
storage: DocsStorage,
80+
blobs_store: S,
81+
default_author_storage: DefaultAuthorStorage,
82+
endpoint: Endpoint,
83+
gossip: Gossip,
84+
downloader: Downloader,
85+
) -> anyhow::Result<Option<Engine>> {
86+
let docs_store = match storage {
87+
DocsStorage::Disabled => return Ok(None),
88+
DocsStorage::Memory => iroh_docs::store::fs::Store::memory(),
89+
DocsStorage::Persistent(path) => iroh_docs::store::fs::Store::persistent(path)?,
90+
};
91+
let engine = Engine::spawn(
92+
endpoint,
93+
gossip,
94+
docs_store,
95+
blobs_store,
96+
downloader,
97+
default_author_storage,
98+
)
99+
.await?;
100+
Ok(Some(engine))
101+
}
102+
74103
/// Builder for the [`Node`].
75104
///
76105
/// You must supply a blob store and a document store.
@@ -651,7 +680,7 @@ where
651680

652681
// Spawn the docs engine, if enabled.
653682
// This returns None for DocsStorage::Disabled, otherwise Some(DocsProtocol).
654-
let docs = DocsProtocol::spawn(
683+
let docs = spawn_docs(
655684
self.docs_storage,
656685
self.blobs_store.clone(),
657686
self.storage.default_author_storage(),
@@ -809,7 +838,7 @@ impl<D: iroh_blobs::store::Store> ProtocolBuilder<D> {
809838
store: D,
810839
gossip: Gossip,
811840
downloader: Downloader,
812-
docs: Option<DocsProtocol>,
841+
docs: Option<Engine>,
813842
) -> Self {
814843
// Register blobs.
815844
let blobs_proto = BlobsProtocol::new_with_events(

iroh/src/node/protocol.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

iroh/src/node/protocol/docs.rs

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)