From 60cd9517748106fd40ddc07130bdb37853b16fcb Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 9 Sep 2017 12:47:23 -0700 Subject: [PATCH] Rename localIp/remoteIp fields to localAddress/remoteAddress to prepare for DNS names --- .../computers/ComputerDatabaseManager.java | 17 +++++---- .../computers/ComputerManagerService.java | 36 +++++++++---------- .../com/limelight/utils/ServerHelper.java | 2 +- moonlight-common | 2 +- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/com/limelight/computers/ComputerDatabaseManager.java b/app/src/main/java/com/limelight/computers/ComputerDatabaseManager.java index 6c500cee..142beb0a 100644 --- a/app/src/main/java/com/limelight/computers/ComputerDatabaseManager.java +++ b/app/src/main/java/com/limelight/computers/ComputerDatabaseManager.java @@ -1,6 +1,5 @@ package com.limelight.computers; -import java.net.Inet6Address; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.LinkedList; @@ -63,8 +62,8 @@ public class ComputerDatabaseManager { ContentValues values = new ContentValues(); values.put(COMPUTER_NAME_COLUMN_NAME, details.name); values.put(COMPUTER_UUID_COLUMN_NAME, details.uuid.toString()); - values.put(LOCAL_IP_COLUMN_NAME, ADDRESS_PREFIX+details.localIp.getHostAddress()); - values.put(REMOTE_IP_COLUMN_NAME, ADDRESS_PREFIX+details.remoteIp.getHostAddress()); + values.put(LOCAL_IP_COLUMN_NAME, ADDRESS_PREFIX+details.localAddress.getHostAddress()); + values.put(REMOTE_IP_COLUMN_NAME, ADDRESS_PREFIX+details.remoteAddress.getHostAddress()); values.put(MAC_COLUMN_NAME, details.macAddress); return -1 != computerDb.insertWithOnConflict(COMPUTER_TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_REPLACE); } @@ -87,14 +86,14 @@ public class ComputerDatabaseManager { // too. To disambiguate, we'll need to prefix them with a string // greater than the allowable IP address length. try { - details.localIp = InetAddress.getByAddress(c.getBlob(2)); + details.localAddress = InetAddress.getByAddress(c.getBlob(2)); LimeLog.warning("DB: Legacy local address for "+details.name); } catch (UnknownHostException e) { // This is probably a hostname/address with the prefix string String stringData = c.getString(2); if (stringData.startsWith(ADDRESS_PREFIX)) { try { - details.localIp = InetAddress.getByName(c.getString(2).substring(ADDRESS_PREFIX.length())); + details.localAddress = InetAddress.getByName(c.getString(2).substring(ADDRESS_PREFIX.length())); } catch (UnknownHostException e1) { e1.printStackTrace(); } @@ -105,14 +104,14 @@ public class ComputerDatabaseManager { } try { - details.remoteIp = InetAddress.getByAddress(c.getBlob(3)); + details.remoteAddress = InetAddress.getByAddress(c.getBlob(3)); LimeLog.warning("DB: Legacy remote address for "+details.name); } catch (UnknownHostException e) { // This is probably a hostname/address with the prefix string String stringData = c.getString(3); if (stringData.startsWith(ADDRESS_PREFIX)) { try { - details.remoteIp = InetAddress.getByName(c.getString(3).substring(ADDRESS_PREFIX.length())); + details.remoteAddress = InetAddress.getByName(c.getString(3).substring(ADDRESS_PREFIX.length())); } catch (UnknownHostException e1) { e1.printStackTrace(); } @@ -138,7 +137,7 @@ public class ComputerDatabaseManager { ComputerDetails details = getComputerFromCursor(c); // If a field is corrupt or missing, skip the database entry - if (details.uuid == null || details.localIp == null || details.remoteIp == null || + if (details.uuid == null || details.localAddress == null || details.remoteAddress == null || details.macAddress == null) { continue; } @@ -164,7 +163,7 @@ public class ComputerDatabaseManager { c.close(); // If a field is corrupt or missing, delete the database entry - if (details.uuid == null || details.localIp == null || details.remoteIp == null || + if (details.uuid == null || details.localAddress == null || details.remoteAddress == null || details.macAddress == null) { deleteComputer(details.name); return null; diff --git a/app/src/main/java/com/limelight/computers/ComputerManagerService.java b/app/src/main/java/com/limelight/computers/ComputerManagerService.java index 928fa550..d7f5e8c7 100644 --- a/app/src/main/java/com/limelight/computers/ComputerManagerService.java +++ b/app/src/main/java/com/limelight/computers/ComputerManagerService.java @@ -155,7 +155,7 @@ public class ComputerManagerService extends Service { } } }; - t.setName("Polling thread for " + tuple.computer.localIp.getHostAddress()); + t.setName("Polling thread for " + tuple.computer.localAddress.getHostAddress()); return t; } @@ -313,8 +313,8 @@ public class ComputerManagerService extends Service { if (tuple.computer.uuid.equals(details.uuid)) { // Update details anyway in case this machine has been re-added by IP // after not being reachable by our existing information - tuple.computer.localIp = details.localIp; - tuple.computer.remoteIp = details.remoteIp; + tuple.computer.localAddress = details.localAddress; + tuple.computer.remoteAddress = details.remoteAddress; // Start a polling thread if polling is active if (pollingActive && tuple.thread == null) { @@ -342,8 +342,8 @@ public class ComputerManagerService extends Service { public boolean addComputerBlocking(InetAddress addr) { // Setup a placeholder ComputerDetails fakeDetails = new ComputerDetails(); - fakeDetails.localIp = addr; - fakeDetails.remoteIp = addr; + fakeDetails.localAddress = addr; + fakeDetails.remoteAddress = addr; // Block while we try to fill the details try { @@ -500,13 +500,13 @@ public class ComputerManagerService extends Service { // If the local address is routable across the Internet, // always consider this PC remote to be conservative - if (details.localIp.equals(details.remoteIp)) { + if (details.localAddress.equals(details.remoteAddress)) { reachability = ComputerDetails.Reachability.REMOTE; } else { // Do a TCP-level connection to the HTTP server to see if it's listening - LimeLog.info("Starting fast poll for "+details.name+" ("+details.localIp+", "+details.remoteIp+")"); - reachability = fastPollPc(details.localIp, details.remoteIp); + LimeLog.info("Starting fast poll for "+details.name+" ("+details.localAddress +", "+details.remoteAddress +")"); + reachability = fastPollPc(details.localAddress, details.remoteAddress); 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 @@ -518,39 +518,39 @@ public class ComputerManagerService extends Service { boolean localFirst = (reachability == ComputerDetails.Reachability.LOCAL); if (localFirst) { - polledDetails = tryPollIp(details, details.localIp); + polledDetails = tryPollIp(details, details.localAddress); } else { - polledDetails = tryPollIp(details, details.remoteIp); + polledDetails = tryPollIp(details, details.remoteAddress); } InetAddress reachableAddr = null; - if (polledDetails == null && !details.localIp.equals(details.remoteIp)) { + if (polledDetails == null && !details.localAddress.equals(details.remoteAddress)) { // Failed, so let's try the fallback if (!localFirst) { - polledDetails = tryPollIp(details, details.localIp); + polledDetails = tryPollIp(details, details.localAddress); } else { - polledDetails = tryPollIp(details, details.remoteIp); + polledDetails = tryPollIp(details, details.remoteAddress); } if (polledDetails != null) { // The fallback poll worked - reachableAddr = !localFirst ? details.localIp : details.remoteIp; + reachableAddr = !localFirst ? details.localAddress : details.remoteAddress; } } else if (polledDetails != null) { - reachableAddr = localFirst ? details.localIp : details.remoteIp; + reachableAddr = localFirst ? details.localAddress : details.remoteAddress; } if (reachableAddr == null) { return null; } - if (polledDetails.remoteIp.equals(reachableAddr)) { + if (polledDetails.remoteAddress.equals(reachableAddr)) { polledDetails.reachability = ComputerDetails.Reachability.REMOTE; } - else if (polledDetails.localIp.equals(reachableAddr)) { + else if (polledDetails.localAddress.equals(reachableAddr)) { polledDetails.reachability = ComputerDetails.Reachability.LOCAL; } else { @@ -572,7 +572,7 @@ public class ComputerManagerService extends Service { ReachabilityTuple confirmationReachTuple = pollForReachability(initialReachTuple.computer); if (confirmationReachTuple == null) { // Neither of those seem to work, so we'll hold onto the address that did work - initialReachTuple.computer.localIp = initialReachTuple.reachableAddress; + initialReachTuple.computer.localAddress = initialReachTuple.reachableAddress; initialReachTuple.computer.reachability = ComputerDetails.Reachability.LOCAL; } else { diff --git a/app/src/main/java/com/limelight/utils/ServerHelper.java b/app/src/main/java/com/limelight/utils/ServerHelper.java index 24b6194e..c05736a5 100644 --- a/app/src/main/java/com/limelight/utils/ServerHelper.java +++ b/app/src/main/java/com/limelight/utils/ServerHelper.java @@ -20,7 +20,7 @@ import java.net.UnknownHostException; public class ServerHelper { public static InetAddress getCurrentAddressFromComputer(ComputerDetails computer) { return computer.reachability == ComputerDetails.Reachability.LOCAL ? - computer.localIp : computer.remoteIp; + computer.localAddress : computer.remoteAddress; } public static Intent createStartIntent(Activity parent, NvApp app, ComputerDetails computer, diff --git a/moonlight-common b/moonlight-common index 66567753..bea3830a 160000 --- a/moonlight-common +++ b/moonlight-common @@ -1 +1 @@ -Subproject commit 66567753b77b7d8efe24ec4a110c1089f653613a +Subproject commit bea3830a63b4a8c537dc2f22c8b91e24c0545155