Merge branch 'documentation' of flavien/Projet_JAVA_P2P_STRI2A into etape4
flavien's git/Projet_JAVA_P2P_STRI2A/pipeline/pr-master This commit looks good Details

closes #34
pull/47/head
Louis Royer 5 years ago committed by Gitea
commit bc4d7b94d5

@ -185,7 +185,11 @@ public class ClientDownloadPartTCP implements Runnable {
}
}
public ProtocolP2PPacketTCP reqPart(Long offset) {
/** Send a request for a specific offset.
* @param offset Offset of the file part to download
* @return ProtocolP2PPacketTCP used to send request
*/
private ProtocolP2PPacketTCP reqPart(Long offset) {
System.err.println("New request: "+ offset);
// maintain tracking of tasks
if (toDoTasks.contains(offset)) {
@ -226,6 +230,10 @@ public class ClientDownloadPartTCP implements Runnable {
}
}
/** Download file part associated to the request send (d).
* @param d request packet
* @return true on failure, else false
*/
public boolean downloadPart(ProtocolP2PPacketTCP d) {
if (d == null) {
System.err.println("Error: downloadPart -> d is null.");

@ -180,7 +180,11 @@ public class ClientDownloadPartUDP implements Runnable {
}
}
public ProtocolP2PPacketUDP reqPart(Long offset) {
/** Send a request for a specific offset.
* @param offset Offset of the file part to download
* @return ProtocolP2PPacketTCP used to send request
*/
private ProtocolP2PPacketUDP reqPart(Long offset) {
System.err.println("New request: "+ offset);
// maintain tracking of tasks
if (toDoTasks.contains(offset)) {
@ -218,6 +222,10 @@ public class ClientDownloadPartUDP implements Runnable {
}
}
/** Download file part associated to the request send (d).
* @param d request packet
* @return true on failure, else false
*/
public boolean downloadPart(ProtocolP2PPacketUDP d) {
if (d == null) {
System.err.println("Error: downloadPart -> d is null.");

@ -352,6 +352,9 @@ public class ClientDownloadTCP implements Runnable {
return success;
}
/** Reassemble file from file parts.
* Set success to true if file is reassembled successfully.
*/
private void reassembleFile() {
boolean firstPart = true;
boolean abort = false;

@ -346,6 +346,9 @@ public class ClientDownloadUDP implements Runnable {
return success;
}
/** Reassemble file from file parts.
* Set success to true if file is reassembled successfully.
*/
private void reassembleFile() {
boolean firstPart = true;
boolean abort = false;

@ -12,8 +12,6 @@ import remoteException.ProtocolRemoteError;
import remoteException.VersionRemoteError;
import java.net.UnknownHostException;
import java.util.Scanner;
//import java.net.InetAddress;
//import java.net.SocketException;
import java.io.IOException;
import java.nio.file.Files;
import java.io.File;

@ -12,9 +12,7 @@ import remoteException.ProtocolRemoteError;
import remoteException.VersionRemoteError;
import java.net.UnknownHostException;
import java.util.Scanner;
//import java.net.InetAddress;
import java.net.DatagramSocket;
//import java.net.SocketException;
import java.io.IOException;
import java.nio.file.Files;
import java.io.File;

@ -11,8 +11,13 @@ import java.util.Scanner;
import java.util.List;
import tools.HostItem;
import tools.HostList;
import java.lang.NumberFormatException;
/** Client + Server implementation.
* @author Louis Royer
* @author Flavien Haas
* @author JS Auge
* @version 1.0
*/
public class ClientP2P {
static private final String subdir = "seeded/";
static private String parts = ".parts";
@ -23,6 +28,10 @@ public class ClientP2P {
private List<HostItem> hostList;
private static final int defaultPort = 20000;
/** Initialize logger if directories and logger are null,
* else fail silently.
*/
public void initLogger() {
if (directories == null && logger == null) {
directories = new Directories("P2P_JAVA_PROJECT" + port);
@ -30,6 +39,9 @@ public class ClientP2P {
}
}
/** Constructor with portStr as parameter.
* @param portStr String containing port for server listenning.
*/
public ClientP2P(String portStr) {
try{
port = Integer.valueOf(Integer.parseInt(portStr));
@ -49,6 +61,11 @@ public class ClientP2P {
System.out.println("Please enter list of servers to use; first one will be used to ask list of files");
}
/** Main program entry point.
* 1rst parameter is optionnal, and is used to
* define port used by the server module to listen. If not provided, default to another port.
* @param args server listenning port
*/
public static void main(String [] args) {
ClientP2P c;
try {
@ -57,21 +74,25 @@ public class ClientP2P {
c = new ClientP2P("" + defaultPort);
}
// Server threads
ServerManagementUDP smudp = new ServerManagementUDP(c.directories.getDataHomeDirectory() + subdir, c.port, c.logger);
ServerManagementTCP smtcp = new ServerManagementTCP(c.directories.getDataHomeDirectory() + subdir, c.port, c.logger);
Thread tudp = new Thread(smudp);
tudp.setName("server UDP P2P-JAVA-PROJECT");
tudp.setName("server UDP P2P-JAVA-PROJECT (port: " + c.port + ")");
tudp.start();
Thread ttcp = new Thread(smtcp);
ttcp.setName("server TCP P2P-JAVA-PROJECT");
ttcp.setName("server TCP P2P-JAVA-PROJECT (port: " + c.port + ")");
ttcp.start();
// Wait a bit before printing client interface
// This is not required, but allow to have a cleaner interface
try {
Thread.sleep(100);
} catch(InterruptedException e) {
Thread.currentThread().interrupt();
}
// initialize Host lists
c.hostList = HostList.getServList();
System.out.println("Client : Which transport protocol do you want to use? [TCP/udp]");
Scanner sc = new Scanner(System.in);

@ -4,13 +4,22 @@ import serverP2P.ServerManagementTCP;
import tools.Directories;
import tools.Logger;
/** Server only implementation
* First argument of main method is port listened by the server, and is mandatory.
* @author Louis Royer
* @author Flavien Haas
* @author JS Auge
* @version 1.0
*/
public class ServerP2P {
private int port;
private Directories directories;
static private final String subdir = "seeded/";
private Logger logger;
/** Constructor with portStr containing a port number.
* @param portStr String containing port number of listening.
*/
public ServerP2P(String portStr) {
port = Integer.valueOf(Integer.parseInt(portStr));
directories = new Directories("P2P_JAVA_PROJECT_SERVER_" + port);
@ -19,10 +28,13 @@ public class ServerP2P {
System.out.println("Server will listen on port " + port + " and serve files from " + directories.getDataHomeDirectory() + subdir);
directories.askOpenDataHomeDirectory(subdir);
}
/** Main program entry point
* first parameter is port number and is mandatory
* to test, run with: java -ea serverP2P.ServerP2P -- <portNumber>
* @param args parameters
*/
public static void main(String [] args) {
/* first arg must be port number
* run with: java -ea serverP2P.ServerP2P -- <portNumber>
* */
ServerP2P s = new ServerP2P(args[1]);
ServerManagementUDP smudp = new ServerManagementUDP(s.directories.getDataHomeDirectory() + subdir, s.port, s.logger);
ServerManagementTCP smtcp = new ServerManagementTCP(s.directories.getDataHomeDirectory() + subdir, s.port, s.logger);

Loading…
Cancel
Save