crypto: Don't add the same session twice to the memory session store.
parent
bedb788432
commit
514ced1243
|
@ -37,7 +37,10 @@ impl SessionStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a session to the store.
|
/// Add a session to the store.
|
||||||
pub async fn add(&mut self, session: Session) {
|
///
|
||||||
|
/// Returns true if the the session was already in the store, false
|
||||||
|
/// otherwise.
|
||||||
|
pub async fn add(&mut self, session: Session) -> bool {
|
||||||
if !self.entries.contains_key(&*session.sender_key) {
|
if !self.entries.contains_key(&*session.sender_key) {
|
||||||
self.entries.insert(
|
self.entries.insert(
|
||||||
session.sender_key.to_string(),
|
session.sender_key.to_string(),
|
||||||
|
@ -45,7 +48,13 @@ impl SessionStore {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
let sessions = self.entries.get_mut(&*session.sender_key).unwrap();
|
let sessions = self.entries.get_mut(&*session.sender_key).unwrap();
|
||||||
|
|
||||||
|
if !sessions.lock().await.contains(&session) {
|
||||||
sessions.lock().await.push(session);
|
sessions.lock().await.push(session);
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get all the sessions that belong to the given sender key.
|
/// Get all the sessions that belong to the given sender key.
|
||||||
|
@ -75,6 +84,9 @@ impl GroupSessionStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a inbound group session to the store.
|
/// Add a inbound group session to the store.
|
||||||
|
///
|
||||||
|
/// Returns true if the the session was already in the store, false
|
||||||
|
/// otherwise.
|
||||||
pub fn add(&mut self, session: InboundGroupSession) -> bool {
|
pub fn add(&mut self, session: InboundGroupSession) -> bool {
|
||||||
if !self.entries.contains_key(&session.room_id) {
|
if !self.entries.contains_key(&session.room_id) {
|
||||||
let room_id = &*session.room_id;
|
let room_id = &*session.room_id;
|
||||||
|
@ -228,7 +240,9 @@ mod test {
|
||||||
let (account, session) = get_account_and_session().await;
|
let (account, session) = get_account_and_session().await;
|
||||||
|
|
||||||
let mut store = SessionStore::new();
|
let mut store = SessionStore::new();
|
||||||
store.add(session.clone()).await;
|
|
||||||
|
assert!(!store.add(session.clone()).await);
|
||||||
|
assert!(store.add(session.clone()).await);
|
||||||
|
|
||||||
let sessions = store.get(&session.sender_key).unwrap();
|
let sessions = store.get(&session.sender_key).unwrap();
|
||||||
let sessions = sessions.lock().await;
|
let sessions = sessions.lock().await;
|
||||||
|
|
Loading…
Reference in New Issue