Skip to content

Commit b9a07b5

Browse files
committed
track counts and hashes in smp/ntf servers via triggers, smp server stats for service subscription, update SMP protocol to pass expected count and hash in SSUB/NSSUB commands
1 parent 967d22c commit b9a07b5

File tree

27 files changed

+481
-250
lines changed

27 files changed

+481
-250
lines changed

src/Simplex/Messaging/Agent.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ import Simplex.Messaging.Protocol
200200
ErrorType (AUTH),
201201
MsgBody,
202202
MsgFlags (..),
203-
IdsHash,
204203
NtfServer,
205204
ProtoServerWithAuth (..),
206205
ProtocolServer (..),
@@ -211,6 +210,7 @@ import Simplex.Messaging.Protocol
211210
SMPMsgMeta,
212211
SParty (..),
213212
SProtocolType (..),
213+
ServiceSub (..),
214214
SndPublicAuthKey,
215215
SubscriptionMode (..),
216216
UserProtocol,
@@ -466,7 +466,7 @@ resubscribeConnections :: AgentClient -> [ConnId] -> AE (Map ConnId (Either Agen
466466
resubscribeConnections c = withAgentEnv c . resubscribeConnections' c
467467
{-# INLINE resubscribeConnections #-}
468468

469-
subscribeClientServices :: AgentClient -> UserId -> AE (Map SMPServer (Either AgentErrorType (Int64, IdsHash)))
469+
subscribeClientServices :: AgentClient -> UserId -> AE (Map SMPServer (Either AgentErrorType ServiceSub))
470470
subscribeClientServices c = withAgentEnv c . subscribeClientServices' c
471471
{-# INLINE subscribeClientServices #-}
472472

@@ -1362,15 +1362,15 @@ resubscribeConnections' c connIds = do
13621362
-- union is left-biased, so results returned by subscribeConnections' take precedence
13631363
(`M.union` r) <$> subscribeConnections' c connIds'
13641364

1365-
-- TODO [serts rcv] compare hash with lock
1366-
subscribeClientServices' :: AgentClient -> UserId -> AM (Map SMPServer (Either AgentErrorType (Int64, IdsHash)))
1365+
-- TODO [serts rcv] compare hash. possibly, it should return both expected and returned counts
1366+
subscribeClientServices' :: AgentClient -> UserId -> AM (Map SMPServer (Either AgentErrorType ServiceSub))
13671367
subscribeClientServices' c userId =
13681368
ifM useService subscribe $ throwError $ CMD PROHIBITED "no user service allowed"
13691369
where
13701370
useService = liftIO $ (Just True ==) <$> TM.lookupIO userId (useClientServices c)
13711371
subscribe = do
13721372
srvs <- withStore' c (`getClientServiceServers` userId)
1373-
lift $ M.fromList . zip srvs <$> mapConcurrently (tryAllErrors' . subscribeClientService c userId) srvs
1373+
lift $ M.fromList <$> mapConcurrently (\(srv, ServiceSub _ n idsHash) -> fmap (srv,) $ tryAllErrors' $ subscribeClientService c userId srv n idsHash) srvs
13741374

13751375
-- requesting messages sequentially, to reduce memory usage
13761376
getConnectionMessages' :: AgentClient -> NonEmpty ConnMsgReq -> AM' (NonEmpty (Either AgentErrorType (Maybe SMPMsgMeta)))

src/Simplex/Messaging/Agent/Client.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ import Simplex.Messaging.Protocol
270270
RcvNtfPublicDhKey,
271271
SMPMsgMeta (..),
272272
SProtocolType (..),
273+
ServiceSub,
273274
SndPublicAuthKey,
274275
SubscriptionMode (..),
275276
NewNtfCreds (..),
@@ -1578,10 +1579,10 @@ subscribeQueues c qs = do
15781579
processSubResults = mapM_ $ uncurry $ processSubResult c sessId
15791580
resubscribe = resubscribeSMPSession c tSess `runReaderT` env
15801581

1581-
subscribeClientService :: AgentClient -> UserId -> SMPServer -> AM (Int64, IdsHash)
1582-
subscribeClientService c userId srv =
1583-
withLogClient c NRMBackground (userId, srv, Nothing) B.empty "SUBS" $
1584-
(`subscribeService` SMP.SRecipientService) . connectedClient
1582+
subscribeClientService :: AgentClient -> UserId -> SMPServer -> Int64 -> IdsHash -> AM ServiceSub
1583+
subscribeClientService c userId srv n idsHash =
1584+
withLogClient c NRMBackground (userId, srv, Nothing) B.empty "SUBS" $ \(SMPConnectedClient smp _) ->
1585+
subscribeService smp SMP.SRecipientService n idsHash
15851586

15861587
activeClientSession :: AgentClient -> SMPTransportSession -> SessionId -> STM Bool
15871588
activeClientSession c tSess sessId = sameSess <$> tryReadSessVar tSess (smpClients c)

src/Simplex/Messaging/Agent/NtfSubSupervisor.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ runNtfWorker c srv Worker {doWork} =
314314
_ -> ((ntfSubConnId sub, INTERNAL "NSACheck - no subscription ID") : errs, subs, subIds)
315315
updateSub :: DB.Connection -> NtfServer -> UTCTime -> UTCTime -> (NtfSubscription, NtfSubStatus) -> IO (Maybe SMPServer)
316316
updateSub db ntfServer ts nextCheckTs (sub, status)
317-
| ntfShouldSubscribe status =
317+
| status `elem` subscribeNtfStatuses =
318318
let sub' = sub {ntfSubStatus = NASCreated status}
319319
in Nothing <$ updateNtfSubscription db sub' (NSANtf NSACheck) nextCheckTs
320320
-- ntf server stopped subscribing to this queue

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,19 +409,20 @@ getClientService db userId srv =
409409
where
410410
toService (kh, cert, pk, serviceId_) = ((kh, (cert, pk)), serviceId_)
411411

412-
getClientServiceServers :: DB.Connection -> UserId -> IO [SMPServer]
412+
getClientServiceServers :: DB.Connection -> UserId -> IO [(SMPServer, ServiceSub)]
413413
getClientServiceServers db userId =
414414
map toServer
415415
<$> DB.query
416416
db
417417
[sql|
418-
SELECT c.host, c.port, s.key_hash
418+
SELECT c.host, c.port, s.key_hash, c.rcv_service_id, c.rcv_service_queue_count, c.rcv_service_queue_ids_hash
419419
FROM client_services c
420420
JOIN servers s ON s.host = c.host AND s.port = c.port
421421
|]
422422
(Only userId)
423423
where
424-
toServer (host, port, kh) = SMPServer host port kh
424+
toServer (host, port, kh, serviceId, n, Binary idsHash) =
425+
(SMPServer host port kh, ServiceSub serviceId n (IdsHash idsHash))
425426

426427
setClientServiceId :: DB.Connection -> UserId -> SMPServer -> ServiceId -> IO ()
427428
setClientServiceId db userId srv serviceId =

src/Simplex/Messaging/Agent/Store/SQLite/Migrations/M20250815_service_certs.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ CREATE TABLE client_services(
1717
service_cert_hash BLOB NOT NULL,
1818
service_priv_key BLOB NOT NULL,
1919
rcv_service_id BLOB,
20-
rcv_queues_hash BLOB NOT NULL DEFAULT x'',
20+
rcv_service_queue_count INTEGER NOT NULL DEFAULT 0,
21+
rcv_service_queue_ids_hash BLOB NOT NULL DEFAULT x'00000000000000000000000000000000',
2122
FOREIGN KEY(host, port) REFERENCES servers ON UPDATE CASCADE ON DELETE RESTRICT
2223
);
2324

src/Simplex/Messaging/Agent/Store/SQLite/Migrations/agent_schema.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,8 @@ CREATE TABLE client_services(
446446
service_cert_hash BLOB NOT NULL,
447447
service_priv_key BLOB NOT NULL,
448448
rcv_service_id BLOB,
449-
rcv_queues_hash BLOB NOT NULL DEFAULT x'',
449+
rcv_service_queue_count INTEGER NOT NULL DEFAULT 0,
450+
rcv_service_queue_ids_hash BLOB NOT NULL DEFAULT x'00000000000000000000000000000000',
450451
FOREIGN KEY(host, port) REFERENCES servers ON UPDATE CASCADE ON DELETE RESTRICT
451452
);
452453
CREATE UNIQUE INDEX idx_rcv_queues_ntf ON rcv_queues(host, port, ntf_id);

src/Simplex/Messaging/Client.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -892,18 +892,18 @@ nsubResponse_ = \case
892892
{-# INLINE nsubResponse_ #-}
893893

894894
-- This command is always sent in background request mode
895-
subscribeService :: forall p. (PartyI p, ServiceParty p) => SMPClient -> SParty p -> ExceptT SMPClientError IO (Int64, IdsHash)
896-
subscribeService c party = case smpClientService c of
895+
subscribeService :: forall p. (PartyI p, ServiceParty p) => SMPClient -> SParty p -> Int64 -> IdsHash -> ExceptT SMPClientError IO ServiceSub
896+
subscribeService c party n idsHash = case smpClientService c of
897897
Just THClientService {serviceId, serviceKey} -> do
898898
liftIO $ enablePings c
899899
sendSMPCommand c NRMBackground (Just (C.APrivateAuthKey C.SEd25519 serviceKey)) serviceId subCmd >>= \case
900-
SOKS n idsHash -> pure (n, idsHash)
900+
SOKS n' idsHash' -> pure $ ServiceSub serviceId n' idsHash'
901901
r -> throwE $ unexpectedResponse r
902902
where
903903
subCmd :: Command p
904904
subCmd = case party of
905-
SRecipientService -> SUBS
906-
SNotifierService -> NSUBS
905+
SRecipientService -> SUBS n idsHash
906+
SNotifierService -> NSUBS n idsHash
907907
Nothing -> throwE PCEServiceUnavailable
908908

909909
smpClientService :: SMPClient -> Maybe THClientService

src/Simplex/Messaging/Client/Agent.hs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import Crypto.Random (ChaChaDRG)
4545
import Data.ByteString.Char8 (ByteString)
4646
import qualified Data.ByteString.Char8 as B
4747
import Data.Constraint (Dict (..))
48-
import Data.Int (Int64)
4948
import Data.List.NonEmpty (NonEmpty)
5049
import qualified Data.List.NonEmpty as L
5150
import Data.Map.Strict (Map)
@@ -69,10 +68,12 @@ import Simplex.Messaging.Protocol
6968
ProtocolServer (..),
7069
QueueId,
7170
SMPServer,
71+
ServiceSub (..),
7272
SParty (..),
7373
ServiceParty,
7474
serviceParty,
75-
partyServiceRole
75+
partyServiceRole,
76+
queueIdsHash,
7677
)
7778
import Simplex.Messaging.Session
7879
import Simplex.Messaging.TMap (TMap)
@@ -91,14 +92,14 @@ data SMPClientAgentEvent
9192
| CADisconnected SMPServer (NonEmpty QueueId)
9293
| CASubscribed SMPServer (Maybe ServiceId) (NonEmpty QueueId)
9394
| CASubError SMPServer (NonEmpty (QueueId, SMPClientError))
94-
| CAServiceDisconnected SMPServer (ServiceId, Int64)
95-
| CAServiceSubscribed SMPServer (ServiceId, Int64) Int64
96-
| CAServiceSubError SMPServer (ServiceId, Int64) SMPClientError
95+
| CAServiceDisconnected SMPServer ServiceSub
96+
| CAServiceSubscribed {subServer :: SMPServer, expected :: ServiceSub, subscribed :: ServiceSub}
97+
| CAServiceSubError SMPServer ServiceSub SMPClientError
9798
-- CAServiceUnavailable is used when service ID in pending subscription is different from the current service in connection.
9899
-- This will require resubscribing to all queues associated with this service ID individually, creating new associations.
99100
-- It may happen if, for example, SMP server deletes service information (e.g. via downgrade and upgrade)
100101
-- and assigns different service ID to the service certificate.
101-
| CAServiceUnavailable SMPServer (ServiceId, Int64)
102+
| CAServiceUnavailable SMPServer ServiceSub
102103

103104
data SMPClientAgentConfig = SMPClientAgentConfig
104105
{ smpCfg :: ProtocolClientConfig SMPVersion,
@@ -142,11 +143,11 @@ data SMPClientAgent p = SMPClientAgent
142143
-- Only one service subscription can exist per server with this agent.
143144
-- With correctly functioning SMP server, queue and service subscriptions can't be
144145
-- active at the same time.
145-
activeServiceSubs :: TMap SMPServer (TVar (Maybe ((ServiceId, Int64), SessionId))),
146+
activeServiceSubs :: TMap SMPServer (TVar (Maybe (ServiceSub, SessionId))),
146147
activeQueueSubs :: TMap SMPServer (TMap QueueId (SessionId, C.APrivateAuthKey)),
147148
-- Pending service subscriptions can co-exist with pending queue subscriptions
148149
-- on the same SMP server during subscriptions being transitioned from per-queue to service.
149-
pendingServiceSubs :: TMap SMPServer (TVar (Maybe (ServiceId, Int64))),
150+
pendingServiceSubs :: TMap SMPServer (TVar (Maybe ServiceSub)),
150151
pendingQueueSubs :: TMap SMPServer (TMap QueueId C.APrivateAuthKey),
151152
smpSubWorkers :: TMap SMPServer (SessionVar (Async ())),
152153
workerSeq :: TVar Int
@@ -256,7 +257,7 @@ connectClient ca@SMPClientAgent {agentCfg, smpClients, smpSessions, msgQ, random
256257
removeClientAndSubs smp >>= serverDown
257258
logInfo . decodeUtf8 $ "Agent disconnected from " <> showServer srv
258259

259-
removeClientAndSubs :: SMPClient -> IO (Maybe (ServiceId, Int64), Maybe (Map QueueId C.APrivateAuthKey))
260+
removeClientAndSubs :: SMPClient -> IO (Maybe ServiceSub, Maybe (Map QueueId C.APrivateAuthKey))
260261
removeClientAndSubs smp = do
261262
-- Looking up subscription vars outside of STM transaction to reduce re-evaluation.
262263
-- It is possible because these vars are never removed, they are only added.
@@ -287,7 +288,7 @@ connectClient ca@SMPClientAgent {agentCfg, smpClients, smpSessions, msgQ, random
287288
then pure Nothing
288289
else Just subs <$ addSubs_ (pendingQueueSubs ca) srv subs
289290

290-
serverDown :: (Maybe (ServiceId, Int64), Maybe (Map QueueId C.APrivateAuthKey)) -> IO ()
291+
serverDown :: (Maybe ServiceSub, Maybe (Map QueueId C.APrivateAuthKey)) -> IO ()
291292
serverDown (sSub, qSubs) = do
292293
mapM_ (notify ca . CAServiceDisconnected srv) sSub
293294
let qIds = L.nonEmpty . M.keys =<< qSubs
@@ -317,7 +318,7 @@ reconnectClient ca@SMPClientAgent {active, agentCfg, smpSubWorkers, workerSeq} s
317318
loop
318319
ProtocolClientConfig {networkConfig = NetworkConfig {tcpConnectTimeout}} = smpCfg agentCfg
319320
noPending (sSub, qSubs) = isNothing sSub && maybe True M.null qSubs
320-
getPending :: Monad m => (forall a. SMPServer -> TMap SMPServer a -> m (Maybe a)) -> (forall a. TVar a -> m a) -> m (Maybe (ServiceId, Int64), Maybe (Map QueueId C.APrivateAuthKey))
321+
getPending :: Monad m => (forall a. SMPServer -> TMap SMPServer a -> m (Maybe a)) -> (forall a. TVar a -> m a) -> m (Maybe ServiceSub, Maybe (Map QueueId C.APrivateAuthKey))
321322
getPending lkup rd = do
322323
sSub <- lkup srv (pendingServiceSubs ca) $>>= rd
323324
qSubs <- lkup srv (pendingQueueSubs ca) >>= mapM rd
@@ -329,7 +330,7 @@ reconnectClient ca@SMPClientAgent {active, agentCfg, smpSubWorkers, workerSeq} s
329330
whenM (isEmptyTMVar $ sessionVar v) retry
330331
removeSessVar v srv smpSubWorkers
331332

332-
reconnectSMPClient :: forall p. SMPClientAgent p -> SMPServer -> (Maybe (ServiceId, Int64), Maybe (Map QueueId C.APrivateAuthKey)) -> ExceptT SMPClientError IO ()
333+
reconnectSMPClient :: forall p. SMPClientAgent p -> SMPServer -> (Maybe ServiceSub, Maybe (Map QueueId C.APrivateAuthKey)) -> ExceptT SMPClientError IO ()
333334
reconnectSMPClient ca@SMPClientAgent {agentCfg, agentParty} srv (sSub_, qSubs_) =
334335
withSMP ca srv $ \smp -> liftIO $ case serviceParty agentParty of
335336
Just Dict -> resubscribe smp
@@ -430,7 +431,7 @@ smpSubscribeQueues ca smp srv subs = do
430431
let acc@(_, _, (qOks, sQs), notPending) = foldr (groupSub pending) (False, [], ([], []), []) (L.zip subs rs)
431432
unless (null qOks) $ addActiveSubs ca srv qOks
432433
unless (null sQs) $ forM_ smpServiceId $ \serviceId ->
433-
updateActiveServiceSub ca srv ((serviceId, fromIntegral $ length sQs), sessId)
434+
updateActiveServiceSub ca srv (ServiceSub serviceId (fromIntegral $ length sQs) (queueIdsHash sQs), sessId)
434435
unless (null notPending) $ removePendingSubs ca srv notPending
435436
pure acc
436437
sessId = sessionId $ thParams smp
@@ -454,40 +455,40 @@ smpSubscribeQueues ca smp srv subs = do
454455
notify_ :: (SMPServer -> NonEmpty a -> SMPClientAgentEvent) -> [a] -> IO ()
455456
notify_ evt qs = mapM_ (notify ca . evt srv) $ L.nonEmpty qs
456457

457-
subscribeServiceNtfs :: SMPClientAgent 'NotifierService -> SMPServer -> (ServiceId, Int64) -> IO ()
458+
subscribeServiceNtfs :: SMPClientAgent 'NotifierService -> SMPServer -> ServiceSub -> IO ()
458459
subscribeServiceNtfs = subscribeService_
459460
{-# INLINE subscribeServiceNtfs #-}
460461

461-
subscribeService_ :: (PartyI p, ServiceParty p) => SMPClientAgent p -> SMPServer -> (ServiceId, Int64) -> IO ()
462+
subscribeService_ :: (PartyI p, ServiceParty p) => SMPClientAgent p -> SMPServer -> ServiceSub -> IO ()
462463
subscribeService_ ca srv serviceSub = do
463464
atomically $ setPendingServiceSub ca srv $ Just serviceSub
464465
runExceptT (getSMPServerClient' ca srv) >>= \case
465466
Right smp -> smpSubscribeService ca smp srv serviceSub
466467
Left _ -> pure () -- no call to reconnectClient - failing getSMPServerClient' does that
467468

468-
smpSubscribeService :: (PartyI p, ServiceParty p) => SMPClientAgent p -> SMPClient -> SMPServer -> (ServiceId, Int64) -> IO ()
469-
smpSubscribeService ca smp srv serviceSub@(serviceId, _) = case smpClientService smp of
469+
smpSubscribeService :: (PartyI p, ServiceParty p) => SMPClientAgent p -> SMPClient -> SMPServer -> ServiceSub -> IO ()
470+
smpSubscribeService ca smp srv serviceSub@(ServiceSub serviceId n idsHash) = case smpClientService smp of
470471
Just service | serviceAvailable service -> subscribe
471472
_ -> notifyUnavailable
472473
where
473474
subscribe = do
474-
r <- runExceptT $ subscribeService smp $ agentParty ca
475+
r <- runExceptT $ subscribeService smp (agentParty ca) n idsHash
475476
ok <-
476477
atomically $
477478
ifM
478479
(activeClientSession ca smp srv)
479480
(True <$ processSubscription r)
480481
(pure False)
481482
if ok
482-
then case r of -- TODO [certs rcv] compare hash
483-
Right (n, _idsHash) -> notify ca $ CAServiceSubscribed srv serviceSub n
483+
then case r of
484+
Right serviceSub' -> notify ca $ CAServiceSubscribed srv serviceSub serviceSub'
484485
Left e
485486
| smpClientServiceError e -> notifyUnavailable
486487
| temporaryClientError e -> reconnectClient ca srv
487488
| otherwise -> notify ca $ CAServiceSubError srv serviceSub e
488489
else reconnectClient ca srv
489-
processSubscription = mapM_ $ \(n, _idsHash) -> do -- TODO [certs rcv] validate hash here?
490-
setActiveServiceSub ca srv $ Just ((serviceId, n), sessId)
490+
processSubscription = mapM_ $ \serviceSub' -> do -- TODO [certs rcv] validate hash here?
491+
setActiveServiceSub ca srv $ Just (serviceSub', sessId)
491492
setPendingServiceSub ca srv Nothing
492493
serviceAvailable THClientService {serviceRole, serviceId = serviceId'} =
493494
serviceId == serviceId' && partyServiceRole (agentParty ca) == serviceRole
@@ -529,11 +530,11 @@ addSubs_ subs srv ss =
529530
Just m -> TM.union ss m
530531
_ -> TM.insertM srv (newTVar ss) subs
531532

532-
setActiveServiceSub :: SMPClientAgent p -> SMPServer -> Maybe ((ServiceId, Int64), SessionId) -> STM ()
533+
setActiveServiceSub :: SMPClientAgent p -> SMPServer -> Maybe (ServiceSub, SessionId) -> STM ()
533534
setActiveServiceSub = setServiceSub_ activeServiceSubs
534535
{-# INLINE setActiveServiceSub #-}
535536

536-
setPendingServiceSub :: SMPClientAgent p -> SMPServer -> Maybe (ServiceId, Int64) -> STM ()
537+
setPendingServiceSub :: SMPClientAgent p -> SMPServer -> Maybe ServiceSub -> STM ()
537538
setPendingServiceSub = setServiceSub_ pendingServiceSubs
538539
{-# INLINE setPendingServiceSub #-}
539540

@@ -548,12 +549,12 @@ setServiceSub_ subsSel ca srv sub =
548549
Just v -> writeTVar v sub
549550
Nothing -> TM.insertM srv (newTVar sub) (subsSel ca)
550551

551-
updateActiveServiceSub :: SMPClientAgent p -> SMPServer -> ((ServiceId, Int64), SessionId) -> STM ()
552-
updateActiveServiceSub ca srv sub@((serviceId', n'), sessId') =
552+
updateActiveServiceSub :: SMPClientAgent p -> SMPServer -> (ServiceSub, SessionId) -> STM ()
553+
updateActiveServiceSub ca srv sub@(ServiceSub serviceId' n' idsHash', sessId') =
553554
TM.lookup srv (activeServiceSubs ca) >>= \case
554555
Just v -> modifyTVar' v $ \case
555-
Just ((serviceId, n), sessId) | serviceId == serviceId' && sessId == sessId' ->
556-
Just ((serviceId, n + n'), sessId)
556+
Just (ServiceSub serviceId n idsHash, sessId) | serviceId == serviceId' && sessId == sessId' ->
557+
Just (ServiceSub serviceId (n + n') (idsHash <> idsHash'), sessId)
557558
_ -> Just sub
558559
Nothing -> TM.insertM srv (newTVar $ Just sub) (activeServiceSubs ca)
559560

src/Simplex/Messaging/Crypto.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ module Simplex.Messaging.Crypto
177177
sha512Hash,
178178
sha3_256,
179179
sha3_384,
180+
md5Hash,
180181

181182
-- * Message padding / un-padding
182183
canPad,
@@ -215,7 +216,7 @@ import Crypto.Cipher.AES (AES256)
215216
import qualified Crypto.Cipher.Types as AES
216217
import qualified Crypto.Cipher.XSalsa as XSalsa
217218
import qualified Crypto.Error as CE
218-
import Crypto.Hash (Digest, SHA3_256, SHA3_384, SHA256 (..), SHA512 (..), hash, hashDigestSize)
219+
import Crypto.Hash (Digest, MD5, SHA3_256, SHA3_384, SHA256 (..), SHA512 (..), hash, hashDigestSize)
219220
import qualified Crypto.KDF.HKDF as H
220221
import qualified Crypto.MAC.Poly1305 as Poly1305
221222
import qualified Crypto.PubKey.Curve25519 as X25519
@@ -1006,6 +1007,9 @@ sha3_384 :: ByteString -> ByteString
10061007
sha3_384 = BA.convert . (hash :: ByteString -> Digest SHA3_384)
10071008
{-# INLINE sha3_384 #-}
10081009

1010+
md5Hash :: ByteString -> ByteString
1011+
md5Hash = BA.convert . (hash :: ByteString -> Digest MD5)
1012+
10091013
-- | AEAD-GCM encryption with associated data.
10101014
--
10111015
-- Used as part of double ratchet encryption.

src/Simplex/Messaging/Notifications/Protocol.hs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -489,17 +489,9 @@ data NtfSubStatus
489489
NSErr ByteString
490490
deriving (Eq, Ord, Show)
491491

492-
ntfShouldSubscribe :: NtfSubStatus -> Bool
493-
ntfShouldSubscribe = \case
494-
NSNew -> True
495-
NSPending -> True
496-
NSActive -> True
497-
NSInactive -> True
498-
NSEnd -> False
499-
NSDeleted -> False
500-
NSAuth -> False
501-
NSService -> True
502-
NSErr _ -> False
492+
-- if these statuses change, the queue ID hashes for services need to be updated in a new migration (see m20250830_queue_ids_hash)
493+
subscribeNtfStatuses :: [NtfSubStatus]
494+
subscribeNtfStatuses = [NSNew, NSPending, NSActive, NSInactive]
503495

504496
instance Encoding NtfSubStatus where
505497
smpEncode = \case

0 commit comments

Comments
 (0)