Skip to content

Commit

Permalink
feat(iroh): disable docs by default
Browse files Browse the repository at this point in the history
## Breaking Changes

- removed: `iroh::node::Builder::disable_docs`
- added: `iroh::node::Builder::enable_docs`
- by default `iroh::node::Node::memory` & `persistent` have docs disabled
  • Loading branch information
dignifiedquire committed Sep 25, 2024
1 parent 19c8fd3 commit 4a3caff
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions iroh-cli/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ pub(crate) async fn start_node(
Node::persistent(iroh_data_root)
.await?
.relay_mode(relay_mode)
.enable_docs()
.enable_rpc_with_addr(rpc_addr)
.await?
.spawn()
Expand Down
2 changes: 1 addition & 1 deletion iroh/src/client/authors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ mod tests {

#[tokio::test]
async fn test_authors() -> Result<()> {
let node = Node::memory().spawn().await?;
let node = Node::memory().enable_docs().spawn().await?;

// default author always exists
let authors: Vec<_> = node.authors().list().await?.try_collect().await?;
Expand Down
6 changes: 3 additions & 3 deletions iroh/src/client/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ mod tests {
async fn test_drop_doc_client_sync() -> Result<()> {
let _guard = iroh_test::logging::setup();

let node = crate::node::Node::memory().spawn().await?;
let node = crate::node::Node::memory().enable_docs().spawn().await?;

let client = node.client();
let doc = client.docs().create().await?;
Expand All @@ -778,7 +778,7 @@ mod tests {
async fn test_doc_close() -> Result<()> {
let _guard = iroh_test::logging::setup();

let node = crate::node::Node::memory().spawn().await?;
let node = crate::node::Node::memory().enable_docs().spawn().await?;
let author = node.authors().default().await?;
// open doc two times
let doc1 = node.docs().create().await?;
Expand All @@ -801,7 +801,7 @@ mod tests {
async fn test_doc_import_export() -> Result<()> {
let _guard = iroh_test::logging::setup();

let node = crate::node::Node::memory().spawn().await?;
let node = crate::node::Node::memory().enable_docs().spawn().await?;

// create temp file
let temp_dir = tempfile::tempdir().context("tempdir")?;
Expand Down
10 changes: 8 additions & 2 deletions iroh/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,11 @@ mod tests {

let iroh_root = tempfile::TempDir::new()?;
{
let iroh = Node::persistent(iroh_root.path()).await?.spawn().await?;
let iroh = Node::persistent(iroh_root.path())
.await?
.enable_docs()
.spawn()
.await?;
let doc = iroh.docs().create().await?;
drop(doc);
iroh.shutdown().await?;
Expand Down Expand Up @@ -734,7 +738,7 @@ mod tests {

#[tokio::test]
async fn test_default_author_memory() -> Result<()> {
let iroh = Node::memory().spawn().await?;
let iroh = Node::memory().enable_docs().spawn().await?;
let author = iroh.authors().default().await?;
assert!(iroh.authors().export(author).await?.is_some());
assert!(iroh.authors().delete(author).await.is_err());
Expand All @@ -756,6 +760,7 @@ mod tests {
let iroh = Node::persistent(iroh_root)
.await
.unwrap()
.enable_docs()
.spawn()
.await
.unwrap();
Expand All @@ -771,6 +776,7 @@ mod tests {
let iroh = Node::persistent(iroh_root)
.await
.unwrap()
.enable_docs()
.spawn()
.await
.unwrap();
Expand Down
20 changes: 15 additions & 5 deletions iroh/src/node/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl Default for Builder<iroh_blobs::store::mem::Store> {
rpc_endpoint: mk_external_rpc(),
rpc_addr: None,
gc_policy: GcPolicy::Disabled,
docs_storage: DocsStorage::Memory,
docs_storage: DocsStorage::Disabled,
node_discovery: Default::default(),
#[cfg(any(test, feature = "test-utils"))]
insecure_skip_relay_cert_verify: false,
Expand Down Expand Up @@ -318,7 +318,12 @@ where
.with_context(|| {
format!("Failed to load blobs database from {}", blob_dir.display())
})?;
let docs_storage = DocsStorage::Persistent(IrohPaths::DocsDatabase.with_root(root));
let docs_storage = match self.docs_storage {
DocsStorage::Persistent(_) | DocsStorage::Memory => {
DocsStorage::Persistent(IrohPaths::DocsDatabase.with_root(root))
}
DocsStorage::Disabled => DocsStorage::Disabled,
};

let secret_key_path = IrohPaths::SecretKey.with_root(root);
let secret_key = load_secret_key(secret_key_path).await?;
Expand Down Expand Up @@ -384,9 +389,14 @@ where
self
}

/// Disables documents support on this node completely.
pub fn disable_docs(mut self) -> Self {
self.docs_storage = DocsStorage::Disabled;
/// Enables documents support on this node.
pub fn enable_docs(mut self) -> Self {
self.docs_storage = match self.storage {
StorageConfig::Mem => DocsStorage::Memory,
StorageConfig::Persistent(ref root) => {
DocsStorage::Persistent(IrohPaths::DocsDatabase.with_root(root))
}
};
self
}

Expand Down

0 comments on commit 4a3caff

Please sign in to comment.