mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-20 12:22:23 +00:00
improve comments
This commit is contained in:
@@ -2443,8 +2443,7 @@ encodeConnInfoPQ pqSup chatMsgEvent = do
|
||||
let info = ChatMessage {chatVRange = vr cxt, msgId = Nothing, chatMsgEvent}
|
||||
case encodeChatMessage maxEncodedInfoLength info of
|
||||
ECMEncoded connInfo -> case pqSup of
|
||||
-- with PQ off the budget is larger, so compressing is wasted work; service payloads need no
|
||||
-- such gate because the request JOIN is PQSupportOn and the reply inherits it
|
||||
-- with PQ off the size budget is larger, so the body always fits and compressing is wasted work
|
||||
PQSupportOn -> maybe (throwChatError $ CEException "large compressed info") pure $ compressBodyTo maxCompressedInfoLength connInfo
|
||||
_ -> pure connInfo
|
||||
ECMLarge -> throwChatError $ CEException "large info"
|
||||
|
||||
@@ -1404,8 +1404,7 @@ processAgentMessageConn cxt user@User {userId} entity gks_ corrId agentConnId ag
|
||||
True -> case parseServiceBody payload of
|
||||
Right request -> toView $ CEvtServiceRequest user (AgentInvId invId) sigKey_ request
|
||||
Left e -> logError ("service request dropped, invalid payload: " <> tshow e) >> dropSReq
|
||||
-- the requester gets no reply and waits out its timeout, so this must be visible
|
||||
-- to whoever deployed the service without enabling service requests
|
||||
-- logged, not silent: this is a deployment mistake, and the requester only sees a timeout
|
||||
False -> logError "service request dropped: service requests are not enabled" >> dropSReq
|
||||
where
|
||||
dropSReq = withAgent $ \a -> rejectServiceRequest a NRMBackground (aUserId user) invId Nothing
|
||||
|
||||
@@ -1039,7 +1039,6 @@ markCompressedBatch :: ByteString -> ByteString
|
||||
markCompressedBatch = B.cons 'X'
|
||||
{-# INLINE markCompressedBatch #-}
|
||||
|
||||
-- Compress a body that is over the bound, and fail when it is still over it compressed.
|
||||
compressBodyTo :: Int -> ByteString -> Maybe ByteString
|
||||
compressBodyTo maxLen body
|
||||
| B.length body <= maxLen = Just body
|
||||
@@ -1048,9 +1047,8 @@ compressBodyTo maxLen body
|
||||
where
|
||||
body' = compressedBatchMsgBody_ body
|
||||
|
||||
-- Service payloads are padded to e2eEncConnInfoLength, the same budget as connection info,
|
||||
-- so they use the compression, marker and size bound of encodeConnInfoPQ. A JSON payload
|
||||
-- never starts with 'X', so the marker is unambiguous.
|
||||
-- A service payload is padded to the same size as connection info, so it gets the same bound.
|
||||
-- JSON never starts with 'X', so that marker unambiguously means the body is compressed.
|
||||
compressServiceBody :: ByteString -> Either String ByteString
|
||||
compressServiceBody = maybe (Left "service payload is too large") Right . compressBodyTo maxCompressedInfoLength
|
||||
|
||||
@@ -1067,8 +1065,8 @@ decompressServiceBody body = case B.uncons body of
|
||||
Right _ -> Left "unexpected compressed batch"
|
||||
_ -> Right body
|
||||
|
||||
-- The apps decode a service payload recursively on a fixed stack, and no service nests deeper
|
||||
-- than a few levels, so depth is bounded here rather than left to each client.
|
||||
-- The apps decode this payload recursively on a small stack, so deep nesting crashes them.
|
||||
-- Bounded here rather than in each client, as no service needs more than a few levels.
|
||||
maxServiceBodyDepth :: Int
|
||||
maxServiceBodyDepth = 32
|
||||
|
||||
|
||||
Reference in New Issue
Block a user