From a3c3ec76b2800f2b8843b96f06e69a4d638f9813 Mon Sep 17 00:00:00 2001 From: geosearchef Date: Fri, 16 Jul 2021 10:20:48 +0100 Subject: [PATCH] increase log verbosity, wrap tray notification in event dispatch --- .../iceadapter/ice/PeerIceModule.java | 19 +++++++++++++------ .../iceadapter/util/PingWrapper.java | 2 ++ .../faforever/iceadapter/util/TrayIcon.java | 11 +++++++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/ice/PeerIceModule.java b/ice-adapter/src/main/java/com/faforever/iceadapter/ice/PeerIceModule.java index 643734c..a562c52 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/ice/PeerIceModule.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/ice/PeerIceModule.java @@ -8,15 +8,18 @@ import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.ice4j.Transport; +import org.ice4j.TransportAddress; import org.ice4j.ice.*; import org.ice4j.ice.harvest.StunCandidateHarvester; import org.ice4j.ice.harvest.TurnCandidateHarvester; import org.ice4j.security.LongTermCredential; -import javax.swing.text.html.Option; import java.io.IOException; import java.net.DatagramPacket; -import java.util.*; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.Optional; import java.util.concurrent.CancellationException; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; @@ -136,11 +139,10 @@ private void gatherCandidates() { int previousConnectivityAttempts = getConnectivityAttempsInThePast(FORCE_SRFLX_RELAY_INTERVAL); CandidatesMessage localCandidatesMessage = CandidateUtil.packCandidates(IceAdapter.id, peer.getRemoteId(), agent, component, previousConnectivityAttempts < FORCE_SRFLX_COUNT && IceAdapter.ALLOW_HOST, previousConnectivityAttempts < FORCE_RELAY_COUNT && IceAdapter.ALLOW_REFLEXIVE, IceAdapter.ALLOW_RELAY); - log.debug(getLogPrefix() + "Sending own candidates to {}", peer.getRemoteId()); + log.debug(getLogPrefix() + "Sending own candidates to {}, offered candidates: {}", peer.getRemoteId(), localCandidatesMessage.getCandidates().stream().map(it -> it.getType().toString() + "(" + it.getProtocol() + ")").collect(Collectors.joining(", "))); setState(AWAITING_CANDIDATES); RPCService.onIceMsg(localCandidatesMessage); - //TODO: is this a good fix for awaiting candidates loop???? //Make sure to abort the connection process and reinitiate when we haven't received an answer to our offer in 6 seconds, candidate packet was probably lost final int currentacei = ++awaitingCandidatesEventId; Executor.executeDelayed(6000, () -> { @@ -172,6 +174,7 @@ private List getViableIceServers() { .filter(IceServer::hasAcceptableLatency) .collect(Collectors.toList()); if (!viableIceServers.isEmpty()) { + log.info("Using official ice servers: {}", viableIceServers.stream().map(it -> "[" + it.getTurnAddresses().stream().map(TransportAddress::toString).collect(Collectors.joining(", ")) + "]").collect(Collectors.joining(", "))); return viableIceServers; } @@ -180,6 +183,7 @@ private List getViableIceServers() { .filter(IceServer::hasAcceptableLatency) .collect(Collectors.toList()); if (!viableIceServers.isEmpty()) { + log.info("Using all viable ice servers: {}", viableIceServers.stream().map(it -> "[" + it.getTurnAddresses().stream().map(TransportAddress::toString).collect(Collectors.joining(", ")) + "]").collect(Collectors.joining(", "))); return viableIceServers; } @@ -188,12 +192,15 @@ private List getViableIceServers() { .filter(server -> server.getRoundTripTime().join().isPresent()) .min(Comparator.comparing(server -> server.getRoundTripTime().join().getAsDouble())); if (closestIceServer.isPresent()) { + log.info("Using closest ice server: {}", closestIceServer.get().getTurnAddresses().stream().map(TransportAddress::toString).collect(Collectors.joining(", "))); viableIceServers.add(closestIceServer.get()); } if (!viableIceServers.isEmpty()) { + log.info("Using all reachable ice servers: {}", viableIceServers.stream().map(it -> "[" + it.getTurnAddresses().stream().map(TransportAddress::toString).collect(Collectors.joining(", ")) + "]").collect(Collectors.joining(", "))); return viableIceServers; } + log.info("Using all ice servers: {}", viableIceServers.stream().map(it -> "[" + it.getTurnAddresses().stream().map(TransportAddress::toString).collect(Collectors.joining(", ")) + "]").collect(Collectors.joining(", "))); return allIceServers; } @@ -209,7 +216,7 @@ public synchronized void onIceMessageReceived(CandidatesMessage remoteCandidates //Start ICE async as it's blocking and this is the RPC thread new Thread(() -> { - log.debug(getLogPrefix() + "Got IceMsg for peer"); + log.debug(getLogPrefix() + "Got IceMsg for peer, offered candidates: {}", remoteCandidatesMessage.getCandidates().stream().map(it -> it.getType().toString() + "(" + it.getProtocol() + ")").collect(Collectors.joining(", "))); if (peer.isLocalOffer()) { if (iceState != AWAITING_CANDIDATES) { @@ -269,7 +276,7 @@ private void startIce() { } } - log.debug(getLogPrefix() + "ICE terminated"); + log.debug(getLogPrefix() + "ICE terminated, connected, selected candidate pair: " + component.getSelectedPair().getLocalCandidate().getType().toString() + " <-> " + component.getSelectedPair().getRemoteCandidate().getType().toString()); //We are connected connected = true; diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/util/PingWrapper.java b/ice-adapter/src/main/java/com/faforever/iceadapter/util/PingWrapper.java index fb60f17..021b7a0 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/util/PingWrapper.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/util/PingWrapper.java @@ -64,8 +64,10 @@ public static CompletableFuture getLatency(String address, Integer count if(fallbackServers.containsKey(address)) { String fallback = fallbackServers.get(address); log.info("Falling back to " + fallback + " for latency estimation"); + TrayIcon.showMessage("Failed to estimate latency to " + address + ". Falling back to " + fallback + "."); return getLatency(fallback, IceAdapter.PING_COUNT).get(); } + TrayIcon.showMessage("Unable to contact relay server!"); throw new RuntimeException("Failed to contact the host"); } } catch (InterruptedException | IOException | RuntimeException | ExecutionException e) { diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/util/TrayIcon.java b/ice-adapter/src/main/java/com/faforever/iceadapter/util/TrayIcon.java index a1d45ea..6c7b060 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/util/TrayIcon.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/util/TrayIcon.java @@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j; import javax.imageio.ImageIO; +import javax.swing.*; import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; @@ -16,7 +17,7 @@ public class TrayIcon { public static final String FAF_LOGO_URL = "https://faforever.com/images/faf-logo.png"; - private static java.awt.TrayIcon trayIcon; + private static volatile java.awt.TrayIcon trayIcon; public static void create() { @@ -79,9 +80,11 @@ public void mouseExited(MouseEvent mouseEvent) { } public static void showMessage(String message) { - if (trayIcon != null) { - trayIcon.displayMessage("FAForever Connection ICE Adapter", message, java.awt.TrayIcon.MessageType.INFO); - } + SwingUtilities.invokeLater(() -> { + if (trayIcon != null) { + trayIcon.displayMessage("FAForever Connection ICE Adapter", message, java.awt.TrayIcon.MessageType.INFO); + } + }); } public static void close() {