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);
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) {

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 {
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);
}

View File

@ -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 {