In JV#8 - Download the whole file, I can download the pieces, but their hashes never match the ones in the metafile. I’ve already passed the previous stage, ND2 - Download a piece, and whenever I run the tests for that stage, the piece hash always matches the metafile. So I don’t think my logic is wrong, but when I run the tests for JV#8, the piece hashes never match the ones in the metafile.
Is anyone else experiencing the same issue, or does anyone have suggestions on how to pass this stage?
My code is here, and the test log is below.
❯ codecrafters test --previous
Initiating test run...
⚡ This is a turbo test run. https://codecrafters.io/turbo
Running tests on your code. Logs should appear shortly...
[compile] Compiling codecrafters-bittorrent v0.1.0 (/app)
[compile] Finished `release` profile [optimized] target(s) in 6.24s
[compile] Moved ./.codecrafters/run.sh → ./your_program.sh
[compile] Compilation successful.
[tester::#NS2] Running tests for Stage #NS2 (Decode bencoded strings)
[tester::#NS2] Running ./your_program.sh decode 5:mango
[your_program] "mango"
[tester::#NS2] Running ./your_program.sh decode 55:http://bittorrent-test-tracker.codecrafters.io/announce
[your_program] "http://bittorrent-test-tracker.codecrafters.io/announce"
[tester::#NS2] Test passed.
[tester::#EB4] Running tests for Stage #EB4 (Decode bencoded integers)
[tester::#EB4] Running ./your_program.sh decode i1519629117e
[your_program] 1519629117
[tester::#EB4] Running ./your_program.sh decode i4294967300e
[your_program] 4294967300
[tester::#EB4] Running ./your_program.sh decode i-52e
[your_program] -52
[tester::#EB4] Test passed.
[tester::#AH1] Running tests for Stage #AH1 (Decode bencoded lists)
[tester::#AH1] Running ./your_program.sh decode le
[tester::#AH1] Expected output: []
[your_program] []
[tester::#AH1] Running ./your_program.sh decode l9:blueberryi241ee
[tester::#AH1] Expected output: ["blueberry",241]
[your_program] ["blueberry",241]
[tester::#AH1] Running ./your_program.sh decode lli241e9:blueberryee
[tester::#AH1] Expected output: [[241,"blueberry"]]
[your_program] [[241,"blueberry"]]
[tester::#AH1] Running ./your_program.sh decode lli4eei5ee
[tester::#AH1] Expected output: [[4],5]
[your_program] [[4],5]
[tester::#AH1] Test passed.
[tester::#MN6] Running tests for Stage #MN6 (Decode bencoded dictionaries)
[tester::#MN6] Running ./your_program.sh decode de
[tester::#MN6] Expected output: {}
[your_program] {}
[tester::#MN6] Running ./your_program.sh decode d3:foo5:apple5:helloi52ee
[tester::#MN6] Expected output: {"foo":"apple","hello":52}
[your_program] {"foo":"apple","hello":52}
[tester::#MN6] Running ./your_program.sh decode d10:inner_dictd4:key16:value14:key2i42e8:list_keyl5:item15:item2i3eeee
[tester::#MN6] Expected output: {"inner_dict":{"key1":"value1","key2":42,"list_key":["item1","item2",3]}}
[your_program] {"inner_dict":{"key1":"value1","key2":42,"list_key":["item1","item2",3]}}
[tester::#MN6] Test passed.
[tester::#OW9] Running tests for Stage #OW9 (Parse torrent file)
[tester::#OW9] Running ./your_program.sh info /tmp/torrents3625981531/itsworking.gif.torrent
[your_program] Tracker URL: http://bittorrent-test-tracker.codecrafters.io/announce
[your_program] Length: 2549700
[your_program] Info Hash: 70edcac2611a8829ebf467a6849f5d8408d9d8f4
[your_program] Piece Length: 262144
[your_program] Piece Hashes:
[your_program] 01cc17bbe60fa5a52f64bd5f5b64d99286d50aa5
[your_program] 838f703cf7f6f08d1c497ed390df78f90d5f7566
[your_program] 45bf10974b5816491e30628b78a382ca36c4e05f
[your_program] 84be4bd855b34bcedc0c6e98f66d3e7c63353d1e
[your_program] 86427ac94d6e4f21a6d0d6c8b7ffa4c393c3b131
[your_program] 7c70cd5f44d1ac5505cb855d526ceb0f5f1cd5e3
[your_program] 3796ab05af1fa874173a0a6c1298625ad47b4fe6
[your_program] 272a8ff8fc865b053d974a78681414b38077d7b1
[your_program] b07128d3a6018062bfe779db96d3a93c05fb81d4
[your_program] 7affc94f0985b985eb888a36ec92652821a21be4
[tester::#OW9] Tracker URL is correct
[tester::#OW9] Length is correct
[tester::#OW9] Test passed.
[tester::#RB2] Running tests for Stage #RB2 (Calculate info hash)
[tester::#RB2] Running ./your_program.sh info /tmp/torrents391313600/codercat.gif.torrent
[your_program] Tracker URL: http://bittorrent-test-tracker.codecrafters.io/announce
[your_program] Length: 2994120
[your_program] Info Hash: c77829d2a77d6516f88cd7a3de1a26abcbfab0db
[your_program] Piece Length: 262144
[your_program] Piece Hashes:
[your_program] 3c34309faebf01e49c0f63c90b7edcc2259b6ad0
[your_program] b8519b2ea9bb373ff567f644428156c98a1d00fc
[your_program] 9dc81366587536f48c2098a1d79692f2590fd9a6
[your_program] 033c61e717f8c0d1e55850680eb451e3543b6203
[your_program] 6f54e746ec369f65f32d45f77b1f1c37621fb965
[your_program] c656704b78107ed553bd0813f92fef780267c07b
[your_program] 7431b8683137d20ff594b1f1bf3f8835165d68fb
[your_program] 0432bd8e779608d27782b779c7738062e9b50ab5
[your_program] d6bc0409a0f3a9503857669d47fe752d4577ea00
[your_program] a86ee6abbc30cddb800a0b62d7a296111166d839
[your_program] 783f52b70f0c902d56196bd3ee7f379b5db57e3b
[your_program] 3d8db9e34db63b4ba1be27930911aa37b3f997dd
[tester::#RB2] Running ./your_program.sh info /tmp/torrents391313600/congratulations.gif.torrent
[your_program] Tracker URL: http://bittorrent-test-tracker.codecrafters.io/announce
[your_program] Length: 820892
[your_program] Info Hash: 1cad4a486798d952614c394eb15e75bec587fd08
[your_program] Piece Length: 262144
[your_program] Piece Hashes:
[your_program] 3d42a20edb1cf840cd3528d3a9e921db6338a463
[your_program] 69f885b3988a52ffb03591985402b6d5285940ab
[your_program] 76869e6c9c1f101f94f39de153e468be6a638f4f
[your_program] bded68d02de011a2b687f75b5833f46cce8e3e9c
[tester::#RB2] Running ./your_program.sh info /tmp/torrents391313600/itsworking.gif.torrent
[your_program] Tracker URL: http://bittorrent-test-tracker.codecrafters.io/announce
[your_program] Length: 2549700
[your_program] Info Hash: 70edcac2611a8829ebf467a6849f5d8408d9d8f4
[your_program] Piece Length: 262144
[your_program] Piece Hashes:
[your_program] 01cc17bbe60fa5a52f64bd5f5b64d99286d50aa5
[your_program] 838f703cf7f6f08d1c497ed390df78f90d5f7566
[your_program] 45bf10974b5816491e30628b78a382ca36c4e05f
[your_program] 84be4bd855b34bcedc0c6e98f66d3e7c63353d1e
[your_program] 86427ac94d6e4f21a6d0d6c8b7ffa4c393c3b131
[your_program] 7c70cd5f44d1ac5505cb855d526ceb0f5f1cd5e3
[your_program] 3796ab05af1fa874173a0a6c1298625ad47b4fe6
[your_program] 272a8ff8fc865b053d974a78681414b38077d7b1
[your_program] b07128d3a6018062bfe779db96d3a93c05fb81d4
[your_program] 7affc94f0985b985eb888a36ec92652821a21be4
[tester::#RB2] Test passed.
[tester::#BF7] Running tests for Stage #BF7 (Piece hashes)
[tester::#BF7] Running ./your_program.sh info /tmp/torrents2246206848/test.torrent
[your_program] Tracker URL: http://bttracker.debian.org:6969/announce
[your_program] Length: 1572864
[your_program] Info Hash: 679ba7b878576815ce4aee9200a9033c5019ec24
[your_program] Piece Length: 262144
[your_program] Piece Hashes:
[your_program] a58dc4143cb9c036c91104abbaff97e3fdd4773d
[your_program] 2827aa0fc1815126e1fccc6b66ebe7fea91d5194
[your_program] aa6dbb4345b8ff1c35c266cdc11593ac5409a483
[your_program] 9452c39dd3fbabe0545b05c9d6a59115c6b1dc4a
[your_program] ede5930280feddb121494c5767934b4cc0bc162f
[your_program] 70edcac2611a8829ebf467a6849f5d8408d9d8f4
[tester::#BF7] Test passed.
[tester::#FI9] Running tests for Stage #FI9 (Discover peers)
[tester::#FI9] Running ./your_program.sh peers /tmp/torrents2655284466/test.torrent
[your_program] 188.119.61.177:6881
[your_program] 185.107.13.235:54542
[your_program] 88.99.2.101:6881
[tester::#FI9] Test passed.
[tester::#CA4] Running tests for Stage #CA4 (Peer handshake)
[tester::#CA4] Running ./your_program.sh handshake /tmp/torrents3000333403/test.torrent 127.0.0.1:43477
[your_program] Peer ID: f1dce5cb8dec01aebf0d8f7fdafbab6dc660c88a
[tester::#CA4] Test passed.
[tester::#ND2] Running tests for Stage #ND2 (Download a piece)
[tester::#ND2] Running ./your_program.sh download_piece -o /tmp/torrents2295448719/piece-2 /tmp/torrents2295448719/congratulations.gif.torrent 2
[your_program] Found 3 peers
[your_program] Peer 1: 165.232.35.114:51494
[your_program] Peer 2: 165.232.38.164:51482
[your_program] Peer 3: 165.232.41.73:51507
[your_program] Expected hash for piece 2: 76869e6c9c1f101f94f39de153e468be6a638f4f
[your_program] Downloaded piece 2 from Peer: 165.232.35.114:51494. Length: 262144. Hash: 76869e6c9c1f101f94f39de153e468be6a638f4f
[your_program] 🎉 Piece 2 downloaded and verified.
[tester::#ND2] Running ./your_program.sh download_piece -o /tmp/torrents2295448719/piece-3 /tmp/torrents2295448719/congratulations.gif.torrent 3
[your_program] Found 3 peers
[your_program] Peer 1: 165.232.35.114:51494
[your_program] Peer 2: 165.232.38.164:51482
[your_program] Peer 3: 165.232.41.73:51507
[your_program] Expected hash for piece 3: bded68d02de011a2b687f75b5833f46cce8e3e9c
[your_program] Downloaded piece 3 from Peer: 165.232.35.114:51494. Length: 34460. Hash: bded68d02de011a2b687f75b5833f46cce8e3e9c
[your_program] 🎉 Piece 3 downloaded and verified.
[tester::#ND2] Test passed.
[tester::#JV8] Running tests for Stage #JV8 (Download the whole file)
[tester::#JV8] Running ./your_program.sh download -o /tmp/torrents515183366/congratulations.gif /tmp/torrents515183366/congratulations.gif.torrent
[your_program] Found 3 peers
[your_program] Peer 1: 165.232.35.114:51494
[your_program] Peer 2: 165.232.38.164:51482
[your_program] Peer 3: 165.232.41.73:51507
[your_program] Piece Length: 262144
[your_program] Piece hash: 3d42a20edb1cf840cd3528d3a9e921db6338a463
[your_program] Piece hash: 69f885b3988a52ffb03591985402b6d5285940ab
[your_program] Piece hash: 76869e6c9c1f101f94f39de153e468be6a638f4f
[your_program] Piece hash: bded68d02de011a2b687f75b5833f46cce8e3e9c
[your_program] Downloaded piece 1/4 from Peer: 165.232.35.114:51494. Length: 262144
[your_program] 🤔 Hash mismatch for piece 1. Expected 3d42a20edb1cf840cd3528d3a9e921db6338a463, got b406d6841fb5e75339d00e8bd5a3a46a7b04ed8f. Retrying 1/5
[your_program] Downloaded piece 2/4 from Peer: 165.232.38.164:51482. Length: 262144
[your_program] 🤔 Hash mismatch for piece 2. Expected 69f885b3988a52ffb03591985402b6d5285940ab, got 7eb2535d2568e43b6ad970929a28e929c235ba91. Retrying 1/5
[your_program] Downloaded piece 3/4 from Peer: 165.232.41.73:51507. Length: 262144
[your_program] 🤔 Hash mismatch for piece 3. Expected 76869e6c9c1f101f94f39de153e468be6a638f4f, got b7d76cf973ddbd5f00b78f304bee5e023e83e377. Retrying 1/5
[your_program] Downloaded piece 4/4 from Peer: 165.232.35.114:51494. Length: 34460
[your_program] 🤔 Hash mismatch for piece 4. Expected bded68d02de011a2b687f75b5833f46cce8e3e9c, got 75c4696e499e41097e7c0bab2963f4d745c26e69. Retrying 1/5
[your_program] Downloaded piece 1/4 from Peer: 165.232.38.164:51482. Length: 262144
[your_program] 🤔 Hash mismatch for piece 1. Expected 3d42a20edb1cf840cd3528d3a9e921db6338a463, got b406d6841fb5e75339d00e8bd5a3a46a7b04ed8f. Retrying 2/5
[your_program] Downloaded piece 2/4 from Peer: 165.232.41.73:51507. Length: 262144
[your_program] 🤔 Hash mismatch for piece 2. Expected 69f885b3988a52ffb03591985402b6d5285940ab, got 7eb2535d2568e43b6ad970929a28e929c235ba91. Retrying 2/5
[your_program] Downloaded piece 3/4 from Peer: 165.232.35.114:51494. Length: 262144
[your_program] 🤔 Hash mismatch for piece 3. Expected 76869e6c9c1f101f94f39de153e468be6a638f4f, got b7d76cf973ddbd5f00b78f304bee5e023e83e377. Retrying 2/5
[your_program] Downloaded piece 4/4 from Peer: 165.232.38.164:51482. Length: 34460
[your_program] 🤔 Hash mismatch for piece 4. Expected bded68d02de011a2b687f75b5833f46cce8e3e9c, got 75c4696e499e41097e7c0bab2963f4d745c26e69. Retrying 2/5
[your_program] Downloaded piece 1/4 from Peer: 165.232.41.73:51507. Length: 262144
[your_program] 🤔 Hash mismatch for piece 1. Expected 3d42a20edb1cf840cd3528d3a9e921db6338a463, got b406d6841fb5e75339d00e8bd5a3a46a7b04ed8f. Retrying 3/5
[your_program] Downloaded piece 2/4 from Peer: 165.232.35.114:51494. Length: 262144
[your_program] 🤔 Hash mismatch for piece 2. Expected 69f885b3988a52ffb03591985402b6d5285940ab, got 7eb2535d2568e43b6ad970929a28e929c235ba91. Retrying 3/5
[your_program] Downloaded piece 3/4 from Peer: 165.232.38.164:51482. Length: 262144
[your_program] 🤔 Hash mismatch for piece 3. Expected 76869e6c9c1f101f94f39de153e468be6a638f4f, got b7d76cf973ddbd5f00b78f304bee5e023e83e377. Retrying 3/5
[your_program] Downloaded piece 4/4 from Peer: 165.232.41.73:51507. Length: 34460
[your_program] 🤔 Hash mismatch for piece 4. Expected bded68d02de011a2b687f75b5833f46cce8e3e9c, got 75c4696e499e41097e7c0bab2963f4d745c26e69. Retrying 3/5
[tester::#JV8] timed out, test exceeded 20 seconds
[tester::#JV8] Test failed
View our article on debugging test failures: https://codecrafters.io/debug