Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
codabrink committed Dec 13, 2024
1 parent 15fdc75 commit 61ce53e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 29 deletions.
2 changes: 1 addition & 1 deletion xmtp_mls/src/groups/mls_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ where

let decrypted_message = locked_openmls_group.process_message(provider, message)?;
let (sender_inbox_id, sender_installation_id) = extract_message_sender(
&mut *locked_openmls_group,
&mut locked_openmls_group,
&decrypted_message,
envelope_timestamp_ns,
)?;
Expand Down
2 changes: 0 additions & 2 deletions xmtp_mls/src/groups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use openmls::{
};
use openmls_traits::OpenMlsProvider;
use prost::Message;
use serial::SerialOpenMlsGroup;
use thiserror::Error;
use tokio::sync::Mutex;

Expand All @@ -60,7 +59,6 @@ use self::{
group_permissions::PolicySet,
validated_commit::CommitValidationError,
};
use std::ops::{Deref, DerefMut};
use std::{collections::HashSet, sync::Arc};
use xmtp_common::time::now_ns;
use xmtp_cryptography::signature::{sanitize_evm_addresses, AddressValidationError};
Expand Down
37 changes: 12 additions & 25 deletions xmtp_mls/src/groups/serial.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
use openmls::{
credentials::{BasicCredential, CredentialType},
error::LibraryError,
extensions::{
Extension, ExtensionType, Extensions, Metadata, RequiredCapabilitiesExtension,
UnknownExtension,
},
group::{
CreateGroupContextExtProposalError, MlsGroupCreateConfig, MlsGroupJoinConfig,
ProcessedWelcome,
},
messages::proposals::ProposalType,
prelude::{
BasicCredentialError, Capabilities, CredentialWithKey, Error as TlsCodecError, GroupId,
MlsGroup as OpenMlsGroup, StagedWelcome, Welcome as MlsWelcome, WireFormatPolicy,
},
};
use openmls::prelude::MlsGroup as OpenMlsGroup;

use std::{
collections::HashMap,
Expand All @@ -28,29 +12,31 @@ pub static MLS_COMMIT_LOCK: LazyLock<parking_lot::Mutex<HashMap<Vec<u8>, Arc<Mut

pub struct SerialOpenMlsGroup<'a> {
group: &'a mut OpenMlsGroup,
lock: MutexGuard<'a, ()>,
_lock: MutexGuard<'a, ()>,
_mutex: Arc<Mutex<()>>,
}

impl<'a> Deref for SerialOpenMlsGroup<'a> {
impl Deref for SerialOpenMlsGroup<'_> {
type Target = OpenMlsGroup;
fn deref(&self) -> &Self::Target {
&self.group
self.group
}
}

impl<'a> DerefMut for SerialOpenMlsGroup<'a> {
impl DerefMut for SerialOpenMlsGroup<'_> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.group
}
}

#[allow(unused)]
pub(crate) trait OpenMlsLock {
fn lock_blocking<'a>(&'a mut self) -> SerialOpenMlsGroup<'a>;
async fn lock<'a>(&'a mut self) -> SerialOpenMlsGroup<'a>;
fn lock_blocking(&mut self) -> SerialOpenMlsGroup;
async fn lock(&mut self) -> SerialOpenMlsGroup;
}

impl OpenMlsLock for OpenMlsGroup {
#[allow(clippy::needless_lifetimes)]
async fn lock<'a>(&'a mut self) -> SerialOpenMlsGroup<'a> {
// .clone() is important here so that the outer lock gets dropped
let mutex = MLS_COMMIT_LOCK
Expand All @@ -68,11 +54,12 @@ impl OpenMlsLock for OpenMlsGroup {

SerialOpenMlsGroup {
group: self,
lock,
_lock: lock,
_mutex: mutex,
}
}

#[allow(clippy::needless_lifetimes)]
fn lock_blocking<'a>(&'a mut self) -> SerialOpenMlsGroup<'a> {
// .clone() is important here so that the outer lock gets dropped
let mutex = MLS_COMMIT_LOCK
Expand All @@ -90,7 +77,7 @@ impl OpenMlsLock for OpenMlsGroup {

SerialOpenMlsGroup {
group: self,
lock,
_lock: lock,
_mutex: mutex,
}
}
Expand Down
1 change: 0 additions & 1 deletion xmtp_mls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ pub trait Delete<Model> {
fn delete(&self, key: Self::Key) -> Result<usize, StorageError>;
}

use crate::groups::GroupError;
pub use stream_handles::{
spawn, AbortHandle, GenericStreamHandle, StreamHandle, StreamHandleError,
};
Expand Down

0 comments on commit 61ce53e

Please sign in to comment.