From 01ebc489014b0b43e907ae79324cd2d43151b749 Mon Sep 17 00:00:00 2001 From: Alois Date: Mon, 6 Jul 2026 00:13:53 +0200 Subject: [PATCH 1/2] (feat): more crypto migration --- type-maps.yaml | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/type-maps.yaml b/type-maps.yaml index 354f186..34d0757 100644 --- a/type-maps.yaml +++ b/type-maps.yaml @@ -99,13 +99,10 @@ type_maps: AppChallengeResponse: 133 AppIdentificationResponse: 134 LoadTxtRecord: 135 - SetEncryptedDeviceSecret: 139 - GetEncryptedDeviceSecret: 140 - EncryptedDeviceSecretResponse: 141 - EncryptedMessage: 142 - EncryptedMessageAck: 143 - EncryptedMessagesGet: 144 - EncryptedMessagesResponse: 145 + SetChatSecret: 139 + GetChatSecret: 140 + ChatSecretResponse: 141 + ChatSecretForward: 142 DataTypes: ErrorType: 32 ErrorProtocol: 33 @@ -213,18 +210,9 @@ type_maps: SecretId: 142 VersionNumber: 143 EncryptedSecret: 144 - WrappingPublicKeyId: 145 WrappingScheme: 146 UpdatedAt: 147 - MessageId: 148 - ConversationId: 149 - SenderClientId: 150 - RecipientClientId: 151 + ChatId: 148 + KemCiphertext: 149 SenderUserId: 152 RecipientUserId: 153 - EncryptionVersion: 154 - HasMore: 155 - NextCursor: 156 - Since: 157 - Limit: 158 - PeerClientId: 159 From 32c053dfa51b2b1d0f9f30fad90b123328262147 Mon Sep 17 00:00:00 2001 From: Alois Date: Mon, 6 Jul 2026 18:50:00 +0200 Subject: [PATCH 2/2] (feat): chat crypto migrations --- src/rho/iota_connection.rs | 43 +++++++++++++++++++++++++++++++++++++- type-maps.yaml | 2 ++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/rho/iota_connection.rs b/src/rho/iota_connection.rs index dca059c..95956a4 100755 --- a/src/rho/iota_connection.rs +++ b/src/rho/iota_connection.rs @@ -19,13 +19,16 @@ use mtp::crypto::KemPublicKey; use mtp::host::Receiver; use mtp::host::Sender; use std::collections::BTreeMap; -use std::{collections::HashMap, sync::Arc, time::Duration}; +use std::{collections::HashMap, sync::Arc, sync::LazyLock, time::Duration}; use tokio::sync::RwLock; use tokio::sync::mpsc; use super::{rho_connection::RhoConnection, rho_manager}; use crate::omega::omega_connection::OmegaConnection; +static PENDING_CHAT_SECRETS: LazyLock>> = + LazyLock::new(DashMap::new); + #[allow(dead_code)] pub struct IotaConnection { pub iota_id: u64, @@ -101,6 +104,10 @@ impl IotaConnection { let user_ids_i64: Vec = user_ids.into_iter().map(|u| u as i64).collect(); rho_conn.set_user_ids(user_ids_i64).await; } + + for user_id in self.get_user_ids().await { + self.flush_pending_chat_secrets(user_id).await; + } } pub async fn add_user_id(&self, user_id: u64) { @@ -117,9 +124,33 @@ impl IotaConnection { if let Some(rho_conn) = self.get_rho_connection().await { rho_conn.add_user_id(user_id as i64).await; } + + self.flush_pending_chat_secrets(user_id).await; } } + async fn flush_pending_chat_secrets(&self, user_id: u64) { + let Some((_, messages)) = PENDING_CHAT_SECRETS.remove(&user_id) else { + return; + }; + + for message in messages { + self.send_message(&message).await; + } + } + + fn store_pending_chat_secret(cv: CommunicationValue) { + let receiver_id = cv.get_receiver(); + if receiver_id == 0 || !cv.is_type(CommunicationType::SetChatSecret) { + return; + } + + PENDING_CHAT_SECRETS + .entry(receiver_id) + .or_default() + .push(cv); + } + /// Get current ping pub async fn get_ping(&self) -> i64 { *self.ping.read().await @@ -301,6 +332,16 @@ impl IotaConnection { if let Some(target_rho) = rho_manager::get_rho_con_for_user(receiver_id as i64).await { target_rho.message_to_iota(cv).await; } else { + if cv.is_type(CommunicationType::SetChatSecret) { + Self::store_pending_chat_secret(cv.clone()); + let success = CommunicationValue::new(CommunicationType::Success) + .with_id(cv.get_id()) + .with_sender(cv.get_sender()) + .with_receiver(cv.get_sender()); + self.send_message(&success).await; + return; + } + let error = CommunicationValue::new(CommunicationType::ErrorNoIota) .with_id(cv.get_id()) .with_sender(cv.get_sender()); diff --git a/type-maps.yaml b/type-maps.yaml index 34d0757..db7fc47 100644 --- a/type-maps.yaml +++ b/type-maps.yaml @@ -99,6 +99,7 @@ type_maps: AppChallengeResponse: 133 AppIdentificationResponse: 134 LoadTxtRecord: 135 + ErrorNotSet: 136 SetChatSecret: 139 GetChatSecret: 140 ChatSecretResponse: 141 @@ -216,3 +217,4 @@ type_maps: KemCiphertext: 149 SenderUserId: 152 RecipientUserId: 153 + Recipients: 154