1
1
use serde:: { Serialize , Deserialize } ;
2
2
use anyhow:: { Result , Error , anyhow} ;
3
3
use std:: path:: PathBuf ;
4
+ use std:: any:: Any ;
4
5
use iroh_blobs:: Hash ;
5
6
use std:: sync:: Arc ;
6
7
use veilid_core:: {
7
- CryptoKey , DHTRecordDescriptor , CryptoTyped , CryptoSystemVLD0 , RoutingContext , SharedSecret , TypedKey
8
+ CryptoKey , DHTRecordDescriptor , CryptoTyped , CryptoSystemVLD0 , RoutingContext , SharedSecret , TypedKey , ProtectedStore
8
9
} ;
9
10
use veilid_iroh_blobs:: iroh:: VeilidIrohBlobs ;
10
- use crate :: common:: DHTEntity ;
11
+ use crate :: common:: { DHTEntity , DHTRecordInfo } ;
11
12
use crate :: repo:: Repo ;
12
13
13
14
#[ derive( Clone ) ]
@@ -67,7 +68,7 @@ impl Group {
67
68
}
68
69
}
69
70
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 > {
71
72
if let Some ( iroh_blobs) = & self . iroh_blobs {
72
73
// Upload the file and get the hash
73
74
let hash = iroh_blobs. upload_from_path ( file_path) . await ?;
@@ -79,11 +80,22 @@ impl Group {
79
80
self . routing_context . set_dht_value (
80
81
self . dht_record . key ( ) . clone ( ) ,
81
82
1 ,
82
- root_hash_hex. into ( ) ,
83
+ root_hash_hex. clone ( ) . into ( ) ,
83
84
None
84
85
)
85
86
. await
86
87
. 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
+
87
99
88
100
Ok ( hash)
89
101
} else {
0 commit comments