diff --git a/src/Simplex/Messaging/Agent/Client.hs b/src/Simplex/Messaging/Agent/Client.hs index 382608fde..13e230249 100644 --- a/src/Simplex/Messaging/Agent/Client.hs +++ b/src/Simplex/Messaging/Agent/Client.hs @@ -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 diff --git a/src/Simplex/Messaging/Protocol.hs b/src/Simplex/Messaging/Protocol.hs index 3d3322522..78943eb11 100644 --- a/src/Simplex/Messaging/Protocol.hs +++ b/src/Simplex/Messaging/Protocol.hs @@ -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 diff --git a/tests/SMPProxyTests.hs b/tests/SMPProxyTests.hs index 467949878..ff756869f 100644 --- a/tests/SMPProxyTests.hs +++ b/tests/SMPProxyTests.hs @@ -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" $ \_ -> diff --git a/tests/ServerTests.hs b/tests/ServerTests.hs index 55fca1122..146a1d46f 100644 --- a/tests/ServerTests.hs +++ b/tests/ServerTests.hs @@ -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)