Rework active address to not be based on reachability and allow for a manual address

This commit is contained in:
Cameron Gutman 2018-10-27 01:39:43 -07:00
parent c9cf485025
commit 514e0ca2c9
3 changed files with 35 additions and 27 deletions

View File

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

View File

@ -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 ?

View File

@ -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