From 04377962328b0b9e722d502f5cab91a189f43dbc Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sun, 14 Aug 2022 21:10:34 +0100 Subject: [PATCH] support multiple server hosts with notifications (#498) * support multiple server hosts with notifications * remove unused type * remove unused import * update server hosts during parsing --- src/Simplex/Messaging/Agent.hs | 3 ++- src/Simplex/Messaging/Agent/Protocol.hs | 1 + src/Simplex/Messaging/Notifications/Protocol.hs | 11 ++++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Simplex/Messaging/Agent.hs b/src/Simplex/Messaging/Agent.hs index 11eddb842..b1db5855a 100644 --- a/src/Simplex/Messaging/Agent.hs +++ b/src/Simplex/Messaging/Agent.hs @@ -91,7 +91,6 @@ import qualified Data.Text as T import Data.Time.Clock import Data.Time.Clock.System (systemToUTCTime) import qualified Database.SQLite.Simple as DB --- import GHC.Conc (unsafeIOToSTM) import Simplex.Messaging.Agent.Client import Simplex.Messaging.Agent.Env.SQLite import Simplex.Messaging.Agent.NtfSubSupervisor @@ -119,6 +118,8 @@ import UnliftIO.Concurrent (forkFinally, forkIO, threadDelay) import qualified UnliftIO.Exception as E import UnliftIO.STM +-- import GHC.Conc (unsafeIOToSTM) + -- | Creates an SMP agent client instance getSMPAgentClient :: (MonadRandom m, MonadUnliftIO m) => AgentConfig -> InitialAgentServers -> m AgentClient getSMPAgentClient cfg initServers = newSMPAgentEnv cfg >>= runReaderT runAgent diff --git a/src/Simplex/Messaging/Agent/Protocol.hs b/src/Simplex/Messaging/Agent/Protocol.hs index 6a1928232..c3454db3e 100644 --- a/src/Simplex/Messaging/Agent/Protocol.hs +++ b/src/Simplex/Messaging/Agent/Protocol.hs @@ -98,6 +98,7 @@ module Simplex.Messaging.Agent.Protocol queueStatusT, agentMessageType, extraSMPServerHosts, + updateSMPServerHosts, -- * TCP transport functions tPut, diff --git a/src/Simplex/Messaging/Notifications/Protocol.hs b/src/Simplex/Messaging/Notifications/Protocol.hs index d7f568509..5ce280b1b 100644 --- a/src/Simplex/Messaging/Notifications/Protocol.hs +++ b/src/Simplex/Messaging/Notifications/Protocol.hs @@ -23,6 +23,7 @@ import Data.Type.Equality import Data.Word (Word16) import Database.SQLite.Simple.FromField (FromField (..)) import Database.SQLite.Simple.ToField (ToField (..)) +import Simplex.Messaging.Agent.Protocol (updateSMPServerHosts) import qualified Simplex.Messaging.Crypto as C import Simplex.Messaging.Encoding import Simplex.Messaging.Encoding.String @@ -332,12 +333,16 @@ data SMPQueueNtf = SMPQueueNtf instance Encoding SMPQueueNtf where smpEncode SMPQueueNtf {smpServer, notifierId} = smpEncode (smpServer, notifierId) smpP = do - (smpServer, notifierId) <- smpP - pure $ SMPQueueNtf {smpServer, notifierId} + smpServer <- updateSMPServerHosts <$> smpP + notifierId <- smpP + pure SMPQueueNtf {smpServer, notifierId} instance StrEncoding SMPQueueNtf where strEncode SMPQueueNtf {smpServer, notifierId} = strEncode smpServer <> "/" <> strEncode notifierId - strP = SMPQueueNtf <$> strP <* A.char '/' <*> strP + strP = do + smpServer <- updateSMPServerHosts <$> strP + notifierId <- A.char '/' *> strP + pure SMPQueueNtf {smpServer, notifierId} data PushProvider = PPApnsDev | PPApnsProd | PPApnsTest deriving (Eq, Ord, Show)