mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-05-08 13:15:43 +00:00
488398df9f
* types and encodings for double ratchet integration * upgrade stack resolver * type classes for version agreement, encode/decode connection request links and E2E params with versioning * encode/decode client parameters (version and DH key) in SMP queue URI using query string parameters * restore support of the current SMP queue URI format * update AMessage to only send queues in REPLY message (not the full connection request) * new agent message evnvelopes (tests fail) * new message envelopes - tests pass * store fully encrypted messages before sending * unify message delivery via DB queue (excluding confirmation and invitation) * remove activateSecuredQueue * linter hints * remove comment * export order * save rachet-encrypted message, not per-queue encrypted * delete message after it is accepted by the server, reduce message delivery interval for the tests Co-authored-by: Efim Poberezkin <8711996+efim-poberezkin@users.noreply.github.com>
80 lines
2.4 KiB
Haskell
80 lines
2.4 KiB
Haskell
{-# LANGUAGE DataKinds #-}
|
|
{-# LANGUAGE DuplicateRecordFields #-}
|
|
{-# LANGUAGE NamedFieldPuns #-}
|
|
{-# LANGUAGE NumericUnderscores #-}
|
|
{-# OPTIONS_GHC -fno-warn-unticked-promoted-constructors #-}
|
|
|
|
module Simplex.Messaging.Agent.Env.SQLite where
|
|
|
|
import Control.Monad.IO.Unlift
|
|
import Crypto.Random
|
|
import Data.List.NonEmpty (NonEmpty)
|
|
import Network.Socket
|
|
import Numeric.Natural
|
|
import Simplex.Messaging.Agent.Protocol (SMPServer)
|
|
import Simplex.Messaging.Agent.RetryInterval
|
|
import Simplex.Messaging.Agent.Store.SQLite
|
|
import qualified Simplex.Messaging.Agent.Store.SQLite.Migrations as Migrations
|
|
import Simplex.Messaging.Client
|
|
import qualified Simplex.Messaging.Crypto as C
|
|
import System.Random (StdGen, newStdGen)
|
|
import UnliftIO.STM
|
|
|
|
data AgentConfig = AgentConfig
|
|
{ tcpPort :: ServiceName,
|
|
smpServers :: NonEmpty SMPServer,
|
|
cmdSignAlg :: C.SignAlg,
|
|
connIdBytes :: Int,
|
|
tbqSize :: Natural,
|
|
dbFile :: FilePath,
|
|
dbPoolSize :: Int,
|
|
smpCfg :: SMPClientConfig,
|
|
reconnectInterval :: RetryInterval,
|
|
caCertificateFile :: FilePath,
|
|
privateKeyFile :: FilePath,
|
|
certificateFile :: FilePath
|
|
}
|
|
|
|
minute :: Int
|
|
minute = 60_000_000
|
|
|
|
defaultAgentConfig :: AgentConfig
|
|
defaultAgentConfig =
|
|
AgentConfig
|
|
{ tcpPort = "5224",
|
|
smpServers = undefined, -- TODO move it elsewhere?
|
|
cmdSignAlg = C.SignAlg C.SEd448,
|
|
connIdBytes = 12,
|
|
tbqSize = 16,
|
|
dbFile = "smp-agent.db",
|
|
dbPoolSize = 4,
|
|
smpCfg = smpDefaultConfig,
|
|
reconnectInterval =
|
|
RetryInterval
|
|
{ initialInterval = 1_000_000,
|
|
increaseAfter = 10_000_000,
|
|
maxInterval = 10_000_000
|
|
},
|
|
-- CA certificate private key is not needed for initialization
|
|
-- ! we do not generate these
|
|
caCertificateFile = "/etc/opt/simplex-agent/ca.crt",
|
|
privateKeyFile = "/etc/opt/simplex-agent/agent.key",
|
|
certificateFile = "/etc/opt/simplex-agent/agent.crt"
|
|
}
|
|
|
|
data Env = Env
|
|
{ config :: AgentConfig,
|
|
store :: SQLiteStore,
|
|
idsDrg :: TVar ChaChaDRG,
|
|
clientCounter :: TVar Int,
|
|
randomServer :: TVar StdGen
|
|
}
|
|
|
|
newSMPAgentEnv :: (MonadUnliftIO m, MonadRandom m) => AgentConfig -> m Env
|
|
newSMPAgentEnv cfg = do
|
|
idsDrg <- newTVarIO =<< drgNew
|
|
store <- liftIO $ createSQLiteStore (dbFile cfg) (dbPoolSize cfg) Migrations.app
|
|
clientCounter <- newTVarIO 0
|
|
randomServer <- newTVarIO =<< liftIO newStdGen
|
|
return Env {config = cfg, store, idsDrg, clientCounter, randomServer}
|