From f181cf8e04432cca5b3abdd622aa790a843a756c Mon Sep 17 00:00:00 2001 From: sh Date: Mon, 4 May 2026 12:27:40 +0000 Subject: [PATCH 1/2] 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. --- src/Simplex/Messaging/Agent.hs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Simplex/Messaging/Agent.hs b/src/Simplex/Messaging/Agent.hs index c466795bf..3a6ae8609 100644 --- a/src/Simplex/Messaging/Agent.hs +++ b/src/Simplex/Messaging/Agent.hs @@ -59,6 +59,7 @@ module Simplex.Messaging.Agent deleteConnectionAsync, deleteConnectionsAsync, createConnection, + createConnectionOnServer, prepareConnectionLink, createConnectionForLink, setConnShortLink, @@ -398,9 +399,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, Maybe ClientServiceId)) -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, Maybe ClientServiceId)) +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. @@ -914,9 +922,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, Maybe ClientServiceId)) -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, Maybe ClientServiceId)) +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,) From 3439505d9fa167ecd88e8c4324b13a5c544c151d Mon Sep 17 00:00:00 2001 From: Evgeny Date: Tue, 5 May 2026 09:23:13 +0100 Subject: [PATCH 2/2] simpler --- src/Simplex/Messaging/Agent.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Simplex/Messaging/Agent.hs b/src/Simplex/Messaging/Agent.hs index 3a6ae8609..909176eca 100644 --- a/src/Simplex/Messaging/Agent.hs +++ b/src/Simplex/Messaging/Agent.hs @@ -404,9 +404,9 @@ createConnection c nm userId enableNtfs checkNotices cMode linkData_ clientData {-# 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, Maybe ClientServiceId)) -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 +createConnectionOnServer :: ConnectionModeI c => AgentClient -> NetworkRequestMode -> UserId -> Bool -> Bool -> SConnectionMode c -> Maybe (UserConnLinkData c) -> Maybe CRClientData -> Maybe SMPServerWithAuth -> CR.InitialKeys -> SubscriptionMode -> AE (ConnId, (CreatedConnLink c, Maybe ClientServiceId)) +createConnectionOnServer c nm userId enableNtfs checkNotices cMode linkData_ clientData srv_ pqInitKeys subMode = + withAgentEnv c $ newConn c nm userId enableNtfs checkNotices cMode linkData_ clientData srv_ pqInitKeys subMode {-# INLINE createConnectionOnServer #-} -- | Prepare connection link for contact mode (no network call).