handle upload of domain public key to metaverse API

This commit is contained in:
Stephen Birarda 2016-02-19 16:55:12 -08:00
parent 6e4ecffb09
commit 837c4c0810
2 changed files with 15 additions and 3 deletions

View file

@ -489,6 +489,10 @@ void DomainServer::setupICEHeartbeatForFullNetworking() {
limitedNodeList->startSTUNPublicSocketUpdate();
// to send ICE heartbeats we'd better have a private key locally with an uploaded public key
auto& accountManager = AccountManager::getInstance();
if (!accountManager.getAccountInfo().hasPrivateKey()) {
accountManager.generateNewDomainKeypair(limitedNodeList->getSessionUUID());
}
if (!_iceHeartbeatTimer) {
// setup a timer to heartbeat with the ice-server every so often

View file

@ -589,7 +589,7 @@ void AccountManager::requestProfileError(QNetworkReply::NetworkError error) {
void AccountManager::generateNewKeypair(bool isUserKeypair, const QUuid& domainID) {
if (!isUserKeypair && domainID.isNull()) {
qWarning() << "AccountManager::generateNewKeypair called for domain keypair with no domain ID. Will not generate keypair.";
qCWarning(networking) << "AccountManager::generateNewKeypair called for domain keypair with no domain ID. Will not generate keypair.";
return;
}
@ -633,7 +633,15 @@ void AccountManager::processGeneratedKeypair() {
persistAccountToSettings();
// upload the public key so data-web has an up-to-date key
const QString PUBLIC_KEY_UPDATE_PATH = "api/v1/user/public_key";
const QString USER_PUBLIC_KEY_UPDATE_PATH = "api/v1/user/public_key";
const QString DOMAIN_PUBLIC_KEY_UPDATE_PATH = "api/v1/domains/%1/public_key";
QString uploadPath;
if (keypairGenerator->getDomainID().isNull()) {
uploadPath = USER_PUBLIC_KEY_UPDATE_PATH;
} else {
uploadPath = DOMAIN_PUBLIC_KEY_UPDATE_PATH.arg(uuidStringWithoutCurlyBraces(keypairGenerator->getDomainID()));
}
// setup a multipart upload to send up the public key
QHttpMultiPart* requestMultiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
@ -646,7 +654,7 @@ void AccountManager::processGeneratedKeypair() {
requestMultiPart->append(keyPart);
sendRequest(PUBLIC_KEY_UPDATE_PATH, AccountManagerAuth::Required, QNetworkAccessManager::PutOperation,
sendRequest(uploadPath, AccountManagerAuth::Required, QNetworkAccessManager::PutOperation,
JSONCallbackParameters(), QByteArray(), requestMultiPart);
keypairGenerator->deleteLater();