Skip to content

Commit e417d35

Browse files
committed
Merge branch 'master' into ntf-storage
2 parents 2f0cdc4 + deaec3c commit e417d35

File tree

14 files changed

+108
-52
lines changed

14 files changed

+108
-52
lines changed

simplexmq.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cabal-version: 1.12
22

33
name: simplexmq
4-
version: 6.4.0.1
4+
version: 6.4.0.2
55
synopsis: SimpleXMQ message broker
66
description: This package includes <./docs/Simplex-Messaging-Server.html server>,
77
<./docs/Simplex-Messaging-Client.html client> and

src/Simplex/Messaging/Agent.hs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ subscribeConnections c = withAgentEnv c . subscribeConnections' c
439439
{-# INLINE subscribeConnections #-}
440440

441441
-- | Get messages for connections (GET commands)
442-
getConnectionMessages :: AgentClient -> NonEmpty ConnId -> IO (NonEmpty (Maybe SMPMsgMeta))
442+
getConnectionMessages :: AgentClient -> NonEmpty ConnMsgReq -> IO (NonEmpty (Either AgentErrorType (Maybe SMPMsgMeta)))
443443
getConnectionMessages c = withAgentEnv' c . getConnectionMessages' c
444444
{-# INLINE getConnectionMessages #-}
445445

@@ -1276,24 +1276,26 @@ resubscribeConnections' c connIds = do
12761276
-- union is left-biased, so results returned by subscribeConnections' take precedence
12771277
(`M.union` r) <$> subscribeConnections' c connIds'
12781278

1279-
getConnectionMessages' :: AgentClient -> NonEmpty ConnId -> AM' (NonEmpty (Maybe SMPMsgMeta))
1280-
getConnectionMessages' c = mapM getMsg
1279+
-- requesting messages sequentially, to reduce memory usage
1280+
getConnectionMessages' :: AgentClient -> NonEmpty ConnMsgReq -> AM' (NonEmpty (Either AgentErrorType (Maybe SMPMsgMeta)))
1281+
getConnectionMessages' c = mapM $ tryAgentError' . getConnectionMessage
12811282
where
1282-
getMsg :: ConnId -> AM' (Maybe SMPMsgMeta)
1283-
getMsg connId =
1284-
getConnectionMessage connId `catchAgentError'` \e -> do
1285-
logError $ "Error loading message: " <> tshow e
1286-
pure Nothing
1287-
getConnectionMessage :: ConnId -> AM (Maybe SMPMsgMeta)
1288-
getConnectionMessage connId = do
1283+
getConnectionMessage :: ConnMsgReq -> AM (Maybe SMPMsgMeta)
1284+
getConnectionMessage (ConnMsgReq connId dbQueueId msgTs_) = do
12891285
whenM (atomically $ hasActiveSubscription c connId) . throwE $ CMD PROHIBITED "getConnectionMessage: subscribed"
12901286
SomeConn _ conn <- withStore c (`getConn` connId)
1291-
case conn of
1292-
DuplexConnection _ (rq :| _) _ -> getQueueMessage c rq
1293-
RcvConnection _ rq -> getQueueMessage c rq
1294-
ContactConnection _ rq -> getQueueMessage c rq
1287+
rq <- case conn of
1288+
DuplexConnection _ (rq :| _) _ -> pure rq
1289+
RcvConnection _ rq -> pure rq
1290+
ContactConnection _ rq -> pure rq
12951291
SndConnection _ _ -> throwE $ CONN SIMPLEX
12961292
NewConnection _ -> throwE $ CMD PROHIBITED "getConnectionMessage: NewConnection"
1293+
msg_ <- getQueueMessage c rq `catchAgentError` \e -> atomically (releaseGetLock c rq) >> throwError e
1294+
when (isNothing msg_) $ do
1295+
atomically $ releaseGetLock c rq
1296+
forM_ msgTs_ $ \msgTs -> withStore' c $ \db -> setLastBrokerTs db connId (DBQueueId dbQueueId) msgTs
1297+
pure msg_
1298+
{-# INLINE getConnectionMessages' #-}
12971299

12981300
getNotificationConns' :: AgentClient -> C.CbNonce -> ByteString -> AM (NonEmpty NotificationInfo)
12991301
getNotificationConns' c nonce encNtfInfo =
@@ -1308,25 +1310,26 @@ getNotificationConns' c nonce encNtfInfo =
13081310
lastNtfInfo = Just . fst <$$> getNtfInfo db lastNtf
13091311
in initNtfInfos <> [lastNtfInfo]
13101312
let (errs, ntfInfos_) = partitionEithers rs
1311-
logError $ "Error(s) loading notifications: " <> tshow errs
1313+
unless (null errs) $ logError $ "Error(s) loading notifications: " <> tshow errs
13121314
case L.nonEmpty $ catMaybes ntfInfos_ of
13131315
Just r -> pure r
13141316
Nothing -> throwE $ INTERNAL "getNotificationConns: couldn't get conn info"
13151317
_ -> throwE $ CMD PROHIBITED "getNotificationConns"
13161318
where
13171319
getNtfInfo :: DB.Connection -> PNMessageData -> IO (Either AgentErrorType (NotificationInfo, Maybe UTCTime))
13181320
getNtfInfo db PNMessageData {smpQueue, ntfTs, nmsgNonce, encNMsgMeta} = runExceptT $ do
1319-
(ntfConnId, rcvNtfDhSecret, lastBrokerTs_) <- liftError' storeError $ getNtfRcvQueue db smpQueue
1321+
(ntfConnId, ntfDbQueueId, rcvNtfDhSecret, lastBrokerTs_) <- liftError' storeError $ getNtfRcvQueue db smpQueue
13201322
let ntfMsgMeta = eitherToMaybe $ smpDecode =<< first show (C.cbDecrypt rcvNtfDhSecret nmsgNonce encNMsgMeta)
1321-
ntfInfo = NotificationInfo {ntfConnId, ntfTs, ntfMsgMeta}
1323+
ntfInfo = NotificationInfo {ntfConnId, ntfDbQueueId, ntfTs, ntfMsgMeta}
13221324
pure (ntfInfo, lastBrokerTs_)
13231325
getInitNtfInfo :: DB.Connection -> PNMessageData -> IO (Either AgentErrorType (Maybe NotificationInfo))
13241326
getInitNtfInfo db msgData = runExceptT $ do
1325-
(nftInfo, lastBrokerTs_) <- ExceptT $ getNtfInfo db msgData
1326-
pure $ case (ntfMsgMeta nftInfo, lastBrokerTs_) of
1327-
(Just SMP.NMsgMeta {msgTs}, Just lastBrokerTs)
1328-
| systemToUTCTime msgTs > lastBrokerTs -> Just nftInfo
1327+
(ntfInfo, lastBrokerTs_) <- ExceptT $ getNtfInfo db msgData
1328+
pure $ case ntfMsgMeta ntfInfo of
1329+
Just SMP.NMsgMeta {msgTs}
1330+
| maybe True (systemToUTCTime msgTs >) lastBrokerTs_ -> Just ntfInfo
13291331
_ -> Nothing
1332+
{-# INLINE getNotificationConns' #-}
13301333

13311334
-- | Send message to the connection (SEND command) in Reader monad
13321335
sendMessage' :: AgentClient -> ConnId -> PQEncryption -> MsgFlags -> MsgBody -> AM (AgentMsgId, PQEncryption)

src/Simplex/Messaging/Agent/Client.hs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ data AgentClient = AgentClient
326326
xftpServers :: TMap UserId (UserServers 'PXFTP),
327327
xftpClients :: TMap XFTPTransportSession XFTPClientVar,
328328
useNetworkConfig :: TVar (NetworkConfig, NetworkConfig), -- (slow, fast) networks
329+
presetSMPDomains :: [HostName],
329330
userNetworkInfo :: TVar UserNetworkInfo,
330331
userNetworkUpdated :: TVar (Maybe UTCTime),
331332
subscrConns :: TVar (Set ConnId),
@@ -478,7 +479,7 @@ data UserNetworkType = UNNone | UNCellular | UNWifi | UNEthernet | UNOther
478479

479480
-- | Creates an SMP agent client instance that receives commands and sends responses via 'TBQueue's.
480481
newAgentClient :: Int -> InitialAgentServers -> UTCTime -> Env -> IO AgentClient
481-
newAgentClient clientId InitialAgentServers {smp, ntf, xftp, netCfg} currentTs agentEnv = do
482+
newAgentClient clientId InitialAgentServers {smp, ntf, xftp, netCfg, presetDomains} currentTs agentEnv = do
482483
let cfg = config agentEnv
483484
qSize = tbqSize cfg
484485
proxySessTs <- newTVarIO =<< getCurrentTime
@@ -532,6 +533,7 @@ newAgentClient clientId InitialAgentServers {smp, ntf, xftp, netCfg} currentTs a
532533
xftpServers,
533534
xftpClients,
534535
useNetworkConfig,
536+
presetSMPDomains = presetDomains,
535537
userNetworkInfo,
536538
userNetworkUpdated,
537539
subscrConns,
@@ -690,7 +692,7 @@ smpConnectClient c@AgentClient {smpClients, msgQ, proxySessTs} tSess@(_, srv, _)
690692
env <- ask
691693
liftError (protocolClientError SMP $ B.unpack $ strEncode srv) $ do
692694
ts <- readTVarIO proxySessTs
693-
smp <- ExceptT $ getProtocolClient g tSess cfg (Just msgQ) ts $ smpClientDisconnected c tSess env v' prs
695+
smp <- ExceptT $ getProtocolClient g tSess cfg (presetSMPDomains c) (Just msgQ) ts $ smpClientDisconnected c tSess env v' prs
694696
pure SMPConnectedClient {connectedClient = smp, proxiedRelays = prs}
695697

696698
smpClientDisconnected :: AgentClient -> SMPTransportSession -> Env -> SMPClientVar -> TMap SMPServer ProxiedRelayVar -> SMPClient -> IO ()
@@ -793,7 +795,7 @@ getNtfServerClient c@AgentClient {active, ntfClients, workerSeq, proxySessTs} tS
793795
g <- asks random
794796
ts <- readTVarIO proxySessTs
795797
liftError' (protocolClientError NTF $ B.unpack $ strEncode srv) $
796-
getProtocolClient g tSess cfg Nothing ts $
798+
getProtocolClient g tSess cfg [] Nothing ts $
797799
clientDisconnected v
798800

799801
clientDisconnected :: NtfClientVar -> NtfClient -> IO ()
@@ -1225,7 +1227,7 @@ runSMPServerTest c userId (ProtoServerWithAuth srv auth) = do
12251227
liftIO $ do
12261228
let tSess = (userId, srv, Nothing)
12271229
ts <- readTVarIO $ proxySessTs c
1228-
getProtocolClient g tSess cfg Nothing ts (\_ -> pure ()) >>= \case
1230+
getProtocolClient g tSess cfg (presetSMPDomains c) Nothing ts (\_ -> pure ()) >>= \case
12291231
Right smp -> do
12301232
rKeys@(_, rpKey) <- atomically $ C.generateAuthKeyPair ra g
12311233
(sKey, spKey) <- atomically $ C.generateAuthKeyPair sa g
@@ -1302,7 +1304,7 @@ runNTFServerTest c userId (ProtoServerWithAuth srv _) = do
13021304
liftIO $ do
13031305
let tSess = (userId, srv, Nothing)
13041306
ts <- readTVarIO $ proxySessTs c
1305-
getProtocolClient g tSess cfg Nothing ts (\_ -> pure ()) >>= \case
1307+
getProtocolClient g tSess cfg [] Nothing ts (\_ -> pure ()) >>= \case
13061308
Right ntf -> do
13071309
(nKey, npKey) <- atomically $ C.generateAuthKeyPair a g
13081310
(dhKey, _) <- atomically $ C.generateKeyPair g
@@ -1652,6 +1654,7 @@ getQueueMessage c rq@RcvQueue {server, rcvId, rcvPrivateKey} = do
16521654
l <- maybe (newTMVar ()) pure l_
16531655
takeTMVar l
16541656
pure $ Just l
1657+
{-# INLINE getQueueMessage #-}
16551658

16561659
decryptSMPMessage :: RcvQueue -> SMP.RcvMessage -> AM SMP.ClientRcvMsgBody
16571660
decryptSMPMessage rq SMP.RcvMessage {msgId, msgBody = SMP.EncRcvMsgBody body} =
@@ -1741,10 +1744,12 @@ sendAck c rq@RcvQueue {rcvId, rcvPrivateKey} msgId =
17411744
hasGetLock :: AgentClient -> RcvQueue -> IO Bool
17421745
hasGetLock c RcvQueue {server, rcvId} =
17431746
TM.memberIO (server, rcvId) $ getMsgLocks c
1747+
{-# INLINE hasGetLock #-}
17441748

17451749
releaseGetLock :: AgentClient -> RcvQueue -> STM ()
17461750
releaseGetLock c RcvQueue {server, rcvId} =
17471751
TM.lookup (server, rcvId) (getMsgLocks c) >>= mapM_ (`tryPutTMVar` ())
1752+
{-# INLINE releaseGetLock #-}
17481753

17491754
suspendQueue :: AgentClient -> RcvQueue -> AM ()
17501755
suspendQueue c rq@RcvQueue {rcvId, rcvPrivateKey} =

src/Simplex/Messaging/Agent/Env/SQLite.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ data InitialAgentServers = InitialAgentServers
9696
{ smp :: Map UserId (NonEmpty (ServerCfg 'PSMP)),
9797
ntf :: [NtfServer],
9898
xftp :: Map UserId (NonEmpty (ServerCfg 'PXFTP)),
99-
netCfg :: NetworkConfig
99+
netCfg :: NetworkConfig,
100+
presetDomains :: [HostName]
100101
}
101102

102103
data ServerCfg p = ServerCfg

src/Simplex/Messaging/Agent/Protocol.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ module Simplex.Messaging.Agent.Protocol
147147
AgentMsgId,
148148
NotificationsMode (..),
149149
NotificationInfo (..),
150+
ConnMsgReq (..),
150151

151152
-- * Encode/decode
152153
serializeCommand,
@@ -678,11 +679,21 @@ instance FromField NotificationsMode where fromField = blobFieldDecoder $ parseA
678679

679680
data NotificationInfo = NotificationInfo
680681
{ ntfConnId :: ConnId,
682+
ntfDbQueueId :: Int64,
681683
ntfTs :: SystemTime,
684+
-- Nothing means that the message failed to decrypt or to decode,
685+
-- we can still show event notification
682686
ntfMsgMeta :: Maybe NMsgMeta
683687
}
684688
deriving (Show)
685689

690+
data ConnMsgReq = ConnMsgReq
691+
{ msgConnId :: ConnId,
692+
msgDbQueueId :: Int64,
693+
msgTs :: Maybe UTCTime
694+
}
695+
deriving (Show)
696+
686697
data ConnectionMode = CMInvitation | CMContact
687698
deriving (Eq, Show)
688699

src/Simplex/Messaging/Agent/Store/AgentStore.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ module Simplex.Messaging.Agent.Store.AgentStore
9898
-- Messages
9999
updateRcvIds,
100100
createRcvMsg,
101+
setLastBrokerTs,
101102
updateRcvMsgHash,
102103
createSndMsgBody,
103104
updateSndIds,
@@ -855,7 +856,11 @@ createRcvMsg db connId rq@RcvQueue {dbQueueId} rcvMsgData@RcvMsgData {msgMeta =
855856
insertRcvMsgBase_ db connId rcvMsgData
856857
insertRcvMsgDetails_ db connId rq rcvMsgData
857858
updateRcvMsgHash db connId sndMsgId internalRcvId internalHash
858-
DB.execute db "UPDATE rcv_queues SET last_broker_ts = ? WHERE conn_id = ? AND rcv_queue_id = ?" (brokerTs, connId, dbQueueId)
859+
setLastBrokerTs db connId dbQueueId brokerTs
860+
861+
setLastBrokerTs :: DB.Connection -> ConnId -> DBQueueId 'QSStored -> UTCTime -> IO ()
862+
setLastBrokerTs db connId dbQueueId brokerTs =
863+
DB.execute db "UPDATE rcv_queues SET last_broker_ts = ? WHERE conn_id = ? AND rcv_queue_id = ? AND (last_broker_ts IS NULL OR last_broker_ts < ?)" (brokerTs, connId, dbQueueId, brokerTs)
859864

860865
createSndMsgBody :: DB.Connection -> AMessage -> IO Int64
861866
createSndMsgBody db aMessage =
@@ -1781,19 +1786,19 @@ getActiveNtfToken db =
17811786
ntfMode = fromMaybe NMPeriodic ntfMode_
17821787
in NtfToken {deviceToken = DeviceToken provider dt, ntfServer, ntfTokenId, ntfPubKey, ntfPrivKey, ntfDhKeys, ntfDhSecret, ntfTknStatus, ntfTknAction, ntfMode}
17831788

1784-
getNtfRcvQueue :: DB.Connection -> SMPQueueNtf -> IO (Either StoreError (ConnId, RcvNtfDhSecret, Maybe UTCTime))
1789+
getNtfRcvQueue :: DB.Connection -> SMPQueueNtf -> IO (Either StoreError (ConnId, Int64, RcvNtfDhSecret, Maybe UTCTime))
17851790
getNtfRcvQueue db SMPQueueNtf {smpServer = (SMPServer host port _), notifierId} =
17861791
firstRow' res SEConnNotFound $
17871792
DB.query
17881793
db
17891794
[sql|
1790-
SELECT conn_id, rcv_ntf_dh_secret, last_broker_ts
1795+
SELECT conn_id, rcv_queue_id, rcv_ntf_dh_secret, last_broker_ts
17911796
FROM rcv_queues
17921797
WHERE host = ? AND port = ? AND ntf_id = ? AND deleted = 0
17931798
|]
17941799
(host, port, notifierId)
17951800
where
1796-
res (connId, Just rcvNtfDhSecret, lastBrokerTs_) = Right (connId, rcvNtfDhSecret, lastBrokerTs_)
1801+
res (connId, dbQueueId, Just rcvNtfDhSecret, lastBrokerTs_) = Right (connId, dbQueueId, rcvNtfDhSecret, lastBrokerTs_)
17971802
res _ = Left SEConnNotFound
17981803

17991804
setConnectionNtfs :: DB.Connection -> ConnId -> Bool -> IO ()

src/Simplex/Messaging/Client.hs

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ module Simplex.Messaging.Client
8484
SocksMode (..),
8585
SMPProxyMode (..),
8686
SMPProxyFallback (..),
87+
SMPWebPortServers (..),
8788
defaultClientConfig,
8889
defaultSMPClientConfig,
8990
defaultNetworkConfig,
@@ -129,7 +130,7 @@ import qualified Data.ByteString.Char8 as B
129130
import qualified Data.ByteString.Base64 as B64
130131
import Data.Functor (($>))
131132
import Data.Int (Int64)
132-
import Data.List (find)
133+
import Data.List (find, isSuffixOf)
133134
import Data.List.NonEmpty (NonEmpty (..))
134135
import qualified Data.List.NonEmpty as L
135136
import Data.Maybe (catMaybes, fromMaybe)
@@ -138,7 +139,7 @@ import qualified Data.Text as T
138139
import Data.Time.Clock (UTCTime (..), diffUTCTime, getCurrentTime)
139140
import qualified Data.X509 as X
140141
import qualified Data.X509.Validation as XV
141-
import Network.Socket (ServiceName)
142+
import Network.Socket (HostName, ServiceName)
142143
import Network.Socks5 (SocksCredentials (..))
143144
import Numeric.Natural
144145
import qualified Simplex.Messaging.Crypto as C
@@ -291,7 +292,7 @@ data NetworkConfig = NetworkConfig
291292
-- | Fallback to direct connection when destination SMP relay does not support SMP proxy protocol extensions
292293
smpProxyFallback :: SMPProxyFallback,
293294
-- | use web port 443 for SMP protocol
294-
smpWebPort :: Bool,
295+
smpWebPortServers :: SMPWebPortServers,
295296
-- | timeout for the initial client TCP/TLS connection (microseconds)
296297
tcpConnectTimeout :: Int,
297298
-- | timeout of protocol commands (microseconds)
@@ -327,6 +328,12 @@ data SMPProxyFallback
327328
| SPFProhibit -- prohibit direct connection to destination relay.
328329
deriving (Eq, Show)
329330

331+
data SMPWebPortServers
332+
= SWPAll
333+
| SWPPreset
334+
| SWPOff
335+
deriving (Eq, Show)
336+
330337
instance StrEncoding SMPProxyMode where
331338
strEncode = \case
332339
SPMAlways -> "always"
@@ -353,6 +360,18 @@ instance StrEncoding SMPProxyFallback where
353360
"no" -> pure SPFProhibit
354361
_ -> fail "Invalid SMP proxy fallback mode"
355362

363+
instance StrEncoding SMPWebPortServers where
364+
strEncode = \case
365+
SWPAll -> "all"
366+
SWPPreset -> "preset"
367+
SWPOff -> "off"
368+
strP =
369+
A.takeTill (== ' ') >>= \case
370+
"all" -> pure SWPAll
371+
"preset" -> pure SWPPreset
372+
"off" -> pure SWPOff
373+
_ -> fail "Invalid SMP wep port setting"
374+
356375
defaultNetworkConfig :: NetworkConfig
357376
defaultNetworkConfig =
358377
NetworkConfig
@@ -363,7 +382,7 @@ defaultNetworkConfig =
363382
sessionMode = TSMSession,
364383
smpProxyMode = SPMNever,
365384
smpProxyFallback = SPFAllow,
366-
smpWebPort = False,
385+
smpWebPortServers = SWPPreset,
367386
tcpConnectTimeout = defaultTcpConnectTimeout,
368387
tcpTimeout = 15_000_000,
369388
tcpTimeoutPerKb = 5_000,
@@ -498,15 +517,15 @@ type TransportSession msg = (UserId, ProtoServer msg, Maybe ByteString)
498517
--
499518
-- A single queue can be used for multiple 'SMPClient' instances,
500519
-- as 'SMPServerTransmission' includes server information.
501-
getProtocolClient :: forall v err msg. Protocol v err msg => TVar ChaChaDRG -> TransportSession msg -> ProtocolClientConfig v -> Maybe (TBQueue (ServerTransmissionBatch v err msg)) -> UTCTime -> (ProtocolClient v err msg -> IO ()) -> IO (Either (ProtocolClientError err) (ProtocolClient v err msg))
502-
getProtocolClient g transportSession@(_, srv, _) cfg@ProtocolClientConfig {qSize, networkConfig, clientALPN, serverVRange, agreeSecret, proxyServer, useSNI} msgQ proxySessTs disconnected = do
520+
getProtocolClient :: forall v err msg. Protocol v err msg => TVar ChaChaDRG -> TransportSession msg -> ProtocolClientConfig v -> [HostName] -> Maybe (TBQueue (ServerTransmissionBatch v err msg)) -> UTCTime -> (ProtocolClient v err msg -> IO ()) -> IO (Either (ProtocolClientError err) (ProtocolClient v err msg))
521+
getProtocolClient g transportSession@(_, srv, _) cfg@ProtocolClientConfig {qSize, networkConfig, clientALPN, serverVRange, agreeSecret, proxyServer, useSNI} presetDomains msgQ proxySessTs disconnected = do
503522
case chooseTransportHost networkConfig (host srv) of
504523
Right useHost ->
505524
(getCurrentTime >>= mkProtocolClient useHost >>= runClient useTransport useHost)
506525
`catch` \(e :: IOException) -> pure . Left $ PCEIOError e
507526
Left e -> pure $ Left e
508527
where
509-
NetworkConfig {smpWebPort, tcpConnectTimeout, tcpTimeout, smpPingInterval} = networkConfig
528+
NetworkConfig {smpWebPortServers, tcpConnectTimeout, tcpTimeout, smpPingInterval} = networkConfig
510529
mkProtocolClient :: TransportHost -> UTCTime -> IO (PClient v err msg)
511530
mkProtocolClient transportHost ts = do
512531
connected <- newTVarIO False
@@ -554,6 +573,13 @@ getProtocolClient g transportSession@(_, srv, _) cfg@ProtocolClientConfig {qSize
554573
SPSMP | smpWebPort -> ("443", transport @TLS)
555574
_ -> defaultTransport cfg
556575
p -> (p, transport @TLS)
576+
where
577+
smpWebPort = case smpWebPortServers of
578+
SWPAll -> True
579+
SWPPreset -> case srv of
580+
ProtocolServer {host = THDomainName h :| _} -> any (`isSuffixOf` h) presetDomains
581+
_ -> False
582+
SWPOff -> False
557583

558584
client :: forall c. Transport c => TProxy c -> PClient v err msg -> TMVar (Either (ProtocolClientError err) (ProtocolClient v err msg)) -> c -> IO ()
559585
client _ c cVar h = do
@@ -775,6 +801,7 @@ getSMPMessage c rpKey rId =
775801
OK -> pure Nothing
776802
cmd@(MSG msg) -> liftIO (writeSMPMessage c rId cmd) $> Just msg
777803
r -> throwE $ unexpectedResponse r
804+
{-# INLINE getSMPMessage #-}
778805

779806
-- | Subscribe to the SMP queue notifications.
780807
--
@@ -1262,6 +1289,8 @@ $(J.deriveJSON (enumJSON $ dropPrefix "SPM") ''SMPProxyMode)
12621289

12631290
$(J.deriveJSON (enumJSON $ dropPrefix "SPF") ''SMPProxyFallback)
12641291

1292+
$(J.deriveJSON (enumJSON $ dropPrefix "SWP") ''SMPWebPortServers)
1293+
12651294
$(J.deriveJSON defaultJSON ''NetworkConfig)
12661295

12671296
$(J.deriveJSON (sumTypeJSON $ dropPrefix "Proxy") ''ProxyClientError)

src/Simplex/Messaging/Client/Agent.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ isOwnServer SMPClientAgent {agentCfg} ProtocolServer {host} =
198198
-- | Run an SMP client for SMPClientVar
199199
connectClient :: SMPClientAgent -> SMPServer -> SMPClientVar -> IO (Either SMPClientError SMPClient)
200200
connectClient ca@SMPClientAgent {agentCfg, smpClients, smpSessions, msgQ, randomDrg, startedAt} srv v =
201-
getProtocolClient randomDrg (1, srv, Nothing) (smpCfg agentCfg) (Just msgQ) startedAt clientDisconnected
201+
getProtocolClient randomDrg (1, srv, Nothing) (smpCfg agentCfg) [] (Just msgQ) startedAt clientDisconnected
202202
where
203203
clientDisconnected :: SMPClient -> IO ()
204204
clientDisconnected smp = do

0 commit comments

Comments
 (0)