@@ -109,9 +109,8 @@ public struct Session: Codable {
109109
110110 try identityStore. saveIdentity ( theirIdentityKey, for: address)
111111
112- let lock = SessionLock ( address: address)
113- lock. lock ( )
114- defer { lock. unlock ( ) }
112+ try sessionStore. lockSession ( for: address)
113+ defer { sessionStore. unlockSession ( for: address) }
115114
116115 var session = try sessionStore. loadSession ( for: address)
117116 if nil == session {
@@ -159,9 +158,8 @@ public struct Session: Codable {
159158 throw DXError . untrustedIdentity ( " Abort processing PreKey Message for untrusted identity " )
160159 }
161160
162- let lock = SessionLock ( address: address)
163- lock. lock ( )
164- defer { lock. unlock ( ) }
161+ try sessionStore. lockSession ( for: address)
162+ defer { sessionStore. unlockSession ( for: address) }
165163
166164 let theirBaseKey = message. senderBaseKey
167165 let messageVersion = Int ( message. messageVersion)
@@ -235,9 +233,8 @@ public struct Session: Codable {
235233 for address: ProtocolAddress ,
236234 sessionStore: SessionStorable ,
237235 identityStore: IdentityKeyStorable ) throws -> MessageContainer {
238- let lock = SessionLock ( address: address)
239- lock. lock ( )
240- defer { lock. unlock ( ) }
236+ try sessionStore. lockSession ( for: address)
237+ defer { sessionStore. unlockSession ( for: address) }
241238
242239 guard var session = try sessionStore. loadSession ( for: address) else {
243240 throw DXError . sessionNotFound ( " Failed to find session while encrypting message " )
@@ -327,9 +324,8 @@ extension Session {
327324 identityStore: IdentityKeyStorable ,
328325 preKeyStore: PreKeyStorable ,
329326 signedPreKeyStore: SignedPreKeyStorable ) throws -> Data {
330- let lock = SessionLock ( address: address)
331- lock. lock ( )
332- defer { lock. unlock ( ) }
327+ try sessionStore. lockSession ( for: address)
328+ defer { sessionStore. unlockSession ( for: address) }
333329
334330 var session = try self . processPreKeyMessage (
335331 preKeyMessage,
@@ -367,9 +363,8 @@ extension Session {
367363 from address: ProtocolAddress ,
368364 sessionStore: SessionStorable ,
369365 identityStore: IdentityKeyStorable ) throws -> Data {
370- let lock = SessionLock ( address: address)
371- lock. lock ( )
372- defer { lock. unlock ( ) }
366+ try sessionStore. lockSession ( for: address)
367+ defer { sessionStore. unlockSession ( for: address) }
373368
374369 guard var session = try sessionStore. loadSession ( for: address) else {
375370 throw DXError . sessionNotFound ( " Failed to find session while decrypting message " )
0 commit comments