From a6145ee55e0b6282228217568fd1de26b513fb2c Mon Sep 17 00:00:00 2001 From: Andrew Plaza Date: Thu, 2 Nov 2023 11:06:55 -0400 Subject: [PATCH] fix group membership enum --- Cargo.lock | 99 ++++++++++++++++++- xmtp_mls/src/storage/encrypted_store/group.rs | 10 +- .../storage/encrypted_store/group_intent.rs | 5 +- .../storage/encrypted_store/group_message.rs | 2 + .../encrypted_store/key_store_entry.rs | 21 +--- 5 files changed, 111 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6ed71ff32..e955b0b0b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2926,6 +2926,15 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + [[package]] name = "matches" version = "0.1.10" @@ -3182,6 +3191,16 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi 0.3.9", +] + [[package]] name = "num-bigint" version = "0.4.4" @@ -3531,6 +3550,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "p256" version = "0.13.2" @@ -4342,10 +4367,19 @@ checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick", "memchr", - "regex-automata", + "regex-automata 0.4.3", "regex-syntax 0.8.2", ] +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + [[package]] name = "regex-automata" version = "0.4.3" @@ -4357,6 +4391,12 @@ dependencies = [ "regex-syntax 0.8.2", ] +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + [[package]] name = "regex-syntax" version = "0.7.2" @@ -4999,6 +5039,15 @@ dependencies = [ "keccak", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -5358,6 +5407,16 @@ dependencies = [ "syn 2.0.38", ] +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if 1.0.0", + "once_cell", +] + [[package]] name = "time" version = "0.1.45" @@ -5701,6 +5760,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" dependencies = [ "once_cell", + "valuable", ] [[package]] @@ -5713,6 +5773,35 @@ dependencies = [ "tracing", ] +[[package]] +name = "tracing-log" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f751112709b4e791d8ce53e32c4ed2d353565a795ce84da2285393f41557bdf2" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + [[package]] name = "try-lock" version = "0.2.4" @@ -5844,6 +5933,12 @@ dependencies = [ "rand 0.8.5", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "vcpkg" version = "0.2.15" @@ -6502,6 +6597,8 @@ dependencies = [ "tls_codec", "tokio", "toml 0.7.4", + "tracing", + "tracing-subscriber", "xmtp_api_grpc", "xmtp_cryptography", "xmtp_proto", diff --git a/xmtp_mls/src/storage/encrypted_store/group.rs b/xmtp_mls/src/storage/encrypted_store/group.rs index 9e958299f..9e3865373 100644 --- a/xmtp_mls/src/storage/encrypted_store/group.rs +++ b/xmtp_mls/src/storage/encrypted_store/group.rs @@ -3,7 +3,7 @@ use super::schema::groups; use crate::impl_fetch_and_store; use diesel::prelude::*; -use diesel::{backend::Backend, sqlite::Sqlite, serialize::{self, Output, ToSql, IsNull}, deserialize::{self, FromSql}, sql_types::Integer, expression::AsExpression}; +use diesel::{backend::Backend, sqlite::Sqlite, serialize::{self, Output, ToSql, IsNull}, deserialize::{self, FromSql, FromSqlRow}, sql_types::Integer, expression::AsExpression}; /// The Group ID type. pub type ID = Vec; @@ -18,7 +18,7 @@ pub struct StoredGroup { /// based on timestamp of this welcome message pub created_at_ns: i64, /// enum, [`GroupMembershipState`] representing access to the group. - pub membership_state: i32, + pub membership_state: GroupMembershipState, } impl_fetch_and_store!(StoredGroup, groups, Vec); @@ -26,13 +26,13 @@ impl_fetch_and_store!(StoredGroup, groups, Vec); impl StoredGroup { pub fn new(id: ID, created_at_ns: i64, membership_state: GroupMembershipState) -> Self { Self { - id, created_at_ns, membership_state: membership_state as i32 + id, created_at_ns, membership_state: membership_state } } } #[repr(i32)] -#[derive(Debug, Clone, Copy, AsExpression)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, AsExpression, FromSqlRow)] #[diesel(sql_type = Integer)] /// Status of membership in a group, once a user sends a request to join pub enum GroupMembershipState { @@ -113,7 +113,7 @@ mod tests { test_group.store(&mut conn).unwrap(); let updated_group = store.update_group_membership(&mut conn, id, GroupMembershipState::Rejected).unwrap(); - assert_eq!(updated_group, StoredGroup { membership_state: GroupMembershipState::Rejected as i32, ..test_group }); + assert_eq!(updated_group, StoredGroup { membership_state: GroupMembershipState::Rejected, ..test_group }); }) } } diff --git a/xmtp_mls/src/storage/encrypted_store/group_intent.rs b/xmtp_mls/src/storage/encrypted_store/group_intent.rs index 7da2954d9..6d2eb5a81 100644 --- a/xmtp_mls/src/storage/encrypted_store/group_intent.rs +++ b/xmtp_mls/src/storage/encrypted_store/group_intent.rs @@ -7,9 +7,9 @@ use diesel::prelude::*; pub struct StoredGroupIntent { pub id: i32, pub kind: i32, - pub state: i32, pub group_id: Vec, pub data: Vec, + pub state: i32, pub payload_hash: Option>, pub post_commit_data: Option>, } @@ -18,7 +18,8 @@ pub struct StoredGroupIntent { #[diesel(table_name = group_intents)] pub struct NewGroupIntent { pub kind: i32, - pub state: i32, pub group_id: Vec, pub data: Vec, + pub state: i32, } + diff --git a/xmtp_mls/src/storage/encrypted_store/group_message.rs b/xmtp_mls/src/storage/encrypted_store/group_message.rs index de6fd6b1c..8ecffd8ff 100644 --- a/xmtp_mls/src/storage/encrypted_store/group_message.rs +++ b/xmtp_mls/src/storage/encrypted_store/group_message.rs @@ -15,6 +15,8 @@ pub struct StoredGroupMessage { pub decrypted_message_bytes: Vec, /// Time in nanoseconds the message was sent. pub sent_at_ns: i64, + /// Group Message Kind Enum + pub kind: i32, /// The ID of the App Installation this message was sent from. pub sender_installation_id: Vec, /// Network wallet address of the Sender diff --git a/xmtp_mls/src/storage/encrypted_store/key_store_entry.rs b/xmtp_mls/src/storage/encrypted_store/key_store_entry.rs index f2cb87e7a..453d68863 100644 --- a/xmtp_mls/src/storage/encrypted_store/key_store_entry.rs +++ b/xmtp_mls/src/storage/encrypted_store/key_store_entry.rs @@ -1,6 +1,7 @@ use super::DbConnection; use super::{schema::openmls_key_store, StorageError}; -use crate::{Delete, Fetch, Store}; +use crate::impl_fetch_and_store; +use crate::Delete; use diesel::prelude::*; #[derive(Insertable, Queryable, Debug, Clone)] @@ -11,23 +12,7 @@ pub struct StoredKeyStoreEntry { pub value_bytes: Vec, } -impl Store for StoredKeyStoreEntry { - fn store(&self, into: &mut DbConnection) -> Result<(), StorageError> { - diesel::insert_into(openmls_key_store::table) - .values(self) - .execute(into)?; - - Ok(()) - } -} - -impl Fetch for DbConnection { - type Key = Vec; - fn fetch(&mut self, key: Vec) -> Result, StorageError> where { - use super::schema::openmls_key_store::dsl::*; - Ok(openmls_key_store.find(key).first(self).optional()?) - } -} +impl_fetch_and_store!(StoredKeyStoreEntry, openmls_key_store, Vec); impl Delete for DbConnection { type Key = Vec;