mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-19 19:13:03 +00:00
Fix race condition causing loss of manual IP address after mDNS discovery
This commit is contained in:
parent
113a0e2c45
commit
8d09f56a0e
@ -105,18 +105,28 @@ public class ComputerManagerService extends Service {
|
|||||||
|
|
||||||
// If it's online, update our persistent state
|
// If it's online, update our persistent state
|
||||||
if (details.state == ComputerDetails.State.ONLINE) {
|
if (details.state == ComputerDetails.State.ONLINE) {
|
||||||
if (!newPc) {
|
ComputerDetails existingComputer = dbManager.getComputerByUUID(details.uuid);
|
||||||
|
|
||||||
// Check if it's in the database because it could have been
|
// Check if it's in the database because it could have been
|
||||||
// removed after this was issued
|
// removed after this was issued
|
||||||
if (dbManager.getComputerByUUID(details.uuid) == null) {
|
if (!newPc && existingComputer == null) {
|
||||||
// It's gone
|
// It's gone
|
||||||
releaseLocalDatabaseReference();
|
releaseLocalDatabaseReference();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
// If we already have an entry for this computer in the DB, we must
|
||||||
|
// combine the existing data with this new data (which may be partially available
|
||||||
|
// due to detecting the PC via mDNS) without the saved external address. If we
|
||||||
|
// write to the DB without doing this first, we can overwrite our existing data.
|
||||||
|
if (existingComputer != null) {
|
||||||
|
existingComputer.update(details);
|
||||||
|
dbManager.updateComputer(existingComputer);
|
||||||
|
}
|
||||||
|
else {
|
||||||
dbManager.updateComputer(details);
|
dbManager.updateComputer(details);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Don't call the listener if this is a failed lookup of a new PC
|
// Don't call the listener if this is a failed lookup of a new PC
|
||||||
if ((!newPc || details.state == ComputerDetails.State.ONLINE) && listener != null) {
|
if ((!newPc || details.state == ComputerDetails.State.ONLINE) && listener != null) {
|
||||||
@ -304,7 +314,7 @@ public class ComputerManagerService extends Service {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addTuple(ComputerDetails details, boolean manuallyAdded) {
|
private void addTuple(ComputerDetails details) {
|
||||||
synchronized (pollingTuples) {
|
synchronized (pollingTuples) {
|
||||||
for (PollingTuple tuple : pollingTuples) {
|
for (PollingTuple tuple : pollingTuples) {
|
||||||
// Check if this is the same computer
|
// Check if this is the same computer
|
||||||
@ -365,7 +375,7 @@ public class ComputerManagerService extends Service {
|
|||||||
LimeLog.info("New PC ("+fakeDetails.name+") is UUID "+fakeDetails.uuid);
|
LimeLog.info("New PC ("+fakeDetails.name+") is UUID "+fakeDetails.uuid);
|
||||||
|
|
||||||
// Start a polling thread for this machine
|
// Start a polling thread for this machine
|
||||||
addTuple(fakeDetails, manuallyAdded);
|
addTuple(fakeDetails);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -537,7 +547,7 @@ public class ComputerManagerService extends Service {
|
|||||||
// b) if it's null, it will be unexpectedly nulling the activeAddress of a possibly online PC
|
// b) if it's null, it will be unexpectedly nulling the activeAddress of a possibly online PC
|
||||||
LimeLog.info("Starting fast poll for "+details.name+" ("+details.localAddress +", "+details.remoteAddress +", "+details.manualAddress +")");
|
LimeLog.info("Starting fast poll for "+details.name+" ("+details.localAddress +", "+details.remoteAddress +", "+details.manualAddress +")");
|
||||||
String candidateAddress = fastPollPc(details.localAddress, details.remoteAddress, details.manualAddress);
|
String candidateAddress = fastPollPc(details.localAddress, details.remoteAddress, details.manualAddress);
|
||||||
LimeLog.info("Fast poll for "+details.name+" returned active address: "+details.activeAddress);
|
LimeLog.info("Fast poll for "+details.name+" returned candidate address: "+candidateAddress);
|
||||||
|
|
||||||
// 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 (candidateAddress == null) {
|
if (candidateAddress == null) {
|
||||||
@ -593,7 +603,7 @@ public class ComputerManagerService extends Service {
|
|||||||
|
|
||||||
for (ComputerDetails computer : dbManager.getAllComputers()) {
|
for (ComputerDetails computer : dbManager.getAllComputers()) {
|
||||||
// Add tuples for each computer
|
// Add tuples for each computer
|
||||||
addTuple(computer, true);
|
addTuple(computer);
|
||||||
}
|
}
|
||||||
|
|
||||||
releaseLocalDatabaseReference();
|
releaseLocalDatabaseReference();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user