forked from n0-computer/iroh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(iroh): allow to disable docs engine completely (n0-computer#2390)
Make the docs engine optional on the iroh node. * Add `Builder::disable_docs()` to disable the docs engine completely * If called, the docs engine will not be spawned and the docs protocol will not be registered. Incoming docs connnections will be dropped, and all docs-related RPC calls will return an error "docs are disabled". * `iroh::node::Builder::with_db_and_store` now takes a `DocsStorage` enum instead of a `iroh_docs::store::Store`. <!-- Any notes, remarks or open questions you have to make about the PR. --> - [x] Self-review. - [x] Documentation updates if relevant. - [ ] Tests if relevant. - [x] All breaking changes documented.
- Loading branch information
Showing
9 changed files
with
265 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use std::{ops::Deref, sync::Arc}; | ||
|
||
use anyhow::Result; | ||
use futures_lite::future::Boxed as BoxedFuture; | ||
use iroh_blobs::downloader::Downloader; | ||
use iroh_gossip::net::Gossip; | ||
|
||
use iroh_docs::engine::{DefaultAuthorStorage, Engine}; | ||
use iroh_net::{endpoint::Connecting, Endpoint}; | ||
|
||
use crate::node::{DocsStorage, ProtocolHandler}; | ||
|
||
/// Wrapper around [`Engine`] so that we can implement our RPC methods directly. | ||
#[derive(Debug, Clone)] | ||
pub(crate) struct DocsEngine(Engine); | ||
|
||
impl DocsEngine { | ||
pub async fn spawn<S: iroh_blobs::store::Store>( | ||
storage: DocsStorage, | ||
blobs_store: S, | ||
default_author_storage: DefaultAuthorStorage, | ||
endpoint: Endpoint, | ||
gossip: Gossip, | ||
downloader: Downloader, | ||
) -> anyhow::Result<Option<Self>> { | ||
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(DocsEngine(engine))) | ||
} | ||
} | ||
|
||
impl Deref for DocsEngine { | ||
type Target = Engine; | ||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl ProtocolHandler for DocsEngine { | ||
fn accept(self: Arc<Self>, conn: Connecting) -> BoxedFuture<Result<()>> { | ||
Box::pin(async move { self.handle_connection(conn).await }) | ||
} | ||
} |
Oops, something went wrong.