From 5b3b4aedbe9c58bbb05b8bd43a567e041e78662b Mon Sep 17 00:00:00 2001 From: Brutus5000 Date: Wed, 12 Jun 2024 16:28:32 +0200 Subject: [PATCH] Count echos received per peer --- .../com/faforever/iceadapter/debug/DebugWindow.java | 11 +++++++---- .../iceadapter/debug/DebugWindowController.java | 2 ++ .../ice/PeerConnectivityCheckerModule.java | 13 +++++++++---- ice-adapter/src/main/resources/debugWindow.fxml | 1 + 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/debug/DebugWindow.java b/ice-adapter/src/main/java/com/faforever/iceadapter/debug/DebugWindow.java index 447e269..db47567 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/debug/DebugWindow.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/debug/DebugWindow.java @@ -177,14 +177,16 @@ public void peerStateChanged(Peer peer) { @Override public void peerConnectivityUpdate(Peer peer) { - new Thread(() -> { + runOnUIThread(() -> { synchronized (peers) { peers.stream().filter(p -> p.id.get() == peer.getRemoteId()).forEach(p -> { - p.averageRtt.set(Optional.ofNullable(peer.getIce().getConnectivityChecker()).map(PeerConnectivityCheckerModule::getAverageRTT).orElse(-1.0f).intValue()); - p.lastReceived.set(Optional.ofNullable(peer.getIce().getConnectivityChecker()).map(PeerConnectivityCheckerModule::getLastPacketReceived).map(last -> System.currentTimeMillis() - last).orElse(-1L).intValue()); + Optional connectivityChecker = Optional.ofNullable(peer.getIce().getConnectivityChecker()); + p.averageRtt.set(connectivityChecker.map(PeerConnectivityCheckerModule::getAverageRTT).orElse(-1.0f).intValue()); + p.lastReceived.set(connectivityChecker.map(PeerConnectivityCheckerModule::getLastPacketReceived).map(last -> System.currentTimeMillis() - last).orElse(-1L).intValue()); + p.echosReceived.set(connectivityChecker.map(PeerConnectivityCheckerModule::getEchosReceived).orElse(-1L).intValue()); }); } - }).start(); + }); } private void runOnUIThread(Runnable runnable) { @@ -210,6 +212,7 @@ public static class DebugPeer { public SimpleStringProperty state = new SimpleStringProperty(""); public SimpleIntegerProperty averageRtt = new SimpleIntegerProperty(-1); public SimpleIntegerProperty lastReceived = new SimpleIntegerProperty(-1); + public SimpleIntegerProperty echosReceived = new SimpleIntegerProperty(-1); public SimpleStringProperty localCandidate = new SimpleStringProperty(""); public SimpleStringProperty remoteCandidate = new SimpleStringProperty(""); diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/debug/DebugWindowController.java b/ice-adapter/src/main/java/com/faforever/iceadapter/debug/DebugWindowController.java index aebd16c..74bb361 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/debug/DebugWindowController.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/debug/DebugWindowController.java @@ -36,6 +36,7 @@ public class DebugWindowController { public TableColumn stateColumn; public TableColumn rttColumn; public TableColumn lastColumn; + public TableColumn echosRcvColumn; public TableColumn localCandColumn; public TableColumn remoteCandColumn; @@ -64,6 +65,7 @@ private void initialize() { stateColumn.setCellValueFactory(new PropertyValueFactory<>("state")); rttColumn.setCellValueFactory(new PropertyValueFactory<>("averageRtt")); lastColumn.setCellValueFactory(new PropertyValueFactory<>("lastReceived")); + echosRcvColumn.setCellValueFactory(new PropertyValueFactory<>("echosReceived")); localCandColumn.setCellValueFactory(new PropertyValueFactory<>("localCandidate")); remoteCandColumn.setCellValueFactory(new PropertyValueFactory<>("remoteCandidate")); diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/ice/PeerConnectivityCheckerModule.java b/ice-adapter/src/main/java/com/faforever/iceadapter/ice/PeerConnectivityCheckerModule.java index 4220eeb..ade26bd 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/ice/PeerConnectivityCheckerModule.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/ice/PeerConnectivityCheckerModule.java @@ -23,6 +23,7 @@ public class PeerConnectivityCheckerModule { @Getter private float averageRTT = 0.0f; @Getter private long lastPacketReceived; + @Getter private long echosReceived = 0; public PeerConnectivityCheckerModule(PeerIceModule ice) { this.ice = ice; @@ -56,7 +57,7 @@ synchronized void stop() { running = false; if (checkerThread != null) { - checkerThread.stop(); + checkerThread.interrupt(); checkerThread = null; } } @@ -68,6 +69,8 @@ synchronized void stop() { * @param length */ void echoReceived(byte[] data, int offset, int length) { + echosReceived++; + if (length != 9) { log.trace("Received echo of wrong length, length: {}", length); } @@ -86,7 +89,7 @@ void echoReceived(byte[] data, int offset, int length) { } private void checkerThread() { - while (running) { + while (!Thread.currentThread().isInterrupted()) { log.trace("Running connectivity checker"); byte[] data = new byte[9]; @@ -102,7 +105,9 @@ private void checkerThread() { try { Thread.sleep(ECHO_INTERVAL); } catch (InterruptedException e) { - log.warn("Sleeping checkerThread was interrupted"); + log.warn("{} (sleeping checkerThread) was interrupted", Thread.currentThread().getName()); + Thread.currentThread().interrupt(); + return; } if (System.currentTimeMillis() - lastPacketReceived > 10000) { @@ -112,6 +117,6 @@ private void checkerThread() { } } - log.info(getThreadName()+" stopped gracefully"); + log.info("{} stopped gracefully", Thread.currentThread().getName()); } } diff --git a/ice-adapter/src/main/resources/debugWindow.fxml b/ice-adapter/src/main/resources/debugWindow.fxml index c353653..5bd31b5 100644 --- a/ice-adapter/src/main/resources/debugWindow.fxml +++ b/ice-adapter/src/main/resources/debugWindow.fxml @@ -62,6 +62,7 @@ +