|
|
|
@ -1,11 +1,14 @@
|
|
|
|
|
package clientP2P;
|
|
|
|
|
import tools.HostItem;
|
|
|
|
|
import tools.Logger;
|
|
|
|
|
import tools.LogLevel;
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import localException.ProtocolError;
|
|
|
|
|
import tools.ServeErrors;
|
|
|
|
|
import java.security.MessageDigest;
|
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.net.UnknownHostException;
|
|
|
|
|
import protocolP2P.RequestResponseCode;
|
|
|
|
|
import protocolP2P.FileList;
|
|
|
|
|
import protocolP2P.ProtocolP2PPacket;
|
|
|
|
@ -13,6 +16,7 @@ import protocolP2P.DiscoverRequest;
|
|
|
|
|
import protocolP2P.DiscoverResponse;
|
|
|
|
|
import protocolP2P.Payload;
|
|
|
|
|
import protocolP2P.HashAlgorithm;
|
|
|
|
|
import localException.ProtocolError;
|
|
|
|
|
import localException.InternalError;
|
|
|
|
|
import localException.ProtocolError;
|
|
|
|
|
import localException.SizeError;
|
|
|
|
@ -26,15 +30,10 @@ import remoteException.NotFound;
|
|
|
|
|
import remoteException.ProtocolRemoteError;
|
|
|
|
|
import remoteException.VersionRemoteError;
|
|
|
|
|
import remoteException.NotATracker;
|
|
|
|
|
import remoteException.UnknownHost;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.security.MessageDigest;
|
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
|
import java.net.UnknownHostException;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
|
|
import tools.ServeErrors;
|
|
|
|
|
import tools.HostItem;
|
|
|
|
|
import tools.Logger;
|
|
|
|
|
import tools.LogLevel;
|
|
|
|
|
|
|
|
|
|
/** Implementation of P2P-JAVA-PROJECT CLIENT
|
|
|
|
|
* @author Louis Royer
|
|
|
|
@ -51,7 +50,7 @@ public abstract class ClientManagement extends ServeErrors implements Runnable {
|
|
|
|
|
protected Logger logger;
|
|
|
|
|
protected Scanner scanner;
|
|
|
|
|
protected ClientDownload downLoader;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Constructor with baseDirectory, tracker, partsSubdir, logger, and scanner parameters.
|
|
|
|
|
* @param baseDirectory the root directory where files are stored
|
|
|
|
|
* @param tracker Tracker hostItem
|
|
|
|
@ -78,7 +77,7 @@ public abstract class ClientManagement extends ServeErrors implements Runnable {
|
|
|
|
|
|
|
|
|
|
/** Getter for tracker socket
|
|
|
|
|
*/
|
|
|
|
|
protected abstract Object getTrackerSocket();
|
|
|
|
|
protected abstract Object getTrackerSocket();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Initialize hostList from tracker
|
|
|
|
@ -230,14 +229,30 @@ public abstract class ClientManagement extends ServeErrors implements Runnable {
|
|
|
|
|
*/
|
|
|
|
|
public void run() {
|
|
|
|
|
try {
|
|
|
|
|
int i = 1;
|
|
|
|
|
String[] list = listDirectory();
|
|
|
|
|
System.out.println("Files present on the server:");
|
|
|
|
|
System.out.println("0 : Exit the program");
|
|
|
|
|
for(String listItem: list) {
|
|
|
|
|
System.out.println(listItem);
|
|
|
|
|
System.out.println(i + " : " + listItem);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
System.out.println("Name of the file to download:");
|
|
|
|
|
System.out.println("Type the number associated with the file to download:");
|
|
|
|
|
String f = scanner.nextLine();
|
|
|
|
|
download(f);
|
|
|
|
|
if(f.equals("0")){
|
|
|
|
|
System.out.println("on ferme tout");
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
int j = Integer.parseInt(f);
|
|
|
|
|
if(j <= list.length){
|
|
|
|
|
j = j-1;
|
|
|
|
|
download(list[j]);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
System.out.println("Wrong number");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//download(f);
|
|
|
|
|
System.out.println("File " + f + " sucessfully downloaded");
|
|
|
|
|
writeLog("File " + f + " sucessfully downloaded", LogLevel.Info);
|
|
|
|
|
} catch (EmptyDirectory e) {
|
|
|
|
|