Skip to content

Commit e285bdd

Browse files
committed
Add DHTRecordInfo struct for storage in protected store in upload_blob
1 parent 0953fc6 commit e285bdd

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/group.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use serde::{Serialize, Deserialize};
22
use anyhow::{Result, Error, anyhow};
33
use std::path::PathBuf;
4+
use std::any::Any;
45
use iroh_blobs::Hash;
56
use std::sync::Arc;
67
use veilid_core::{
7-
CryptoKey, DHTRecordDescriptor, CryptoTyped, CryptoSystemVLD0, RoutingContext, SharedSecret, TypedKey
8+
CryptoKey, DHTRecordDescriptor, CryptoTyped, CryptoSystemVLD0, RoutingContext, SharedSecret, TypedKey, ProtectedStore
89
};
910
use veilid_iroh_blobs::iroh::VeilidIrohBlobs;
10-
use crate::common::DHTEntity;
11+
use crate::common::{ DHTEntity, DHTRecordInfo };
1112
use crate::repo::Repo;
1213

1314
#[derive(Clone)]
@@ -67,7 +68,7 @@ impl Group {
6768
}
6869
}
6970

70-
pub async fn upload_blob(&self, file_path: PathBuf) -> Result<Hash> {
71+
pub async fn upload_blob(&self, file_path: PathBuf, protected_store: &ProtectedStore) -> Result<Hash> {
7172
if let Some(iroh_blobs) = &self.iroh_blobs {
7273
// Upload the file and get the hash
7374
let hash = iroh_blobs.upload_from_path(file_path).await?;
@@ -79,11 +80,22 @@ impl Group {
7980
self.routing_context.set_dht_value(
8081
self.dht_record.key().clone(),
8182
1,
82-
root_hash_hex.into(),
83+
root_hash_hex.clone().into(),
8384
None
8485
)
8586
.await
8687
.map_err(|e| anyhow!("Failed to store collection blob in DHT: {}", e))?;
88+
89+
// Create an instance of DHTRecordInfo
90+
let dht_record_info = DHTRecordInfo {
91+
id: self.get_id().clone(),
92+
dht_key: self.dht_record.key().value,
93+
cid: Some(root_hash_hex),
94+
};
95+
96+
// Store the DHT record info and CID in the Veilid protected store
97+
dht_record_info.store(protected_store).await.map_err(|e| anyhow!("Failed to store DHT record info: {}", e))?;
98+
8799

88100
Ok(hash)
89101
} else {

0 commit comments

Comments
 (0)