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.
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
|
||||
run {
|
||||
standardInput = System.in
|
||||
}
|
@ -36,7 +36,7 @@ public class App {
|
||||
// Initialisation du dispatcher et des servers
|
||||
FileFrontEnd ffe = new FileFrontEnd(clientRep, storeRep, protocolRep);
|
||||
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.
|
||||
|
||||
|
@ -6,6 +6,7 @@ import lightcontainer.interfaces.ProtocolRepository;
|
||||
import lightcontainer.protocol.ProtocolReader;
|
||||
import lightcontainer.protocol.rules.reader.HelloRule;
|
||||
import lightcontainer.repository.FileFrontEnd;
|
||||
import lightcontainer.utils.NetChooser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.*;
|
||||
@ -25,6 +26,7 @@ public class MulticastServerListener implements Runnable {
|
||||
// Variable
|
||||
private final String multicast_address;
|
||||
private final int multicast_port;
|
||||
private final String network_interface;
|
||||
private FileFrontEnd ffe;
|
||||
private final MulticastSPR repository;
|
||||
private final ProtocolRepository protocolRep;
|
||||
@ -33,12 +35,13 @@ public class MulticastServerListener implements Runnable {
|
||||
private MulticastSocket listener;
|
||||
|
||||
// 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.repository = repository;
|
||||
this.protocolRep = protocolRep;
|
||||
this.multicast_address = multicast_address;
|
||||
this.multicast_port = multicast_port;
|
||||
this.network_interface = network_interface;
|
||||
repository.setServerListener(this);
|
||||
}
|
||||
|
||||
@ -54,6 +57,9 @@ public class MulticastServerListener implements Runnable {
|
||||
try {
|
||||
// Create a new listening socket
|
||||
this.listener = new MulticastSocket(this.multicast_port);
|
||||
|
||||
this.selectInterface();
|
||||
|
||||
// Create an identifier for the multicast group on the specified ip
|
||||
InetAddress listener_group = InetAddress.getByName(this.multicast_address);
|
||||
// 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.
|
||||
*
|
||||
|
@ -158,4 +158,8 @@ public class Repository {
|
||||
public List<String> getStringifiedFilesOf(String login) {
|
||||
return this.appData.getStringifiedFilesOf(login);
|
||||
}
|
||||
|
||||
public String getNetworkInterface() {
|
||||
return this.appData.getAppConfig().getNetworkInterface();
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,9 @@ public class NetChooser {
|
||||
|
||||
public NetChooser() {
|
||||
loadInterfaces();
|
||||
}
|
||||
|
||||
public NetworkInterface requestInterface() {
|
||||
Scanner console = new Scanner(System.in);
|
||||
String[] allInterfaceNames = getInterfaces();
|
||||
for(int index=0; index < allInterfaceNames.length; ++index) {
|
||||
@ -21,7 +24,7 @@ public class NetChooser {
|
||||
System.out.printf("Select your interface :");
|
||||
NetworkInterface selected = getInterfacesByIndex(console.nextInt());
|
||||
System.out.printf("Selected interface: %s\n", selected.getDisplayName());
|
||||
|
||||
return selected;
|
||||
}
|
||||
|
||||
private void loadInterfaces() {
|
||||
|
Loading…
Reference in New Issue
Block a user