From 14c03f0b37ad59cf5f815657dda87980bff9118c Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 19 Sep 2014 18:57:20 -0700 Subject: [PATCH] Improve connection negotiation speed by caching serverinfo --- .../com/limelight/nvstream/NvConnection.java | 18 +++++++++------ .../com/limelight/nvstream/http/NvHTTP.java | 22 ++++++++++++------- .../nvstream/http/PairingManager.java | 11 ++-------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/moonlight-common/src/com/limelight/nvstream/NvConnection.java b/moonlight-common/src/com/limelight/nvstream/NvConnection.java index 43acc4f6..eacb52af 100644 --- a/moonlight-common/src/com/limelight/nvstream/NvConnection.java +++ b/moonlight-common/src/com/limelight/nvstream/NvConnection.java @@ -102,12 +102,14 @@ public class NvConnection { { NvHTTP h = new NvHTTP(hostAddr, uniqueId, localDeviceName, cryptoProvider); - if (!h.getServerVersion().startsWith("3.")) { + String serverInfo = h.getServerInfo(uniqueId); + + if (!h.getServerVersion(serverInfo).startsWith("3.")) { listener.displayMessage("Limelight now requires GeForce Experience 2.1.1 or later. Please upgrade GFE on your PC and try again."); return false; } - if (h.getPairState() != PairingManager.PairState.PAIRED) { + if (h.getPairState(serverInfo) != PairingManager.PairState.PAIRED) { listener.displayMessage("Device not paired with computer"); return false; } @@ -119,12 +121,14 @@ public class NvConnection { } // If there's a game running, resume it - if (h.getCurrentGame() != 0) { + if (h.getCurrentGame(serverInfo) != 0) { try { - if (h.getCurrentGame() == app.getAppId() && !h.resumeApp(riKey, riKeyId)) { - listener.displayMessage("Failed to resume existing session"); - return false; - } else if (h.getCurrentGame() != app.getAppId()) { + if (h.getCurrentGame(serverInfo) == app.getAppId()) { + if (!h.resumeApp(riKey, riKeyId)) { + listener.displayMessage("Failed to resume existing session"); + return false; + } + } else if (h.getCurrentGame(serverInfo) != app.getAppId()) { return quitAndLaunch(h, app); } } catch (GfeHttpResponseException e) { diff --git a/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java b/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java index b70352e7..b14758a3 100644 --- a/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java +++ b/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java @@ -100,9 +100,13 @@ public class NvHTTP { } } + public String getServerInfo(String uniqueId) throws MalformedURLException, IOException { + return openHttpConnectionToString(baseUrl + "/serverinfo?uniqueid=" + uniqueId); + } + public ComputerDetails getComputerDetails() throws MalformedURLException, IOException, XmlPullParserException { ComputerDetails details = new ComputerDetails(); - String serverInfo = openHttpConnectionToString(baseUrl + "/serverinfo?uniqueid=" + uniqueId); + String serverInfo = getServerInfo(uniqueId); details.name = getXmlString(serverInfo, "hostname").trim(); details.uuid = UUID.fromString(getXmlString(serverInfo, "uniqueid").trim()); @@ -170,18 +174,20 @@ public class NvHTTP { return str; } - public String getServerVersion() throws XmlPullParserException, IOException { - InputStream in = openHttpConnection(baseUrl + "/serverinfo?uniqueid=" + uniqueId); - return getXmlString(in, "appversion"); + public String getServerVersion(String serverInfo) throws XmlPullParserException, IOException { + return getXmlString(serverInfo, "appversion"); } public PairingManager.PairState getPairState() throws IOException, XmlPullParserException { - return pm.getPairState(uniqueId); + return pm.getPairState(getServerInfo(uniqueId)); } - public int getCurrentGame() throws IOException, XmlPullParserException { - InputStream in = openHttpConnection(baseUrl + "/serverinfo?uniqueid=" + uniqueId); - String game = getXmlString(in, "currentgame"); + public PairingManager.PairState getPairState(String serverInfo) throws IOException, XmlPullParserException { + return pm.getPairState(serverInfo); + } + + public int getCurrentGame(String serverInfo) throws IOException, XmlPullParserException { + String game = getXmlString(serverInfo, "currentgame"); return Integer.parseInt(game); } diff --git a/moonlight-common/src/com/limelight/nvstream/http/PairingManager.java b/moonlight-common/src/com/limelight/nvstream/http/PairingManager.java index 60a2e8e3..61a4c293 100644 --- a/moonlight-common/src/com/limelight/nvstream/http/PairingManager.java +++ b/moonlight-common/src/com/limelight/nvstream/http/PairingManager.java @@ -219,19 +219,12 @@ public class PairingManager { r.nextInt(10), r.nextInt(10)); } - public PairState getPairState(String uniqueId) throws MalformedURLException, IOException, XmlPullParserException { - String serverInfo = http.openHttpConnectionToString(http.baseUrl + "/serverinfo?uniqueid="+uniqueId); + public PairState getPairState(String serverInfo) throws MalformedURLException, IOException, XmlPullParserException { if (!NvHTTP.getXmlString(serverInfo, "PairStatus").equals("1")) { return PairState.NOT_PAIRED; } - String pairChallenge = http.openHttpConnectionToString(http.baseUrl + "/pair?uniqueid="+uniqueId+"&devicename=roth&updateState=1&phrase=pairchallenge"); - if (NvHTTP.getXmlString(pairChallenge, "paired").equals("1")) { - return PairState.PAIRED; - } - else { - return PairState.NOT_PAIRED; - } + return PairState.PAIRED; } public PairState pair(String uniqueId, String pin) throws MalformedURLException, IOException, XmlPullParserException, CertificateException, InvalidKeyException, NoSuchAlgorithmException, SignatureException, ShortBufferException, IllegalBlockSizeException, BadPaddingException, NoSuchPaddingException {