Merge branch 'benjamin' into dev
This commit is contained in:
commit
cd9a8164ef
@ -35,3 +35,8 @@ tasks.named('test') {
|
|||||||
// Use JUnit Platform for unit tests.
|
// Use JUnit Platform for unit tests.
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
run {
|
||||||
|
standardInput = System.in
|
||||||
|
}
|
@ -36,7 +36,7 @@ public class App {
|
|||||||
// Initialisation du dispatcher et des servers
|
// Initialisation du dispatcher et des servers
|
||||||
FileFrontEnd ffe = new FileFrontEnd(clientRep, storeRep, protocolRep);
|
FileFrontEnd ffe = new FileFrontEnd(clientRep, storeRep, protocolRep);
|
||||||
new UnicastServerListener(ffe, clientRep, protocolRep, repositoryStorage, repositoryStorage.getUnicastPort());
|
new UnicastServerListener(ffe, clientRep, protocolRep, repositoryStorage, repositoryStorage.getUnicastPort());
|
||||||
new MulticastServerListener(ffe, storeRep, protocolRep, repositoryStorage.getMulticastIp(), repositoryStorage.getMulticastPort());
|
new MulticastServerListener(ffe, storeRep, protocolRep, repositoryStorage.getMulticastIp(), repositoryStorage.getMulticastPort(), repositoryStorage.getNetworkInterface());
|
||||||
|
|
||||||
// close repo et client et server.
|
// close repo et client et server.
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import lightcontainer.interfaces.ProtocolRepository;
|
|||||||
import lightcontainer.protocol.ProtocolReader;
|
import lightcontainer.protocol.ProtocolReader;
|
||||||
import lightcontainer.protocol.rules.reader.HelloRule;
|
import lightcontainer.protocol.rules.reader.HelloRule;
|
||||||
import lightcontainer.repository.FileFrontEnd;
|
import lightcontainer.repository.FileFrontEnd;
|
||||||
|
import lightcontainer.utils.NetChooser;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
@ -25,6 +26,7 @@ public class MulticastServerListener implements Runnable {
|
|||||||
// Variable
|
// Variable
|
||||||
private final String multicast_address;
|
private final String multicast_address;
|
||||||
private final int multicast_port;
|
private final int multicast_port;
|
||||||
|
private final String network_interface;
|
||||||
private FileFrontEnd ffe;
|
private FileFrontEnd ffe;
|
||||||
private final MulticastSPR repository;
|
private final MulticastSPR repository;
|
||||||
private final ProtocolRepository protocolRep;
|
private final ProtocolRepository protocolRep;
|
||||||
@ -33,12 +35,13 @@ public class MulticastServerListener implements Runnable {
|
|||||||
private MulticastSocket listener;
|
private MulticastSocket listener;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
public MulticastServerListener(FileFrontEnd ffe, MulticastSPR repository, ProtocolRepository protocolRep, String multicast_address, int multicast_port) {
|
public MulticastServerListener(FileFrontEnd ffe, MulticastSPR repository, ProtocolRepository protocolRep, String multicast_address, int multicast_port, String network_interface) {
|
||||||
this.ffe = ffe;
|
this.ffe = ffe;
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.protocolRep = protocolRep;
|
this.protocolRep = protocolRep;
|
||||||
this.multicast_address = multicast_address;
|
this.multicast_address = multicast_address;
|
||||||
this.multicast_port = multicast_port;
|
this.multicast_port = multicast_port;
|
||||||
|
this.network_interface = network_interface;
|
||||||
repository.setServerListener(this);
|
repository.setServerListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,6 +57,9 @@ public class MulticastServerListener implements Runnable {
|
|||||||
try {
|
try {
|
||||||
// Create a new listening socket
|
// Create a new listening socket
|
||||||
this.listener = new MulticastSocket(this.multicast_port);
|
this.listener = new MulticastSocket(this.multicast_port);
|
||||||
|
|
||||||
|
this.selectInterface();
|
||||||
|
|
||||||
// Create an identifier for the multicast group on the specified ip
|
// Create an identifier for the multicast group on the specified ip
|
||||||
InetAddress listener_group = InetAddress.getByName(this.multicast_address);
|
InetAddress listener_group = InetAddress.getByName(this.multicast_address);
|
||||||
// Creation of a packet for the information received
|
// Creation of a packet for the information received
|
||||||
@ -87,6 +93,23 @@ public class MulticastServerListener implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permet de choisir l'interface réseau d'écoute en Multicast
|
||||||
|
*/
|
||||||
|
private void selectInterface() {
|
||||||
|
try {
|
||||||
|
this.listener.setNetworkInterface(NetworkInterface.getByName(network_interface));
|
||||||
|
} catch (SocketException| NullPointerException e) {
|
||||||
|
NetChooser netChooser = new NetChooser();
|
||||||
|
try {
|
||||||
|
this.listener.setNetworkInterface(netChooser.requestInterface());
|
||||||
|
} catch (SocketException socketException) {
|
||||||
|
socketException.printStackTrace();
|
||||||
|
this.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the MulticastSocket connection and aborts the listening and infinite listening loop.
|
* Closes the MulticastSocket connection and aborts the listening and infinite listening loop.
|
||||||
*
|
*
|
||||||
|
@ -158,4 +158,8 @@ public class Repository {
|
|||||||
public List<String> getStringifiedFilesOf(String login) {
|
public List<String> getStringifiedFilesOf(String login) {
|
||||||
return this.appData.getStringifiedFilesOf(login);
|
return this.appData.getStringifiedFilesOf(login);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getNetworkInterface() {
|
||||||
|
return this.appData.getAppConfig().getNetworkInterface();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,9 @@ public class NetChooser {
|
|||||||
|
|
||||||
public NetChooser() {
|
public NetChooser() {
|
||||||
loadInterfaces();
|
loadInterfaces();
|
||||||
|
}
|
||||||
|
|
||||||
|
public NetworkInterface requestInterface() {
|
||||||
Scanner console = new Scanner(System.in);
|
Scanner console = new Scanner(System.in);
|
||||||
String[] allInterfaceNames = getInterfaces();
|
String[] allInterfaceNames = getInterfaces();
|
||||||
for(int index=0; index < allInterfaceNames.length; ++index) {
|
for(int index=0; index < allInterfaceNames.length; ++index) {
|
||||||
@ -21,7 +24,7 @@ public class NetChooser {
|
|||||||
System.out.printf("Select your interface :");
|
System.out.printf("Select your interface :");
|
||||||
NetworkInterface selected = getInterfacesByIndex(console.nextInt());
|
NetworkInterface selected = getInterfacesByIndex(console.nextInt());
|
||||||
System.out.printf("Selected interface: %s\n", selected.getDisplayName());
|
System.out.printf("Selected interface: %s\n", selected.getDisplayName());
|
||||||
|
return selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadInterfaces() {
|
private void loadInterfaces() {
|
||||||
|
Loading…
Reference in New Issue
Block a user