@@ -19,12 +19,13 @@ module Simplex.FileTransfer.Server.StoreLog
1919 )
2020where
2121
22+ import Control.Applicative ((<|>) )
2223import Control.Concurrent.STM
2324import Control.Monad.Except
2425import qualified Data.Attoparsec.ByteString.Char8 as A
2526import qualified Data.ByteString.Char8 as B
2627import qualified Data.ByteString.Lazy.Char8 as LB
27- import Data.Composition ((.:) , (.:. ) )
28+ import Data.Composition ((.:) , (.:: ) )
2829import Data.List.NonEmpty (NonEmpty )
2930import qualified Data.List.NonEmpty as L
3031import Data.Map.Strict (Map )
@@ -33,13 +34,13 @@ import Simplex.FileTransfer.Protocol (FileInfo (..))
3334import Simplex.FileTransfer.Server.Store
3435import Simplex.Messaging.Encoding.String
3536import Simplex.Messaging.Protocol (BlockingInfo , RcvPublicAuthKey , RecipientId , SenderId )
36- import Simplex.Messaging.Server.QueueStore (RoundedSystemTime )
37+ import Simplex.Messaging.Server.QueueStore (RoundedSystemTime , ServerEntityStatus ( .. ) )
3738import Simplex.Messaging.Server.StoreLog
3839import Simplex.Messaging.Util (bshow )
3940import System.IO
4041
4142data FileStoreLogRecord
42- = AddFile SenderId FileInfo RoundedSystemTime
43+ = AddFile SenderId FileInfo RoundedSystemTime ServerEntityStatus
4344 | PutFile SenderId FilePath
4445 | AddRecipients SenderId (NonEmpty FileRecipient )
4546 | DeleteFile SenderId
@@ -49,15 +50,15 @@ data FileStoreLogRecord
4950
5051instance StrEncoding FileStoreLogRecord where
5152 strEncode = \ case
52- AddFile sId file createdAt -> strEncode (Str " FNEW" , sId, file, createdAt)
53+ AddFile sId file createdAt status -> strEncode (Str " FNEW" , sId, file, createdAt, status )
5354 PutFile sId path -> strEncode (Str " FPUT" , sId, path)
5455 AddRecipients sId rcps -> strEncode (Str " FADD" , sId, rcps)
5556 DeleteFile sId -> strEncode (Str " FDEL" , sId)
5657 BlockFile sId info -> strEncode (Str " FBLK" , sId, info)
5758 AckFile rId -> strEncode (Str " FACK" , rId)
5859 strP =
5960 A. choice
60- [ " FNEW " *> (AddFile <$> strP_ <*> strP_ <*> strP),
61+ [ " FNEW " *> (AddFile <$> strP_ <*> strP_ <*> strP <*> (_strP <|> pure EntityActive ) ),
6162 " FPUT " *> (PutFile <$> strP_ <*> strP),
6263 " FADD " *> (AddRecipients <$> strP_ <*> strP),
6364 " FDEL " *> (DeleteFile <$> strP),
@@ -68,8 +69,8 @@ instance StrEncoding FileStoreLogRecord where
6869logFileStoreRecord :: StoreLog 'WriteMode -> FileStoreLogRecord -> IO ()
6970logFileStoreRecord = writeStoreLogRecord
7071
71- logAddFile :: StoreLog 'WriteMode -> SenderId -> FileInfo -> RoundedSystemTime -> IO ()
72- logAddFile s = logFileStoreRecord s .:. AddFile
72+ logAddFile :: StoreLog 'WriteMode -> SenderId -> FileInfo -> RoundedSystemTime -> ServerEntityStatus -> IO ()
73+ logAddFile s = logFileStoreRecord s .:: AddFile
7374
7475logPutFile :: StoreLog 'WriteMode -> SenderId -> FilePath -> IO ()
7576logPutFile s = logFileStoreRecord s .: PutFile
@@ -99,7 +100,7 @@ readFileStore f st = mapM_ (addFileLogRecord . LB.toStrict) . LB.lines =<< LB.re
99100 Left e -> B. putStrLn $ " Log processing error (" <> bshow e <> " ): " <> B. take 100 s
100101 _ -> pure ()
101102 addToStore = \ case
102- AddFile sId file createdAt -> addFile st sId file createdAt
103+ AddFile sId file createdAt status -> addFile st sId file createdAt status
103104 PutFile qId path -> setFilePath st qId path
104105 AddRecipients sId rcps -> runExceptT $ addRecipients sId rcps
105106 DeleteFile sId -> deleteFile st sId
@@ -113,8 +114,9 @@ writeFileStore s FileStore {files, recipients} = do
113114 readTVarIO files >>= mapM_ (logFile allRcps)
114115 where
115116 logFile :: Map RecipientId (SenderId , RcvPublicAuthKey ) -> FileRec -> IO ()
116- logFile allRcps FileRec {senderId, fileInfo, filePath, recipientIds, createdAt} = do
117- logAddFile s senderId fileInfo createdAt
117+ logFile allRcps FileRec {senderId, fileInfo, filePath, recipientIds, createdAt, fileStatus} = do
118+ status <- readTVarIO fileStatus
119+ logAddFile s senderId fileInfo createdAt status
118120 (rcpErrs, rcps) <- M. mapEither getRcp . M. fromSet id <$> readTVarIO recipientIds
119121 mapM_ (logAddRecipients s senderId) $ L. nonEmpty $ M. elems rcps
120122 mapM_ (B. putStrLn . (" Error storing log: " <> )) rcpErrs
0 commit comments