Reputation: 3235
I'm just trying to get a response from router.utorrent.com
to potentially make a DHT service down the track. For example, given a magnet link with:
xt=urn:btih:a78c852bcc0379e612e1bd794e1fd19061b84d11
the hash is:
a78c852bcc0379e612e1bd794e1fd19061b84d11
Then in the terminal I entered this:
nc -u router.utorrent.com 6881
d1:ad2:id20:a78c852bcc0379e612e1bd794e1fd19061b84d11e1:q4:ping1:t1:01:y1:qe
based on this documentation but i dont get any response. I even tried Wireshark to check if any packet at all was coming back and still nothing. Why doesn't μTorrent talk to me?
Upvotes: 4
Views: 2358
Reputation: 129775
As explained in the other answer, bencoding is a binary format, not a text format. You seem to be trying to enter the message body into netcat using a terminal. Terminals are designed for entering textual input to programs, not binary, and so you will not be able to directly enter that sequence into netcat's stdin.
The ID in your ping request should not be the torrent's infohash. It should be a unique ID to identify your client to the DHT network. For testing, you really could just pick an ID made up entirely of 20 ASCII characters, and avoid these encoding issues, but in practice you'll want to use uniformly random binary IDs.
If you want to a binary ID in a terminal, you shouldn't try inputting it directly into netcat. Instead you can use your shell's echo
command and hex encoding to produce the data in the intended format, and pipe that into netcat. For example, in bash:
echo -n $'d1:ad2:id20:\x23\x71\x0c\x1c\xb4\x50\x7d\x87\x29\xb8\x3f\x87\x2c\xc6\xa2\xa4\x4c\x39\x73\x67e1:q4:ping1:t1:01:y1:qe' | nc -u router.utorrent.com 6881
Note that the response you get from the node will be unescaped binary, not necessarily text, so displaying it directly in your terminal as we're doing here could result in things appearing strangely or your current terminal session being messed up some way.
Upvotes: 1
Reputation: 43052
The hash should be in binary. In bencoding the number + colon is the length prefix for a string. A sha1 in hex is 40 bytes long, for it to be actually 20 bytes long it needs to be the raw output of the hash function.
You basically need to conver the hex string to binary (40 hex -> 20 binary) for it to work.
Upvotes: 3