TrackerLoadTesterpublic class TrackerLoadTester extends Object
Fields Summary |
---|
private static final String | trackerUrl |
Constructors Summary |
---|
public TrackerLoadTester(int nbTorrents, int nbClientsPerTorrent)
for(int i = 0 ; i < nbTorrents ; i++) {
byte[] hash = generate20BytesHash(i);
//System.out.println("Adding torrent " + hash);
for(int j = 0 ; j < nbClientsPerTorrent ; j++) {
byte[] peerId = generate20BytesHash(j);
announce(trackerUrl,hash,peerId,6881+j);
}
}
|
Methods Summary |
---|
private void | announce(java.lang.String trackerURL, byte[] hash, byte[] peerId, int port)
try {
String strUrl = trackerURL
+ "?info_hash=" + URLEncoder.encode(new String(hash, Constants.BYTE_ENCODING), Constants.BYTE_ENCODING).replaceAll("\\+", "%20")
+ "&peer_id=" + URLEncoder.encode(new String(peerId, Constants.BYTE_ENCODING), Constants.BYTE_ENCODING).replaceAll("\\+", "%20")
+ "&port=" + port
+ "&uploaded=0&downloaded=0&left=0&numwant=50&no_peer_id=1&compact=1";
//System.out.println(strUrl);
URL url = new URL(strUrl);
URLConnection con = url.openConnection();
con.connect();
con.getContent();
} catch(Exception e) {
e.printStackTrace();
}
| private byte[] | generate20BytesHash(int iter)
byte[] result = new byte[20];
int pos = 0;
while(iter > 0) {
result[pos++] = (byte) (iter % 255);
iter = iter / 255;
}
return result;
| public static void | main(java.lang.String[] args)
if(args.length < 2) return;
int nbTorrents = Integer.parseInt(args[0]);
int nbClientsPerTorrent = Integer.parseInt(args[1]);
new TrackerLoadTester(nbTorrents,nbClientsPerTorrent);
|
|