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:
Evgeny @ SimpleX Chat authored and GitHub committed 2026-11-13 23:04:11 +00:00
1 parent 962b4a9a94
commit 3f9ebbdcc3
3 files changed
+47 -6

No files matched your search

+9 -6
View File
@@ -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
+3
View File
@@ -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_