File hash doesn't match (#ND2)

I’m stuck on Stage #ND2 =(

I’ve tried downloading the piece, but the file hash doesn’t match the expected hash from the torrent info.

Here are my logs:

[your_program] Response received: 16397 bytes
[your_program] Socket 0, Piece 0, Offset 229376 successfully downloaded in 92ms
[your_program] Sending message. Piece index 0, Block offset: 245760, Block size: 16384
[your_program] Response received: 16397 bytes
[your_program] Socket 0, Piece 0, Offset 245760 successfully downloaded in 91ms
[your_program] Download finished. Saving to /tmp/torrents2671258469/piece-0
[your_program] Socket end
[your_program] Connection closed
[tester::#ND2] File SHA-1 does not match expected SHA-1. Expected: 3c34309faebf01e49c0f63c90b7edcc2259b6ad0 Actual: 2354d053bb7ce7f85337594b7306df07ae436ae7
[tester::#ND2] Test failed

I’ve pushed all my changes to the Git repo. Any help would be much appreciated.

I’ll take a look shortly.

1 Like

Hi @joelburger, I added a few logs like the following:

async function downloadBlock(socket, torrent, pieceIndex, blockOffset) {
  const { messageId, payload: blockPayload } = parsePeerMessageResponse(response);
  console.log('Block payload length:', blockPayload.length);
  console.log('Block payload [0:32]:', blockPayload.subarray(0, 32));

Looks like all the data are being parsed correctly:

The bug occurs when the whole blockPayload (length: 16392 = 16K + 8) is copied directly into pieceBuffer.

You will need to remove (and ideally verify) index and begin (combined length of 8 bytes), and copy only block (length: 16k):

1 Like

Thanks Andy.

I’ve managed to match the expected hashes for pieces before the last one.

The last piece from the sample.torrent file doesn’t seem to match though. The total size I have for this last piece is 22625.

Sending message. Piece index 2, Block offset: 0, Block size: 16384
Response received: 14480 bytes
Response received: 1917 bytes
Piece 2, Offset 0, Block size: 16384 successfully fetched in 609ms
Sending message. Piece index 2, Block offset: 16384, Block size: 6241
Response received: 6254 bytes
Piece 2, Offset 16384, Block size: 6241 successfully fetched in 406ms
Failed to download piece: Error: Invalid piece hash. Size: 22625, Expected: f00d937a0213df1982bc8d097227ad9e909acc17, Actual: abab7072869e6861fb035dffb90206666c015fe1

Thanks again for getting back so quickly Andy

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.