From 20c5697301ba984736c1c75a63de891a84e518b0 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sun, 13 Mar 2022 21:12:19 +0100 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20:=20Deux=20SBE=20de=20m?= =?UTF-8?q?=C3=AAme=20domaine=20et=20ports=20diff=C3=A9rents=20ne=20peuven?= =?UTF-8?q?t=20plus=20=C3=AAtre=20connect=C3=A9s=20en=20m=C3=AAme=20temps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domains/client/StoreProcessor.java | 3 +- .../server/MulticastServerListener.java | 12 ++--- .../interfaces/MulticastSPR.java | 2 +- .../repository/StoreProcessorRepository.java | 9 ++-- app/src/main/resources/appdata.json | 44 ++++++++++++++++++- 5 files changed, 58 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java index 8fb1316..158f308 100644 --- a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java +++ b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java @@ -45,7 +45,6 @@ public class StoreProcessor extends Thread implements AutoCloseable { this.store = socket; this.protocolRep = protocolRep; this.client_run = false; - initStore(); } /** @@ -55,7 +54,7 @@ public class StoreProcessor extends Thread implements AutoCloseable { * @see PrintWriter * @since 1.0 */ - private void initStore() { + public void startStore() { try { this.reader = new BufferedReader(new InputStreamReader( this.store.getInputStream(), diff --git a/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java b/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java index 96342f0..fe4b12a 100644 --- a/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java +++ b/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java @@ -70,13 +70,15 @@ public class MulticastServerListener implements Runnable { HelloRule.Result readerResult = protocolRep.executeReader(null, data); System.out.printf("Nouveau SBE : Domain=%s | Port=%d\n", readerResult.getDomain(), readerResult.getPort()); - Socket socket = new Socket(packet.getAddress(), readerResult.getPort()); + if (!this.repository.hasDomain(readerResult.getDomain())){ + Socket socket = new Socket(packet.getAddress(), readerResult.getPort()); - // Create the store processor - StoreProcessor storeProcessor = new StoreProcessor(socket, readerResult.getDomain(), ffe, protocolRep); // TODO : Voir comment on procède get via repo ou ici ?! + // Create the store processor + StoreProcessor storeProcessor = new StoreProcessor(socket, readerResult.getDomain(), ffe, protocolRep); // TODO : Voir comment on procède get via repo ou ici ?! - // Add the store processor to its repository - this.repository.addStore(storeProcessor); + // Add the store processor to its repository + this.repository.addStore(storeProcessor); + } } catch (IOException ignore) { ignore.printStackTrace(); } diff --git a/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java index 5f352e7..9d1caa2 100644 --- a/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java +++ b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java @@ -19,7 +19,7 @@ public interface MulticastSPR { * Add a StorePorcessor. * @param store Store processor to add. */ - void addStore(StoreProcessor store); + boolean addStore(StoreProcessor store); String findDomain(Task task); diff --git a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java index 769208a..293b1a4 100644 --- a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java +++ b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java @@ -50,9 +50,12 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { * @since 1.0 */ @Override - public void addStore(StoreProcessor store) { - this.handlers.add(store); - + public boolean addStore(StoreProcessor store) { + if (!this.hasDomain(store.getDomain())) { + store.startStore(); + return this.handlers.add(store); + } + return false; } @Override diff --git a/app/src/main/resources/appdata.json b/app/src/main/resources/appdata.json index f9171fe..a32ef4a 100644 --- a/app/src/main/resources/appdata.json +++ b/app/src/main/resources/appdata.json @@ -1 +1,43 @@ -{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"My network interface","tls":true,"storagePath":"/home/benjamin/ffe","users":[{"name":"aaaaa","password":"5d628c274ebb008324f1e199d3bfff0a3fe839730a7f2355e82850d7acca5e5ca64db9071abf3d91034295695f84a617","aes_key":"qlTH6TijnfMRnrS0Qf+k6IPKGp5LoRMXGxCq16e+mF4=","passwordSalt":"Ns8Al6DpqPsIDlCSRBVTEg==","files":[{"name":"main.py","fileNameSalt":"IJNYL681pFqbF9OHzRuHIg==","size":854,"iv":"bPCnwYbenKvFfwbhq+HI5A==","storage":["lightcontainerSB01"]},{"name":"README.md","fileNameSalt":"/jo0zYyQs96gWI9OgBXiPQ==","size":17,"iv":"rvOFhgEvgFMISO44jqlSRg==","storage":["lightcontainerSB01"]}]}]} \ No newline at end of file +{ + "unicast_port": 8000, + "multicast_ip": "224.66.66.1", + "multicast_port": 15502, + "network_interface": "My network interface", + "tls": true, + "storagePath": "/home/benjamin/ffe", + "users": [ + { + "name": "aaaaa", + "password": "5d628c274ebb008324f1e199d3bfff0a3fe839730a7f2355e82850d7acca5e5ca64db9071abf3d91034295695f84a617", + "aes_key": "qlTH6TijnfMRnrS0Qf+k6IPKGp5LoRMXGxCq16e+mF4=", + "passwordSalt": "Ns8Al6DpqPsIDlCSRBVTEg==", + "files": [ + { + "name": "main.py", + "fileNameSalt": "IJNYL681pFqbF9OHzRuHIg==", + "size": 854, + "iv": "bPCnwYbenKvFfwbhq+HI5A==", + "storage": [ + "lightcontainerSB01" + ] + }, + { + "name": "README.md", + "fileNameSalt": "/jo0zYyQs96gWI9OgBXiPQ==", + "size": 17, + "iv": "rvOFhgEvgFMISO44jqlSRg==", + "storage": [ + "lightcontainerSB01" + ] + } + ] + }, + { + "name": "test1", + "password": "4348c6955fc61e81fd952e218734cb8af04df549adca990ad6bd7f46e983ebcc1ea6ddb1bee08db8c670100219597e92", + "aes_key": "UZsJ6PT6WfKptNXIlY5vPnXkjlvL36Pq3z3vLdVl/5s=", + "passwordSalt": "1a5BS3tyqpSSwvv/nTQcVA==", + "files": [] + } + ] +} \ No newline at end of file