Skip to content

Commit

Permalink
Count echos received per peer
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed Jun 12, 2024
1 parent 243950e commit 5b3b4ae
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<PeerConnectivityCheckerModule> 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) {
Expand All @@ -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("");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,7 +57,7 @@ synchronized void stop() {
running = false;

if (checkerThread != null) {
checkerThread.stop();
checkerThread.interrupt();
checkerThread = null;
}
}
Expand All @@ -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);
}
Expand All @@ -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];
Expand All @@ -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) {
Expand All @@ -112,6 +117,6 @@ private void checkerThread() {
}
}

log.info(getThreadName()+" stopped gracefully");
log.info("{} stopped gracefully", Thread.currentThread().getName());
}
}
1 change: 1 addition & 0 deletions ice-adapter/src/main/resources/debugWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<TableColumn fx:id="offerColumn" prefWidth="100.0" text="localOffer" />
<TableColumn fx:id="rttColumn" prefWidth="100.0" text="average rtt" />
<TableColumn fx:id="lastColumn" prefWidth="100.0" text="last recv" />
<TableColumn fx:id="echosRcvColumn" prefWidth="100.0" text="echos recv" />
</columns>
</TableView>

Expand Down

0 comments on commit 5b3b4ae

Please sign in to comment.