@@ -25,9 +25,9 @@ use tokio::sync::{
2525use tracing:: info;
2626use url:: Url ;
2727use veilid_core:: {
28- api_startup_config, vld0_generate_keypair , CryptoKey , CryptoSystem , CryptoSystemVLD0 ,
29- CryptoTyped , DHTSchema , KeyPair , ProtectedStore , RoutingContext , SharedSecret , TypedKey ,
30- UpdateCallback , VeilidAPI , VeilidConfigInner , VeilidConfigProtectedStore , VeilidUpdate ,
28+ api_startup_config, PublicKey , SecretKey , RecordKey , CryptoSystem ,
29+ CryptoTyped , DHTSchema , KeyPair , ProtectedStore , RoutingContext , SharedSecret , TypedRecordKey ,
30+ UpdateCallback , VeilidAPI , VeilidConfig , VeilidConfigProtectedStore , VeilidUpdate ,
3131 CRYPTO_KEY_LENGTH , CRYPTO_KIND_VLD0 ,
3232} ;
3333use veilid_iroh_blobs:: iroh:: VeilidIrohBlobs ;
@@ -36,14 +36,14 @@ use xdg::BaseDirectories;
3636
3737#[ derive( Serialize , Deserialize , Debug ) ]
3838pub struct KnownGroupList {
39- groups : Vec < CryptoKey > ,
39+ groups : Vec < RecordKey > ,
4040}
4141
4242pub struct BackendInner {
4343 path : PathBuf ,
4444 veilid_api : Option < VeilidAPI > ,
4545 update_rx : Option < broadcast:: Receiver < VeilidUpdate > > ,
46- groups : HashMap < CryptoKey , Box < Group > > ,
46+ groups : HashMap < RecordKey , Box < Group > > ,
4747 pub iroh_blobs : Option < VeilidIrohBlobs > ,
4848 on_new_route_callback : Option < OnNewRouteCallback > ,
4949}
@@ -54,7 +54,7 @@ impl BackendInner {
5454
5555 let info = KnownGroupList { groups } ;
5656
57- println ! ( "Saving group IDs {:?}" , info ) ;
57+ println ! ( "Saving group IDs {info :?}" ) ;
5858 let data =
5959 serde_cbor:: to_vec ( & info) . map_err ( |e| anyhow ! ( "Failed to serialize keypair: {}" , e) ) ?;
6060 self . veilid ( ) ?
@@ -160,16 +160,17 @@ impl Backend {
160160 let mut inner = backend. inner . lock ( ) . await ;
161161
162162 // Initialize iroh_blobs
163- inner . iroh_blobs = Some ( VeilidIrohBlobs :: new (
164- veilid_api. clone ( ) ,
165- routing_context,
163+ let config = veilid_iroh_blobs :: iroh :: VeilidIrohBlobsConfig {
164+ veilid : veilid_api. clone ( ) ,
165+ router : routing_context,
166166 route_id_blob,
167167 route_id,
168- inner. update_rx . as_ref ( ) . unwrap ( ) . resubscribe ( ) ,
168+ updates : inner. update_rx . as_ref ( ) . unwrap ( ) . resubscribe ( ) ,
169169 store,
170- Some ( on_disconnected_callback) , // TODO: Notify application of route closure?
171- Some ( on_new_route_callback) ,
172- ) ) ;
170+ on_route_disconnected_callback : Some ( on_disconnected_callback) , // TODO: Notify application of route closure?
171+ on_new_route_callback : Some ( on_new_route_callback) ,
172+ } ;
173+ inner. iroh_blobs = Some ( VeilidIrohBlobs :: new ( config) ) ;
173174
174175 drop ( inner) ;
175176
@@ -229,16 +230,17 @@ impl Backend {
229230 } ) ;
230231
231232 // Initialize iroh_blobs
232- inner . iroh_blobs = Some ( VeilidIrohBlobs :: new (
233- veilid_api. clone ( ) ,
234- routing_context,
233+ let config = veilid_iroh_blobs :: iroh :: VeilidIrohBlobsConfig {
234+ veilid : veilid_api. clone ( ) ,
235+ router : routing_context,
235236 route_id_blob,
236237 route_id,
237- update_rx. resubscribe ( ) ,
238+ updates : update_rx. resubscribe ( ) ,
238239 store,
239- None , // TODO: Notify application of route closure?
240- Some ( on_new_route_callback) ,
241- ) ) ;
240+ on_route_disconnected_callback : None , // TODO: Notify application of route closure?
241+ on_new_route_callback : Some ( on_new_route_callback) ,
242+ } ;
243+ inner. iroh_blobs = Some ( VeilidIrohBlobs :: new ( config) ) ;
242244
243245 drop ( inner) ;
244246
@@ -300,7 +302,7 @@ impl Backend {
300302 . get ( CRYPTO_KIND_VLD0 )
301303 . ok_or_else ( || anyhow ! ( "Unable to init crypto system" ) ) ;
302304
303- let record_key = TypedKey :: new ( CRYPTO_KIND_VLD0 , keys. id ) ;
305+ let record_key = TypedRecordKey :: new ( CRYPTO_KIND_VLD0 , keys. id ) ;
304306 // First open the DHT record
305307 let dht_record = routing_context
306308 . open_dht_record ( record_key. clone ( ) , None ) // Don't pass a writer here yet
@@ -385,7 +387,7 @@ impl Backend {
385387 Ok ( group)
386388 }
387389
388- pub async fn get_group ( & self , record_key : & CryptoKey ) -> Result < Box < Group > > {
390+ pub async fn get_group ( & self , record_key : & RecordKey ) -> Result < Box < Group > > {
389391 let mut inner = self . inner . lock ( ) . await ;
390392 if let Some ( group) = inner. groups . get ( record_key) {
391393 return Ok ( group. clone ( ) ) ;
@@ -409,7 +411,7 @@ impl Backend {
409411 // Use the owner key from the DHT record as the default writer
410412 let owner_key = retrieved_keypair. public_key ; // Call the owner() method to get the owner key
411413 let owner_secret = retrieved_keypair. secret_key ;
412- let record_key = TypedKey :: new ( CRYPTO_KIND_VLD0 , * record_key) ;
414+ let record_key = TypedRecordKey :: new ( CRYPTO_KIND_VLD0 , * record_key) ;
413415
414416 let owner = owner_secret. map ( |secret| KeyPair :: new ( owner_key, secret) ) ;
415417
@@ -448,7 +450,7 @@ impl Backend {
448450 Ok ( ( ) )
449451 }
450452
451- pub async fn list_known_group_ids ( & self ) -> Result < Vec < CryptoKey > > {
453+ pub async fn list_known_group_ids ( & self ) -> Result < Vec < RecordKey > > {
452454 let mut inner = self . inner . lock ( ) . await ;
453455 let veilid = inner. veilid ( ) ?;
454456 let data = veilid
@@ -461,7 +463,7 @@ impl Backend {
461463 Ok ( info. groups )
462464 }
463465
464- pub async fn close_group ( & self , key : CryptoKey ) -> Result < ( ) > {
466+ pub async fn close_group ( & self , key : RecordKey ) -> Result < ( ) > {
465467 let mut inner = self . inner . lock ( ) . await ;
466468 if let Some ( group) = inner. groups . remove ( & key) {
467469 group. close ( ) . await . map_err ( |e| anyhow ! ( e) ) ?;
@@ -540,23 +542,45 @@ fn find_query(url: &Url, key: &str) -> Result<String> {
540542 Err ( anyhow ! ( "Unable to find parameter {} in URL {:?}" , key, url) )
541543}
542544
543- pub fn crypto_key_from_query ( url : & Url , key : & str ) -> Result < CryptoKey > {
545+ pub fn record_key_from_query ( url : & Url , key : & str ) -> Result < RecordKey > {
546+ let value = find_query ( url, key) ?;
547+ let bytes = hex:: decode ( value) ?;
548+ let mut key_vec: [ u8 ; 32 ] = [ 0 ; 32 ] ;
549+ key_vec. copy_from_slice ( bytes. as_slice ( ) ) ;
550+ Ok ( RecordKey :: new ( key_vec) )
551+ }
552+
553+ pub fn public_key_from_query ( url : & Url , key : & str ) -> Result < PublicKey > {
544554 let value = find_query ( url, key) ?;
545555 let bytes = hex:: decode ( value) ?;
546- let mut key_vec: [ u8 ; CRYPTO_KEY_LENGTH ] = [ 0 ; CRYPTO_KEY_LENGTH ] ;
556+ let mut key_vec: [ u8 ; 32 ] = [ 0 ; 32 ] ;
547557 key_vec. copy_from_slice ( bytes. as_slice ( ) ) ;
558+ Ok ( PublicKey :: new ( key_vec) )
559+ }
548560
549- let key = CryptoKey :: from ( key_vec) ;
550- Ok ( key)
561+ pub fn secret_key_from_query ( url : & Url , key : & str ) -> Result < SecretKey > {
562+ let value = find_query ( url, key) ?;
563+ let bytes = hex:: decode ( value) ?;
564+ let mut key_vec: [ u8 ; 32 ] = [ 0 ; 32 ] ;
565+ key_vec. copy_from_slice ( bytes. as_slice ( ) ) ;
566+ Ok ( SecretKey :: new ( key_vec) )
567+ }
568+
569+ pub fn shared_secret_from_query ( url : & Url , key : & str ) -> Result < SharedSecret > {
570+ let value = find_query ( url, key) ?;
571+ let bytes = hex:: decode ( value) ?;
572+ let mut key_vec: [ u8 ; 32 ] = [ 0 ; 32 ] ;
573+ key_vec. copy_from_slice ( bytes. as_slice ( ) ) ;
574+ Ok ( SharedSecret :: new ( key_vec) )
551575}
552576
553577pub fn parse_url ( url_string : & str ) -> Result < CommonKeypair > {
554578 let url = Url :: parse ( url_string) ?;
555579
556- let id = crypto_key_from_query ( & url, URL_DHT_KEY ) ?;
557- let encryption_key = crypto_key_from_query ( & url, URL_ENCRYPTION_KEY ) ?;
558- let public_key = crypto_key_from_query ( & url, URL_PUBLIC_KEY ) ?;
559- let secret_key = Some ( crypto_key_from_query ( & url, URL_SECRET_KEY ) ?) ;
580+ let id = record_key_from_query ( & url, URL_DHT_KEY ) ?;
581+ let encryption_key = shared_secret_from_query ( & url, URL_ENCRYPTION_KEY ) ?;
582+ let public_key = public_key_from_query ( & url, URL_PUBLIC_KEY ) ?;
583+ let secret_key = Some ( secret_key_from_query ( & url, URL_SECRET_KEY ) ?) ;
560584
561585 Ok ( CommonKeypair {
562586 id,
0 commit comments