Refactor NvPairingManager, NvComputer, and NvHTTP to reduce passing of addresses

This commit is contained in:
Cameron Gutman 2021-07-02 17:14:48 -05:00
parent bee8378795
commit 5afab126b3
9 changed files with 48 additions and 17 deletions

View file

@ -106,7 +106,7 @@ void BoxArtManager::handleBoxArtLoadComplete(NvComputer* computer, NvApp app, QU
QUrl BoxArtManager::loadBoxArtFromNetwork(NvComputer* computer, int appId) QUrl BoxArtManager::loadBoxArtFromNetwork(NvComputer* computer, int appId)
{ {
NvHTTP http(computer->activeAddress, computer->serverCert); NvHTTP http(computer);
QString cachePath = getFilePathForBoxArt(computer, appId); QString cachePath = getFilePathForBoxArt(computer, appId);
QImage image; QImage image;

View file

@ -38,7 +38,7 @@ private:
return false; return false;
} }
NvComputer newState(address, serverInfo, QSslCertificate()); NvComputer newState(http, serverInfo);
// Ensure the machine that responded is the one we intended to contact // Ensure the machine that responded is the one we intended to contact
if (m_Computer->uuid != newState.uuid) { if (m_Computer->uuid != newState.uuid) {
@ -54,7 +54,7 @@ private:
{ {
Q_ASSERT(m_Computer->activeAddress != nullptr); Q_ASSERT(m_Computer->activeAddress != nullptr);
NvHTTP http(m_Computer->activeAddress, m_Computer->serverCert); NvHTTP http(m_Computer);
QVector<NvApp> appList; QVector<NvApp> appList;
@ -470,7 +470,7 @@ signals:
private: private:
void run() void run()
{ {
NvPairingManager pairingManager(m_Computer->activeAddress); NvPairingManager pairingManager(m_Computer);
try { try {
NvPairingManager::PairState result = pairingManager.pair(m_Computer->appVersion, m_Pin, m_Computer->serverCert); NvPairingManager::PairState result = pairingManager.pair(m_Computer->appVersion, m_Pin, m_Computer->serverCert);
@ -526,7 +526,7 @@ signals:
private: private:
void run() void run()
{ {
NvHTTP http(m_Computer->activeAddress, m_Computer->serverCert); NvHTTP http(m_Computer);
try { try {
if (m_Computer->currentGameId != 0) { if (m_Computer->currentGameId != 0) {
@ -677,7 +677,7 @@ private:
} }
// Create initial newComputer using HTTP serverinfo with no pinned cert // Create initial newComputer using HTTP serverinfo with no pinned cert
NvComputer* newComputer = new NvComputer(http.address(), serverInfo, QSslCertificate()); NvComputer* newComputer = new NvComputer(http, serverInfo);
// Check if we have a record of this host UUID to pull the pinned cert // Check if we have a record of this host UUID to pull the pinned cert
NvComputer* existingComputer; NvComputer* existingComputer;
@ -697,7 +697,7 @@ private:
} }
// Update the polled computer with the HTTPS information // Update the polled computer with the HTTPS information
NvComputer httpsComputer(http.address(), serverInfo, QSslCertificate()); NvComputer httpsComputer(http, serverInfo);
newComputer->update(httpsComputer); newComputer->update(httpsComputer);
} }

View file

@ -87,9 +87,9 @@ void NvComputer::sortAppList()
}); });
} }
NvComputer::NvComputer(QString address, QString serverInfo, QSslCertificate serverCert) NvComputer::NvComputer(NvHTTP& http, QString serverInfo)
{ {
this->serverCert = serverCert; this->serverCert = http.serverCert();
this->hasCustomName = false; this->hasCustomName = false;
this->name = NvHTTP::getXmlString(serverInfo, "hostname"); this->name = NvHTTP::getXmlString(serverInfo, "hostname");
@ -142,7 +142,7 @@ NvComputer::NvComputer(QString address, QString serverInfo, QSslCertificate serv
this->appVersion = NvHTTP::getXmlString(serverInfo, "appversion"); this->appVersion = NvHTTP::getXmlString(serverInfo, "appversion");
this->gfeVersion = NvHTTP::getXmlString(serverInfo, "GfeVersion"); this->gfeVersion = NvHTTP::getXmlString(serverInfo, "GfeVersion");
this->gpuModel = NvHTTP::getXmlString(serverInfo, "gputype"); this->gpuModel = NvHTTP::getXmlString(serverInfo, "gputype");
this->activeAddress = address; this->activeAddress = http.address();
this->state = NvComputer::CS_ONLINE; this->state = NvComputer::CS_ONLINE;
this->pendingQuit = false; this->pendingQuit = false;
this->isSupportedServerVersion = CompatFetcher::isGfeVersionSupported(this->gfeVersion); this->isSupportedServerVersion = CompatFetcher::isGfeVersionSupported(this->gfeVersion);

View file

@ -21,7 +21,7 @@ private:
bool pendingQuit; bool pendingQuit;
public: public:
explicit NvComputer(QString address, QString serverInfo, QSslCertificate serverCert); explicit NvComputer(NvHTTP& http, QString serverInfo);
explicit NvComputer(QSettings& settings); explicit NvComputer(QSettings& settings);

View file

@ -1,4 +1,4 @@
#include "nvhttp.h" #include "nvcomputer.h"
#include <Limelight.h> #include <Limelight.h>
#include <QDebug> #include <QDebug>
@ -35,6 +35,12 @@ NvHTTP::NvHTTP(QString address, QSslCertificate serverCert) :
connect(&m_Nam, &QNetworkAccessManager::sslErrors, this, &NvHTTP::handleSslErrors); connect(&m_Nam, &QNetworkAccessManager::sslErrors, this, &NvHTTP::handleSslErrors);
} }
NvHTTP::NvHTTP(NvComputer* computer) :
NvHTTP(computer->activeAddress, computer->serverCert)
{
}
void NvHTTP::setServerCert(QSslCertificate serverCert) void NvHTTP::setServerCert(QSslCertificate serverCert)
{ {
m_ServerCert = serverCert; m_ServerCert = serverCert;
@ -55,6 +61,21 @@ QString NvHTTP::address()
return m_Address; return m_Address;
} }
QSslCertificate NvHTTP::serverCert()
{
return m_ServerCert;
}
uint16_t NvHTTP::httpPort()
{
return m_BaseUrlHttp.port();
}
uint16_t NvHTTP::httpsPort()
{
return m_BaseUrlHttps.port();
}
QVector<int> QVector<int>
NvHTTP::parseQuad(QString quad) NvHTTP::parseQuad(QString quad)
{ {

View file

@ -9,6 +9,8 @@
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QNetworkReply> #include <QNetworkReply>
class NvComputer;
class NvDisplayMode class NvDisplayMode
{ {
public: public:
@ -108,6 +110,8 @@ public:
explicit NvHTTP(QString address, QSslCertificate serverCert); explicit NvHTTP(QString address, QSslCertificate serverCert);
explicit NvHTTP(NvComputer* computer);
static static
int int
getCurrentGame(QString serverInfo); getCurrentGame(QString serverInfo);
@ -142,6 +146,12 @@ public:
QString address(); QString address();
QSslCertificate serverCert();
uint16_t httpPort();
uint16_t httpsPort();
static static
QVector<int> QVector<int>
parseQuad(QString quad); parseQuad(QString quad);

View file

@ -11,8 +11,8 @@
#define REQUEST_TIMEOUT_MS 5000 #define REQUEST_TIMEOUT_MS 5000
NvPairingManager::NvPairingManager(QString address) : NvPairingManager::NvPairingManager(NvComputer* computer) :
m_Http(address, QSslCertificate()) m_Http(computer)
{ {
QByteArray cert = IdentityManager::get()->getCertificate(); QByteArray cert = IdentityManager::get()->getCertificate();
BIO *bio = BIO_new_mem_buf(cert.data(), -1); BIO *bio = BIO_new_mem_buf(cert.data(), -1);

View file

@ -17,7 +17,7 @@ public:
ALREADY_IN_PROGRESS ALREADY_IN_PROGRESS
}; };
explicit NvPairingManager(QString address); explicit NvPairingManager(NvComputer* computer);
~NvPairingManager(); ~NvPairingManager();

View file

@ -782,7 +782,7 @@ private:
// Perform a best-effort app quit // Perform a best-effort app quit
if (shouldQuit) { if (shouldQuit) {
NvHTTP http(m_Session->m_Computer->activeAddress, m_Session->m_Computer->serverCert); NvHTTP http(m_Session->m_Computer);
// Logging is already done inside NvHTTP // Logging is already done inside NvHTTP
try { try {
@ -1029,7 +1029,7 @@ bool Session::startConnectionAsync()
QString rtspSessionUrl; QString rtspSessionUrl;
try { try {
NvHTTP http(m_Computer->activeAddress, m_Computer->serverCert); NvHTTP http(m_Computer);
if (m_Computer->currentGameId != 0) { if (m_Computer->currentGameId != 0) {
http.resumeApp(&m_StreamConfig, rtspSessionUrl); http.resumeApp(&m_StreamConfig, rtspSessionUrl);
} }