diff --git a/src/Simplex/Messaging/Agent.hs b/src/Simplex/Messaging/Agent.hs index f267baf28..15c0dbd38 100644 --- a/src/Simplex/Messaging/Agent.hs +++ b/src/Simplex/Messaging/Agent.hs @@ -2534,6 +2534,7 @@ processSMPTransmissions c@AgentClient {subQ} (tSess@(userId, srv, _), _v, sessId smpConfirmation :: SMP.MsgId -> Connection c -> Maybe C.APublicAuthKey -> C.PublicKeyX25519 -> Maybe (CR.SndE2ERatchetParams 'C.X448) -> ByteString -> VersionSMPC -> VersionSMPA -> AM () smpConfirmation srvMsgId conn' senderKey e2ePubKey e2eEncryption encConnInfo smpClientVersion agentVersion = do + liftIO $ threadDelay' 3000000 logServer "<--" c srv rId $ "MSG :" <> logSecret' srvMsgId AgentConfig {smpClientVRange, smpAgentVRange, e2eEncryptVRange} <- asks config let ConnData {pqSupport} = toConnData conn' @@ -2879,8 +2880,15 @@ secureConfirmQueue c cData@ConnData {connId, connAgentVersion, pqSupport} sq srv sqSecured <- agentSecureSndQueue c cData sq msg <- mkConfirmation =<< mkAgentConfirmation c cData sq srv connInfo subMode void $ sendConfirmation c sq msg - withStore' c $ \db -> setSndQueueStatus db sq Confirmed - pure sqSecured + counter <- asks counter + n <- readTVarIO counter + if n == 0 + then do + atomically $ modifyTVar' counter succ + throwE $ INTERNAL "secureConfirmQueue fail" + else do + withStore' c $ \db -> setSndQueueStatus db sq Confirmed + pure sqSecured where mkConfirmation :: AgentMessage -> AM MsgBody mkConfirmation aMessage = do diff --git a/src/Simplex/Messaging/Agent/Env/SQLite.hs b/src/Simplex/Messaging/Agent/Env/SQLite.hs index a78fb428e..924f8a8ba 100644 --- a/src/Simplex/Messaging/Agent/Env/SQLite.hs +++ b/src/Simplex/Messaging/Agent/Env/SQLite.hs @@ -259,7 +259,8 @@ data Env = Env randomServer :: TVar StdGen, ntfSupervisor :: NtfSupervisor, xftpAgent :: XFTPAgent, - multicastSubscribers :: TMVar Int + multicastSubscribers :: TMVar Int, + counter :: TVar Int } newSMPAgentEnv :: AgentConfig -> SQLiteStore -> IO Env @@ -269,7 +270,8 @@ newSMPAgentEnv config store = do ntfSupervisor <- newNtfSubSupervisor $ tbqSize config xftpAgent <- newXFTPAgent multicastSubscribers <- newTMVarIO 0 - pure Env {config, store, random, randomServer, ntfSupervisor, xftpAgent, multicastSubscribers} + counter <- newTVarIO 0 + pure Env {config, store, random, randomServer, ntfSupervisor, xftpAgent, multicastSubscribers, counter} createAgentStore :: FilePath -> ScrubbedBytes -> Bool -> MigrationConfirmation -> IO (Either MigrationError SQLiteStore) createAgentStore dbFilePath dbKey keepKey = createSQLiteStore dbFilePath dbKey keepKey Migrations.app