From 6f62d7ff05b9d25bca4f822c04ee83a102c34e42 Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Thu, 15 Feb 2024 13:24:46 +0400 Subject: [PATCH] agent: add numRecipients parameter to send description (#993) --- src/Simplex/FileTransfer/Agent.hs | 6 +++--- src/Simplex/Messaging/Agent.hs | 4 ++-- tests/XFTPAgent.hs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Simplex/FileTransfer/Agent.hs b/src/Simplex/FileTransfer/Agent.hs index 18f39de42..3bed1ce21 100644 --- a/src/Simplex/FileTransfer/Agent.hs +++ b/src/Simplex/FileTransfer/Agent.hs @@ -311,8 +311,8 @@ xftpSendFile' c userId file numRecipients = do void $ getXFTPSndWorker True c Nothing pure fId -xftpSendDescription' :: forall m. AgentMonad m => AgentClient -> UserId -> ValidFileDescription 'FRecipient -> m SndFileId -xftpSendDescription' c userId (ValidFileDescription fdDirect@FileDescription {size, digest}) = do +xftpSendDescription' :: forall m. AgentMonad m => AgentClient -> UserId -> ValidFileDescription 'FRecipient -> Int -> m SndFileId +xftpSendDescription' c userId (ValidFileDescription fdDirect@FileDescription {size, digest}) numRecipients = do g <- asks random prefixPath <- getPrefixPath "snd.xftp" createDirectory prefixPath @@ -323,7 +323,7 @@ xftpSendDescription' c userId (ValidFileDescription fdDirect@FileDescription {si liftError (INTERNAL . show) $ CF.writeFile file (LB.fromStrict $ strEncode fdDirect) key <- atomically $ C.randomSbKey g nonce <- atomically $ C.randomCbNonce g - fId <- withStore c $ \db -> createSndFile db g userId file 1 relPrefixPath key nonce $ Just RedirectFileInfo {size, digest} + fId <- withStore c $ \db -> createSndFile db g userId file numRecipients relPrefixPath key nonce $ Just RedirectFileInfo {size, digest} void $ getXFTPSndWorker True c Nothing pure fId diff --git a/src/Simplex/Messaging/Agent.hs b/src/Simplex/Messaging/Agent.hs index 911358992..da309d545 100644 --- a/src/Simplex/Messaging/Agent.hs +++ b/src/Simplex/Messaging/Agent.hs @@ -403,8 +403,8 @@ xftpSendFile :: AgentErrorMonad m => AgentClient -> UserId -> CryptoFile -> Int xftpSendFile c = withAgentEnv c .:. xftpSendFile' c -- | Send XFTP file -xftpSendDescription :: AgentErrorMonad m => AgentClient -> UserId -> ValidFileDescription 'FRecipient -> m SndFileId -xftpSendDescription c = withAgentEnv c .: xftpSendDescription' c +xftpSendDescription :: AgentErrorMonad m => AgentClient -> UserId -> ValidFileDescription 'FRecipient -> Int -> m SndFileId +xftpSendDescription c = withAgentEnv c .:. xftpSendDescription' c -- | Delete XFTP snd file internally (deletes work files from file system and db records) xftpDeleteSndFileInternal :: AgentErrorMonad m => AgentClient -> SndFileId -> m () diff --git a/tests/XFTPAgent.hs b/tests/XFTPAgent.hs index 69f067731..6ac64a4c1 100644 --- a/tests/XFTPAgent.hs +++ b/tests/XFTPAgent.hs @@ -158,7 +158,7 @@ testXFTPAgentSendReceiveRedirect = withXFTPServer $ do sfGet sndr >>= \case (_, _, SFDONE _snd (vfd : _)) -> pure vfd r -> error $ "Expected SFDONE, got " <> show r - redirectFileId <- runRight $ xftpSendDescription sndr 1 vfdDirect + redirectFileId <- runRight $ xftpSendDescription sndr 1 vfdDirect 1 logInfo $ "File sent, sending redirect: " <> tshow redirectFileId sfGet sndr `shouldReturn` ("", redirectFileId, SFPROG 65536 65536) vfdRedirect@(ValidFileDescription fdRedirect) <-