From b415537ba593d30df89e9b6935fdd73e06e7e2a1 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Thu, 6 Jan 2022 16:41:39 +0000 Subject: [PATCH] simplify message delivery --- src/Simplex/Messaging/Agent.hs | 2 +- src/Simplex/Messaging/Agent/Store.hs | 2 +- src/Simplex/Messaging/Agent/Store/SQLite.hs | 7 ++----- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Simplex/Messaging/Agent.hs b/src/Simplex/Messaging/Agent.hs index dcb0c29dc..093e585f0 100644 --- a/src/Simplex/Messaging/Agent.hs +++ b/src/Simplex/Messaging/Agent.hs @@ -439,7 +439,7 @@ runSmpQueueMsgDelivery c@AgentClient {subQ} connId sq = do withStore (\st -> E.try $ getPendingMsgData st connId msgId) >>= \case Left (e :: E.SomeException) -> notify $ MERR mId (INTERNAL $ show e) - Right (sq, rq_, (msgType, msgBody)) -> do + Right (rq_, (msgType, msgBody)) -> do withRetryInterval ri $ \loop -> do tryError (sendAgentMessage c sq msgBody) >>= \case Left e -> case e of diff --git a/src/Simplex/Messaging/Agent/Store.hs b/src/Simplex/Messaging/Agent/Store.hs index 43e752353..3b50985df 100644 --- a/src/Simplex/Messaging/Agent/Store.hs +++ b/src/Simplex/Messaging/Agent/Store.hs @@ -61,7 +61,7 @@ class Monad m => MonadAgentStore s m where createRcvMsg :: s -> ConnId -> RcvMsgData -> m () updateSndIds :: s -> ConnId -> m (InternalId, InternalSndId, PrevSndMsgHash) createSndMsg :: s -> ConnId -> SndMsgData -> m () - getPendingMsgData :: s -> ConnId -> InternalId -> m (SndQueue, Maybe RcvQueue, (AMsgType, MsgBody)) + getPendingMsgData :: s -> ConnId -> InternalId -> m (Maybe RcvQueue, (AMsgType, MsgBody)) getPendingMsgs :: s -> ConnId -> m [InternalId] checkRcvMsg :: s -> ConnId -> InternalId -> m () deleteMsg :: s -> ConnId -> InternalId -> m () diff --git a/src/Simplex/Messaging/Agent/Store/SQLite.hs b/src/Simplex/Messaging/Agent/Store/SQLite.hs index 33e092195..fc45571ef 100644 --- a/src/Simplex/Messaging/Agent/Store/SQLite.hs +++ b/src/Simplex/Messaging/Agent/Store/SQLite.hs @@ -439,10 +439,9 @@ instance (MonadUnliftIO m, MonadError StoreError m) => MonadAgentStore SQLiteSto insertSndMsgDetails_ db connId sndMsgData updateHashSnd_ db connId sndMsgData - getPendingMsgData :: SQLiteStore -> ConnId -> InternalId -> m (SndQueue, Maybe RcvQueue, (AMsgType, MsgBody)) + getPendingMsgData :: SQLiteStore -> ConnId -> InternalId -> m (Maybe RcvQueue, (AMsgType, MsgBody)) getPendingMsgData st connId msgId = liftIOEither . withTransaction st $ \db -> runExceptT $ do - sq <- ExceptT $ sndQueue <$> getSndQueueByConnAlias_ db connId rq_ <- liftIO $ getRcvQueueByConnAlias_ db connId msgData <- ExceptT $ @@ -456,13 +455,11 @@ instance (MonadUnliftIO m, MonadError StoreError m) => MonadAgentStore SQLiteSto WHERE m.conn_alias = ? AND m.internal_id = ? |] (connId, msgId) - pure (sq, rq_, msgData) + pure (rq_, msgData) where sndMsgData :: [(AMsgType, MsgBody)] -> Either StoreError (AMsgType, MsgBody) sndMsgData [msgData] = Right msgData sndMsgData _ = Left SEMsgNotFound - sndQueue :: Maybe SndQueue -> Either StoreError SndQueue - sndQueue = maybe (Left SEConnNotFound) Right getPendingMsgs :: SQLiteStore -> ConnId -> m [InternalId] getPendingMsgs st connId =