|
|
@ -21,7 +21,7 @@ import tools.TrackerPortRange;
|
|
|
|
* @version 1.0
|
|
|
|
* @version 1.0
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
public class ClientP2P {
|
|
|
|
public class ClientP2Pgui {
|
|
|
|
private String logDir = "logs/";
|
|
|
|
private String logDir = "logs/";
|
|
|
|
private String partsDir = ".parts/";
|
|
|
|
private String partsDir = ".parts/";
|
|
|
|
private Logger loggerServer;
|
|
|
|
private Logger loggerServer;
|
|
|
@ -55,26 +55,29 @@ public class ClientP2P {
|
|
|
|
* @param hostnameTracker hostname of tracker
|
|
|
|
* @param hostnameTracker hostname of tracker
|
|
|
|
* @param portTracker port of tracker
|
|
|
|
* @param portTracker port of tracker
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public ClientP2P(String hostnameServer, int portServer, String hostnameTracker, int portTracker, String protocolP2P) {
|
|
|
|
public ClientP2Pgui(String hostnameServer, int portServer, String hostnameTracker, int portTracker, String protocolP2P) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (directories == null && loggerServer == null && loggerClient == null) {
|
|
|
|
|
|
|
|
directories = new Directories("P2P_JAVA_PROJECT_" + server.getPort());
|
|
|
|
|
|
|
|
directories.createSubdir(logDir);
|
|
|
|
|
|
|
|
loggerServer = new Logger(directories.getDataHomeDirectory() + logDir + "server.log", DEBUG);
|
|
|
|
|
|
|
|
loggerClient = new Logger(directories.getDataHomeDirectory() + logDir + "client.log", DEBUG);
|
|
|
|
|
|
|
|
directories.createSubdir(partsDir);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.hostnameServer = hostnameServer;
|
|
|
|
this.hostnameServer = hostnameServer;
|
|
|
|
this.hostnameTracker = hostnameTracker;
|
|
|
|
this.hostnameTracker = hostnameTracker;
|
|
|
|
this.portServer = portServer;
|
|
|
|
this.portServer = portServer;
|
|
|
|
this.portTracker = portTracker;
|
|
|
|
this.portTracker = portTracker;
|
|
|
|
this.protocolP2P = protocolP2P;
|
|
|
|
this.protocolP2P = protocolP2P;
|
|
|
|
|
|
|
|
|
|
|
|
final ServerPortRange serverPortRange = new ServerPortRange();
|
|
|
|
final ServerPortRange serverPortRange = new ServerPortRange();
|
|
|
|
final TrackerPortRange trackerPortRange = new TrackerPortRange();
|
|
|
|
final TrackerPortRange trackerPortRange = new TrackerPortRange();
|
|
|
|
|
|
|
|
|
|
|
|
if (!serverPortRange.isPortInRange(portServer)){
|
|
|
|
if (!serverPortRange.isPortInRange(portServer)){
|
|
|
|
ErrorFrame erreur = new ErrorFrame("SERVER: Port not in range. ");
|
|
|
|
ErrorFrame erreur = new ErrorFrame("SERVER: Port not in range. ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!trackerPortRange.isPortInRange(portTracker)){
|
|
|
|
if (!trackerPortRange.isPortInRange(portTracker)){
|
|
|
|
ErrorFrame erreur = new ErrorFrame("TRACKER: Port not in range");
|
|
|
|
ErrorFrame erreur = new ErrorFrame("TRACKER: Port not in range");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server = new HostItem(hostnameServer, portServer);
|
|
|
|
server = new HostItem(hostnameServer, portServer);
|
|
|
|
tracker = new HostItem(hostnameTracker, portTracker);
|
|
|
|
tracker = new HostItem(hostnameTracker, portTracker);
|
|
|
|
initDirectoriesAndLoggers();
|
|
|
|
initDirectoriesAndLoggers();
|
|
|
@ -106,14 +109,14 @@ public class ClientP2P {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Thread tclient;
|
|
|
|
Thread tclient;
|
|
|
|
switch (protocolClient) {
|
|
|
|
switch (protocolP2P) {
|
|
|
|
case "UDP":
|
|
|
|
case "UDP":
|
|
|
|
case "udp":
|
|
|
|
case "udp":
|
|
|
|
case "upd": // to avoid users typos
|
|
|
|
case "upd": // to avoid users typos
|
|
|
|
case "2" :
|
|
|
|
case "2" :
|
|
|
|
System.out.println("Starting with UDP");
|
|
|
|
System.out.println("Starting with UDP");
|
|
|
|
ClientManagementUDP cmudp = new ClientManagementUDP(directories.getDataHomeDirectory(), tracker, directories.getDataHomeDirectory() + partsDir, loggerClient, server);
|
|
|
|
ClientManagementUDP cmudp = new ClientManagementUDP(directories.getDataHomeDirectory(), tracker, directories.getDataHomeDirectory() + partsDir, loggerClient, server);
|
|
|
|
tclient = new Thread(new ClientInterfaceCLI(cmudp, loggerClient));
|
|
|
|
tclient = new Thread(new ClientInterfaceGUI(cmudp, loggerClient));
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "TCP":
|
|
|
|
case "TCP":
|
|
|
|
case "tcp":
|
|
|
|
case "tcp":
|
|
|
@ -121,10 +124,10 @@ public class ClientP2P {
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
System.out.println("Starting with TCP");
|
|
|
|
System.out.println("Starting with TCP");
|
|
|
|
ClientManagementTCP cmtcp = new ClientManagementTCP(directories.getDataHomeDirectory(), tracker, directories.getDataHomeDirectory() + partsDir, loggerClient, server);
|
|
|
|
ClientManagementTCP cmtcp = new ClientManagementTCP(directories.getDataHomeDirectory(), tracker, directories.getDataHomeDirectory() + partsDir, loggerClient, server);
|
|
|
|
tclient = new Thread(new ClientInterfaceCLI(cmtcp, loggerClient));
|
|
|
|
tclient = new Thread(new ClientInterfaceGUI(cmtcp, loggerClient));
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tclient.setName("client P2P-JAVA-PROJECT");
|
|
|
|
tclient.setName("client P2P-JAVA-PROJECT GUI");
|
|
|
|
tclient.start();
|
|
|
|
tclient.start();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
tclient.join();
|
|
|
|
tclient.join();
|
|
|
|