1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-19 08:52:15 +01:00

Make board disappear via ttl instead then reachability

Thanks @kurtgo for the hint
Solves #6832
This commit is contained in:
Martino Facchin 2017-10-19 14:29:59 +02:00
parent 3e50aee4cf
commit 80915600c9

View File

@ -37,13 +37,10 @@ import javax.jmdns.*;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.*; import java.util.*;
import cc.arduino.packages.discoverers.network.BoardReachabilityFilter;
public class NetworkDiscovery implements Discovery, ServiceListener, Runnable { public class NetworkDiscovery implements Discovery, ServiceListener, Runnable {
private final List<BoardPort> reachableBoardPorts = new LinkedList<>(); private final List<BoardPort> reachableBoardPorts = new LinkedList<>();
private final List<BoardPort> boardPortsDiscoveredWithJmDNS = new LinkedList<>(); private final List<BoardPort> boardPortsDiscoveredWithJmDNS = new LinkedList<>();
private Timer reachabilityTimer;
private JmmDNS jmdns = null; private JmmDNS jmdns = null;
private void removeDuplicateBoards(BoardPort newBoard) { private void removeDuplicateBoards(BoardPort newBoard) {
@ -81,6 +78,7 @@ public class NetworkDiscovery implements Discovery, ServiceListener, Runnable {
} }
ServiceInfo info = serviceEvent.getInfo(); ServiceInfo info = serviceEvent.getInfo();
for (InetAddress inetAddress : info.getInet4Addresses()) { for (InetAddress inetAddress : info.getInet4Addresses()) {
String address = inetAddress.getHostAddress(); String address = inetAddress.getHostAddress();
String name = serviceEvent.getName(); String name = serviceEvent.getName();
@ -145,10 +143,9 @@ public class NetworkDiscovery implements Discovery, ServiceListener, Runnable {
@Override @Override
public void start() { public void start() {
System.getProperties().setProperty("net.dns.ttl", "10");
jmdns = JmmDNS.Factory.getInstance(); jmdns = JmmDNS.Factory.getInstance();
jmdns.addServiceListener("_arduino._tcp.local.", this); jmdns.addServiceListener("_arduino._tcp.local.", this);
reachabilityTimer = new Timer();
new BoardReachabilityFilter(this).start(reachabilityTimer);
} }
@Override @Override
@ -164,15 +161,12 @@ public class NetworkDiscovery implements Discovery, ServiceListener, Runnable {
e.printStackTrace(); e.printStackTrace();
} }
*/ */
if (reachabilityTimer != null) {
reachabilityTimer.cancel();
}
} }
@Override @Override
public List<BoardPort> listDiscoveredBoards() { public List<BoardPort> listDiscoveredBoards() {
synchronized (reachableBoardPorts) { synchronized (reachableBoardPorts) {
return new LinkedList<>(reachableBoardPorts); return getBoardPortsDiscoveredWithJmDNS();
} }
} }