I read the DHT Protocol in bep_0005 page.
But when I send a ping query or a find_node query, the server response a garbled text (both of router.bittorrent.com:6881>
Map
dict = bencode.decode(result, Type.DICTIONARY);
This gives you the decoded root dictionary of the message as Map
. Within that you should find the r
dictionary as another map and with in that map the id
value. What type the id has will depend on the bedecoding library you are using.
If it is ByteBuffer
or byte[]
then you should have 20 bytes that you can hexencode (to 40 characters) if you need it to be human-readable. The DHT protocol deals in raw hashes, not hex values.
If it is a String
then you will have to convert the string back into byte[]
before hex-encoding it. That is only possible when the bdecoder used ISO 8859-1 to decode because that charset is roundtrip-safe while utf-8 is not for arbitrary byte sequences.