mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-11-04 12:58:02 +00:00
agent: known host, smp protocol: parse empty messages (#1953)
Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com>
This commit is contained in:
1 parent
8bc4d36012
commit
fa0d1be801
4 files changed
+10
-6
No files matched your search
@@ -1194,10 +1194,10 @@ sendOrProxySMPCommand c nm userId destSrv@ProtocolServer {host = destHosts} conn
|
||||
cfg <- getNetworkConfig c
|
||||
case smpProxyMode cfg of
|
||||
SPMAlways -> pure True
|
||||
SPMUnknown -> unknownServer
|
||||
SPMUnknown -> unknownServer cfg
|
||||
SPMUnprotected
|
||||
| ipAddressProtected cfg destSrv -> pure False
|
||||
| otherwise -> unknownServer
|
||||
| otherwise -> unknownServer cfg
|
||||
SPMNever -> pure False
|
||||
directAllowed = do
|
||||
cfg <- getNetworkConfig c
|
||||
@@ -1205,7 +1205,7 @@ sendOrProxySMPCommand c nm userId destSrv@ProtocolServer {host = destHosts} conn
|
||||
SPFAllow -> True
|
||||
SPFAllowProtected -> ipAddressProtected cfg destSrv
|
||||
SPFProhibit -> False
|
||||
unknownServer = liftIO $ maybe True (\srvs -> all (`S.notMember` knownHosts srvs) destHosts) <$> TM.lookupIO userId (smpServers c)
|
||||
unknownServer cfg = liftIO $ maybe True (\srvs -> either (const True) (`S.notMember` knownHosts srvs) $ chooseTransportHost cfg destHosts) <$> TM.lookupIO userId (smpServers c)
|
||||
sendViaProxy :: Maybe SMPServerWithAuth -> SMPTransportSession -> AM (Maybe SMPServer, a)
|
||||
sendViaProxy proxySrv_ destSess@(_, _, connId_) = do
|
||||
r <- tryAllErrors . withProxySession c nm proxySrv_ destSess entId ("PFWD " <> cmdStr) $ \(SMPConnectedClient smp _, proxySess@ProxiedRelay {prBasicAuth}) -> do
|
||||
|
||||
@@ -884,7 +884,7 @@ instance StrEncoding Message where
|
||||
msgQuotaP msgId msgTs = "quota" $> MessageQuota {msgId, msgTs}
|
||||
msgP msgId msgTs = do
|
||||
msgFlags <- ("flags=" *> strP_) <|> pure noMsgFlags
|
||||
msgBody <- strP
|
||||
msgBody <- strP <|> (C.unsafeMaxLenBS "" <$ A.endOfInput)
|
||||
pure Message {msgId, msgTs, msgFlags, msgBody}
|
||||
|
||||
type EncNMsgMeta = ByteString
|
||||
|
||||
@@ -142,6 +142,10 @@ smpProxyTests = do
|
||||
agentDeliverMessageViaProxy ([srv1], SPMNever, False) ([srv2], SPMNever, False) C.SEd448 "hello 1" "hello 2" 1
|
||||
it "first via proxy for unknown" $ twoServers $
|
||||
agentDeliverMessageViaProxy ([srv1], SPMUnknown, True) ([srv1, srv2], SPMUnknown, False) C.SEd448 "hello 1" "hello 2" 1
|
||||
it "first via proxy for unknown chosen host" $ twoServers $
|
||||
agentDeliverMessageViaProxy ([srv1], SPMUnknown, True) ([SMPServer (testHost2 <> testHost) testPort2 testKeyHash], SPMUnknown, False) C.SEd448 "hello 1" "hello 2" 1
|
||||
it "first without proxy for known chosen host" $ twoServers $
|
||||
agentDeliverMessageViaProxy ([srv1], SPMUnknown, False) ([SMPServer (testHost <> testHost2) testPort2 testKeyHash], SPMUnknown, False) C.SEd448 "hello 1" "hello 2" 1
|
||||
it "retries sending when destination or proxy relay is offline" $ \_ ->
|
||||
agentViaProxyRetryOffline
|
||||
it "retries sending when destination relay session disconnects in proxy" $ \_ ->
|
||||
|
||||
@@ -1091,7 +1091,7 @@ testRestoreMessages =
|
||||
-- messages below are delivered after server restart
|
||||
sId <- readTVarIO senderId
|
||||
Resp "2" _ OK <- signSendRecv h sKey ("2", sId, _SEND "hello 2")
|
||||
Resp "3" _ OK <- signSendRecv h sKey ("3", sId, _SEND "hello 3")
|
||||
Resp "3" _ OK <- signSendRecv h sKey ("3", sId, _SEND "")
|
||||
Resp "4" _ OK <- signSendRecv h sKey ("4", sId, _SEND "hello 4")
|
||||
Resp "5" _ OK <- signSendRecv h sKey ("5", sId, _SEND "hello 5")
|
||||
Resp "6" _ (ERR QUOTA) <- signSendRecv h sKey ("6", sId, _SEND "hello 6")
|
||||
@@ -1108,7 +1108,7 @@ testRestoreMessages =
|
||||
(Resp "2" _ (SOK Nothing), Resp "" _ (Msg mId2 msg2)) <- signSendRecv2 h rKey ("2", rId, SUB)
|
||||
(dec mId2 msg2, Right "hello 2") #== "restored message delivered"
|
||||
Resp "3" _ (Msg mId3 msg3) <- signSendRecv h rKey ("3", rId, ACK mId2)
|
||||
(dec mId3 msg3, Right "hello 3") #== "restored message delivered"
|
||||
(dec mId3 msg3, Right "") #== "restored message delivered"
|
||||
Resp "4" _ (Msg mId4 msg4) <- signSendRecv h rKey ("4", rId, ACK mId3)
|
||||
(dec mId4 msg4, Right "hello 4") #== "restored message delivered"
|
||||
logSize testStoreLogFile `shouldReturn` (if compacting then 1 else 2)
|
||||
|
||||
Reference in new issue
Block a user