decrease initial delay for HELLO retries on online activation (#174)

* decrease initial delay for HELLO retries on online activation

* move retry interval to config

Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
This commit is contained in:
Efim Poberezkin
2021-08-01 22:51:40 +10:00
committed by GitHub
parent 30c36b488a
commit 8a4bced569
5 changed files with 45 additions and 47 deletions

View File

@@ -270,33 +270,15 @@ newConn c connId viaInv connLevel = do
addSubscription c rq connId'
pure (connId', qInfo)
minute :: Int
minute = 60_000_000
onlineInterval :: RetryInterval
onlineInterval =
RetryInterval
{ initialInterval = 1_000_000,
increaseAfter = minute,
maxInterval = 10 * minute
}
resumeInterval :: RetryInterval
resumeInterval =
RetryInterval
{ initialInterval = 5_000_000,
increaseAfter = 0,
maxInterval = 10 * minute
}
joinConn :: AgentMonad m => AgentClient -> ConnId -> SMPQueueInfo -> ConnInfo -> Maybe InvitationId -> Int -> m ConnId
joinConn c connId qInfo cInfo viaInv connLevel = do
(sq, senderKey, verifyKey) <- newSndQueue qInfo
g <- asks idsDrg
cfg <- asks config
let cData = ConnData {connId, viaInv, connLevel}
connId' <- withStore $ \st -> createSndConn st g cData sq
confirmQueue c sq senderKey cInfo
activateQueueJoining c connId' sq verifyKey onlineInterval
activateQueueJoining c connId' sq verifyKey $ retryInterval cfg
pure connId'
activateQueueJoining :: forall m. AgentMonad m => AgentClient -> ConnId -> SndQueue -> VerificationKey -> RetryInterval -> m ()
@@ -370,7 +352,7 @@ subscribeConnection' c connId =
_ -> throwError $ INTERNAL "unexpected queue status"
SomeConn _ (SndConnection _ sq) -> case status (sq :: SndQueue) of
Confirmed -> withVerifyKey sq $ \verifyKey ->
activateQueueJoining c connId sq verifyKey resumeInterval
activateQueueJoining c connId sq verifyKey =<< resumeInterval
Active -> throwError $ CONN SIMPLEX
_ -> throwError $ INTERNAL "unexpected queue status"
SomeConn _ (RcvConnection _ rq) -> subscribeQueue c rq connId
@@ -381,8 +363,12 @@ subscribeConnection' c connId =
in maybe err action . C.publicKey $ signKey sq
activateSecuredQueue :: RcvQueue -> SndQueue -> C.PublicKey -> m ()
activateSecuredQueue rq sq verifyKey = do
activateQueueInitiating c connId sq verifyKey resumeInterval
activateQueueInitiating c connId sq verifyKey =<< resumeInterval
subscribeQueue c rq connId
resumeInterval :: m RetryInterval
resumeInterval = do
r <- asks $ retryInterval . config
pure r {initialInterval = 5_000_000}
-- | Send message to the connection (SEND command) in Reader monad
sendMessage' :: forall m. AgentMonad m => AgentClient -> ConnId -> MsgBody -> m InternalId
@@ -540,7 +526,8 @@ processSMPTransmission c@AgentClient {subQ} (srv, rId, cmd) = do
withStore $ \st -> upgradeRcvConnToDuplex st connId sq
confirmQueue c sq senderKey ownConnInfo
withStore (`removeConfirmations` connId)
activateQueueInitiating c connId sq verifyKey onlineInterval
cfg <- asks config
activateQueueInitiating c connId sq verifyKey $ retryInterval cfg
_ -> prohibited
introMsg :: IntroId -> ConnInfo -> m ()

View File

@@ -254,12 +254,6 @@ sendConfirmation c sq@SndQueue {server, sndId} senderKey cInfo =
mkConfirmation :: SMPClient -> m MsgBody
mkConfirmation smp = encryptAndSign smp sq . serializeSMPMessage $ SMPConfirmation senderKey cInfo
data RetryInterval = RetryInterval
{ initialInterval :: Int,
increaseAfter :: Int,
maxInterval :: Int
}
sendHello :: forall m. AgentMonad m => AgentClient -> SndQueue -> VerificationKey -> RetryInterval -> m ()
sendHello c sq@SndQueue {server, sndId, sndPrivateKey} verifyKey RetryInterval {initialInterval, increaseAfter, maxInterval} =
withLogSMP_ c server sndId "SEND <HELLO> (retrying)" $ \smp -> do

View File

@@ -1,6 +1,7 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NumericUnderscores #-}
{-# OPTIONS_GHC -fno-warn-unticked-promoted-constructors #-}
module Simplex.Messaging.Agent.Env.SQLite where
@@ -25,9 +26,38 @@ data AgentConfig = AgentConfig
tbqSize :: Natural,
dbFile :: FilePath,
dbPoolSize :: Int,
smpCfg :: SMPClientConfig
smpCfg :: SMPClientConfig,
retryInterval :: RetryInterval
}
minute :: Int
minute = 60_000_000
data RetryInterval = RetryInterval
{ initialInterval :: Int,
increaseAfter :: Int,
maxInterval :: Int
}
defaultAgentConfig :: AgentConfig
defaultAgentConfig =
AgentConfig
{ tcpPort = "5224",
smpServers = undefined,
rsaKeySize = 2048 `div` 8,
connIdBytes = 12,
tbqSize = 16,
dbFile = "smp-agent.db",
dbPoolSize = 4,
smpCfg = smpDefaultConfig,
retryInterval =
RetryInterval
{ initialInterval = 1_000_000,
increaseAfter = minute,
maxInterval = 10 * minute
}
}
data Env = Env
{ config :: AgentConfig,
store :: SQLiteStore,