agent: add createConnectionOnServer

New createConnectionOnServer wrapper takes an SMPServerWithAuth and
uses it for the new queue instead of getSMPServer. createConnection
keeps its existing signature and now calls newConn with Nothing.
This commit is contained in:
sh
2026-05-04 12:27:40 +00:00
parent 61ee188ee0
commit add96a5b34
+12 -4
View File
@@ -60,6 +60,7 @@ module Simplex.Messaging.Agent
deleteConnectionAsync,
deleteConnectionsAsync,
createConnection,
createConnectionOnServer,
prepareConnectionLink,
createConnectionForLink,
setConnShortLink,
@@ -409,9 +410,16 @@ deleteConnectionsAsync c waitDelivery = withAgentEnv c . deleteConnectionsAsync'
-- | Create SMP agent connection (NEW command)
createConnection :: ConnectionModeI c => AgentClient -> NetworkRequestMode -> UserId -> Bool -> Bool -> SConnectionMode c -> Maybe (UserConnLinkData c) -> Maybe CRClientData -> CR.InitialKeys -> SubscriptionMode -> AE (ConnId, CreatedConnLink c)
createConnection c nm userId enableNtfs checkNotices = withAgentEnv c .::. newConn c nm userId enableNtfs checkNotices
createConnection c nm userId enableNtfs checkNotices cMode linkData_ clientData pqInitKeys subMode =
withAgentEnv c $ newConn c nm userId enableNtfs checkNotices cMode linkData_ clientData Nothing pqInitKeys subMode
{-# INLINE createConnection #-}
-- | Create SMP agent connection on a specific SMP server.
createConnectionOnServer :: ConnectionModeI c => AgentClient -> NetworkRequestMode -> UserId -> Bool -> Bool -> SConnectionMode c -> Maybe (UserConnLinkData c) -> Maybe CRClientData -> SMPServerWithAuth -> CR.InitialKeys -> SubscriptionMode -> AE (ConnId, CreatedConnLink c)
createConnectionOnServer c nm userId enableNtfs checkNotices cMode linkData_ clientData srv pqInitKeys subMode =
withAgentEnv c $ newConn c nm userId enableNtfs checkNotices cMode linkData_ clientData (Just srv) pqInitKeys subMode
{-# INLINE createConnectionOnServer #-}
-- | Prepare connection link for contact mode (no network call).
-- Caller provides root signing key pair and link entity ID.
-- Returns the created link and internal params.
@@ -954,9 +962,9 @@ switchConnectionAsync' c corrId connId =
connectionStats c $ DuplexConnection cData rqs' sqs
_ -> throwE $ CMD PROHIBITED "switchConnectionAsync: not duplex"
newConn :: ConnectionModeI c => AgentClient -> NetworkRequestMode -> UserId -> Bool -> Bool -> SConnectionMode c -> Maybe (UserConnLinkData c) -> Maybe CRClientData -> CR.InitialKeys -> SubscriptionMode -> AM (ConnId, CreatedConnLink c)
newConn c nm userId enableNtfs checkNotices cMode linkData_ clientData pqInitKeys subMode = do
srv <- getSMPServer c userId
newConn :: ConnectionModeI c => AgentClient -> NetworkRequestMode -> UserId -> Bool -> Bool -> SConnectionMode c -> Maybe (UserConnLinkData c) -> Maybe CRClientData -> Maybe SMPServerWithAuth -> CR.InitialKeys -> SubscriptionMode -> AM (ConnId, CreatedConnLink c)
newConn c nm userId enableNtfs checkNotices cMode linkData_ clientData srv_ pqInitKeys subMode = do
srv <- maybe (getSMPServer c userId) pure srv_
when (checkNotices && connMode cMode == CMContact) $ checkClientNotices c srv
connId <- newConnNoQueues c userId enableNtfs cMode (CR.connPQEncryption pqInitKeys)
(connId,)