Fix discovery issues when adding a PC

This commit is contained in:
Cameron Gutman 2015-09-16 18:04:18 -07:00
parent 59a00a38c9
commit 1a6f639b81

View File

@ -465,11 +465,11 @@ public class ComputerManagerService extends Service {
LimeLog.info("Starting fast poll for "+details.name+" ("+details.localIp+", "+details.remoteIp+")"); LimeLog.info("Starting fast poll for "+details.name+" ("+details.localIp+", "+details.remoteIp+")");
reachability = fastPollPc(details.localIp, details.remoteIp); reachability = fastPollPc(details.localIp, details.remoteIp);
LimeLog.info("Fast poll for "+details.name+" returned "+reachability.toString()); LimeLog.info("Fast poll for "+details.name+" returned "+reachability.toString());
}
// If no connection could be established to either IP address, there's nothing we can do // If no connection could be established to either IP address, there's nothing we can do
if (reachability == ComputerDetails.Reachability.OFFLINE) { if (reachability == ComputerDetails.Reachability.OFFLINE) {
return false; return false;
}
} }
boolean localFirst = (reachability == ComputerDetails.Reachability.LOCAL); boolean localFirst = (reachability == ComputerDetails.Reachability.LOCAL);
@ -481,6 +481,7 @@ public class ComputerManagerService extends Service {
polledDetails = tryPollIp(details, details.remoteIp); polledDetails = tryPollIp(details, details.remoteIp);
} }
InetAddress reachableAddr = null;
if (polledDetails == null && !details.localIp.equals(details.remoteIp)) { if (polledDetails == null && !details.localIp.equals(details.remoteIp)) {
// Failed, so let's try the fallback // Failed, so let's try the fallback
if (!localFirst) { if (!localFirst) {
@ -490,15 +491,13 @@ public class ComputerManagerService extends Service {
polledDetails = tryPollIp(details, details.remoteIp); polledDetails = tryPollIp(details, details.remoteIp);
} }
// The fallback poll worked
if (polledDetails != null) { if (polledDetails != null) {
polledDetails.reachability = !localFirst ? ComputerDetails.Reachability.LOCAL : // The fallback poll worked
ComputerDetails.Reachability.REMOTE; reachableAddr = !localFirst ? details.localIp : details.remoteIp;
} }
} }
else if (polledDetails != null) { else if (polledDetails != null) {
polledDetails.reachability = localFirst ? ComputerDetails.Reachability.LOCAL : reachableAddr = localFirst ? details.localIp : details.remoteIp;
ComputerDetails.Reachability.REMOTE;
} }
// Machine was unreachable both tries // Machine was unreachable both tries
@ -506,6 +505,26 @@ public class ComputerManagerService extends Service {
return false; return false;
} }
// Determine the machine's reachability based on the address we reached it on
if (polledDetails.remoteIp.equals(reachableAddr)) {
polledDetails.reachability = ComputerDetails.Reachability.REMOTE;
}
else if (polledDetails.localIp.equals(reachableAddr)) {
polledDetails.reachability = ComputerDetails.Reachability.LOCAL;
}
else {
// Neither IP address reported in the serverinfo response was the one we used.
// We'll do a fast poll now to see if the machine is reachable via either of
// these.
polledDetails.reachability = fastPollPc(polledDetails.localIp, polledDetails.remoteIp);
LimeLog.info("Fast poll for reachability returned "+reachability.toString());
if (polledDetails.reachability == ComputerDetails.Reachability.OFFLINE) {
// Neither of those seem to work, so we'll hold onto the address that did work
polledDetails.localIp = reachableAddr;
polledDetails.reachability = ComputerDetails.Reachability.LOCAL;
}
}
// Save the old MAC address // Save the old MAC address
String savedMacAddress = details.macAddress; String savedMacAddress = details.macAddress;