From 8d56b0ba8519bdc68a3777d8d0672fbe01957479 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Wed, 17 Jul 2024 13:01:17 +0100 Subject: [PATCH] agent: allow starting only XFTP sending workers (#1232) * agent: allow starting only XFTP sending workers * use Bool param * flip bool * update --- src/Simplex/FileTransfer/Agent.hs | 15 ++++++++++++--- src/Simplex/Messaging/Agent.hs | 7 ++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Simplex/FileTransfer/Agent.hs b/src/Simplex/FileTransfer/Agent.hs index 4683143c5..725444086 100644 --- a/src/Simplex/FileTransfer/Agent.hs +++ b/src/Simplex/FileTransfer/Agent.hs @@ -12,6 +12,7 @@ module Simplex.FileTransfer.Agent ( startXFTPWorkers, + startXFTPSndWorkers, closeXFTPAgent, toFSFilePath, -- Receiving files @@ -82,13 +83,21 @@ import UnliftIO.Directory import qualified UnliftIO.Exception as E startXFTPWorkers :: AgentClient -> Maybe FilePath -> AM () -startXFTPWorkers c workDir = do +startXFTPWorkers = startXFTPWorkers_ True +{-# INLINE startXFTPWorkers #-} + +startXFTPSndWorkers :: AgentClient -> Maybe FilePath -> AM () +startXFTPSndWorkers = startXFTPWorkers_ False +{-# INLINE startXFTPSndWorkers #-} + +startXFTPWorkers_ :: Bool -> AgentClient -> Maybe FilePath -> AM () +startXFTPWorkers_ allWorkers c workDir = do wd <- asks $ xftpWorkDir . xftpAgent atomically $ writeTVar wd workDir cfg <- asks config - startRcvFiles cfg + when allWorkers $ startRcvFiles cfg startSndFiles cfg - startDelFiles cfg + when allWorkers $ startDelFiles cfg where startRcvFiles :: AgentConfig -> AM () startRcvFiles AgentConfig {rcvFilesTTL} = do diff --git a/src/Simplex/Messaging/Agent.hs b/src/Simplex/Messaging/Agent.hs index c08e04298..94ed7f44f 100644 --- a/src/Simplex/Messaging/Agent.hs +++ b/src/Simplex/Messaging/Agent.hs @@ -92,6 +92,7 @@ module Simplex.Messaging.Agent getNtfTokenData, toggleConnectionNtfs, xftpStartWorkers, + xftpStartSndWorkers, xftpReceiveFile, xftpDeleteRcvFile, xftpDeleteRcvFiles, @@ -146,7 +147,7 @@ import Data.Time.Clock import Data.Time.Clock.System (systemToUTCTime) import Data.Traversable (mapAccumL) import Data.Word (Word16) -import Simplex.FileTransfer.Agent (closeXFTPAgent, deleteSndFileInternal, deleteSndFileRemote, deleteSndFilesInternal, deleteSndFilesRemote, startXFTPWorkers, toFSFilePath, xftpDeleteRcvFile', xftpDeleteRcvFiles', xftpReceiveFile', xftpSendDescription', xftpSendFile') +import Simplex.FileTransfer.Agent (closeXFTPAgent, deleteSndFileInternal, deleteSndFileRemote, deleteSndFilesInternal, deleteSndFilesRemote, startXFTPSndWorkers, startXFTPWorkers, toFSFilePath, xftpDeleteRcvFile', xftpDeleteRcvFiles', xftpReceiveFile', xftpSendDescription', xftpSendFile') import Simplex.FileTransfer.Description (ValidFileDescription) import Simplex.FileTransfer.Protocol (FileParty (..)) import Simplex.FileTransfer.Types (RcvFileId, SndFileId) @@ -522,6 +523,10 @@ xftpStartWorkers :: AgentClient -> Maybe FilePath -> AE () xftpStartWorkers c = withAgentEnv c . startXFTPWorkers c {-# INLINE xftpStartWorkers #-} +xftpStartSndWorkers :: AgentClient -> Maybe FilePath -> AE () +xftpStartSndWorkers c = withAgentEnv c . startXFTPSndWorkers c +{-# INLINE xftpStartSndWorkers #-} + -- | Receive XFTP file xftpReceiveFile :: AgentClient -> UserId -> ValidFileDescription 'FRecipient -> Maybe CryptoFileArgs -> Bool -> AE RcvFileId xftpReceiveFile c = withAgentEnv c .:: xftpReceiveFile' c