diff --git a/app/src/main/java/lightcontainer/domains/Task.java b/app/src/main/java/lightcontainer/domains/Task.java index 2ae95ed..d073814 100644 --- a/app/src/main/java/lightcontainer/domains/Task.java +++ b/app/src/main/java/lightcontainer/domains/Task.java @@ -42,6 +42,7 @@ public class Task { * @return TRUE si le client doit recevoir cette réponse. */ public boolean isResponseOfClient(String storeDomain) { + System.out.println(status + " - " + context.getDomain() + " | " + storeDomain); return (status == TaskStatus.PROCESSING && context.getDomain().equals(storeDomain)); } diff --git a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java index 5a5b439..dc9136f 100644 --- a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java +++ b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java @@ -110,30 +110,33 @@ public class ClientHandler implements Runnable, AutoCloseable { ProtocolWriter.ProtocolResult writerCommand = ruleResult.getResultCommand(); // TODO : Vérifier que le StorBackEnd demandé (Pas toujours demandé) est disponible if (ruleResult.getReceiver() == ProtocolReader.ResultCmdReceiver.STOREBACKEND && !fileFrontEnd.canExecuteCommand(ruleResult.getRequestDomain())) { + System.out.println("[1] 1"); writer.print(ruleResult.onNotExecutable(context)); // Renvoie au client writer.flush(); } else if (ruleResult.getReceiver() == ProtocolReader.ResultCmdReceiver.STOREBACKEND) { - + System.out.println("[1] 2"); fileFrontEnd.newCommand(context, writerCommand); // Envoie dans la file de tâche FileFrontEnd en attente d'un traitement d'un StorBackEnd // Attend la fin de la réalisation de la tâche waitTaskResponse(); - + System.out.println("[1] 4"); if (response != null) { + System.out.println("[1] 5"); writer.write(response.getCommand()); // Renvoie au client writer.flush(); response.write(this.client.getOutputStream()); // Ecrit au client si nécessaire } else { + System.out.println("[1] 6"); writer.print(ruleResult.onNotExecutable(context)); // Renvoie au client writer.flush(); } } else { + System.out.println("[1] 3"); writer.print(writerCommand.getCommand()); // Renvoie au client writer.flush(); } } else { - System.out.println(4); accessDenied(); } } catch (IOException e) { diff --git a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java index 9016510..7a90ddf 100644 --- a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java +++ b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java @@ -92,6 +92,7 @@ public class StoreProcessor extends Thread implements AutoCloseable { protocolResult.write(this.store.getOutputStream()); } catch (IOException writeException) { // Si SBE fermé System.out.println("STOPPER"); + writeException.printStackTrace(); // Envoie au client que la requête n'a pu être traitée alertAvailable(null); break; @@ -103,7 +104,7 @@ public class StoreProcessor extends Thread implements AutoCloseable { responseCommand += "\r\n"; ProtocolReader.ProtocolResult responseResult = protocolRep.executeReader(context, responseCommand); if (responseResult != null) { - System.out.println("StoreBackEnd response to client: " + responseResult.getResultCommand()); + System.out.println("StoreBackEnd (" + domain + ") response to client: " + responseResult.getResultCommand()); responseResult.read( this.store.getInputStream() ); @@ -207,7 +208,8 @@ public class StoreProcessor extends Thread implements AutoCloseable { return Objects.hash(domain); } - public boolean canProcessTask(Task task) { + public boolean canProcessTask() { + System.out.println("[OK 2] " + protocolResult + " - " + domain); return this.protocolResult == null; // Vérifier si tâche veut ce SBE } diff --git a/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java index 7d5b83a..7aee90a 100644 --- a/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java +++ b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java @@ -23,7 +23,7 @@ public interface MulticastSPR { */ boolean addStore(StoreProcessor store); - String findDomain(Task task); + String findDomain(); void assignTask(String stor, Task task); diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java index 0b97a1c..8b94735 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java @@ -19,7 +19,7 @@ import java.io.InputStream; */ public class SavefileRule extends ProtocolReader { // Constants - private static final String PATTERN = "^SAVE_FILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$"; + private static final String PATTERN = "^SAVEFILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$"; private static final String NAME = "SAVEFILE"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java index 132f20f..3fb0d57 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SendErrorRule.java @@ -12,7 +12,7 @@ public class SendErrorRule extends ProtocolReader { // Constants private static final String PATTERN = "^SEND_ERROR\r\n$"; - private static final String NAME = "SEND_ERROR"; + private static final String NAME = "SENDERROR"; private final ProtocolRepository protocolRep; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java index ef9a9b7..2873e48 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java @@ -28,16 +28,22 @@ public class SaveFileErrorRule extends ProtocolWriter { @Override protected ProtocolResult onExecuted(Context context, String... data) { ProtocolResult result = new ProtocolResult(context); + String fileName = context.getDataString("fileName"); + String fileNameSalt = context.getDataString("fileNameSalt"); - // Suppression du fichier temporaire dans le stockage du FFE - ShaHasher hasher = new ShaHasher(context.getLogin() + "_" + context.getDataString("fileName")); - try { - Files.deleteIfExists(Path.of( - String.format("%s/%s", this.storagePath, - hasher.fromSalt(hasher.saltToByte(context.getDataString("fileNameSalt"))) - ) - )); - } catch (IOException e) {} + + if (fileName != null && fileNameSalt != null) { + // Suppression du fichier temporaire dans le stockage du FFE + ShaHasher hasher = new ShaHasher(context.getLogin() + "_" + fileName); + try { + Files.deleteIfExists(Path.of( + String.format("%s/%s", this.storagePath, + hasher.fromSalt(hasher.saltToByte(fileNameSalt)) + ) + )); + } catch (IOException e) { + } + } return result; } diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java index 230cccd..d13aef2 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java @@ -27,6 +27,7 @@ public class SaveFileOkRule extends ProtocolWriter { protected ProtocolWriter.ProtocolResult onExecuted(Context context, String... data) { ProtocolWriter.ProtocolResult result = new ProtocolWriter.ProtocolResult(context); + System.out.println("===> Save en json " + context.getDomain() + " - " + context.getLogin()); // Sauvegarder dans JSON context.addFile(context.getDataString("fileName"), context.getDataString("fileNameSalt"), context.getDataInt("size"), context.getDataString("iv"), context.getDomain()); diff --git a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java index 39d4809..b816212 100644 --- a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java +++ b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java @@ -32,7 +32,7 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { */ public void alertStoreProcessors(Task task) { // On avertit les stor processors d'une nouvelle tâche - String stor = storeRepository.findDomain(task); + String stor = storeRepository.findDomain(); if (stor != null) { storeRepository.assignTask(stor, task); task.setDomain(stor); @@ -51,9 +51,7 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { Iterator it = tasks.iterator(); while (it.hasNext()) { Task task = it.next(); - System.out.println("Cherche"); if (task.isResponseOfClient(store.getDomain())) { - System.out.println("Task trouvée"); clientRepository.respondToClient(task.getClient(), response); it.remove(); // Suppression de la tâche break; @@ -73,7 +71,7 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { while (it.hasNext()) { Task task = it.next(); - if (store.canProcessTask(task)) { + if (task.getDomain() == null && store.canProcessTask()) { storeRepository.assignTask(store.getDomain(), task); task.setDomain(store.getDomain()); return; diff --git a/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java b/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java index aed6995..277636b 100644 --- a/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java +++ b/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java @@ -31,7 +31,6 @@ public class ProtocolRepositoryImpl implements ProtocolRepository { return command; } } - System.out.println("COMMANDE NULL"); return null; } diff --git a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java index 0d21f9d..78783d6 100644 --- a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java +++ b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java @@ -60,14 +60,14 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { } @Override - public String findDomain(Task task) { - StoreProcessor handler = findSBE(task); + public String findDomain() { + StoreProcessor handler = findSBE(); return handler == null ? null : handler.getDomain(); } - private StoreProcessor findSBE(Task task) { + private StoreProcessor findSBE() { for (StoreProcessor handler : handlers) { - if (handler.canProcessTask(task)) { + if (handler.canProcessTask()) { return handler; } } @@ -77,7 +77,7 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { @Override public void assignTask(String stor, Task task) { - StoreProcessor handler = findSBE(task); + StoreProcessor handler = findSBE(); System.out.println("Find stor : " + handler); handler.executeCommand(task.getContext(), task.getCommand()); } diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index 19b94ab..c053453 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1 +1,42 @@ -{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"wlp1s0","tls":true,"storagePath":"/home/benjamin/ffe","users":[{"name":"aaaaa","password":"$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W","aes_key":"kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=","files":[{"name":"main.py","fileNameSalt":"PLQB1QjPaKdfdM+zjywxcQ==","size":854,"iv":"UnkiNxFMYsRcw5fsEkr+5w==","storage":["lightcontainerSB01"]}]}]} \ No newline at end of file +{ + "unicast_port": 8000, + "multicast_ip": "224.66.66.1", + "multicast_port": 15502, + "network_interface": "wlp1s0", + "tls": true, + "storagePath": "/home/benjamin/ffe", + "users": [ + { + "name": "benjamin", + "password": "$2a$10$I4vHt83CTYuQCP7xvZ04Ne7Vb0cswBiVZhV0n23k9FCxoH0ny9fZG", + "aes_key": "mAP6izUBUhBxIkakH2yB/TplhRz1OQV5Fp6HQmhywns=", + "files": [ + { + "name": "README.md", + "fileNameSalt": "5k8bd3/hn5ehdkCRJ0MGRQ==", + "size": 17, + "iv": "/sEVBG7kKnMaJcg5Wpz2bQ==", + "storage": [ + "lightcontainerSB02" + ] + } + ] + }, + { + "name": "aaaaa", + "password": "$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W", + "aes_key": "kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=", + "files": [ + { + "name": "ca.crt", + "fileNameSalt": "JmISh065QAtDIePgl8IG2A==", + "size": 4207, + "iv": "Tg3aeOm1U0hQI1VqSZbAJw==", + "storage": [ + "lightcontainerSB01" + ] + } + ] + } + ] +} \ No newline at end of file