From cbe602655cfe02d6155e4bee0ebaf0871177f36c Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 9 Nov 2022 20:53:06 -0600 Subject: [PATCH] Pass active HTTPS port if the HTTP port matches the active address --- .../computers/ComputerManagerService.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/limelight/computers/ComputerManagerService.java b/app/src/main/java/com/limelight/computers/ComputerManagerService.java index 8369a1f8..96b79135 100644 --- a/app/src/main/java/com/limelight/computers/ComputerManagerService.java +++ b/app/src/main/java/com/limelight/computers/ComputerManagerService.java @@ -550,14 +550,18 @@ public class ComputerManagerService extends Service { private ComputerDetails tryPollIp(ComputerDetails details, ComputerDetails.AddressTuple address) { try { - // If this PC is currently online at this address, provide the known HTTPS port number - // and extend the timeouts to allow more time for the PC to respond. - boolean isActiveAddress = details.state == ComputerDetails.State.ONLINE && address.equals(details.activeAddress); + // If the current address's port number matches the active address's port number, we can also assume + // the HTTPS port will also match. This assumption is currently safe because Sunshine sets all ports + // as offsets from the base HTTP port and doesn't allow custom HttpsPort responses for WAN vs LAN. + boolean portMatchesActiveAddress = details.activeAddress != null && address.port == details.activeAddress.port; - NvHTTP http = new NvHTTP(address, isActiveAddress ? details.httpsPort : 0, idManager.getUniqueId(), details.serverCert, + NvHTTP http = new NvHTTP(address, portMatchesActiveAddress ? details.httpsPort : 0, idManager.getUniqueId(), details.serverCert, PlatformBinding.getCryptoProvider(ComputerManagerService.this)); - ComputerDetails newDetails = http.getComputerDetails(isActiveAddress); + // If this PC is currently online at this address, extend the timeouts to allow more time for the PC to respond. + boolean isLikelyOnline = details.state == ComputerDetails.State.ONLINE && address.equals(details.activeAddress); + + ComputerDetails newDetails = http.getComputerDetails(isLikelyOnline); // Check if this is the PC we expected if (newDetails.uuid == null) {