Merge branch 'benjamin' into dev

# Conflicts:
#	app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java
#	app/src/main/resources/appdata.json
This commit is contained in:
Benjamin 2022-03-19 14:15:18 +01:00
commit a287bbdb59
11 changed files with 53 additions and 47 deletions

View File

@ -42,6 +42,7 @@ public class Task {
* @return TRUE si le client doit recevoir cette réponse. * @return TRUE si le client doit recevoir cette réponse.
*/ */
public boolean isResponseOfClient(String storeDomain) { public boolean isResponseOfClient(String storeDomain) {
System.out.println(status + " - " + context.getDomain() + " | " + storeDomain);
return (status == TaskStatus.PROCESSING && context.getDomain().equals(storeDomain)); return (status == TaskStatus.PROCESSING && context.getDomain().equals(storeDomain));
} }

View File

@ -110,30 +110,33 @@ public class ClientHandler implements Runnable, AutoCloseable {
ProtocolWriter.ProtocolResult writerCommand = ruleResult.getResultCommand(); ProtocolWriter.ProtocolResult writerCommand = ruleResult.getResultCommand();
// TODO : Vérifier que le StorBackEnd demandé (Pas toujours demandé) est disponible // TODO : Vérifier que le StorBackEnd demandé (Pas toujours demandé) est disponible
if (ruleResult.getReceiver() == ProtocolReader.ResultCmdReceiver.STOREBACKEND && !fileFrontEnd.canExecuteCommand(ruleResult.getRequestDomain())) { if (ruleResult.getReceiver() == ProtocolReader.ResultCmdReceiver.STOREBACKEND && !fileFrontEnd.canExecuteCommand(ruleResult.getRequestDomain())) {
System.out.println("[1] 1");
writer.print(ruleResult.onNotExecutable(context)); // Renvoie au client writer.print(ruleResult.onNotExecutable(context)); // Renvoie au client
writer.flush(); writer.flush();
} else if (ruleResult.getReceiver() == ProtocolReader.ResultCmdReceiver.STOREBACKEND) { } 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 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 // Attend la fin de la réalisation de la tâche
waitTaskResponse(); waitTaskResponse();
System.out.println("[1] 4");
if (response != null) { if (response != null) {
System.out.println("[1] 5");
writer.write(response.getCommand()); // Renvoie au client writer.write(response.getCommand()); // Renvoie au client
writer.flush(); writer.flush();
response.write(this.client.getOutputStream()); // Ecrit au client si nécessaire response.write(this.client.getOutputStream()); // Ecrit au client si nécessaire
} else { } else {
System.out.println("[1] 6");
writer.print(ruleResult.onNotExecutable(context)); // Renvoie au client writer.print(ruleResult.onNotExecutable(context)); // Renvoie au client
writer.flush(); writer.flush();
} }
} else { } else {
System.out.println("[1] 3");
writer.print(writerCommand.getCommand()); // Renvoie au client writer.print(writerCommand.getCommand()); // Renvoie au client
writer.flush(); writer.flush();
} }
} else { } else {
System.out.println(4);
accessDenied(); accessDenied();
} }
} catch (IOException e) { } catch (IOException e) {

View File

@ -79,9 +79,12 @@ public class StoreProcessor extends Thread implements AutoCloseable {
@Override @Override
public void run() { public void run() {
this.client_run = true; this.client_run = true;
while (this.client_run) { while (this.client_run) {
try { try {
waitAction(); if (protocolResult == null) { // Si on n'a pas encore la commande à envoyer
waitAction();
}
System.out.println("[SBE] Envoie commande : " + protocolResult.getCommand()); System.out.println("[SBE] Envoie commande : " + protocolResult.getCommand());
// Request // Request
@ -92,6 +95,7 @@ public class StoreProcessor extends Thread implements AutoCloseable {
protocolResult.write(this.store.getOutputStream()); protocolResult.write(this.store.getOutputStream());
} catch (IOException writeException) { // Si SBE fermé } catch (IOException writeException) { // Si SBE fermé
System.out.println("STOPPER"); System.out.println("STOPPER");
writeException.printStackTrace();
// Envoie au client que la requête n'a pu être traitée // Envoie au client que la requête n'a pu être traitée
alertAvailable(null); alertAvailable(null);
break; break;
@ -103,7 +107,7 @@ public class StoreProcessor extends Thread implements AutoCloseable {
responseCommand += "\r\n"; responseCommand += "\r\n";
ProtocolReader.ProtocolResult responseResult = protocolRep.executeReader(context, responseCommand); ProtocolReader.ProtocolResult responseResult = protocolRep.executeReader(context, responseCommand);
if (responseResult != null) { if (responseResult != null) {
System.out.println("StoreBackEnd response to client: " + responseResult.getResultCommand()); System.out.println("StoreBackEnd (" + domain + ") response to client: " + responseResult.getResultCommand());
responseResult.read( responseResult.read(
this.store.getInputStream() this.store.getInputStream()
); );
@ -207,7 +211,7 @@ public class StoreProcessor extends Thread implements AutoCloseable {
return Objects.hash(domain); return Objects.hash(domain);
} }
public boolean canProcessTask(Task task) { public boolean canProcessTask() {
return this.protocolResult == null; // Vérifier si tâche veut ce SBE return this.protocolResult == null; // Vérifier si tâche veut ce SBE
} }

View File

@ -23,7 +23,7 @@ public interface MulticastSPR {
*/ */
boolean addStore(StoreProcessor store); boolean addStore(StoreProcessor store);
String findDomain(Task task); String findDomain();
void assignTask(String stor, Task task); void assignTask(String stor, Task task);

View File

@ -16,7 +16,7 @@ public class SendErrorRule extends ProtocolReader {
//"^SEND_ERROR\r\n$" //"^SEND_ERROR\r\n$"
private static final String PATTERN = SBE_SEND_RESULT_ERROR; private static final String PATTERN = SBE_SEND_RESULT_ERROR;
private static final String NAME = "SEND_ERROR"; private static final String NAME = "SENDERROR";
private final ProtocolRepository protocolRep; private final ProtocolRepository protocolRep;

View File

@ -31,16 +31,21 @@ public class SaveFileErrorRule extends ProtocolWriter {
@Override @Override
protected ProtocolResult onExecuted(Context context, String... data) { protected ProtocolResult onExecuted(Context context, String... data) {
ProtocolResult result = new ProtocolResult(context); 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")); if (fileName != null && fileNameSalt != null) {
try { // Suppression du fichier temporaire dans le stockage du FFE
Files.deleteIfExists(Path.of( ShaHasher hasher = new ShaHasher(context.getLogin() + "_" + fileName);
String.format("%s/%s", this.storagePath, try {
hasher.fromSalt(hasher.saltToByte(context.getDataString("fileNameSalt"))) Files.deleteIfExists(Path.of(
) String.format("%s/%s", this.storagePath,
)); hasher.fromSalt(hasher.saltToByte(fileNameSalt))
} catch (IOException e) { )
));
} catch (IOException e) {
}
} }
return result; return result;

View File

@ -30,6 +30,7 @@ public class SaveFileOkRule extends ProtocolWriter {
protected ProtocolWriter.ProtocolResult onExecuted(Context context, String... data) { protected ProtocolWriter.ProtocolResult onExecuted(Context context, String... data) {
ProtocolWriter.ProtocolResult result = new ProtocolWriter.ProtocolResult(context); ProtocolWriter.ProtocolResult result = new ProtocolWriter.ProtocolResult(context);
System.out.println("===> Save en json " + context.getDomain() + " - " + context.getLogin());
// Sauvegarder dans JSON // Sauvegarder dans JSON
context.addFile(context.getDataString("fileName"), context.getDataString("fileNameSalt"), context.getDataInt("size"), context.getDataString("iv"), context.getDomain()); context.addFile(context.getDataString("fileName"), context.getDataString("fileNameSalt"), context.getDataInt("size"), context.getDataString("iv"), context.getDomain());

View File

@ -32,7 +32,7 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE {
*/ */
public void alertStoreProcessors(Task task) { public void alertStoreProcessors(Task task) {
// On avertit les stor processors d'une nouvelle tâche // On avertit les stor processors d'une nouvelle tâche
String stor = storeRepository.findDomain(task); String stor = storeRepository.findDomain();
if (stor != null) { if (stor != null) {
storeRepository.assignTask(stor, task); storeRepository.assignTask(stor, task);
task.setDomain(stor); task.setDomain(stor);
@ -51,9 +51,7 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE {
Iterator<Task> it = tasks.iterator(); Iterator<Task> it = tasks.iterator();
while (it.hasNext()) { while (it.hasNext()) {
Task task = it.next(); Task task = it.next();
System.out.println("Cherche");
if (task.isResponseOfClient(store.getDomain())) { if (task.isResponseOfClient(store.getDomain())) {
System.out.println("Task trouvée");
clientRepository.respondToClient(task.getClient(), response); clientRepository.respondToClient(task.getClient(), response);
it.remove(); // Suppression de la tâche it.remove(); // Suppression de la tâche
break; break;
@ -70,12 +68,11 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE {
private void assignOtherTask(StoreProcessor store) { private void assignOtherTask(StoreProcessor store) {
Iterator<Task> it = tasks.iterator(); Iterator<Task> it = tasks.iterator();
while (it.hasNext()) { while (it.hasNext()) {
Task task = it.next(); Task task = it.next();
if (store.canProcessTask(task)) { if (task.getDomain() == null && store.canProcessTask()) {
storeRepository.assignTask(store.getDomain(), task);
task.setDomain(store.getDomain()); task.setDomain(store.getDomain());
store.executeCommand(task.getContext(), task.getCommand());
return; return;
} }
} }

View File

@ -31,7 +31,6 @@ public class ProtocolRepositoryImpl implements ProtocolRepository {
return command; return command;
} }
} }
System.out.println("COMMANDE NULL");
return null; return null;
} }

View File

@ -60,14 +60,24 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR {
} }
@Override @Override
public String findDomain(Task task) { public String findDomain() {
StoreProcessor handler = findSBE(task); StoreProcessor handler = findSBE();
return handler == null ? null : handler.getDomain(); return handler == null ? null : handler.getDomain();
} }
private StoreProcessor findSBE(Task task) { private StoreProcessor findSBE() {
for (StoreProcessor handler : handlers) { for (StoreProcessor handler : handlers) {
if (handler.canProcessTask(task)) { if (handler.canProcessTask()) {
return handler;
}
}
return null;
}
private StoreProcessor getSBE(String stor) {
for (StoreProcessor handler : handlers) {
if (handler.getDomain().equals(stor)) {
return handler; return handler;
} }
} }
@ -77,9 +87,10 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR {
@Override @Override
public void assignTask(String stor, Task task) { public void assignTask(String stor, Task task) {
StoreProcessor handler = findSBE(task); StoreProcessor handler = getSBE(stor);
System.out.println("Find stor : " + handler); if (handler != null) {
handler.executeCommand(task.getContext(), task.getCommand()); handler.executeCommand(task.getContext(), task.getCommand());
}
} }
@Override @Override

View File

@ -1,16 +1 @@
{ {"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":"atK0eGo/J8IBOTCpIZpWow==","size":17,"iv":"fXPzefxl0cO4Hf02Qwi+BA==","storage":["lightcontainerSB01"]}]},{"name":"aaaaa","password":"$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W","aes_key":"kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=","files":[{"name":"ca.crt","fileNameSalt":"qz6FoPGyJJ8Hy+1LIouvZA==","size":4207,"iv":"8v2H+cOzztD++NXHXw5Ofw==","storage":["lightcontainerSB01"]}]}]}
"unicast_port": 8000,
"multicast_ip": "224.66.66.1",
"multicast_port": 15502,
"network_interface": "lo",
"tls": true,
"storagePath": "C:\\Users\\ledou\\Documents\\ffe",
"users": [
{
"name": "aaaaa",
"password": "$2a$10$bRdd0/8R60TNUbwtq2dMbun.TAPOZlqxJ/UB7qL2rgxHBuZownH0.",
"aes_key": "FwwA+Mkg94TsXeBuReE6wD3QEsVnrnuIXPtzCLFtdJM=",
"files": []
}
]
}