@@ -19,11 +19,7 @@ module Simplex.FileTransfer.Client.Main
1919 singleChunkSize ,
2020 prepareChunkSizes ,
2121 prepareChunkSpecs ,
22- maxFileSize ,
23- maxFileSizeHard ,
24- fileSizeLen ,
2522 getChunkDigest ,
26- SentRecipientReplica (.. ),
2723 )
2824where
2925
@@ -34,7 +30,6 @@ import Control.Monad.Trans.Except
3430import Crypto.Random (ChaChaDRG )
3531import qualified Data.Attoparsec.ByteString.Char8 as A
3632import Data.Bifunctor (first )
37- import Data.ByteString.Char8 (ByteString )
3833import qualified Data.ByteString.Char8 as B
3934import qualified Data.ByteString.Lazy.Char8 as LB
4035import Data.Char (toLower )
@@ -45,7 +40,7 @@ import Data.List.NonEmpty (NonEmpty (..), nonEmpty)
4540import qualified Data.List.NonEmpty as L
4641import Data.Map.Strict (Map )
4742import qualified Data.Map.Strict as M
48- import Data.Maybe (fromMaybe , listToMaybe )
43+ import Data.Maybe (fromMaybe )
4944import qualified Data.Text as T
5045import Data.Word (Word32 )
5146import GHC.Records (HasField (getField ))
@@ -80,20 +75,6 @@ import UnliftIO.Directory
8075xftpClientVersion :: String
8176xftpClientVersion = " 1.0.1"
8277
83- -- | Soft limit for XFTP clients. Should be checked and reported to user.
84- maxFileSize :: Int64
85- maxFileSize = gb 1
86-
87- maxFileSizeStr :: String
88- maxFileSizeStr = B. unpack . strEncode $ FileSize maxFileSize
89-
90- -- | Hard internal limit for XFTP agent after which it refuses to prepare chunks.
91- maxFileSizeHard :: Int64
92- maxFileSizeHard = gb 5
93-
94- fileSizeLen :: Int64
95- fileSizeLen = 8
96-
9778newtype CLIError = CLIError String
9879 deriving (Eq , Show , Exception )
9980
@@ -231,16 +212,6 @@ data SentFileChunkReplica = SentFileChunkReplica
231212 }
232213 deriving (Show )
233214
234- data SentRecipientReplica = SentRecipientReplica
235- { chunkNo :: Int ,
236- server :: XFTPServer ,
237- rcvNo :: Int ,
238- replicaId :: ChunkReplicaId ,
239- replicaKey :: C. APrivateAuthKey ,
240- digest :: FileDigest ,
241- chunkSize :: FileSize Word32
242- }
243-
244215logCfg :: LogConfig
245216logCfg = LogConfig {lc_file = Nothing , lc_stderr = True }
246217
@@ -414,13 +385,6 @@ cliSendFileOpts SendOptions {filePath, outputDir, numRecipients, xftpServers, re
414385 B. writeFile fdSndPath $ strEncode fdSnd
415386 pure (fdRcvPaths, fdSndPath)
416387
417- getChunkDigest :: XFTPChunkSpec -> IO ByteString
418- getChunkDigest XFTPChunkSpec {filePath = chunkPath, chunkOffset, chunkSize} =
419- withFile chunkPath ReadMode $ \ h -> do
420- hSeek h AbsoluteSeek $ fromIntegral chunkOffset
421- chunk <- LB. hGet h (fromIntegral chunkSize)
422- pure $! LC. sha256Hash chunk
423-
424388cliReceiveFile :: ReceiveOptions -> ExceptT CLIError IO ()
425389cliReceiveFile ReceiveOptions {fileDescription, filePath, retryCount, tempPath, verbose, yes} =
426390 getFileDescription' fileDescription >>= receive
@@ -536,37 +500,6 @@ getFileDescription' path =
536500 getFileDescription path >>= \ case
537501 AVFD fd -> either (throwE . CLIError ) pure $ checkParty fd
538502
539- singleChunkSize :: Int64 -> Maybe Word32
540- singleChunkSize size' =
541- listToMaybe $ dropWhile (< chunkSize) serverChunkSizes
542- where
543- chunkSize = fromIntegral size'
544-
545- prepareChunkSizes :: Int64 -> [Word32 ]
546- prepareChunkSizes size' = prepareSizes size'
547- where
548- (smallSize, bigSize)
549- | size' > size34 chunkSize3 = (chunkSize2, chunkSize3)
550- | size' > size34 chunkSize2 = (chunkSize1, chunkSize2)
551- | otherwise = (chunkSize0, chunkSize1)
552- size34 sz = (fromIntegral sz * 3 ) `div` 4
553- prepareSizes 0 = []
554- prepareSizes size
555- | size >= fromIntegral bigSize = replicate (fromIntegral n1) bigSize <> prepareSizes remSz
556- | size > size34 bigSize = [bigSize]
557- | otherwise = replicate (fromIntegral n2') smallSize
558- where
559- (n1, remSz) = size `divMod` fromIntegral bigSize
560- n2' = let (n2, remSz2) = (size `divMod` fromIntegral smallSize) in if remSz2 == 0 then n2 else n2 + 1
561-
562- prepareChunkSpecs :: FilePath -> [Word32 ] -> [XFTPChunkSpec ]
563- prepareChunkSpecs filePath chunkSizes = reverse . snd $ foldl' addSpec (0 , [] ) chunkSizes
564- where
565- addSpec :: (Int64 , [XFTPChunkSpec ]) -> Word32 -> (Int64 , [XFTPChunkSpec ])
566- addSpec (chunkOffset, specs) sz =
567- let spec = XFTPChunkSpec {filePath, chunkOffset, chunkSize = sz}
568- in (chunkOffset + fromIntegral sz, spec : specs)
569-
570503getEncPath :: MonadIO m => Maybe FilePath -> String -> m FilePath
571504getEncPath path name = (`uniqueCombine` (name <> " .encrypted" )) =<< maybe (liftIO getCanonicalTemporaryDirectory) pure path
572505
0 commit comments