Commit ec280617 by Andrew Dahl

Initial Commit after my hairy experience...

parents
Showing with 2755 additions and 0 deletions
<?xml version="1.0" encoding="UTF-8" ?>
<adf-config xmlns="http://xmlns.oracle.com/adf/config"></adf-config>
<?xml version = '1.0' encoding = 'UTF-8'?>
<jpr:project xmlns:jpr="http://xmlns.oracle.com/ide/project">
<hash n="component-versions">
<value n="oracle.ide.model.Project" v="11.1.2.0.0"/>
<value n="oracle.ide.model.ResourcePathsMigrator" v="11.1.1.1.0"/>
<value n="oracle.ideimpl.model.TechnologyScopeUpdateMigrator" v="11.1.2.0.0.4"/>
<value n="oracle.jdeveloper.library.ProjectLibraryMigrator" v="11.1.1.1.0"/>
<value n="oracle.jdeveloper.model.OutputDirectoryMigrator" v="11.1.1.1.0"/>
<value n="oracle.jdevimpl.deploy.DeploymentProfilesMigrator" v="11.1.1.1.0"/>
</hash>
<list n="contentSets">
<string v="oracle.mds.internal.dt.ide.MDSLibraryCustCSProvider/mdsContentSet"/>
<string v="oracle.mds.internal.dt.ide.MDSADFLibVirtualNodeCSProvider/mdsLibVirtualNodeContentSet"/>
<string v="oracle.jdeveloper.model.PathsConfiguration/javaContentSet"/>
<string v="oracle.ide.model.ResourcePaths/resourcesContentSet"/>
<string v="oracle.jdeveloper.model.J2eeSettings/webContentSet"/>
<string v="oracle.jdeveloper.offlinedb.model.OfflineDBProjectSettings/offlineDBContentSet"/>
<string v="oracle.adfdtinternal.model.ide.settings.ADFMSettings/adfmContentSet"/>
<string v="oracle.bm.commonIde.data.project.ModelerProjectSettings/modelersContentSet"/>
<string v="oracle.toplink.workbench.addin/toplinkContentSet"/>
</list>
<value n="defaultPackage" v="BitAPI"/>
<hash n="oracle.ide.model.ResourcePaths">
<hash n="resourcesContentSet">
<list n="pattern-filters">
<string v="+*"/>
</list>
<list n="url-path">
<url path="."/>
<url path="src/main/resources/"/>
<url path="pom.xml"/>
</list>
</hash>
</hash>
<hash n="oracle.ide.model.TechnologyScopeConfiguration">
<list n="technologyScope">
<string v="Maven"/>
</list>
</hash>
<hash n="oracle.jdeveloper.compiler.OjcConfiguration">
<value n="internalEncoding" v="UTF8"/>
<list n="Javac.commandline.optionlist">
<string v="-g"/>
<string v="-Xlint:all"/>
<string v="-Xlint:-cast"/>
<string v="-Xlint:-empty"/>
<string v="-Xlint:-fallthrough"/>
<string v="-Xlint:-path"/>
<string v="-Xlint:-processing"/>
<string v="-Xlint:-serial"/>
<string v="-Xlint:-unchecked"/>
</list>
<value n="webIANAEncoding" v="UTF-8"/>
</hash>
<hash n="oracle.jdeveloper.maven.compiler.MavenRunConfiguration">
<url n="pomfileURL" path="pom.xml"/>
</hash>
<hash n="oracle.jdeveloper.model.PathsConfiguration">
<hash n="javaContentSet">
<list n="pattern-filters">
<string v="+**"/>
</list>
<list n="url-path">
<url path="src/main/java/"/>
</list>
</hash>
</hash>
<hash n="oracle.jdevimpl.config.JProjectPaths">
<url n="outputDirectory" path="target/"/>
</hash>
</jpr:project>
<?xml version = '1.0' encoding = 'UTF-8'?>
<jws:workspace xmlns:jws="http://xmlns.oracle.com/ide/project">
<value n="application-package-prefix" v="com.drewdahl"/>
<value n="appTemplateId" v="#mavenApplicationTemplate"/>
<hash n="component-versions">
<value n="oracle.ide.model.Project" v="11.1.1.1.0;11.1.2.0.0"/>
</hash>
<list n="contentSets">
<string v="oracle.jdeveloper.model.PathsConfiguration/ApplicationLevelMavenPOMContentSet"/>
</list>
<list n="listOfChildren">
<hash><url n="URL" path="JTorrent/client.jpr"/></hash>
<hash><url n="URL" path="libJTorrent/libJTorrent.jpr"/></hash>
</list>
<hash n="oracle.jdeveloper.maven.compiler.MavenAppConfiguration">
<hash n="oracle.jdeveloper.maven.compiler.MavenAppConfiguration">
<url n="userSettingsFile" path="../../../.m2/settings.xml"/>
</hash>
</hash>
</jws:workspace>
<?xml version = '1.0' encoding = 'UTF-8'?>
<jpr:project xmlns:jpr="http://xmlns.oracle.com/ide/project">
<hash n="component-versions">
<value n="oracle.ideimpl.model.TechnologyScopeUpdateMigrator" v="11.1.2.0.0.4"/>
</hash>
<list n="contentSets">
<string v="oracle.mds.internal.dt.ide.MDSLibraryCustCSProvider/mdsContentSet"/>
<string v="oracle.mds.internal.dt.ide.MDSADFLibVirtualNodeCSProvider/mdsLibVirtualNodeContentSet"/>
<string v="oracle.jdeveloper.model.PathsConfiguration/javaContentSet"/>
<string v="oracle.ide.model.ResourcePaths/resourcesContentSet"/>
<string v="oracle.jdeveloper.model.J2eeSettings/webContentSet"/>
<string v="oracle.jdeveloper.offlinedb.model.OfflineDBProjectSettings/offlineDBContentSet"/>
<string v="oracle.adfdtinternal.model.ide.settings.ADFMSettings/adfmContentSet"/>
<string v="oracle.bm.commonIde.data.project.ModelerProjectSettings/modelersContentSet"/>
<string v="oracle.toplink.workbench.addin/toplinkContentSet"/>
</list>
<value n="defaultPackage" v="client"/>
<hash n="oracle.ide.model.DependencyConfiguration">
<list n="dependencyList">
<hash>
<hash n="dependable">
<url n="sourceOwnerURL" path="../JTorrent.jws"/>
<url n="sourceURL" path="../libJTorrent/libJTorrent.jpr"/>
</hash>
<value n="recognizerId" v="oracle.jdeveloper.library"/>
</hash>
</list>
</hash>
<hash n="oracle.ide.model.ResourcePaths">
<hash n="resourcesContentSet">
<list n="constituent-sets">
<hash>
<list n="pattern-filters">
<string v="+*"/>
</list>
<list n="url-path">
<url path="."/>
</list>
</hash>
<hash>
<list n="pattern-filters">
<string v="+*"/>
</list>
<list n="url-path">
<url path="src/main/resources/"/>
</list>
</hash>
<hash>
<list n="pattern-filters">
<string v="+*"/>
</list>
<list n="url-path">
<url path="pom.xml"/>
</list>
</hash>
</list>
<list n="url-path"/>
</hash>
</hash>
<hash n="oracle.ide.model.TechnologyScopeConfiguration">
<list n="technologyScope">
<string v="Java"/>
<string v="Maven"/>
<string v="XML"/>
</list>
</hash>
<hash n="oracle.jdeveloper.compiler.OjcConfiguration">
<value n="compiler.name" v="Javac"/>
</hash>
<hash n="oracle.jdeveloper.maven.compiler.MavenRunConfiguration">
<value n="defaultGoal" v="package"/>
<url n="pomfileURL" path="pom.xml"/>
</hash>
<hash n="oracle.jdeveloper.model.J2eeSettings">
<hash n="webContentSet">
<list n="url-path">
<url path="public_html/"/>
</list>
</hash>
</hash>
<hash n="oracle.jdeveloper.model.PathsConfiguration">
<hash n="javaContentSet">
<list n="pattern-filters">
<string v="+**"/>
</list>
<list n="url-path">
<url path="src/main/java/"/>
</list>
</hash>
</hash>
<hash n="oracle.jdeveloper.runner.RunConfigurations">
<hash n="runConfigurationDefinitions">
<hash n="Default">
<value n="custom" v="false"/>
<value n="name" v="Default"/>
<value n="programArguments" v="/home/dahlan/Downloads/Fedora-16-i686-Live-Desktop.torrent"/>
<url n="targetURL" path="src/main/java/com/drewdahl/libjtorrent/client/Main.java"/>
</hash>
</hash>
</hash>
<hash n="oracle.jdevimpl.config.JProjectLibraries">
<hash n="internalDefinitions">
<list n="libraryDefinitions">
<hash>
<list n="classPath">
<url path="../../../../.m2/repository/com/drewdahl/libJTorrent/1.0-SNAPSHOT/libJTorrent-1.0-SNAPSHOT.jar"/>
</list>
<value n="description" v="com.drewdahl:libJTorrent:1.0-SNAPSHOT:jar"/>
<value n="id" v="com.drewdahl:libJTorrent:1.0-SNAPSHOT:jar"/>
<value n="locked" v="true"/>
</hash>
</list>
</hash>
<list n="libraryReferences">
<hash>
<value n="id" v="com.drewdahl:libJTorrent:1.0-SNAPSHOT:jar"/>
<value n="isJDK" v="false"/>
</hash>
</list>
</hash>
<hash n="oracle.jdevimpl.config.JProjectPaths">
<url n="outputDirectory" path="target/classes/"/>
</hash>
</jpr:project>
<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.drewdahl.libjtorrent</groupId>
<artifactId>client</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.drewdahl</groupId>
<artifactId>libJTorrent</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>
1.7
</source>
<target>
1.7
</target>
</configuration>
</plugin>
</plugins>
</build>
<parent>
<groupId>com.drewdahl.libjtorrent</groupId>
<artifactId>JTorrent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
</project>
package com.drewdahl.libjtorrent.client;
import com.drewdahl.libjtorrent.TorrentFile;
import com.drewdahl.libjtorrent.Utils;
import com.drewdahl.libjtorrent.bencode.Bencoder;
import com.drewdahl.libjtorrent.bencode.BencodedValue;
import com.drewdahl.libjtorrent.bencode.InvalidBencodingException;
import com.drewdahl.libjtorrent.downloadmanager.DownloadManager;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.security.SecureRandom;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.IOException;
import javax.crypto.SecretKey;
public class Main {
public Main() {
super();
}
public static void main(String[] args) {
Main main = new Main();
if(args.length != 1) {
System.err.println("Missing or too many arguments. Requires one argument.");
return;
}
TorrentFile tFile = new TorrentFile();
tFile.populate(args[0]);
System.out.println(tFile.toString(false));
DownloadManager dm = new DownloadManager(tFile,Utils.generateUniqueID());
dm.startListening(6881, 6889);
dm.startTracker();
dm.download();
while(true){
}
//System.err.print(tFile.toString(false));
}
}
<?xml version = '1.0' encoding = 'UTF-8'?>
<jpr:project xmlns:jpr="http://xmlns.oracle.com/ide/project">
<hash n="component-versions">
<value n="oracle.ide.model.Project" v="11.1.2.0.0"/>
<value n="oracle.ide.model.ResourcePathsMigrator" v="11.1.1.1.0"/>
<value n="oracle.ideimpl.model.TechnologyScopeUpdateMigrator" v="11.1.2.0.0.4"/>
<value n="oracle.jdeveloper.library.ProjectLibraryMigrator" v="11.1.1.1.0"/>
<value n="oracle.jdeveloper.model.OutputDirectoryMigrator" v="11.1.1.1.0"/>
<value n="oracle.jdevimpl.deploy.DeploymentProfilesMigrator" v="11.1.1.1.0"/>
</hash>
<list n="contentSets">
<string v="oracle.mds.internal.dt.ide.MDSLibraryCustCSProvider/mdsContentSet"/>
<string v="oracle.mds.internal.dt.ide.MDSADFLibVirtualNodeCSProvider/mdsLibVirtualNodeContentSet"/>
<string v="oracle.jdeveloper.model.PathsConfiguration/javaContentSet"/>
<string v="oracle.ide.model.ResourcePaths/resourcesContentSet"/>
<string v="oracle.jdeveloper.model.J2eeSettings/webContentSet"/>
<string v="oracle.jdeveloper.offlinedb.model.OfflineDBProjectSettings/offlineDBContentSet"/>
<string v="oracle.adfdtinternal.model.ide.settings.ADFMSettings/adfmContentSet"/>
<string v="oracle.bm.commonIde.data.project.ModelerProjectSettings/modelersContentSet"/>
<string v="oracle.toplink.workbench.addin/toplinkContentSet"/>
</list>
<value n="defaultPackage" v="com.drewdahl"/>
<hash n="oracle.ide.model.ResourcePaths">
<hash n="resourcesContentSet">
<list n="pattern-filters">
<string v="+*"/>
</list>
<list n="url-path">
<url path="."/>
<url path="src/main/resources/"/>
<url path="pom.xml"/>
</list>
</hash>
</hash>
<hash n="oracle.ide.model.TechnologyScopeConfiguration">
<list n="technologyScope">
<string v="Maven"/>
</list>
</hash>
<hash n="oracle.jdeveloper.compiler.OjcConfiguration">
<value n="internalEncoding" v="UTF8"/>
<list n="Javac.commandline.optionlist">
<string v="-g"/>
<string v="-Xlint:all"/>
<string v="-Xlint:-cast"/>
<string v="-Xlint:-empty"/>
<string v="-Xlint:-fallthrough"/>
<string v="-Xlint:-path"/>
<string v="-Xlint:-processing"/>
<string v="-Xlint:-serial"/>
<string v="-Xlint:-unchecked"/>
</list>
<value n="webIANAEncoding" v="UTF-8"/>
</hash>
<hash n="oracle.jdeveloper.maven.compiler.MavenRunConfiguration">
<url n="pomfileURL" path="pom.xml"/>
</hash>
<hash n="oracle.jdeveloper.model.J2eeSettings">
<hash n="webContentSet">
<list n="url-path">
<url path="public_html/"/>
</list>
</hash>
</hash>
<hash n="oracle.jdeveloper.model.PathsConfiguration">
<hash n="javaContentSet">
<list n="pattern-filters">
<string v="+**"/>
</list>
<list n="url-path">
<url path="src/main/java/"/>
</list>
</hash>
</hash>
<hash n="oracle.jdevimpl.config.JProjectPaths">
<url n="outputDirectory" path="target/"/>
</hash>
</jpr:project>
<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.drewdahl</groupId>
<artifactId>libJTorrent</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>
1.7
</source>
<target>
1.7
</target>
</configuration>
</plugin>
</plugins>
</build>
<parent>
<groupId>com.drewdahl.libjtorrent</groupId>
<artifactId>JTorrent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
</project>
package com.drewdahl.libjtorrent;
import com.drewdahl.libjtorrent.bencode.BencodedValue;
import com.drewdahl.libjtorrent.bencode.Bencoder;
import com.drewdahl.libjtorrent.bencode.InvalidBencodingException;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
public class TorrentFile {
private String announce;
private String comment;
private String createdBy;
private String encoding;
private String saveAs;
private byte[] pieces;
private long creationDate;
private long pieceLength;
private long totalLength;
private ArrayList pieceHashValues;
private String info;
// For Multiple Files
private ArrayList fileNames;
private ArrayList fileLengths;
private static final String DELIM = "//////";
public TorrentFile() {
super();
setAnnounce(new String());
setComment(new String());
setCreatedBy(new String());
setEncoding(new String());
setPieces(new byte[20]);
setSaveAs(new String());
setInfo(new String());
setCreationDate(-1);
setPieceLength(-1);
setTotalLength(0);
setPieceHashValues(new ArrayList());
setFileNames(new ArrayList());
setFileLengths(new ArrayList());
}
public String toString() {
return toString(true);
}
public String toString(Boolean withPieces) {
StringBuilder str = new StringBuilder();
str.append( "Announce => " + getAnnounce() +
"\nComment => " + getComment() +
"\nCreated By => " + getCreatedBy() +
"\nEncoding => " + getEncoding() +
"\nName => " + getSaveAs() +
"\nCreation Date => " + getCreationDate() +
"\nPieceLength => " + getPieceLength());
for(int i = 0; i < getFileNames().size(); i++)
str.append("\nFile[" + i + "] => " + getFileNames().get(i) + " => " + getFileLengths().get(i));
if(withPieces)
for(int i = 0; i < getPieceHashValues().size(); i++)
str.append("\nPiece[" + i + "] => " + new String((byte[])getPieceHashValues().get(i)));
return str.toString() + "\n";
}
public Boolean generate() {
// TODO
return false;
}
public Boolean populate(String file) {
try {
InputStream is = new BufferedInputStream(new FileInputStream(file));
Bencoder coder = new Bencoder(is);
this.setValues(coder.decode());
} catch (FileNotFoundException e) {
System.err.println(e.toString());
return false;
} catch (IOException e) {
System.err.println(e.toString());
return false;
}
if(getPieceLength() == -1)
return false;
ArrayList pieceList = new ArrayList();
byte[] piece;
for(int i = 0; i < getPieces().length/20; i++) {
piece = new byte[20];
System.arraycopy(getPieces(),i*20,piece,0,20);
pieceList.add(piece);
}
setPieceHashValues(pieceList);
if(getFileNames().size() == 0) {
getFileNames().add(getSaveAs());
getFileLengths().add(getTotalLength());
}
return true;
}
private String setValues(BencodedValue value) throws InvalidBencodingException {
if(value.getObject() instanceof byte[]) {
return value.getString();
} else if(value.getObject() instanceof BigInteger) {
return value.getInteger().toString();
} else if(value.getObject() instanceof List) {
List<BencodedValue> list = value.getList();
String str = this.setValues(list.get(0));
for(int i = 1; i < list.size(); i++)
str += DELIM + this.setValues(list.get(i));
return str;
} else if(value.getObject() instanceof Map) {
Map<String, BencodedValue> map = value.getMap();
Iterator it = map.keySet().iterator();
BencodedValue bv;
String key;
while(it.hasNext()) {
key = it.next().toString();
bv = map.get(key);
switch(key) {
case "announce":
setAnnounce(this.setValues(bv));
break;
case "creation date":
setCreationDate(new BigInteger(this.setValues(bv)).longValue());
break;
case "comment":
setComment(this.setValues(bv));
break;
case "encoding":
setEncoding(this.setValues(bv));
break;
case "piece length":
setPieceLength(new BigInteger(this.setValues(bv)).longValue());
break;
case "pieces":
setPieces(bv.getBytes());
break;
case "name":
setSaveAs(this.setValues(bv));
break;
case "path":
fileNames.add(this.setValues(bv).replaceAll(DELIM, "/"));
break;
case "length":
fileLengths.add(new BigInteger(this.setValues(bv)).longValue());
setTotalLength(getTotalLength() + ((Long)fileLengths.get(fileLengths.size()-1)));
break;
case "info":
this.setInfo(bv.toString());
case "files":
this.setValues(bv);
break;
}
}
}
return "";
}
public String getAnnounce() {
return announce;
}
private void setAnnounce(String announce) {
this.announce = announce;
}
public String getComment() {
return comment;
}
private void setComment(String comment) {
this.comment = comment;
}
public String getCreatedBy() {
return createdBy;
}
private void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public String getEncoding() {
return encoding;
}
private void setEncoding(String encoding) {
this.encoding = encoding;
}
public String getSaveAs() {
return saveAs;
}
private void setSaveAs(String saveAs) {
this.saveAs = saveAs;
}
public long getCreationDate() {
return creationDate;
}
private void setCreationDate(long creationDate) {
this.creationDate = creationDate;
}
public long getPieceLength() {
return pieceLength;
}
private void setPieceLength(long pieceLength) {
this.pieceLength = pieceLength;
}
public ArrayList getPieceHashValues() {
return pieceHashValues;
}
private void setPieceHashValues(ArrayList pieceHashValues) {
this.pieceHashValues = pieceHashValues;
}
public ArrayList getFileNames() {
return fileNames;
}
private void setFileNames(ArrayList fileNames) {
this.fileNames = fileNames;
}
public ArrayList getFileLengths() {
return fileLengths;
}
private void setFileLengths(ArrayList fileLengths) {
this.fileLengths = fileLengths;
}
private byte[] getPieces() {
return pieces;
}
private void setPieces(byte[] pieces) {
this.pieces = pieces;
}
public String getInfoHex() {
try {
return Utils.byteArrayToByteString(getInfoHash().getBytes("ISO-8859-1"));
} catch (UnsupportedEncodingException e) {
System.err.println(e.toString());
}
return null;
}
public String getInfoHash() {
try {
return new String(Utils.hash(info.getBytes("ISO-8859-1")),"ISO-8859-1");