BitComet_0_5_7.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
omschaub.clientstuff.clientid |
![]() |
![]() |
AZCVSUpdater |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* Created on Jan 2, 2005
* Created by omschaub
*
*/
package omschaub.clientstuff.clientid;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Random;
import org.gudy.azureus2.plugins.clientid.ClientIDException;
import org.gudy.azureus2.plugins.clientid.ClientIDGenerator;
import org.gudy.azureus2.plugins.torrent.Torrent;
/**
* @author marc
*
*/
public class BitComet_0_5_7 implements ClientIDGenerator{
private Map key_map = new HashMap();
public byte[]
generatePeerID(
Torrent torrent,
boolean for_tracker )
{
return( createPeerID());
}
public void
generateHTTPProperties(
Properties properties )
{
}
public String[]
filterHTTP(
String[] lines_in )
throws ClientIDException
{
/* Info for Mainline BitTorrent 3.4.2
GET /announce?info_hash=%9B%93%F0%25%08%E8%C9%18%87vm%86%AE%03%08%03%CE%B3%DD%0E&peer_id=M3-4-2--ac6cd574a9f9&port=6881&key=fb3c36fc&uploaded=0&downloaded=0&left=176634&compact=1&event=started HTTP/1.0
Host: 127.0.0.1:8080
~~~~~~~~~~~~~~~: ~~~~
User-agent: BitTorrent/3.4.2
*/
// for BitTorrent/3.4.2:
// URL contents order is:
// info_hash, peer_id, port, key, uploaded, downloaded, left, compact, event
// note that key is only hex, not as AZ, so we need to substitute
/*
* GET ?info_hash=%19%CF%A7%0E%C6C%D6%1Cwq6%27%D8Xf%E2%9A5%A3%02&peer_id=-AZ2201-vC7sqCrvMxZe&port=6891&uploaded=0&downloaded=0&left=2552124&event=started&numwant=200&compact=1&key=yw8C75Rq HTTP/1.1
User-Agent: Azureus 2.2.0.1_B16
URL order is:
info_hash, peer_id, port, uploaded, downloaded, left, event, numwant, compact, key
Host: 192.168.1.196:8080
*/
View.addElement("-----------------Start------------------");
for (int i=0;i<lines_in.length;i++)
{
View.addElement("From Azureus: " + lines_in[i]);
//System.out.println( "in: " + lines_in[i]);
}
String get_in = lines_in[0];
// scrape operation not performed by 3.4.2
if ( get_in.indexOf( "scrape?" ) != -1 ){
throw( new ClientIDException( "Scrape not supported by emulated client"));
}
// fiddle around with the url args
// remove HTTP/1.1 part
int last_space_pos = get_in.lastIndexOf(' ');
get_in = get_in.substring(0,last_space_pos).trim();
//int prefix_pos = get_in.indexOf('?');
int prefix_pos = get_in.indexOf("info_hash=" ) - 1;
String prefix = get_in.substring( 0, prefix_pos+1);
Map args = new HashMap();
int pos = prefix_pos+1;
while(true){
int p1 = get_in.indexOf('&', pos );
String arg;
if ( p1 == -1 ){
arg = get_in.substring( pos );
}else{
arg = get_in.substring( pos, p1 );
}
int e_pos = arg.indexOf('=');
args.put( arg.substring(0,e_pos), arg.substring( e_pos+1 ));
if ( p1 == -1 ){
break;
}else{
pos = p1+1;
}
}
String[] lines_out = new String[4];
String get_out = prefix;
String[] arg_list = {
"info_hash", "peer_id", "port", "natmapped", "localip", "uploaded", "downloaded", "left", "numwant", "compact", "no_peer_id", "key", "event"
};
for (int i=0;i<arg_list.length;i++){
String key = arg_list[i];
String arg = (String)args.get(key);
if ( arg != null ){
if ( key.equals( "key" )){
arg = mapKeyValue( arg );
}
if ( key.equals( "peer_id")){
View.setClient(arg.substring(0,4) + " -- BitComet 0.57");
}
get_out += (get_out==prefix?"":"&") + key + "=" + arg;
}
}
lines_out[0] = get_out + " HTTP/1.0";
for (int i=1;i<lines_in.length;i++){
if ( lines_in[i].toLowerCase().indexOf( "host:" ) != -1 ){
lines_out[1] = lines_in[i];
break;
}
}
lines_out[2] = "Accept-encoding: gzip";
lines_out[3] = "User-agent: BitTorrent/3.4.2";
for (int i=0;i<lines_out.length;i++){
View.addElement("Sent to Tracker: " + lines_out[i]);
//System.out.println( "out: " + lines_out[i]);
}
View.addElement("------------------End-------------------");
return( lines_out );
}
protected String
mapKeyValue(
String in )
{
String out = (String)key_map.get(in);
if ( out == null ){
out = "";
for (int i = 0; i < 8; i++) {
int pos = (int) ( Math.random() * chars.length());
out += chars.charAt(pos);
}
key_map.put( in, out );
}
return( out );
}
static final String chars = "abcdef0123456789";
public static byte[]
createPeerID()
{
byte[] peerId = new byte[50];
byte[] version = "exbc".getBytes();
for (int i = 0; i < 4; i++) {
peerId[i] = version[i];
}
byte[] end_stuff = new byte[16];
Random rand1 = new Random();
rand1.nextBytes(end_stuff);
String temp_end_stuff = new String();
try{
for (int i = 0; i < 16; i++){
temp_end_stuff = temp_end_stuff.concat(URLEncoder.encode(Byte.toString(end_stuff[i]),"UTF-8"));
}
}catch (Exception e){
e.printStackTrace();
}
byte[] final_bytes = temp_end_stuff.getBytes();
for (int i = 5; i < final_bytes.length ; i++) {
peerId[i] = final_bytes[i];
}
return( peerId );
}
}
The table below shows all metrics for BitComet_0_5_7.java.




