mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 07:37:20 +02:00
cleanup migrations from previous account file system
This commit is contained in:
parent
f553becabe
commit
fa5f2571d7
3 changed files with 43 additions and 54 deletions
|
@ -96,7 +96,7 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
||||||
// make sure we hear about newly connected nodes from our gatekeeper
|
// make sure we hear about newly connected nodes from our gatekeeper
|
||||||
connect(&_gatekeeper, &DomainGatekeeper::connectedNode, this, &DomainServer::handleConnectedNode);
|
connect(&_gatekeeper, &DomainGatekeeper::connectedNode, this, &DomainServer::handleConnectedNode);
|
||||||
|
|
||||||
if (optionallyReadX509KeyAndCertificate() && optionallySetupOAuth() && optionallySetupAssignmentPayment()) {
|
if (optionallyReadX509KeyAndCertificate() && optionallySetupOAuth()) {
|
||||||
// we either read a certificate and private key or were not passed one
|
// we either read a certificate and private key or were not passed one
|
||||||
// and completed login or did not need to
|
// and completed login or did not need to
|
||||||
|
|
||||||
|
@ -376,15 +376,6 @@ void DomainServer::setupNodeListAndAssignments(const QUuid& sessionUUID) {
|
||||||
addStaticAssignmentsToQueue();
|
addStaticAssignmentsToQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DomainServer::didSetupAccountManagerWithAccessToken() {
|
|
||||||
if (AccountManager::getInstance().hasValidAccessToken()) {
|
|
||||||
// we already gave the account manager a valid access token
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return resetAccountManagerAccessToken();
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString ACCESS_TOKEN_KEY_PATH = "metaverse.access_token";
|
const QString ACCESS_TOKEN_KEY_PATH = "metaverse.access_token";
|
||||||
|
|
||||||
bool DomainServer::resetAccountManagerAccessToken() {
|
bool DomainServer::resetAccountManagerAccessToken() {
|
||||||
|
@ -428,34 +419,6 @@ bool DomainServer::resetAccountManagerAccessToken() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DomainServer::optionallySetupAssignmentPayment() {
|
|
||||||
const QString PAY_FOR_ASSIGNMENTS_OPTION = "pay-for-assignments";
|
|
||||||
const QVariantMap& settingsMap = _settingsManager.getSettingsMap();
|
|
||||||
|
|
||||||
if (settingsMap.contains(PAY_FOR_ASSIGNMENTS_OPTION) &&
|
|
||||||
settingsMap.value(PAY_FOR_ASSIGNMENTS_OPTION).toBool() &&
|
|
||||||
didSetupAccountManagerWithAccessToken()) {
|
|
||||||
|
|
||||||
qDebug() << "Assignments will be paid for via" << qPrintable(_oauthProviderURL.toString());
|
|
||||||
|
|
||||||
// assume that the fact we are authing against HF data server means we will pay for assignments
|
|
||||||
// setup a timer to send transactions to pay assigned nodes every 30 seconds
|
|
||||||
QTimer* creditSetupTimer = new QTimer(this);
|
|
||||||
connect(creditSetupTimer, &QTimer::timeout, this, &DomainServer::setupPendingAssignmentCredits);
|
|
||||||
|
|
||||||
const qint64 CREDIT_CHECK_INTERVAL_MSECS = 5 * 1000;
|
|
||||||
creditSetupTimer->start(CREDIT_CHECK_INTERVAL_MSECS);
|
|
||||||
|
|
||||||
QTimer* nodePaymentTimer = new QTimer(this);
|
|
||||||
connect(nodePaymentTimer, &QTimer::timeout, this, &DomainServer::sendPendingTransactionsToServer);
|
|
||||||
|
|
||||||
const qint64 TRANSACTION_SEND_INTERVAL_MSECS = 30 * 1000;
|
|
||||||
nodePaymentTimer->start(TRANSACTION_SEND_INTERVAL_MSECS);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DomainServer::setupAutomaticNetworking() {
|
void DomainServer::setupAutomaticNetworking() {
|
||||||
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
||||||
|
|
||||||
|
@ -466,7 +429,7 @@ void DomainServer::setupAutomaticNetworking() {
|
||||||
setupICEHeartbeatForFullNetworking();
|
setupICEHeartbeatForFullNetworking();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!didSetupAccountManagerWithAccessToken()) {
|
if (!resetAccountManagerAccessToken()) {
|
||||||
qDebug() << "Cannot send heartbeat to data server without an access token.";
|
qDebug() << "Cannot send heartbeat to data server without an access token.";
|
||||||
qDebug() << "Add an access token to your config file or via the web interface.";
|
qDebug() << "Add an access token to your config file or via the web interface.";
|
||||||
|
|
||||||
|
|
|
@ -83,11 +83,9 @@ private:
|
||||||
void setupNodeListAndAssignments(const QUuid& sessionUUID = QUuid::createUuid());
|
void setupNodeListAndAssignments(const QUuid& sessionUUID = QUuid::createUuid());
|
||||||
bool optionallySetupOAuth();
|
bool optionallySetupOAuth();
|
||||||
bool optionallyReadX509KeyAndCertificate();
|
bool optionallyReadX509KeyAndCertificate();
|
||||||
bool optionallySetupAssignmentPayment();
|
|
||||||
|
|
||||||
void optionallyGetTemporaryName(const QStringList& arguments);
|
void optionallyGetTemporaryName(const QStringList& arguments);
|
||||||
|
|
||||||
bool didSetupAccountManagerWithAccessToken();
|
|
||||||
bool resetAccountManagerAccessToken();
|
bool resetAccountManagerAccessToken();
|
||||||
|
|
||||||
void setupAutomaticNetworking();
|
void setupAutomaticNetworking();
|
||||||
|
|
|
@ -86,6 +86,8 @@ AccountManager::AccountManager() :
|
||||||
|
|
||||||
void AccountManager::setIsAgent(bool isAgent) {
|
void AccountManager::setIsAgent(bool isAgent) {
|
||||||
if (_isAgent != isAgent) {
|
if (_isAgent != isAgent) {
|
||||||
|
_isAgent = isAgent;
|
||||||
|
|
||||||
if (_isAgent) {
|
if (_isAgent) {
|
||||||
// any profile changes in account manager should generate a new keypair
|
// any profile changes in account manager should generate a new keypair
|
||||||
connect(this, &AccountManager::profileChanged, this, &AccountManager::generateNewUserKeypair);
|
connect(this, &AccountManager::profileChanged, this, &AccountManager::generateNewUserKeypair);
|
||||||
|
@ -149,8 +151,9 @@ QVariantMap accountMapFromFile(bool& success) {
|
||||||
|
|
||||||
return accountMap;
|
return accountMap;
|
||||||
} else {
|
} else {
|
||||||
// failed to open file, return empty QVariantMap with failure
|
// failed to open file, return empty QVariantMap
|
||||||
success = false;
|
// there was only an error if the account file existed when we tried to load it
|
||||||
|
success = !accountFile.exists();
|
||||||
|
|
||||||
return QVariantMap();
|
return QVariantMap();
|
||||||
}
|
}
|
||||||
|
@ -163,26 +166,51 @@ void AccountManager::setAuthURL(const QUrl& authURL) {
|
||||||
qCDebug(networking) << "AccountManager URL for authenticated requests has been changed to" << qPrintable(_authURL.toString());
|
qCDebug(networking) << "AccountManager URL for authenticated requests has been changed to" << qPrintable(_authURL.toString());
|
||||||
|
|
||||||
// check if there are existing access tokens to load from settings
|
// check if there are existing access tokens to load from settings
|
||||||
bool loadedFile = false;
|
QFile accountsFile { accountFilePath() };
|
||||||
auto accountsMap = accountMapFromFile(loadedFile);
|
bool loadedMap = false;
|
||||||
|
auto accountsMap = accountMapFromFile(loadedMap);
|
||||||
|
|
||||||
if (loadedFile) {
|
if (accountsFile.exists() && loadedMap) {
|
||||||
// pull out the stored access token and store it in memory
|
// pull out the stored access token and store it in memory
|
||||||
_accountInfo = accountsMap[_authURL.toString()].value<DataServerAccountInfo>();
|
_accountInfo = accountsMap[_authURL.toString()].value<DataServerAccountInfo>();
|
||||||
|
|
||||||
qCDebug(networking) << "Found metaverse API account information for" << qPrintable(_authURL.toString());
|
qCDebug(networking) << "Found metaverse API account information for" << qPrintable(_authURL.toString());
|
||||||
|
} else {
|
||||||
|
// we didn't have a file - see if we can migrate old settings and store them in the new file
|
||||||
|
|
||||||
if (_isAgent) {
|
// check if there are existing access tokens to load from settings
|
||||||
// profile info isn't guaranteed to be saved too
|
Settings settings;
|
||||||
if (_accountInfo.hasProfile()) {
|
settings.beginGroup(ACCOUNTS_GROUP);
|
||||||
emit profileChanged();
|
|
||||||
} else {
|
foreach(const QString& key, settings.allKeys()) {
|
||||||
requestProfile();
|
// take a key copy to perform the double slash replacement
|
||||||
|
QString keyCopy(key);
|
||||||
|
QUrl keyURL(keyCopy.replace(DOUBLE_SLASH_SUBSTITUTE, "//"));
|
||||||
|
|
||||||
|
if (keyURL == _authURL) {
|
||||||
|
// pull out the stored access token and store it in memory
|
||||||
|
_accountInfo = settings.value(key).value<DataServerAccountInfo>();
|
||||||
|
|
||||||
|
qCDebug(networking) << "Migrated an access token for" << qPrintable(keyURL.toString())
|
||||||
|
<< "from previous settings file";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
if (_accountInfo.getAccessToken().token.isEmpty()) {
|
||||||
qCWarning(networking) << "Unable to load account file. No existing account settings will be loaded.";
|
qCWarning(networking) << "Unable to load account file. No existing account settings will be loaded.";
|
||||||
|
} else {
|
||||||
|
// persist the migrated settings to file
|
||||||
|
persistAccountToSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_isAgent && !_accountInfo.getAccessToken().token.isEmpty()) {
|
||||||
|
// profile info isn't guaranteed to be saved too
|
||||||
|
if (_accountInfo.hasProfile()) {
|
||||||
|
emit profileChanged();
|
||||||
|
} else {
|
||||||
|
requestProfile();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// tell listeners that the auth endpoint has changed
|
// tell listeners that the auth endpoint has changed
|
||||||
|
|
Loading…
Reference in a new issue