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

feat(iroh): disable docs by default #2748

Merged
merged 3 commits into from
Sep 30, 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
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/examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tokio_stream::StreamExt;

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

// Could also use `node` directly, as it derefs to the client.
let client = node.client();
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
34 changes: 28 additions & 6 deletions iroh/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,13 +642,21 @@ 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?;
}

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?;

Ok(())
Expand Down Expand Up @@ -734,7 +742,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 +764,7 @@ mod tests {
let iroh = Node::persistent(iroh_root)
.await
.unwrap()
.enable_docs()
.spawn()
.await
.unwrap();
Expand All @@ -771,6 +780,7 @@ mod tests {
let iroh = Node::persistent(iroh_root)
.await
.unwrap()
.enable_docs()
.spawn()
.await
.unwrap();
Expand All @@ -790,6 +800,7 @@ mod tests {
let iroh = Node::persistent(iroh_root)
.await
.unwrap()
.enable_docs()
.spawn()
.await
.unwrap();
Expand All @@ -810,8 +821,12 @@ mod tests {
docs_store.delete_author(default_author).unwrap();
docs_store.flush().unwrap();
drop(docs_store);
let iroh = Node::persistent(iroh_root).await.unwrap().spawn().await;
dbg!(&iroh);
let iroh = Node::persistent(iroh_root)
.await
.unwrap()
.enable_docs()
.spawn()
.await;
assert!(iroh.is_err());

// somehow the blob store is not shutdown correctly (yet?) on macos.
Expand All @@ -823,7 +838,12 @@ mod tests {
.await
.unwrap();
drop(iroh);
let iroh = Node::persistent(iroh_root).await.unwrap().spawn().await;
let iroh = Node::persistent(iroh_root)
.await
.unwrap()
.enable_docs()
.spawn()
.await;
assert!(iroh.is_ok());
iroh.unwrap().shutdown().await.unwrap();
}
Expand All @@ -833,6 +853,7 @@ mod tests {
let iroh = Node::persistent(iroh_root)
.await
.unwrap()
.enable_docs()
.spawn()
.await
.unwrap();
Expand All @@ -846,6 +867,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
8 changes: 8 additions & 0 deletions iroh/tests/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const TIMEOUT: Duration = Duration::from_secs(60);
fn test_node(secret_key: SecretKey) -> Builder<iroh_blobs::store::mem::Store> {
Node::memory()
.secret_key(secret_key)
.enable_docs()
.relay_mode(RelayMode::Disabled)
}

Expand Down Expand Up @@ -493,13 +494,15 @@ async fn test_sync_via_relay() -> Result<()> {
let node1 = Node::memory()
.relay_mode(RelayMode::Custom(relay_map.clone()))
.insecure_skip_relay_cert_verify(true)
.enable_docs()
.spawn()
.await?;
let node1_id = node1.node_id();
let node2 = Node::memory()
.bind_random_port()
.relay_mode(RelayMode::Custom(relay_map.clone()))
.insecure_skip_relay_cert_verify(true)
.enable_docs()
.spawn()
.await?;

Expand Down Expand Up @@ -593,6 +596,7 @@ async fn sync_restart_node() -> Result<()> {
.relay_mode(RelayMode::Custom(relay_map.clone()))
.dns_resolver(discovery_server.dns_resolver())
.node_discovery(discovery_server.discovery(secret_key_1.clone()).into())
.enable_docs()
.spawn()
.await?;
let id1 = node1.node_id();
Expand All @@ -612,6 +616,7 @@ async fn sync_restart_node() -> Result<()> {
.insecure_skip_relay_cert_verify(true)
.dns_resolver(discovery_server.dns_resolver())
.node_discovery(discovery_server.discovery(secret_key_2.clone()).into())
.enable_docs()
.spawn()
.await?;
let id2 = node2.node_id();
Expand Down Expand Up @@ -658,6 +663,7 @@ async fn sync_restart_node() -> Result<()> {
.relay_mode(RelayMode::Custom(relay_map.clone()))
.dns_resolver(discovery_server.dns_resolver())
.node_discovery(discovery_server.discovery(secret_key_1.clone()).into())
.enable_docs()
.spawn()
.await?;
assert_eq!(id1, node1.node_id());
Expand Down Expand Up @@ -979,6 +985,7 @@ async fn test_list_docs_stream() -> Result<()> {
let node = Node::memory()
.node_discovery(iroh::node::DiscoveryConfig::None)
.relay_mode(iroh::net::relay::RelayMode::Disabled)
.enable_docs()
.spawn()
.await?;
let count = 200;
Expand Down Expand Up @@ -1148,6 +1155,7 @@ impl PartialEq<ExpectedEntry> for (Entry, Bytes) {
async fn doc_delete() -> Result<()> {
let node = Node::memory()
.gc_policy(iroh::node::GcPolicy::Interval(Duration::from_millis(100)))
.enable_docs()
.spawn()
.await?;
let client = node.client();
Expand Down
Loading