Updates client streaming to use new piece validator interface

This commit is contained in:
Marcin Czenko 2025-03-20 02:48:52 +01:00
parent 9903473809
commit 1d47cf4870
No known key found for this signature in database
GPG Key ID: 33DEA0C8E30937C0

View File

@ -196,23 +196,18 @@ proc retrieveInfoHash(
let stream =
await node.streamTorrent(torrentManifest, codexManifest, torrentPieceValidator)
let pieceIter = torrentPieceValidator.getNewPieceIterator()
while not stream.atEof:
trace "Waiting for piece..."
let pieceIndex = await torrentPieceValidator.waitForNextPiece()
var pieceIndex = 0
while not pieceIter.finished and not stream.atEof:
trace "Waiting for piece", pieceIndex
if not (await torrentPieceValidator.waitForNextPiece()):
warn "No more torrent pieces expected. TorrentPieceValidator out of sync"
if -1 == pieceIndex:
warn "No more torrent pieces expected. TorrentPieceValidator might be out of sync!"
break
trace "Got piece", pieceIndex
inc pieceIndex
let blocksPerPieceIter = torrentPieceValidator.getNewBlocksPerPieceIterator()
while not stream.atEof:
if blocksPerPieceIter.finished:
break
while not blocksPerPieceIter.finished and not stream.atEof:
var buff = newSeqUninitialized[byte](BitTorrentBlockSize.int)
# wait for the next the piece to prefetch
let len = await stream.readOnce(addr buff[0], buff.len)