@@ -33,6 +33,7 @@ use vodozemac::Curve25519PublicKey;
3333use super :: {
3434 caches:: DeviceStore , Account , BackupKeys , Changes , CryptoStore , DehydratedDeviceKey ,
3535 InboundGroupSession , PendingChanges , RoomKeyCounts , RoomSettings , Session ,
36+ StoredRoomKeyBundleData ,
3637} ;
3738use crate :: {
3839 gossiping:: { GossipRequest , GossippedSecret , SecretInfo } ,
@@ -71,7 +72,7 @@ impl BackupVersion {
7172}
7273
7374/// An in-memory only store that will forget all the E2EE key once it's dropped.
74- #[ derive( Debug ) ]
75+ #[ derive( Default , Debug ) ]
7576pub struct MemoryStore {
7677 static_account : Arc < StdRwLock < Option < StaticAccountData > > > ,
7778
@@ -102,36 +103,10 @@ pub struct MemoryStore {
102103 dehydrated_device_pickle_key : RwLock < Option < DehydratedDeviceKey > > ,
103104 next_batch_token : RwLock < Option < String > > ,
104105 room_settings : StdRwLock < HashMap < OwnedRoomId , RoomSettings > > ,
105- save_changes_lock : Arc < Mutex < ( ) > > ,
106- }
106+ room_key_bundles :
107+ StdRwLock < HashMap < OwnedRoomId , HashMap < OwnedUserId , StoredRoomKeyBundleData > > > ,
107108
108- impl Default for MemoryStore {
109- fn default ( ) -> Self {
110- MemoryStore {
111- static_account : Default :: default ( ) ,
112- account : Default :: default ( ) ,
113- sessions : Default :: default ( ) ,
114- inbound_group_sessions : Default :: default ( ) ,
115- inbound_group_sessions_backed_up_to : Default :: default ( ) ,
116- outbound_group_sessions : Default :: default ( ) ,
117- private_identity : Default :: default ( ) ,
118- tracked_users : Default :: default ( ) ,
119- olm_hashes : Default :: default ( ) ,
120- devices : DeviceStore :: new ( ) ,
121- identities : Default :: default ( ) ,
122- outgoing_key_requests : Default :: default ( ) ,
123- key_requests_by_info : Default :: default ( ) ,
124- direct_withheld_info : Default :: default ( ) ,
125- custom_values : Default :: default ( ) ,
126- leases : Default :: default ( ) ,
127- backup_keys : Default :: default ( ) ,
128- dehydrated_device_pickle_key : Default :: default ( ) ,
129- secret_inbox : Default :: default ( ) ,
130- next_batch_token : Default :: default ( ) ,
131- room_settings : Default :: default ( ) ,
132- save_changes_lock : Default :: default ( ) ,
133- }
134- }
109+ save_changes_lock : Arc < Mutex < ( ) > > ,
135110}
136111
137112impl MemoryStore {
@@ -348,6 +323,16 @@ impl CryptoStore for MemoryStore {
348323 settings. extend ( changes. room_settings ) ;
349324 }
350325
326+ if !changes. received_room_key_bundles . is_empty ( ) {
327+ let mut room_key_bundles = self . room_key_bundles . write ( ) ;
328+ for bundle in changes. received_room_key_bundles {
329+ room_key_bundles
330+ . entry ( bundle. bundle_data . room_id . clone ( ) )
331+ . or_default ( )
332+ . insert ( bundle. sender_user . clone ( ) , bundle) ;
333+ }
334+ }
335+
351336 Ok ( ( ) )
352337 }
353338
@@ -719,6 +704,18 @@ impl CryptoStore for MemoryStore {
719704 Ok ( self . room_settings . read ( ) . get ( room_id) . cloned ( ) )
720705 }
721706
707+ async fn get_received_room_key_bundle_data (
708+ & self ,
709+ room_id : & RoomId ,
710+ user_id : & UserId ,
711+ ) -> Result < Option < StoredRoomKeyBundleData > > {
712+ let guard = self . room_key_bundles . read ( ) ;
713+
714+ let result = guard. get ( room_id) . and_then ( |bundles| bundles. get ( user_id) . cloned ( ) ) ;
715+
716+ Ok ( result)
717+ }
718+
722719 async fn get_custom_value ( & self , key : & str ) -> Result < Option < Vec < u8 > > > {
723720 Ok ( self . custom_values . read ( ) . get ( key) . cloned ( ) )
724721 }
@@ -1249,7 +1246,7 @@ mod integration_tests {
12491246 } ,
12501247 store:: {
12511248 BackupKeys , Changes , CryptoStore , DehydratedDeviceKey , PendingChanges , RoomKeyCounts ,
1252- RoomSettings ,
1249+ RoomSettings , StoredRoomKeyBundleData ,
12531250 } ,
12541251 types:: events:: room_key_withheld:: RoomKeyWithheldEvent ,
12551252 Account , DeviceData , GossipRequest , GossippedSecret , SecretInfo , Session , TrackedUser ,
@@ -1511,6 +1508,14 @@ mod integration_tests {
15111508 self . 0 . get_room_settings ( room_id) . await
15121509 }
15131510
1511+ async fn get_received_room_key_bundle_data (
1512+ & self ,
1513+ room_id : & RoomId ,
1514+ user_id : & UserId ,
1515+ ) -> crate :: store:: Result < Option < StoredRoomKeyBundleData > , Self :: Error > {
1516+ self . 0 . get_received_room_key_bundle_data ( room_id, user_id) . await
1517+ }
1518+
15141519 async fn get_custom_value ( & self , key : & str ) -> Result < Option < Vec < u8 > > , Self :: Error > {
15151520 self . 0 . get_custom_value ( key) . await
15161521 }
0 commit comments