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 {
|
||||
private String subdir = "seeded/";
|
||||
private String parts = ".parts";
|
||||
private String logDir = "logs/";
|
||||
private String partsDir = ".parts/";
|
||||
private Logger loggerServer;
|
||||
private Logger loggerClient;
|
||||
private String host;
|
||||
@ -34,11 +34,13 @@ public class ClientP2P {
|
||||
/** Initialize loggers if directories and logger are null,
|
||||
* else fail silently.
|
||||
*/
|
||||
public void initLogger() {
|
||||
public void initDirectoriesAndLoggers() {
|
||||
if (directories == null && loggerServer == null && loggerClient == null) {
|
||||
directories = new Directories("P2P_JAVA_PROJECT_" + port);
|
||||
loggerServer = new Logger(directories.getDataHomeDirectory() + "server.log");
|
||||
loggerClient = new Logger(directories.getDataHomeDirectory() + "client.log");
|
||||
directories.createSubdir(logDir);
|
||||
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){
|
||||
int oldPort = port;
|
||||
port = defaultPort;
|
||||
initLogger();
|
||||
initDirectoriesAndLoggers();
|
||||
System.err.println("Error incorrect port " + oldPort + " using default port " + defaultPort);
|
||||
loggerServer.write("incorrect port " + oldPort + " using default port " + defaultPort, LogLevel.Info);
|
||||
}
|
||||
initLogger();
|
||||
directories.createSubdir(subdir);
|
||||
directories.createSubdir(parts);
|
||||
initDirectoriesAndLoggers();
|
||||
host = "localhost";
|
||||
System.out.println("Server will listen on port " + port + " and serve files from " + directories.getDataHomeDirectory() + subdir);
|
||||
directories.askOpenDataHomeDirectory(subdir, scanner);
|
||||
System.out.println("Server will listen on port " + port + " and serve files from " + directories.getDataHomeDirectory());
|
||||
directories.askOpenDataHomeDirectory(null, scanner);
|
||||
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
|
||||
ServerManagementUDP smudp = new ServerManagementUDP(c.directories.getDataHomeDirectory() + c.subdir, "localhost", c.port, c.loggerServer, c.tracker);
|
||||
ServerManagementTCP smtcp = new ServerManagementTCP(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(), "localhost", c.port, c.loggerServer, c.tracker);
|
||||
Thread tudp = new Thread(smudp);
|
||||
tudp.setName("server UDP P2P-JAVA-PROJECT (port: " + c.port + ")");
|
||||
tudp.start();
|
||||
@ -96,7 +96,7 @@ public class ClientP2P {
|
||||
// Wait a bit before printing client interface
|
||||
// This is not required, but allow to have a cleaner interface
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
Thread.sleep(200);
|
||||
} catch(InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
@ -112,7 +112,7 @@ public class ClientP2P {
|
||||
case "upd": // alias typo
|
||||
case "2" :
|
||||
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);
|
||||
break;
|
||||
case "TCP":
|
||||
@ -120,7 +120,7 @@ public class ClientP2P {
|
||||
case "1":
|
||||
default:
|
||||
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);
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user