@@ -48,6 +48,7 @@ module Simplex.Messaging.Client
48
48
subscribeSMPQueuesNtfs ,
49
49
secureSMPQueue ,
50
50
secureSndSMPQueue ,
51
+ proxySecureSndSMPQueue ,
51
52
enableSMPQueueNotifications ,
52
53
disableSMPQueueNotifications ,
53
54
enableSMPQueuesNtfs ,
@@ -59,7 +60,7 @@ module Simplex.Messaging.Client
59
60
deleteSMPQueues ,
60
61
connectSMPProxiedRelay ,
61
62
proxySMPMessage ,
62
- forwardSMPMessage ,
63
+ forwardSMPTransmission ,
63
64
getSMPQueueInfo ,
64
65
sendProtocolCommand ,
65
66
@@ -736,6 +737,10 @@ secureSndSMPQueue :: SMPClient -> SndPrivateAuthKey -> SenderId -> SndPublicAuth
736
737
secureSndSMPQueue c spKey sId senderKey = okSMPCommand (SKEY senderKey) c spKey sId
737
738
{-# INLINE secureSndSMPQueue #-}
738
739
740
+ proxySecureSndSMPQueue :: SMPClient -> ProxiedRelay -> SndPrivateAuthKey -> SenderId -> SndPublicAuthKey -> ExceptT SMPClientError IO (Either ProxyClientError () )
741
+ proxySecureSndSMPQueue c proxiedRelay spKey sId senderKey = proxySMPCommand c proxiedRelay (Just spKey) sId (SKEY senderKey)
742
+ {-# INLINE proxySecureSndSMPQueue #-}
743
+
739
744
-- | Enable notifications for the queue for push notifications server.
740
745
--
741
746
-- https://github.com/simplex-chat/simplexmq/blob/master/protocol/simplex-messaging.md#enable-notifications-command
@@ -776,6 +781,9 @@ sendSMPMessage c spKey sId flags msg =
776
781
OK -> pure ()
777
782
r -> throwE $ unexpectedResponse r
778
783
784
+ proxySMPMessage :: SMPClient -> ProxiedRelay -> Maybe SndPrivateAuthKey -> SenderId -> MsgFlags -> MsgBody -> ExceptT SMPClientError IO (Either ProxyClientError () )
785
+ proxySMPMessage c proxiedRelay spKey sId flags msg = proxySMPCommand c proxiedRelay spKey sId (SEND flags msg)
786
+
779
787
-- | Acknowledge message delivery (server deletes the message).
780
788
--
781
789
-- https://github.com/simplex-chat/simplexmq/blob/master/protocol/simplex-messaging.md#acknowledge-message-delivery
@@ -877,39 +885,39 @@ instance StrEncoding ProxyClientError where
877
885
-- 8) PFWD(SEND) -> WTF -> ProxyUnexpectedResponse - client/proxy protocol logic
878
886
-- 9) PFWD(SEND) -> ??? -> ProxyResponseError - client/proxy syntax
879
887
--
880
- -- We report as proxySMPMessage error (ExceptT error) the errors of two kinds:
888
+ -- We report as proxySMPCommand error (ExceptT error) the errors of two kinds:
881
889
-- - protocol errors from the destination relay wrapped in PRES - to simplify processing of AUTH and QUOTA errors, in this case proxy is "transparent" for such errors (PCEProtocolError, PCEUnexpectedResponse, PCEResponseError)
882
890
-- - other response/transport/connection errors from the client connected to proxy itself
883
891
-- Other errors are reported in the function result as `Either ProxiedRelayError ()`, including
884
892
-- - protocol errors from the client connected to proxy in ProxyClientError (PCEProtocolError, PCEUnexpectedResponse, PCEResponseError)
885
893
-- - other errors from the client running on proxy and connected to relay in PREProxiedRelayError
886
894
887
- proxySMPMessage ::
895
+ -- This function proxies Sender commands that return OK or ERR
896
+ proxySMPCommand ::
888
897
SMPClient ->
889
898
-- proxy session from PKEY
890
899
ProxiedRelay ->
891
900
-- message to deliver
892
901
Maybe SndPrivateAuthKey ->
893
902
SenderId ->
894
- MsgFlags ->
895
- MsgBody ->
903
+ Command 'Sender ->
896
904
ExceptT SMPClientError IO (Either ProxyClientError () )
897
- proxySMPMessage c@ ProtocolClient {thParams = proxyThParams, client_ = PClient {clientCorrId = g, tcpTimeout}} (ProxiedRelay sessionId v serverKey) spKey sId flags msg = do
905
+ proxySMPCommand c@ ProtocolClient {thParams = proxyThParams, client_ = PClient {clientCorrId = g, tcpTimeout}} (ProxiedRelay sessionId v serverKey) spKey sId command = do
898
906
-- prepare params
899
907
let serverThAuth = (\ ta -> ta {serverPeerPubKey = serverKey}) <$> thAuth proxyThParams
900
908
serverThParams = smpTHParamsSetVersion v proxyThParams {sessionId, thAuth = serverThAuth}
901
909
(cmdPubKey, cmdPrivKey) <- liftIO . atomically $ C. generateKeyPair @ 'C.X25519 g
902
910
let cmdSecret = C. dh' serverKey cmdPrivKey
903
911
nonce@ (C. CbNonce corrId) <- liftIO . atomically $ C. randomCbNonce g
904
912
-- encode
905
- let TransmissionForAuth {tForAuth, tToSend} = encodeTransmissionForAuth serverThParams (CorrId corrId, sId, Cmd SSender ( SEND flags msg) )
913
+ let TransmissionForAuth {tForAuth, tToSend} = encodeTransmissionForAuth serverThParams (CorrId corrId, sId, Cmd SSender command )
906
914
auth <- liftEitherWith PCETransportError $ authTransmission serverThAuth spKey nonce tForAuth
907
915
b <- case batchTransmissions (batch serverThParams) (blockSize serverThParams) [Right (auth, tToSend)] of
908
916
[] -> throwE $ PCETransportError TELargeMsg
909
917
TBError e _ : _ -> throwE $ PCETransportError e
910
918
TBTransmission s _ : _ -> pure s
911
919
TBTransmissions s _ _ : _ -> pure s
912
- et <- liftEitherWith PCECryptoError $ EncTransmission <$> C. cbEncrypt cmdSecret nonce b paddedProxiedMsgLength
920
+ et <- liftEitherWith PCECryptoError $ EncTransmission <$> C. cbEncrypt cmdSecret nonce b paddedProxiedTLength
913
921
-- proxy interaction errors are wrapped
914
922
let tOut = Just $ 2 * tcpTimeout
915
923
tryE (sendProtocolCommand_ c (Just nonce) tOut Nothing sessionId (Cmd SProxiedClient (PFWD v cmdPubKey et))) >>= \ case
@@ -937,8 +945,8 @@ proxySMPMessage c@ProtocolClient {thParams = proxyThParams, client_ = PClient {c
937
945
-- sends RFWD :: EncFwdTransmission -> Command Sender
938
946
-- receives RRES :: EncFwdResponse -> BrokerMsg
939
947
-- proxy should send PRES to the client with EncResponse
940
- forwardSMPMessage :: SMPClient -> CorrId -> VersionSMP -> C. PublicKeyX25519 -> EncTransmission -> ExceptT SMPClientError IO EncResponse
941
- forwardSMPMessage c@ ProtocolClient {thParams, client_ = PClient {clientCorrId = g}} fwdCorrId fwdVersion fwdKey fwdTransmission = do
948
+ forwardSMPTransmission :: SMPClient -> CorrId -> VersionSMP -> C. PublicKeyX25519 -> EncTransmission -> ExceptT SMPClientError IO EncResponse
949
+ forwardSMPTransmission c@ ProtocolClient {thParams, client_ = PClient {clientCorrId = g}} fwdCorrId fwdVersion fwdKey fwdTransmission = do
942
950
-- prepare params
943
951
sessSecret <- case thAuth thParams of
944
952
Nothing -> throwE $ PCETransportError TENoServerAuth
0 commit comments