From 83e8c248bd009d22ce2b8f233dac48a76824f48e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 23 Feb 2016 11:20:21 -0800 Subject: [PATCH] repairs to failure case for keypair generation --- domain-server/src/DomainServer.cpp | 14 ++++++++++---- libraries/networking/src/AccountManager.cpp | 20 ++++++++++++++++---- libraries/networking/src/AccountManager.h | 4 ++-- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index de34802bb7..408877072d 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -1057,9 +1057,17 @@ void DomainServer::sendHeartbeatToIceServer() { if (!_iceServerSocket.getAddress().isNull()) { auto& accountManager = AccountManager::getInstance(); + auto limitedNodeList = DependencyManager::get(); + if (!accountManager.getAccountInfo().hasPrivateKey()) { qWarning() << "Cannot send an ice-server heartbeat without a private key for signature."; - qWarning() << "Please re-launch your domain-server to generate a new keypair."; + qWarning() << "Waiting for keypair generation to complete before sending ICE heartbeat."; + + if (!limitedNodeList->getSessionUUID().isNull()) { + accountManager.generateNewDomainKeypair(limitedNodeList->getSessionUUID()); + } else { + qWarning() << "Attempting to send ICE server heartbeat with no domain ID. This is not supported"; + } return; } @@ -1068,9 +1076,7 @@ void DomainServer::sendHeartbeatToIceServer() { // QDataStream and the possibility of IPv6 address for the sockets. static auto heartbeatPacket = NLPacket::create(PacketType::ICEServerHeartbeat); - bool shouldRecreatePacket = false; - - auto limitedNodeList = DependencyManager::get(); + bool shouldRecreatePacket = false if (heartbeatPacket->getPayloadSize() > 0) { // if either of our sockets have changed we need to re-sign the heartbeat diff --git a/libraries/networking/src/AccountManager.cpp b/libraries/networking/src/AccountManager.cpp index 8c43f22cad..69a97825cd 100644 --- a/libraries/networking/src/AccountManager.cpp +++ b/libraries/networking/src/AccountManager.cpp @@ -359,6 +359,8 @@ void AccountManager::passSuccessToCallback(QNetworkReply* requestReply) { qCDebug(networking) << "Received JSON response from metaverse API that has no matching callback."; qCDebug(networking) << QJsonDocument::fromJson(requestReply->readAll()); } + + requestReply->deleteLater(); } } @@ -378,6 +380,8 @@ void AccountManager::passErrorToCallback(QNetworkReply* requestReply) { qCDebug(networking) << "Error" << requestReply->error() << "-" << requestReply->errorString(); qCDebug(networking) << requestReply->readAll(); } + + requestReply->deleteLater(); } } @@ -607,7 +611,6 @@ void AccountManager::generateNewKeypair(bool isUserKeypair, const QUuid& domainI if (!isUserKeypair) { keypairGenerator->setDomainID(domainID); _accountInfo.setDomainID(domainID); - qDebug() << "The account info domain ID is now" << _accountInfo.getDomainID(); } // start keypair generation when the thread starts @@ -630,7 +633,7 @@ void AccountManager::generateNewKeypair(bool isUserKeypair, const QUuid& domainI void AccountManager::processGeneratedKeypair() { - qCDebug(networking) << "Generated 2048-bit RSA keypair. Storing private key and uploading public key."; + qCDebug(networking) << "Generated 2048-bit RSA keypair. Uploading public key now."; RSAKeypairGenerator* keypairGenerator = qobject_cast(sender()); @@ -677,7 +680,9 @@ void AccountManager::processGeneratedKeypair() { } } -void AccountManager::publicKeyUploadSuceeded() { +void AccountManager::publicKeyUploadSucceeded(QNetworkReply& reply) { + qDebug() << "Uploaded public key to Metaverse API. RSA keypair generation is completed."; + // public key upload complete - store the matching private key and persist the account to settings _accountInfo.setPrivateKey(_pendingPrivateKey); _pendingPrivateKey.clear(); @@ -687,16 +692,23 @@ void AccountManager::publicKeyUploadSuceeded() { _isWaitingForKeypairResponse = false; emit newKeypair(); + + // delete the reply object now that we are done with it + reply.deleteLater(); } -void AccountManager::publicKeyUploadFailed() { +void AccountManager::publicKeyUploadFailed(QNetworkReply& reply) { // the public key upload has failed + qWarning() << "Public key upload failed from AccountManager" << reply.errorString(); // we aren't waiting for a response any longer _isWaitingForKeypairResponse = false; // clear our pending private key _pendingPrivateKey.clear(); + + // delete the reply object now that we are done with it + reply.deleteLater(); } void AccountManager::handleKeypairGenerationError() { diff --git a/libraries/networking/src/AccountManager.h b/libraries/networking/src/AccountManager.h index 3c1bf38fbe..24a6500d13 100644 --- a/libraries/networking/src/AccountManager.h +++ b/libraries/networking/src/AccountManager.h @@ -105,8 +105,8 @@ private slots: void processReply(); void handleKeypairGenerationError(); void processGeneratedKeypair(); - void publicKeyUploadSuceeded(); - void publicKeyUploadFailed(); + void publicKeyUploadSucceeded(QNetworkReply& reply); + void publicKeyUploadFailed(QNetworkReply& reply); private: AccountManager();