Fix #27
- [x] Télécharger dans le même dossier que celui où on seed - [x] Mettre les logs dans un dossier pas partagé
This commit is contained in:
parent
e0dca481fb
commit
0253f38b4d
@ -19,8 +19,8 @@ import tools.HostItem;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class ClientP2P {
|
public class ClientP2P {
|
||||||
private String subdir = "seeded/";
|
private String logDir = "logs/";
|
||||||
private String parts = ".parts";
|
private String partsDir = ".parts/";
|
||||||
private Logger loggerServer;
|
private Logger loggerServer;
|
||||||
private Logger loggerClient;
|
private Logger loggerClient;
|
||||||
private String host;
|
private String host;
|
||||||
@ -34,11 +34,13 @@ public class ClientP2P {
|
|||||||
/** Initialize loggers if directories and logger are null,
|
/** Initialize loggers if directories and logger are null,
|
||||||
* else fail silently.
|
* else fail silently.
|
||||||
*/
|
*/
|
||||||
public void initLogger() {
|
public void initDirectoriesAndLoggers() {
|
||||||
if (directories == null && loggerServer == null && loggerClient == null) {
|
if (directories == null && loggerServer == null && loggerClient == null) {
|
||||||
directories = new Directories("P2P_JAVA_PROJECT_" + port);
|
directories = new Directories("P2P_JAVA_PROJECT_" + port);
|
||||||
loggerServer = new Logger(directories.getDataHomeDirectory() + "server.log");
|
directories.createSubdir(logDir);
|
||||||
loggerClient = new Logger(directories.getDataHomeDirectory() + "client.log");
|
loggerServer = new Logger(directories.getDataHomeDirectory() + logDir + "server.log");
|
||||||
|
loggerClient = new Logger(directories.getDataHomeDirectory() + logDir + "client.log");
|
||||||
|
directories.createSubdir(partsDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,16 +55,14 @@ public class ClientP2P {
|
|||||||
} catch (NumberFormatException e){
|
} catch (NumberFormatException e){
|
||||||
int oldPort = port;
|
int oldPort = port;
|
||||||
port = defaultPort;
|
port = defaultPort;
|
||||||
initLogger();
|
initDirectoriesAndLoggers();
|
||||||
System.err.println("Error incorrect port " + oldPort + " using default port " + defaultPort);
|
System.err.println("Error incorrect port " + oldPort + " using default port " + defaultPort);
|
||||||
loggerServer.write("incorrect port " + oldPort + " using default port " + defaultPort, LogLevel.Info);
|
loggerServer.write("incorrect port " + oldPort + " using default port " + defaultPort, LogLevel.Info);
|
||||||
}
|
}
|
||||||
initLogger();
|
initDirectoriesAndLoggers();
|
||||||
directories.createSubdir(subdir);
|
|
||||||
directories.createSubdir(parts);
|
|
||||||
host = "localhost";
|
host = "localhost";
|
||||||
System.out.println("Server will listen on port " + port + " and serve files from " + directories.getDataHomeDirectory() + subdir);
|
System.out.println("Server will listen on port " + port + " and serve files from " + directories.getDataHomeDirectory());
|
||||||
directories.askOpenDataHomeDirectory(subdir, scanner);
|
directories.askOpenDataHomeDirectory(null, scanner);
|
||||||
System.out.println("Please enter list of servers to use; first one will be used to ask list of files");
|
System.out.println("Please enter list of servers to use; first one will be used to ask list of files");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,8 +84,8 @@ public class ClientP2P {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Server threads
|
// Server threads
|
||||||
ServerManagementUDP smudp = new ServerManagementUDP(c.directories.getDataHomeDirectory() + c.subdir, "localhost", c.port, c.loggerServer, c.tracker);
|
ServerManagementUDP smudp = new ServerManagementUDP(c.directories.getDataHomeDirectory(), "localhost", c.port, c.loggerServer, c.tracker);
|
||||||
ServerManagementTCP smtcp = new ServerManagementTCP(c.directories.getDataHomeDirectory() + c.subdir, "localhost", c.port, c.loggerServer, c.tracker);
|
ServerManagementTCP smtcp = new ServerManagementTCP(c.directories.getDataHomeDirectory(), "localhost", c.port, c.loggerServer, c.tracker);
|
||||||
Thread tudp = new Thread(smudp);
|
Thread tudp = new Thread(smudp);
|
||||||
tudp.setName("server UDP P2P-JAVA-PROJECT (port: " + c.port + ")");
|
tudp.setName("server UDP P2P-JAVA-PROJECT (port: " + c.port + ")");
|
||||||
tudp.start();
|
tudp.start();
|
||||||
@ -96,7 +96,7 @@ public class ClientP2P {
|
|||||||
// Wait a bit before printing client interface
|
// Wait a bit before printing client interface
|
||||||
// This is not required, but allow to have a cleaner interface
|
// This is not required, but allow to have a cleaner interface
|
||||||
try {
|
try {
|
||||||
Thread.sleep(100);
|
Thread.sleep(200);
|
||||||
} catch(InterruptedException e) {
|
} catch(InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ public class ClientP2P {
|
|||||||
case "upd": // alias typo
|
case "upd": // alias typo
|
||||||
case "2" :
|
case "2" :
|
||||||
System.out.println("Starting with UDP");
|
System.out.println("Starting with UDP");
|
||||||
ClientManagementUDP cmudp = new ClientManagementUDP(c.directories.getDataHomeDirectory(), c.tracker, c.directories.getDataHomeDirectory() + c.parts + "/", c.loggerClient, c.scanner);
|
ClientManagementUDP cmudp = new ClientManagementUDP(c.directories.getDataHomeDirectory(), c.tracker, c.directories.getDataHomeDirectory() + c.partsDir, c.loggerClient, c.scanner);
|
||||||
t = new Thread(cmudp);
|
t = new Thread(cmudp);
|
||||||
break;
|
break;
|
||||||
case "TCP":
|
case "TCP":
|
||||||
@ -120,7 +120,7 @@ public class ClientP2P {
|
|||||||
case "1":
|
case "1":
|
||||||
default:
|
default:
|
||||||
System.out.println("Starting with TCP");
|
System.out.println("Starting with TCP");
|
||||||
ClientManagementTCP cmtcp = new ClientManagementTCP(c.directories.getDataHomeDirectory(), c.tracker, c.directories.getDataHomeDirectory() + c.parts + "/", c.loggerClient, c.scanner);
|
ClientManagementTCP cmtcp = new ClientManagementTCP(c.directories.getDataHomeDirectory(), c.tracker, c.directories.getDataHomeDirectory() + c.partsDir, c.loggerClient, c.scanner);
|
||||||
t = new Thread(cmtcp);
|
t = new Thread(cmtcp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user