Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ppodolsky committed Apr 17, 2024
1 parent c415ec6 commit a0552e7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 34 deletions.
72 changes: 43 additions & 29 deletions src/iroh_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,35 +90,49 @@ impl IrohNode {

let mut tables = HashMap::new();
let storage_configs = config_lock.iroh.storages.clone();
let mut init_futures = vec![];
for (table_name, table_config) in &mut config_lock.iroh.tables {
let iroh_doc = node
.client()
.docs
.open(NamespaceId::from_str(&table_config.id).map_err(Error::storage)?)
.await
.map_err(Error::table)?
.ok_or_else(|| Error::table(format!("{} does not exist", table_config.id)))?;
iroh_doc
.set_download_policy(table_config.download_policy.clone())
.await
.map_err(Error::doc)?;
let table_name = table_name.clone();
let table_config = table_config.clone();
let storage_config = table_config
.storage_name
.as_ref()
.map(|s| storage_configs[s].clone());
let task_tracker = task_tracker.clone();
let cancellation_token = cancellation_token.clone();
let node = node.clone();
let init_future = tokio::spawn(async move {
let iroh_doc = node
.client()
.docs
.open(NamespaceId::from_str(&table_config.id).map_err(Error::storage)?)
.await
.map_err(Error::table)?
.ok_or_else(|| Error::table(format!("{} does not exist", table_config.id)))?;
iroh_doc
.set_download_policy(table_config.download_policy.clone())
.await
.map_err(Error::doc)?;

iroh_doc.start_sync(vec![]).await.map_err(Error::doc)?;
let table = Table::new(
table_name,
author_id,
node.clone(),
iroh_doc.clone(),
table_config
.storage_name
.as_ref()
.map(|s| storage_configs[s].clone()),
table_config.clone(),
cancellation_token.clone(),
task_tracker.clone(),
)
.await?;
tables.insert(table_name.clone(), table);
iroh_doc.start_sync(vec![]).await.map_err(Error::doc)?;
let table = Table::new(
&table_name,
author_id,
node.clone(),
iroh_doc.clone(),
storage_config,
table_config.clone(),
cancellation_token.clone(),
task_tracker.clone(),
)
.await?;
Ok((table_name.clone(), table))
});
init_futures.push(init_future);
}
for init_future in init_futures {
let (table_name, table) = init_future.await.map_err(Error::node_create)??;
tables.insert(table_name, table);
}

let fs_storage_configs = config_lock.iroh.storages.clone();
Expand All @@ -131,8 +145,8 @@ impl IrohNode {
author_id,
config,
fs_storage_configs,
cancellation_token: cancellation_token.clone(),
task_tracker: task_tracker.clone(),
cancellation_token,
task_tracker,
};

Ok(iroh_node)
Expand Down
6 changes: 1 addition & 5 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,7 @@ impl Table {
format: BlobFormat::Raw,
nodes: peers
.iter()
.filter_map(|peer| {
PublicKey::from_bytes(peer)
.map(NodeAddr::from)
.ok()
})
.filter_map(|peer| PublicKey::from_bytes(peer).map(NodeAddr::from).ok())
.collect(),
tag: SetTagOption::Auto,
mode: DownloadMode::Direct,
Expand Down

0 comments on commit a0552e7

Please sign in to comment.