[network] Fix latency parsing on windows 10 (#8781)
Fixes #8776 Signed-off-by: Connor Petty <mistercpp2000+gitsignoff@gmail.com>
This commit is contained in:
parent
ae1d59cf99
commit
ac1e4d8a83
|
@ -22,6 +22,7 @@ import java.util.Set;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@ -65,7 +66,7 @@ public class NetworkDiscoveryService extends AbstractDiscoveryService implements
|
||||||
// TCP port 1025 (Xbox / MS-RPC)
|
// TCP port 1025 (Xbox / MS-RPC)
|
||||||
private Set<Integer> tcpServicePorts = Collections
|
private Set<Integer> tcpServicePorts = Collections
|
||||||
.unmodifiableSet(Stream.of(80, 548, 554, 1025).collect(Collectors.toSet()));
|
.unmodifiableSet(Stream.of(80, 548, 554, 1025).collect(Collectors.toSet()));
|
||||||
private Integer scannedIPcount = 0;
|
private AtomicInteger scannedIPcount = new AtomicInteger(0);
|
||||||
private @Nullable ExecutorService executorService = null;
|
private @Nullable ExecutorService executorService = null;
|
||||||
private final NetworkBindingConfiguration configuration = new NetworkBindingConfiguration();
|
private final NetworkBindingConfiguration configuration = new NetworkBindingConfiguration();
|
||||||
private final NetworkUtils networkUtils = new NetworkUtils();
|
private final NetworkUtils networkUtils = new NetworkUtils();
|
||||||
|
@ -135,7 +136,7 @@ public class NetworkDiscoveryService extends AbstractDiscoveryService implements
|
||||||
logger.trace("Starting Network Device Discovery");
|
logger.trace("Starting Network Device Discovery");
|
||||||
|
|
||||||
final Set<String> networkIPs = networkUtils.getNetworkIPs(MAXIMUM_IPS_PER_INTERFACE);
|
final Set<String> networkIPs = networkUtils.getNetworkIPs(MAXIMUM_IPS_PER_INTERFACE);
|
||||||
scannedIPcount = 0;
|
scannedIPcount.set(0);
|
||||||
|
|
||||||
for (String ip : networkIPs) {
|
for (String ip : networkIPs) {
|
||||||
final PresenceDetection s = new PresenceDetection(this, 2000);
|
final PresenceDetection s = new PresenceDetection(this, 2000);
|
||||||
|
@ -152,12 +153,10 @@ public class NetworkDiscoveryService extends AbstractDiscoveryService implements
|
||||||
service.execute(() -> {
|
service.execute(() -> {
|
||||||
Thread.currentThread().setName("Discovery thread " + ip);
|
Thread.currentThread().setName("Discovery thread " + ip);
|
||||||
s.performPresenceDetection(true);
|
s.performPresenceDetection(true);
|
||||||
synchronized (scannedIPcount) {
|
int count = scannedIPcount.incrementAndGet();
|
||||||
scannedIPcount += 1;
|
if (count == networkIPs.size()) {
|
||||||
if (scannedIPcount == networkIPs.size()) {
|
logger.trace("Scan of {} IPs successful", scannedIPcount);
|
||||||
logger.trace("Scan of {} IPs successful", scannedIPcount);
|
stopScan();
|
||||||
stopScan();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory;
|
||||||
*/
|
*/
|
||||||
public class LatencyParser {
|
public class LatencyParser {
|
||||||
|
|
||||||
|
private static Pattern LATENCY_PATTERN = Pattern.compile(".*time=(.*) ?ms");
|
||||||
private final Logger logger = LoggerFactory.getLogger(LatencyParser.class);
|
private final Logger logger = LoggerFactory.getLogger(LatencyParser.class);
|
||||||
|
|
||||||
// This is how the input looks like on Mac and Linux:
|
// This is how the input looks like on Mac and Linux:
|
||||||
|
@ -47,8 +48,7 @@ public class LatencyParser {
|
||||||
public Optional<Double> parseLatency(String inputLine) {
|
public Optional<Double> parseLatency(String inputLine) {
|
||||||
logger.debug("Parsing latency from input {}", inputLine);
|
logger.debug("Parsing latency from input {}", inputLine);
|
||||||
|
|
||||||
String pattern = ".*time=(.*) ms";
|
Matcher m = LATENCY_PATTERN.matcher(inputLine);
|
||||||
Matcher m = Pattern.compile(pattern).matcher(inputLine);
|
|
||||||
if (m.find() && m.groupCount() == 1) {
|
if (m.find() && m.groupCount() == 1) {
|
||||||
return Optional.of(Double.parseDouble(m.group(1)));
|
return Optional.of(Double.parseDouble(m.group(1)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,4 +58,18 @@ public class LatencyParserTest {
|
||||||
assertFalse(resultLatency.isPresent());
|
assertFalse(resultLatency.isPresent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseWindows10ResultFoundTest() {
|
||||||
|
// Arrange
|
||||||
|
LatencyParser latencyParser = new LatencyParser();
|
||||||
|
String input = "Reply from 192.168.178.207: bytes=32 time=2ms TTL=64";
|
||||||
|
|
||||||
|
// Act
|
||||||
|
Optional<Double> resultLatency = latencyParser.parseLatency(input);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
assertTrue(resultLatency.isPresent());
|
||||||
|
assertEquals(2, resultLatency.get(), 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue