Improve connection negotiation speed by caching serverinfo

This commit is contained in:
Cameron Gutman 2014-09-19 18:57:20 -07:00
parent 5bd30fe3dc
commit 14c03f0b37
3 changed files with 27 additions and 24 deletions

View File

@ -102,12 +102,14 @@ public class NvConnection {
{ {
NvHTTP h = new NvHTTP(hostAddr, uniqueId, localDeviceName, cryptoProvider); 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."); listener.displayMessage("Limelight now requires GeForce Experience 2.1.1 or later. Please upgrade GFE on your PC and try again.");
return false; return false;
} }
if (h.getPairState() != PairingManager.PairState.PAIRED) { if (h.getPairState(serverInfo) != PairingManager.PairState.PAIRED) {
listener.displayMessage("Device not paired with computer"); listener.displayMessage("Device not paired with computer");
return false; return false;
} }
@ -119,12 +121,14 @@ public class NvConnection {
} }
// If there's a game running, resume it // If there's a game running, resume it
if (h.getCurrentGame() != 0) { if (h.getCurrentGame(serverInfo) != 0) {
try { try {
if (h.getCurrentGame() == app.getAppId() && !h.resumeApp(riKey, riKeyId)) { if (h.getCurrentGame(serverInfo) == app.getAppId()) {
if (!h.resumeApp(riKey, riKeyId)) {
listener.displayMessage("Failed to resume existing session"); listener.displayMessage("Failed to resume existing session");
return false; return false;
} else if (h.getCurrentGame() != app.getAppId()) { }
} else if (h.getCurrentGame(serverInfo) != app.getAppId()) {
return quitAndLaunch(h, app); return quitAndLaunch(h, app);
} }
} catch (GfeHttpResponseException e) { } catch (GfeHttpResponseException e) {

View File

@ -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 { public ComputerDetails getComputerDetails() throws MalformedURLException, IOException, XmlPullParserException {
ComputerDetails details = new ComputerDetails(); ComputerDetails details = new ComputerDetails();
String serverInfo = openHttpConnectionToString(baseUrl + "/serverinfo?uniqueid=" + uniqueId); String serverInfo = getServerInfo(uniqueId);
details.name = getXmlString(serverInfo, "hostname").trim(); details.name = getXmlString(serverInfo, "hostname").trim();
details.uuid = UUID.fromString(getXmlString(serverInfo, "uniqueid").trim()); details.uuid = UUID.fromString(getXmlString(serverInfo, "uniqueid").trim());
@ -170,18 +174,20 @@ public class NvHTTP {
return str; return str;
} }
public String getServerVersion() throws XmlPullParserException, IOException { public String getServerVersion(String serverInfo) throws XmlPullParserException, IOException {
InputStream in = openHttpConnection(baseUrl + "/serverinfo?uniqueid=" + uniqueId); return getXmlString(serverInfo, "appversion");
return getXmlString(in, "appversion");
} }
public PairingManager.PairState getPairState() throws IOException, XmlPullParserException { public PairingManager.PairState getPairState() throws IOException, XmlPullParserException {
return pm.getPairState(uniqueId); return pm.getPairState(getServerInfo(uniqueId));
} }
public int getCurrentGame() throws IOException, XmlPullParserException { public PairingManager.PairState getPairState(String serverInfo) throws IOException, XmlPullParserException {
InputStream in = openHttpConnection(baseUrl + "/serverinfo?uniqueid=" + uniqueId); return pm.getPairState(serverInfo);
String game = getXmlString(in, "currentgame"); }
public int getCurrentGame(String serverInfo) throws IOException, XmlPullParserException {
String game = getXmlString(serverInfo, "currentgame");
return Integer.parseInt(game); return Integer.parseInt(game);
} }

View File

@ -219,20 +219,13 @@ public class PairingManager {
r.nextInt(10), r.nextInt(10)); r.nextInt(10), r.nextInt(10));
} }
public PairState getPairState(String uniqueId) throws MalformedURLException, IOException, XmlPullParserException { public PairState getPairState(String serverInfo) throws MalformedURLException, IOException, XmlPullParserException {
String serverInfo = http.openHttpConnectionToString(http.baseUrl + "/serverinfo?uniqueid="+uniqueId);
if (!NvHTTP.getXmlString(serverInfo, "PairStatus").equals("1")) { if (!NvHTTP.getXmlString(serverInfo, "PairStatus").equals("1")) {
return PairState.NOT_PAIRED; 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; return PairState.PAIRED;
} }
else {
return PairState.NOT_PAIRED;
}
}
public PairState pair(String uniqueId, String pin) throws MalformedURLException, IOException, XmlPullParserException, CertificateException, InvalidKeyException, NoSuchAlgorithmException, SignatureException, ShortBufferException, IllegalBlockSizeException, BadPaddingException, NoSuchPaddingException { public PairState pair(String uniqueId, String pin) throws MalformedURLException, IOException, XmlPullParserException, CertificateException, InvalidKeyException, NoSuchAlgorithmException, SignatureException, ShortBufferException, IllegalBlockSizeException, BadPaddingException, NoSuchPaddingException {
// Generate a salt for hashing the PIN // Generate a salt for hashing the PIN