adds BitTorrent specific constants

This commit is contained in:
Marcin Czenko 2025-03-12 02:57:29 +01:00
parent 096dff0714
commit f0a9306320
No known key found for this signature in database
GPG Key ID: 33DEA0C8E30937C0
2 changed files with 7 additions and 3 deletions

View File

@ -24,6 +24,10 @@ import ./errors
export tables
const
# BitTorrent specific
DefaultPieceLength* = NBytes 1024 * 64
BitTorrentBlockSize* = NBytes 1024 * 16
# Size of blocks for storage / network exchange,
DefaultBlockSize* = NBytes 1024 * 64
DefaultCellSize* = NBytes 2048

View File

@ -657,7 +657,7 @@ proc storePieces*(
filename: ?string = string.none,
mimetype: ?string = string.none,
blockSize: NBytes,
pieceLength = NBytes 1024 * 64,
pieceLength = DefaultPieceLength,
): Future[?!BitTorrentManifest] {.async.} =
## Save stream contents as dataset with given blockSize
## to nodes's BlockStore, and return Cid of its manifest
@ -708,7 +708,7 @@ proc storePieces*(
return failure(&"Unable to store block {blk.cid}")
pieceHashCtx.update(chunk)
let idx = pieceIter.next()
trace "stored block in piece with index=", idx
trace "stored block in piece with index", idx
if chunk.len < blockSize.int:
trace "no more block to read"
break
@ -784,7 +784,7 @@ proc storeTorrent*(
without bitTorrentManifest =?
await self.storePieces(
stream, filename = filename, mimetype = mimetype, blockSize = NBytes 1024 * 16
stream, filename = filename, mimetype = mimetype, blockSize = BitTorrentBlockSize
):
return failure("Unable to store BitTorrent data")