X-Git-Url: http://royale.zerezo.com/git/?p=jMoule;a=blobdiff_plain;f=src%2FDonkeyCore.java;fp=src%2FDonkeyCore.java;h=bd79353ab1d212477f0be3c24ba3304d4a766fff;hp=023100efcde5cd71ceba9fb20d686581dd259ad7;hb=cce009a622e1a14cc0b85bbf04b71af996e6f001;hpb=10983cb1be957281ec251d7cb7642ac0382cac82
diff --git a/src/DonkeyCore.java b/src/DonkeyCore.java
old mode 100644
new mode 100755
index 023100e..bd79353
--- a/src/DonkeyCore.java
+++ b/src/DonkeyCore.java
@@ -4,6 +4,12 @@ import java.util.Hashtable;
import java.util.Vector;
import javax.swing.*;
+/**
+ * This class implements mlDonkey Core/GUI protocol.
+ * This is a part of jMoule.
+ * This project is licenced under GPL.
+ * @author Antoine Jacquet
+ */
public class DonkeyCore extends Thread
{
byte[] buffer=new byte[1024*100];
@@ -11,13 +17,50 @@ public class DonkeyCore extends Thread
int nbsearches=0;
Socket connection;
String password;
- Hashtable fileInfos=new Hashtable();
- Hashtable resultInfos=new Hashtable();
- Hashtable serverInfos=new Hashtable();
- Vector searchResults=new Vector();
+
+ /**
+ * This contains the informations about the files being downloaded.
+ * File ID are the hash keys.
+ * The values of the hash are vectors containing file informations : filename, size, downloaded, %, rate, ETA and running state.
+ */
+ public Hashtable fileInfos=new Hashtable();
+
+ /**
+ * This contains the informations about the results of searches.
+ * Files ID are the hash keys.
+ * The values of the hash are vectors containing result informations : filename, size, tags and download state.
+ */
+ public Hashtable resultInfos=new Hashtable();
+
+ /**
+ * This contains the informations about the donkey servers.
+ * Servers ID are the hash keys.
+ * The values of the hash are vectors containing server informations : host, users, files, connected state.
+ */
+ public Hashtable serverInfos=new Hashtable();
+
+ /**
+ * This contains all the searches results.
+ * Each entry is a vector containing a specific search result.
+ * Each specific search result contains vectors with same format as resultInfos.
+ */
+ public Vector searchResults=new Vector();
+
+ /**
+ * This contains statistics informations.
+ * The keys are the variables and the values are numbers.
+ */
+ public Hashtable statInfos=new Hashtable();
+
+ /**
+ * This is a text panel containing console messages...
+ */
+ public JTextArea console=new JTextArea();
//String console=new String();
- JTextArea console=new JTextArea();
+ /**
+ * Constructs an unconnected DonkeyCore.
+ */
public DonkeyCore()
{
/*
@@ -74,12 +117,22 @@ public class DonkeyCore extends Thread
*/
}
+ /**
+ * Constructs a connected DonkeyCore.
+ * Same parameters as "connect".
+ */
public DonkeyCore(String host,int port,String password)
{
this();
connect(host,port,password);
}
+ /**
+ * Connects an unconnected DonkeyCore.
+ * @param host mlDonkey host you wish to connect to.
+ * @param port mlDonkey core port.
+ * @param password Password if needed.
+ */
public boolean connect(String host,int port,String password)
{
this.password=password;
@@ -97,6 +150,9 @@ public class DonkeyCore extends Thread
}
}
+ /**
+ * Disconnects this DonkeyCore.
+ */
public void disconnect()
{
try
@@ -110,6 +166,10 @@ public class DonkeyCore extends Thread
}
}
+ /**
+ * Tests if this DonkeyCore is already connected.
+ * @return true if connected.
+ */
public boolean isConnected()
{
return connection!=null;
@@ -164,12 +224,12 @@ public class DonkeyCore extends Thread
int readInt()
{
- return(readByte()+256*readByte());
+ return(readByte()+(readByte()<<8));
}
long readLong()
{
- return(readByte()+256*(readByte()+256*(readByte()+256*readByte())));
+ return(readInt()+((long)readInt()<<16));
}
String readString()
@@ -202,6 +262,9 @@ public class DonkeyCore extends Thread
}
}
+ /**
+ * Asks the mlDonkey core to connect more servers.
+ */
public void connectMore()
{
byte[] buffer=new byte[2];
@@ -209,6 +272,9 @@ public class DonkeyCore extends Thread
sendMessage(buffer,2);
}
+ /**
+ * Asks the mlDonkey core to clean old servers.
+ */
public void cleanOld()
{
byte[] buffer=new byte[2];
@@ -216,6 +282,9 @@ public class DonkeyCore extends Thread
sendMessage(buffer,2);
}
+ /**
+ * Asks the mlDonkey core to kill (terminate) itself.
+ */
public void kill()
{
byte[] buffer=new byte[2];
@@ -223,6 +292,9 @@ public class DonkeyCore extends Thread
sendMessage(buffer,2);
}
+ /**
+ * Extends (redo) the last search.
+ */
public void extend()
{
byte[] buffer=new byte[2];
@@ -230,6 +302,10 @@ public class DonkeyCore extends Thread
sendMessage(buffer,2);
}
+ /**
+ * Start a new download.
+ * @param fileID ID of the file to download (found in resultInfos key).
+ */
public void download(Long fileID)
{
byte[] buffer=new byte[9];
@@ -246,6 +322,11 @@ public class DonkeyCore extends Thread
sendMessage(buffer,i);
}
+ /**
+ * Pause/Resume a download.
+ * @param fileID ID of the file to switch (found in resultInfos key).
+ * @param bool true = resume, false = pause.
+ */
public void switchDownload(Long fileID,boolean bool)
{
byte[] buffer=new byte[9];
@@ -264,6 +345,10 @@ public class DonkeyCore extends Thread
sendMessage(buffer,i);
}
+ /**
+ * Asks mlDonkey to connect to a new server.
+ * @param serverID ID of the server to connect to (found in serverInfos key).
+ */
public void connectServer(Long serverID)
{
byte[] buffer=new byte[6];
@@ -278,6 +363,10 @@ public class DonkeyCore extends Thread
sendMessage(buffer,i);
}
+ /**
+ * Asks mlDonkey to disconnect from a server.
+ * @param serverID ID of the server to disconnect (found in serverInfos key).
+ */
public void disconnectServer(Long serverID)
{
byte[] buffer=new byte[6];
@@ -292,51 +381,59 @@ public class DonkeyCore extends Thread
sendMessage(buffer,i);
}
+ /**
+ * Start a new search.
+ * @param query A simple string to describe what you want to search.
+ * @return A vector of search results (entries of this vector have same structure as resultInfos entries).
+ */
public Vector search(String query)
{
- byte[] buffer=new byte[1024*100];
- int i=0,j;
- buffer[i++]=42; buffer[i++]=0; // function
- buffer[i++]=(byte)(nbsearches%256); buffer[i++]=(byte)(nbsearches/256);
- buffer[i++]=0; buffer[i++]=0; // num
- buffer[i++]=4; // keywords
- buffer[i++]=0; buffer[i++]=0; // empty string
- buffer[i++]=(byte)(query.length()%256);
- buffer[i++]=(byte)(query.length()/256);
- for (j=0;j0)
+ fileInfo.add(new Float(time/3600.0));
+ else
+ fileInfo.add(new Float(0));
n=readInt();
for (i=0;i