From 514e0ca2c9d822dc72b2c54f4a2342e2d15a5842 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 27 Oct 2018 01:39:43 -0700 Subject: [PATCH] Rework active address to not be based on reachability and allow for a manual address --- .../nvstream/http/ComputerDetails.java | 44 ++++++++++++------- .../com/limelight/nvstream/http/NvHTTP.java | 12 +---- .../nvstream/wol/WakeOnLanSender.java | 6 ++- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/moonlight-common/src/main/java/com/limelight/nvstream/http/ComputerDetails.java b/moonlight-common/src/main/java/com/limelight/nvstream/http/ComputerDetails.java index b605ad77..8c38049b 100644 --- a/moonlight-common/src/main/java/com/limelight/nvstream/http/ComputerDetails.java +++ b/moonlight-common/src/main/java/com/limelight/nvstream/http/ComputerDetails.java @@ -7,25 +7,25 @@ public class ComputerDetails { public enum State { ONLINE, OFFLINE, UNKNOWN } - public enum Reachability { - LOCAL, REMOTE, OFFLINE, UNKNOWN - } - - public State state; - public Reachability reachability; - public String name; + + // Persistent attributes public UUID uuid; + public String name; public String localAddress; public String remoteAddress; - public PairingManager.PairState pairState; + public String manualAddress; public String macAddress; + + // Transient attributes + public State state; + public String activeAddress; + public PairingManager.PairState pairState; public int runningGameId; public String rawAppList; public ComputerDetails() { // Use defaults state = State.UNKNOWN; - reachability = Reachability.UNKNOWN; } public ComputerDetails(ComputerDetails details) { @@ -35,12 +35,23 @@ public class ComputerDetails { public void update(ComputerDetails details) { this.state = details.state; - this.reachability = details.reachability; this.name = details.name; this.uuid = details.uuid; - this.localAddress = details.localAddress; - this.remoteAddress = details.remoteAddress; - this.macAddress = details.macAddress; + if (details.activeAddress != null) { + this.activeAddress = details.activeAddress; + } + if (details.localAddress != null) { + this.localAddress = details.localAddress; + } + if (details.remoteAddress != null) { + this.remoteAddress = details.remoteAddress; + } + if (details.manualAddress != null) { + this.manualAddress = details.manualAddress; + } + if (details.macAddress != null && !details.macAddress.equals("00:00:00:00:00:00")) { + this.macAddress = details.macAddress; + } this.pairState = details.pairState; this.runningGameId = details.runningGameId; this.rawAppList = details.rawAppList; @@ -50,11 +61,12 @@ public class ComputerDetails { public String toString() { StringBuilder str = new StringBuilder(); str.append("State: ").append(state).append("\n"); - str.append("Reachability: ").append(reachability).append("\n"); + str.append("Active Address: ").append(activeAddress).append("\n"); str.append("Name: ").append(name).append("\n"); str.append("UUID: ").append(uuid).append("\n"); - str.append("Local IP: ").append(localAddress).append("\n"); - str.append("Remote IP: ").append(remoteAddress).append("\n"); + str.append("Local Address: ").append(localAddress).append("\n"); + str.append("Remote Address: ").append(remoteAddress).append("\n"); + str.append("Manual Address: ").append(manualAddress).append("\n"); str.append("MAC Address: ").append(macAddress).append("\n"); str.append("Pair State: ").append(pairState).append("\n"); str.append("Running Game ID: ").append(runningGameId).append("\n"); diff --git a/moonlight-common/src/main/java/com/limelight/nvstream/http/NvHTTP.java b/moonlight-common/src/main/java/com/limelight/nvstream/http/NvHTTP.java index 8fe94bb7..06daad3b 100644 --- a/moonlight-common/src/main/java/com/limelight/nvstream/http/NvHTTP.java +++ b/moonlight-common/src/main/java/com/limelight/nvstream/http/NvHTTP.java @@ -215,18 +215,10 @@ public class NvHTTP { details.uuid = UUID.fromString(getXmlString(serverInfo, "uniqueid")); details.macAddress = getXmlString(serverInfo, "mac"); - - // If there's no LocalIP field, use the address we hit the server on details.localAddress = getXmlString(serverInfo, "LocalIP"); - if (details.localAddress == null) { - details.localAddress = address; - } - - // If there's no ExternalIP field, use the address we hit the server on + + // This may be null, but that's okay details.remoteAddress = getXmlString(serverInfo, "ExternalIP"); - if (details.remoteAddress == null) { - details.remoteAddress = address; - } try { details.pairState = Integer.parseInt(getXmlString(serverInfo, "PairStatus")) == 1 ? diff --git a/moonlight-common/src/main/java/com/limelight/nvstream/wol/WakeOnLanSender.java b/moonlight-common/src/main/java/com/limelight/nvstream/wol/WakeOnLanSender.java index 8940e7fa..61c4b5d2 100644 --- a/moonlight-common/src/main/java/com/limelight/nvstream/wol/WakeOnLanSender.java +++ b/moonlight-common/src/main/java/com/limelight/nvstream/wol/WakeOnLanSender.java @@ -26,8 +26,12 @@ public class WakeOnLanSender { // The broadcast address is required to avoid stale ARP cache entries // making the sleeping machine unreachable. for (String unresolvedAddress : new String[] { - computer.localAddress, computer.remoteAddress, "255.255.255.255" + computer.localAddress, computer.remoteAddress, computer.manualAddress, "255.255.255.255" }) { + if (unresolvedAddress == null) { + continue; + } + try { for (InetAddress resolvedAddress : InetAddress.getAllByName(unresolvedAddress)) { // Try all the ports for each resolved address