From f0a9306320868a754e2625b76b0d3b3989360ee5 Mon Sep 17 00:00:00 2001 From: Marcin Czenko Date: Wed, 12 Mar 2025 02:57:29 +0100 Subject: [PATCH] adds BitTorrent specific constants --- codex/codextypes.nim | 4 ++++ codex/node.nim | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/codex/codextypes.nim b/codex/codextypes.nim index 57700087..87c86b51 100644 --- a/codex/codextypes.nim +++ b/codex/codextypes.nim @@ -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 diff --git a/codex/node.nim b/codex/node.nim index a9b420bb..bd769070 100644 --- a/codex/node.nim +++ b/codex/node.nim @@ -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")