mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-11-22 19:58:39 +00:00
agent: report skipped messages when an internal message follows them (#2066)
* agent: MSGERR event, test of a skipped message before QCONT * agent: report skipped messages followed by agent messages * tests: keep the sender online until the expired message is deleted * agent: report integrity errors in one guard before the message dispatch * agent: skip integrity notices of HELLO and QEND, check message types in one guard * agent: report integrity errors in the dispatch branches of QCONT, QADD, QKEY, QUSE and QTEST * agent: use one integrity notice helper in the dispatch and the receipt branch * agent: report integrity errors as MSG without body, remove MSGERR * agent: report integrity errors as MSGERR again, MSG unchanged
This commit is contained in:
1 parent
962b4a9a94
commit
3f9ebbdcc3
3 files changed
+47
-6
No files matched your search
@@ -3751,13 +3751,13 @@ processSMPTransmissions c@AgentClient {subQ, smpServersStats} (tSess@(userId, sr
|
||||
notify $ MSG msgMeta msgFlags body
|
||||
pure ACKPending
|
||||
A_RCVD rcpts -> qDuplex conn'' "RCVD" $ messagesRcvd rcpts msgMeta
|
||||
A_QCONT addr -> qDuplexAckDel conn'' "QCONT" $ continueSending srvMsgId addr
|
||||
QADD qs -> qDuplexAckDel conn'' "QADD" $ qAddMsg srvMsgId qs
|
||||
QKEY qs -> qDuplexAckDel conn'' "QKEY" $ qKeyMsg srvMsgId qs
|
||||
QUSE qs -> qDuplexAckDel conn'' "QUSE" $ qUseMsg srvMsgId qs
|
||||
A_QCONT addr -> notifyIntegrity msgMeta >> qDuplexAckDel conn'' "QCONT" (continueSending srvMsgId addr)
|
||||
QADD qs -> notifyIntegrity msgMeta >> qDuplexAckDel conn'' "QADD" (qAddMsg srvMsgId qs)
|
||||
QKEY qs -> notifyIntegrity msgMeta >> qDuplexAckDel conn'' "QKEY" (qKeyMsg srvMsgId qs)
|
||||
QUSE qs -> notifyIntegrity msgMeta >> qDuplexAckDel conn'' "QUSE" (qUseMsg srvMsgId qs)
|
||||
-- no action needed for QTEST
|
||||
-- any message in the new queue will mark it active and trigger deletion of the old queue
|
||||
QTEST _ -> logServer "<--" c srv rId ("MSG <QTEST>:" <> logSecret' (SMP.unMsgId srvMsgId)) >> ackDel msgId
|
||||
QTEST _ -> notifyIntegrity msgMeta >> logServer "<--" c srv rId ("MSG <QTEST>:" <> logSecret' (SMP.unMsgId srvMsgId)) >> ackDel msgId
|
||||
QEND addrs -> qDuplexAckDel conn'' "QEND" $ qEndMsg srvMsgId addrs
|
||||
EREADY _ -> qDuplexAckDel conn'' "EREADY" $ ereadyMsg rcPrev
|
||||
where
|
||||
@@ -3899,6 +3899,9 @@ processSMPTransmissions c@AgentClient {subQ, smpServersStats} (tSess@(userId, sr
|
||||
logError $ "prohibited: " <> s
|
||||
notify . ERR . AGENT $ A_PROHIBITED $ T.unpack s
|
||||
|
||||
notifyIntegrity :: MsgMeta -> AM ()
|
||||
notifyIntegrity mm = when (integrity mm /= MsgOk) $ notify $ MSGERR mm
|
||||
|
||||
enqueueCmd :: InternalCommand -> AM ()
|
||||
enqueueCmd = enqueueCommand c "" connId (Just srv) . AInternalCommand
|
||||
|
||||
@@ -4085,7 +4088,7 @@ processSMPTransmissions c@AgentClient {subQ, smpServersStats} (tSess@(userId, sr
|
||||
rs <- forM rcpts $ \rcpt -> clientReceipt rcpt `catchAllErrors` \e -> notify (ERR e) $> Nothing
|
||||
case L.nonEmpty . catMaybes $ L.toList rs of
|
||||
Just rs' -> notify (RCVD msgMeta rs') $> ACKPending
|
||||
Nothing -> ack
|
||||
Nothing -> notifyIntegrity msgMeta >> ack
|
||||
where
|
||||
ack :: AM ACKd
|
||||
ack = enqueueCmd (ICAck rId srvMsgId) $> ACKd
|
||||
|
||||
@@ -438,6 +438,7 @@ data AEvent (e :: AEntity) where
|
||||
MSG :: MsgMeta -> MsgFlags -> MsgBody -> AEvent AEConn
|
||||
MSGNTF :: MsgId -> Maybe UTCTime -> AEvent AEConn
|
||||
RCVD :: MsgMeta -> NonEmpty MsgReceipt -> AEvent AEConn
|
||||
MSGERR :: MsgMeta -> AEvent AEConn
|
||||
QCONT :: AEvent AEConn
|
||||
DEL_RCVQS :: NonEmpty (ConnId, SMPServer, SMP.RecipientId, Maybe AgentErrorType) -> AEvent AEConn
|
||||
DEL_CONNS :: NonEmpty ConnId -> AEvent AEConn
|
||||
@@ -522,6 +523,7 @@ data AEventTag (e :: AEntity) where
|
||||
MSG_ :: AEventTag AEConn
|
||||
MSGNTF_ :: AEventTag AEConn
|
||||
RCVD_ :: AEventTag AEConn
|
||||
MSGERR_ :: AEventTag AEConn
|
||||
QCONT_ :: AEventTag AEConn
|
||||
DEL_RCVQS_ :: AEventTag AEConn
|
||||
DEL_CONNS_ :: AEventTag AEConn
|
||||
@@ -588,6 +590,7 @@ aEventTag = \case
|
||||
MSG {} -> MSG_
|
||||
MSGNTF {} -> MSGNTF_
|
||||
RCVD {} -> RCVD_
|
||||
MSGERR _ -> MSGERR_
|
||||
QCONT -> QCONT_
|
||||
DEL_RCVQS _ -> DEL_RCVQS_
|
||||
DEL_CONNS _ -> DEL_CONNS_
|
||||
|
||||
@@ -472,6 +472,7 @@ functionalAPITests ps = do
|
||||
it "should expire multiple messages" $ testExpireManyMessages ps
|
||||
it "should expire one message if quota is exceeded" $ testExpireMessageQuota ps
|
||||
it "should expire multiple messages if quota is exceeded" $ testExpireManyMessagesQuota ps
|
||||
it "should report expired message when the next message is QCONT" $ testExpireMessageBeforeQCONT ps
|
||||
describe "joining a full contact address" $ do
|
||||
it "should retry joining until the address has space" $ testJoinFullContactAsync ps
|
||||
it "should fail joining after quota exceeded timeout" $ testJoinFullContactAsyncExpire ps
|
||||
@@ -2724,6 +2725,40 @@ testExpireManyMessagesQuota (t, msType) = withSmpServerConfigOn t cfg' testPort
|
||||
where
|
||||
cfg' = updateCfg (cfgMS msType) $ \cfg_ -> cfg_ {msgQueueQuota = 1}
|
||||
|
||||
testExpireMessageBeforeQCONT :: (HasCallStack, HasTestEnv) => (ASrvTransport, AStoreType) -> IO ()
|
||||
testExpireMessageBeforeQCONT (t, msType) = withSmpServerConfigOn t cfg' testPort $ \_ -> do
|
||||
a <- getSMPAgentClient' 1 agentCfg {quotaExceededTimeout = 1, messageRetryInterval = fastMessageRetryInterval} initAgentServers testDB
|
||||
b <- getSMPAgentClient' 2 agentCfg initAgentServers testDB2
|
||||
(aId, bId) <- runRight $ do
|
||||
(aId, bId) <- makeConnection a b
|
||||
liftIO $ threadDelay 500000 >> disposeAgentClient b
|
||||
2 <- sendMessage a bId SMP.noMsgFlags "1"
|
||||
get a ##> ("", bId, SENT 2)
|
||||
3 <- sendMessage a bId SMP.noMsgFlags "2"
|
||||
get a =##> \case ("", c, MERR 3 (SMP _ QUOTA)) -> bId == c; _ -> False
|
||||
pure (aId, bId)
|
||||
withAgent 3 agentCfg {messageRetryInterval = fastMessageRetryInterval} initAgentServers testDB2 $ \b' -> runRight_ $ do
|
||||
subscribeConnection b' aId
|
||||
get b' =##> \case ("", c, Msg "1") -> c == aId; _ -> False
|
||||
3 <- sendMessage b' aId SMP.noMsgFlags "hello"
|
||||
get b' ##> ("", aId, SENT 3)
|
||||
get a =##> \case ("", c, Msg "hello") -> c == bId; _ -> False
|
||||
4 <- sendMessage b' aId SMP.noMsgFlags "hello 2"
|
||||
pGet' b' False =##> \case ("", c, AEvt _ (MWARN 4 (SMP _ QUOTA))) -> aId == c; _ -> False
|
||||
ackMessage b' aId 2 Nothing
|
||||
ackMessage a bId 4 Nothing
|
||||
liftIO . getInAnyOrder b' $
|
||||
[ \case ("", c, AEvt SAEConn (MSGERR MsgMeta {integrity = MsgError (MsgSkipped 3 3)})) -> c == aId; _ -> False,
|
||||
\case ("", c, AEvt SAEConn QCONT) -> c == aId; _ -> False,
|
||||
\case ("", c, AEvt SAEConn (SENT 4)) -> c == aId; _ -> False
|
||||
]
|
||||
get a =##> \case ("", c, Msg "hello 2") -> c == bId; _ -> False
|
||||
ackMessage a bId 6 Nothing
|
||||
get a =##> \case ("", c, QCONT) -> c == bId; _ -> False
|
||||
disposeAgentClient a
|
||||
where
|
||||
cfg' = updateCfg (cfgMS msType) $ \cfg_ -> cfg_ {msgQueueQuota = 1}
|
||||
|
||||
testJoinFullContactAsync :: (HasCallStack, HasTestEnv) => (ASrvTransport, AStoreType) -> IO ()
|
||||
testJoinFullContactAsync (t, msType) = withSmpServerConfigOn t cfg' testPort $ \_ -> do
|
||||
(contactId, qInfo) <- fillContactAddress
|
||||
|
||||
Reference in new issue
Block a user