Search code examples
javaudpbittorrent

Getting no seeders and leechers for scrape from udp tracker


I am trying to implement the scrape method for an UDP tracker but I keep getting 0 seeders/leechers as response. I am still getting a 2 as the action so no error is reported. I have hardcoded a hash here just to show that it has no effect on the result I am getting.

    final ByteArrayOutputStream byteStream =new ByteArrayOutputStream();
    final DataOutputStream dataStream =new DataOutputStream(byteStream);
    dataStream.writeInt(connectResponse.get("connectionId0"));
    dataStream.writeInt(connectResponse.get("connectionId1"));
    dataStream.writeInt(2);
    dataStream.write(connectResponse.get("transactionId"));
    bencodeWriter.write(byteOut.toString());
    dataStream.writeChars("1D19CC96C1A4965D184E4B215942DBC0A09FF8F2");
    dataStream.close();
    final byte[] scrapeBytes= byteStream.toByteArray();

I tried different trackers but get the same response. What might be the problem?

Edit: Added the hex dump of all the requests and responses:

Connect Request: Connect request

Connect Response: Connect response

Scrape Request: Scrape request

Scrape Response: Scrape response


Solution

  • In the Scrape request;
    the transaction_id=0x36 is sent as a single byte instead of 4 bytes=0x00000036
    and the info_hash is sent as a 80 bytes string that is hex-encoded were every character is prepended by a zero-byte 0x00 instead of as a raw 20 bytes string.
    I.E. 0x0031004400310039... instead of 0x1D19...

    The Scrape response has no peers, as there is no torrents with the info_hashes sent in the request.