Skip to content

Commit

Permalink
use DocsStorage::Disabled instead of option
Browse files Browse the repository at this point in the history
  • Loading branch information
Frando committed Jun 20, 2024
1 parent 3e91647 commit 4689cd3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
36 changes: 17 additions & 19 deletions iroh/src/node/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const MAX_STREAMS: u64 = 10;
/// Storage backend for documents.
#[derive(Debug, Clone)]
pub enum DocsStorage {
/// Disable docs completely.
Disabled,
/// In-memory storage.
Memory,
/// File-based persistent storage.
Expand Down Expand Up @@ -94,7 +96,7 @@ where
gc_policy: GcPolicy,
dns_resolver: Option<DnsResolver>,
node_discovery: DiscoveryConfig,
docs_storage: Option<DocsStorage>,
docs_storage: DocsStorage,
#[cfg(any(test, feature = "test-utils"))]
insecure_skip_relay_cert_verify: bool,
/// Callback to register when a gc loop is done
Expand Down Expand Up @@ -155,7 +157,7 @@ impl Default for Builder<iroh_blobs::store::mem::Store> {
dns_resolver: None,
rpc_endpoint: Default::default(),
gc_policy: GcPolicy::Disabled,
docs_storage: Some(DocsStorage::Memory),
docs_storage: DocsStorage::Memory,
node_discovery: Default::default(),
#[cfg(any(test, feature = "test-utils"))]
insecure_skip_relay_cert_verify: false,
Expand All @@ -181,7 +183,7 @@ impl<D: Map> Builder<D> {
dns_resolver: None,
rpc_endpoint: Default::default(),
gc_policy: GcPolicy::Disabled,
docs_storage: Some(docs_storage),
docs_storage,
node_discovery: Default::default(),
#[cfg(any(test, feature = "test-utils"))]
insecure_skip_relay_cert_verify: false,
Expand Down Expand Up @@ -245,7 +247,7 @@ where
relay_mode: self.relay_mode,
dns_resolver: self.dns_resolver,
gc_policy: self.gc_policy,
docs_storage: Some(docs_storage),
docs_storage,
node_discovery: self.node_discovery,
#[cfg(any(test, feature = "test-utils"))]
insecure_skip_relay_cert_verify: false,
Expand Down Expand Up @@ -310,7 +312,7 @@ where

/// Disables documents support on this node completely.
pub fn disable_docs(mut self) -> Self {
self.docs_storage = None;
self.docs_storage = DocsStorage::Disabled;
self
}

Expand Down Expand Up @@ -480,20 +482,16 @@ where
let downloader = Downloader::new(self.blobs_store.clone(), endpoint.clone(), lp.clone());

// Spawn the docs engine, if enabled.
let docs = if let Some(docs_storage) = &self.docs_storage {
let docs = DocsEngine::spawn(
docs_storage,
self.blobs_store.clone(),
self.storage.default_author_storage(),
endpoint.clone(),
gossip.clone(),
downloader.clone(),
)
.await?;
Some(docs)
} else {
None
};
// This returns None for DocsStorage::Disabled, otherwise Some(DocsEngine).
let docs = DocsEngine::spawn(
self.docs_storage,
self.blobs_store.clone(),
self.storage.default_author_storage(),
endpoint.clone(),
gossip.clone(),
downloader.clone(),
)
.await?;

// Initialize the internal RPC connection.
let (internal_rpc, controller) = quic_rpc::transport::flume::connection(1);
Expand Down
7 changes: 4 additions & 3 deletions iroh/src/node/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ pub(crate) struct DocsEngine(Engine);

impl DocsEngine {
pub async fn spawn<S: iroh_blobs::store::Store>(
storage: &DocsStorage,
storage: DocsStorage,
blobs_store: S,
default_author_storage: DefaultAuthorStorage,
endpoint: Endpoint,
gossip: Gossip,
downloader: Downloader,
) -> anyhow::Result<Self> {
) -> 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)?,
};
Expand All @@ -36,7 +37,7 @@ impl DocsEngine {
default_author_storage,
)
.await?;
Ok(DocsEngine(engine))
Ok(Some(DocsEngine(engine)))
}
}

Expand Down

0 comments on commit 4689cd3

Please sign in to comment.