Amélioration : Deux SBE de même domaine et ports différents ne peuvent plus être connectés en même temps

This commit is contained in:
Maximilien LEDOUX 2022-03-13 21:12:19 +01:00
parent e5628942a2
commit 20c5697301
5 changed files with 58 additions and 12 deletions

View File

@ -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(),

View File

@ -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();
}

View File

@ -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);

View File

@ -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

View File

@ -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"]}]}]}
{
"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": []
}
]
}