2

I'm using torrent file (ubuntu-14.04.1-desktop-amd64.iso) from

http://torrent.ubuntu.com:6969/

I calculated it's info-hash and it matches with hash on the site. But when i'm trying to send GET request:

http://torrent.ubuntu.com:6969/announce?info_hash=%CB%84%EF%BF%BD%EF%BF%BD%0F%29m%EF%BF%BD-l%40%EF%BF%BDz%07%EF%BF%BDx%EF%BF%BD2%3A%14&peer_id=%EF%BF%BD%07d%EF%BF%BD%EF%BF%BD%EF%BF%BDI%EF%BF%BD%5E%EF%BF%BDCo%D8%97d%7D%EF%BF%BDep%EF%BF%BD&port=6881&event=started

i get:

d14:failure reason63:Requested download is not authorized for use with this tracker.e

I don't understand what i am doing wrong

I generate request this way:

HttpURLConnection connection;
final String INFO_HASH = "info_hash";
final String PEER_ID = "peer_id";
final String PORT = "port";
final String EVENT = "event";

try {
    byte[] peerId = new byte[20];
    Random rnd = new Random();
    rnd.nextBytes(peerId);
    URI uri = new URIBuilder(metaInfo.getAnnounce())
        .addParameter(INFO_HASH, new String(metaInfo.getInfoHash(), "UTF-8"))
        .addParameter(PEER_ID, new String(peerId, "UTF-8"))
        .addParameter(PORT, "6881")
        .addParameter(EVENT, "started").build();
    log.info("Sending request to: " + uri.toURL().toString());
    connection = (HttpURLConnection) uri.toURL().openConnection();
} catch (MalformedURLException e) {
    throw new RuntimeException("Invalid torrent file: illegal announce in torrent file");
} catch (URISyntaxException e) {
    throw new RuntimeException("Couldn't build URI: illegal announce in torrent file");
}

1 Answers1

2

I figured it out. You need to write info_hash in ISO-8859-1 and always specify other fields (uploaded, downloaded, left). Furthermore torrent.ubuntu.com also wanted me to specify compact and no_peer_id

Working version of code:

HttpURLConnection connection;
final String INFO_HASH = "info_hash";
final String PEER_ID = "peer_id";
final String PORT = "port";
final String EVENT = "event";
final String UPLOADED = "uploaded";
final String DOWNLOADED = "downloaded";
final String LEFT = "left";
final String NO_PEER_ID = "no_peer_id";
final String COMPACT = "compact";

try {
    byte[] peerId = new byte[20];
    Random rnd = new Random();
    rnd.nextBytes(peerId);

    URI uri = new URIEncodeBuilder(metaInfo.getAnnounce())
            .addParameter(INFO_HASH, new String(metaInfo.getInfoHash(), "ISO-8859-1"), "ISO-8859-1")
            .addParameter(PEER_ID, "-TO0042-0ab8e8a31019")
            .addParameter(PORT, "6881")
            .addParameter(EVENT, "started")
            .addParameter(UPLOADED, "0")
            .addParameter(DOWNLOADED, "0")
            .addParameter(LEFT, "1028128768")
            .addParameter(COMPACT, "1")
            .addParameter(NO_PEER_ID, "0").build();
    log.info("Maybe: " + uri.toURL().toString());
    connection = (HttpURLConnection) uri.toURL().openConnection();
} catch (MalformedURLException e) {
    throw new RuntimeException("Invalid torrent file: illegal announce in torrent file");
} catch (URISyntaxException e) {
    throw new RuntimeException("Couldn't build URI: illegal announce in torrent file");
}