mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-10-31 05:03:05 +00:00
inline limits
This commit is contained in:
1 parent
3441adaa52
commit
80dd0d5ffd
1 file changed
+2
-8
@@ -226,20 +226,14 @@ validateFileDescription :: FileDescription p -> Either String (ValidFileDescript
|
||||
validateFileDescription fd@FileDescription {size, chunks}
|
||||
| chunkNos /= [1 .. length chunks] = Left "chunk numbers are not sequential"
|
||||
| chunksSize chunks /= unFileSize size = Left "chunks total size is different than file size"
|
||||
| any (> maxChunkReplicas) replicaCounts = Left "too many chunk replicas"
|
||||
| sum replicaCounts > maxFileReplicas = Left "too many file replicas"
|
||||
| any (> 16) replicaCounts = Left "too many chunk replicas"
|
||||
| sum replicaCounts > 4096 = Left "too many file replicas"
|
||||
| otherwise = Right $ ValidFD fd
|
||||
where
|
||||
chunkNos = map (\FileChunk {chunkNo} -> chunkNo) chunks
|
||||
chunksSize = foldl' (\(s :: Int64) FileChunk {chunkSize} -> s + fromIntegral (unFileSize chunkSize)) 0
|
||||
replicaCounts = map (\FileChunk {replicas} -> length replicas) chunks
|
||||
|
||||
maxChunkReplicas :: Int
|
||||
maxChunkReplicas = 16
|
||||
|
||||
maxFileReplicas :: Int
|
||||
maxFileReplicas = 4096
|
||||
|
||||
sharedDescriptionHash :: FileDescription p -> ByteString
|
||||
sharedDescriptionHash FileDescription {size, digest, key, nonce, chunkSize, chunks} =
|
||||
C.sha512Hash $ smpEncode (unFileSize size, unFileDigest digest, C.unSbKey key, nonce, unFileSize chunkSize) <> foldMap chunkFields chunks
|
||||
|
||||
Reference in new issue
Block a user