Test runner is giving error-msg "provided invalid infohash" and timeout on download

Hi, it seems like the test runner is running against a file: “/tmp/torrents925035392/codercat.gif.torrent” I’ve decoded the file and encoded the info dictionary and Sha1 hashed which results in hash:

c77829d2a77d6516f88cd7a3de1a26abcbfab0db

And i’m getting: {“failure reason”:“provided invalid infohash”}

My info-hash is passing all the tests; and it seems to only be a problem with this torrent file? Furthermore when the test runner decides to run a test against another torrent; my client correctly downloads all the pieces, but it errors on a timeout. I’ve tried to multi-thread the download of piece-blocks, but to no avail.

My code is here: GitHub - Matt2843/codecrafters-bittorrent-zig

i’ve base64 encoded the file “codercat.gif.torrent” and printed it to stdout; such that i could get a copy of it locally. now i’ve uploaded it to https://torrent-metadata.vercel.app/ which reports the same info-hash as my program:
c77829d2a77d6516f88cd7a3de1a26abcbfab0db

Here’s the URL i’m sending a GET request to:

http://bittorrent-test-tracker.codecrafters.io/announce?info_hash=%C7x)%D2%A7%7De%16%F8%8C%D7%A3%DE%1A&%AB%CB%FA%B0%DB&peer_id=-mab-ztorrent-001224&port=6881&uploaded=0&downloaded=0&left=2994120&compact=1

Regarding the download timeout here’s the debug info:

remote: [your_program] discovering peers @ 70edcac2611a8829ebf467a6849f5d8408d9d8f4
remote: [your_program] http://bittorrent-test-tracker.codecrafters.io/announce?info_hash=p%ED%CA%C2a%1A%88)%EB%F4g%A6%84%9F%5D%84%08%D9%D8%F4&peer_id=-mab-ztorrent-001224&port=6881&uploaded=0&downloaded=0&left=2549700&compact=1
remote: [your_program] download block index=0 begin=0 len=16384
remote: [your_program] download block index=0 begin=32768 len=16384
remote: [your_program] download block index=0 begin=16384 len=16384
remote: [your_program] download block index=0 begin=81920 len=16384
remote: [your_program] download block index=0 begin=65536 len=16384
remote: [your_program] download block index=0 begin=49152 len=16384

... truncated

remote: [your_program] download block index=9 begin=114688 len=16384
remote: [your_program] download block index=9 begin=98304 len=16384
remote: [your_program] download block index=9 begin=131072 len=16384
remote: [your_program] download block index=9 begin=147456 len=16384
remote: [your_program] download block index=9 begin=163840 len=16384
remote: [your_program] download block index=9 begin=180224 len=10180
remote: [tester::#JV8] execution timed out
remote: [tester::#JV8] Test failed

Hi Matt2843,
The info hash tester is expecting is indeed c77829d2a77d6516f88cd7a3de1a26abcbfab0db

You can find the torrent files here:

You can open them with a torrent program like qBittorrent to validate the info hash (although we’re in agreement on the correct value)

The correct URL we’re expecting to request peers is this:
http://bittorrent-test-tracker.codecrafters.io/announce?compact=1&downloaded=0&info_hash=%C7x%29%D2%A7%7De%16%F8%8C%D7%A3%DE%1A%26%AB%CB%FA%B0%DB&left=2994120&peer_id=%1E%83FP%81%96%24+N%C2%96%F7%B6ep%D9f%97A%88&port=6881&uploaded=0

If you look carefully, parts of your info hash in the URL you provided seem to be incorrect:
http://bittorrent-test-tracker.codecrafters.io/announce?info_hash=%C7x)%D2%A7%7De%16%F8%8C%D7%A3%DE%1A&%AB%CB%FA%B0%DB&peer_id=-mab-ztorrent-001224&port=6881&uploaded=0&downloaded=0&left=2994120&compact=1

Hope this helps, let me know if you have other questions

1 Like

Thanks! My only other question was the 2nd comment in this thread, I don’t understand the test-runner timeout constraint. I’ve tried to multithread my client etc. but to no avail; is it something on my end that should be optimzed?

I digged a little bit into this (as I didn’t write the percent-encoding myself, it came from zig’s std’s Uri). Which implements RFC3986 (RFC 3986: Uniform Resource Identifier (URI): Generic Syntax)

Following the query-grammar of that RFC the byte=0x29 ascii ) does not need to be percent-encoded nor does & which are the two characters that differ in the query-string. The grammar rules are here:

query          = *( pchar / "/" / "?" )
pchar          = unreserved / pct-encoded / sub-delims / ":" / "@"
sub-delims     = "!" / "$" / "&" / "'" / "(" / ")"
                       / "*" / "+" / "," / ";" / "="

So it seems like the agent’s web-server is non-compiant?

I guess when used in a key-value pair query-string we want to encode the values, so we can interpret & as the separator. :slight_smile: i’ll just do it manually, the std.Uri in zig does not have any convenience in this regard. But I still wonder about the timeouts!