mirror of
https://github.com/overte-org/overte.git
synced 2025-06-26 07:09:43 +02:00
Merge pull request #8363 from birarda/no-temp-ice-update
Avoid DS heartbeats with non-metaverse domain ID
This commit is contained in:
commit
652bea8cd0
2 changed files with 98 additions and 58 deletions
|
@ -117,9 +117,18 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
||||||
_settingsManager.apiRefreshGroupInformation();
|
_settingsManager.apiRefreshGroupInformation();
|
||||||
|
|
||||||
setupNodeListAndAssignments();
|
setupNodeListAndAssignments();
|
||||||
|
|
||||||
|
if (_type == MetaverseDomain) {
|
||||||
|
// if we have a metaverse domain, we'll need an access token to heartbeat handle auto-networking
|
||||||
|
resetAccountManagerAccessToken();
|
||||||
|
}
|
||||||
|
|
||||||
setupAutomaticNetworking();
|
setupAutomaticNetworking();
|
||||||
if (!getID().isNull()) {
|
|
||||||
|
if (!getID().isNull() && _type != NonMetaverse) {
|
||||||
|
// setup periodic heartbeats to metaverse API
|
||||||
setupHeartbeatToMetaverse();
|
setupHeartbeatToMetaverse();
|
||||||
|
|
||||||
// send the first heartbeat immediately
|
// send the first heartbeat immediately
|
||||||
sendHeartbeatToMetaverse();
|
sendHeartbeatToMetaverse();
|
||||||
}
|
}
|
||||||
|
@ -301,16 +310,22 @@ void DomainServer::handleTempDomainSuccess(QNetworkReply& requestReply) {
|
||||||
// store the new ID and auto networking setting on disk
|
// store the new ID and auto networking setting on disk
|
||||||
_settingsManager.persistToFile();
|
_settingsManager.persistToFile();
|
||||||
|
|
||||||
// change our domain ID immediately
|
|
||||||
DependencyManager::get<LimitedNodeList>()->setSessionUUID(QUuid { id });
|
|
||||||
|
|
||||||
// store the new token to the account info
|
// store the new token to the account info
|
||||||
auto accountManager = DependencyManager::get<AccountManager>();
|
auto accountManager = DependencyManager::get<AccountManager>();
|
||||||
accountManager->setTemporaryDomain(id, key);
|
accountManager->setTemporaryDomain(id, key);
|
||||||
|
|
||||||
|
// change our domain ID immediately
|
||||||
|
DependencyManager::get<LimitedNodeList>()->setSessionUUID(QUuid { id });
|
||||||
|
|
||||||
|
// change our type to reflect that we are a temporary domain now
|
||||||
|
_type = MetaverseTemporaryDomain;
|
||||||
|
|
||||||
// update our heartbeats to use the correct id
|
// update our heartbeats to use the correct id
|
||||||
setupICEHeartbeatForFullNetworking();
|
setupICEHeartbeatForFullNetworking();
|
||||||
setupHeartbeatToMetaverse();
|
setupHeartbeatToMetaverse();
|
||||||
|
|
||||||
|
// if we have a current ICE server address, update it in the API for the new temporary domain
|
||||||
|
sendICEServerAddressToMetaverseAPI();
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "There were problems parsing the API response containing a temporary domain name. Please try again"
|
qWarning() << "There were problems parsing the API response containing a temporary domain name. Please try again"
|
||||||
<< "via domain-server relaunch or from the domain-server settings.";
|
<< "via domain-server relaunch or from the domain-server settings.";
|
||||||
|
@ -394,6 +409,16 @@ void DomainServer::setupNodeListAndAssignments() {
|
||||||
const QVariant* idValueVariant = valueForKeyPath(settingsMap, METAVERSE_DOMAIN_ID_KEY_PATH);
|
const QVariant* idValueVariant = valueForKeyPath(settingsMap, METAVERSE_DOMAIN_ID_KEY_PATH);
|
||||||
if (idValueVariant) {
|
if (idValueVariant) {
|
||||||
nodeList->setSessionUUID(idValueVariant->toString());
|
nodeList->setSessionUUID(idValueVariant->toString());
|
||||||
|
|
||||||
|
// if we have an ID, we'll assume we're a metaverse domain
|
||||||
|
// now see if we think we're a temp domain (we have an API key) or a full domain
|
||||||
|
const auto& temporaryDomainKey = DependencyManager::get<AccountManager>()->getTemporaryDomainKey(getID());
|
||||||
|
if (temporaryDomainKey.isEmpty()) {
|
||||||
|
_type = MetaverseDomain;
|
||||||
|
} else {
|
||||||
|
_type = MetaverseTemporaryDomain;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
nodeList->setSessionUUID(QUuid::createUuid()); // Use random UUID
|
nodeList->setSessionUUID(QUuid::createUuid()); // Use random UUID
|
||||||
}
|
}
|
||||||
|
@ -477,42 +502,46 @@ bool DomainServer::resetAccountManagerAccessToken() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainServer::setupAutomaticNetworking() {
|
void DomainServer::setupAutomaticNetworking() {
|
||||||
qDebug() << "Updating automatic networking setting in domain-server to" << _automaticNetworkingSetting;
|
|
||||||
|
|
||||||
resetAccountManagerAccessToken();
|
|
||||||
|
|
||||||
_automaticNetworkingSetting =
|
_automaticNetworkingSetting =
|
||||||
_settingsManager.valueOrDefaultValueForKeyPath(METAVERSE_AUTOMATIC_NETWORKING_KEY_PATH).toString();
|
_settingsManager.valueOrDefaultValueForKeyPath(METAVERSE_AUTOMATIC_NETWORKING_KEY_PATH).toString();
|
||||||
|
|
||||||
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
qDebug() << "Configuring automatic networking in domain-server as" << _automaticNetworkingSetting;
|
||||||
const QUuid& domainID = getID();
|
|
||||||
|
|
||||||
if (_automaticNetworkingSetting == FULL_AUTOMATIC_NETWORKING_VALUE) {
|
if (_automaticNetworkingSetting != DISABLED_AUTOMATIC_NETWORKING_VALUE) {
|
||||||
setupICEHeartbeatForFullNetworking();
|
const QUuid& domainID = getID();
|
||||||
}
|
|
||||||
|
|
||||||
if (_automaticNetworkingSetting == IP_ONLY_AUTOMATIC_NETWORKING_VALUE ||
|
if (_automaticNetworkingSetting == FULL_AUTOMATIC_NETWORKING_VALUE) {
|
||||||
_automaticNetworkingSetting == FULL_AUTOMATIC_NETWORKING_VALUE) {
|
setupICEHeartbeatForFullNetworking();
|
||||||
|
}
|
||||||
|
|
||||||
if (!domainID.isNull()) {
|
if (_automaticNetworkingSetting == IP_ONLY_AUTOMATIC_NETWORKING_VALUE ||
|
||||||
qDebug() << "domain-server" << _automaticNetworkingSetting << "automatic networking enabled for ID"
|
_automaticNetworkingSetting == FULL_AUTOMATIC_NETWORKING_VALUE) {
|
||||||
<< uuidStringWithoutCurlyBraces(domainID) << "via" << _oauthProviderURL.toString();
|
|
||||||
|
|
||||||
if (_automaticNetworkingSetting == IP_ONLY_AUTOMATIC_NETWORKING_VALUE) {
|
if (!domainID.isNull()) {
|
||||||
// send any public socket changes to the data server so nodes can find us at our new IP
|
qDebug() << "domain-server" << _automaticNetworkingSetting << "automatic networking enabled for ID"
|
||||||
connect(nodeList.data(), &LimitedNodeList::publicSockAddrChanged,
|
<< uuidStringWithoutCurlyBraces(domainID) << "via" << _oauthProviderURL.toString();
|
||||||
this, &DomainServer::performIPAddressUpdate);
|
|
||||||
|
|
||||||
// have the LNL enable public socket updating via STUN
|
if (_automaticNetworkingSetting == IP_ONLY_AUTOMATIC_NETWORKING_VALUE) {
|
||||||
nodeList->startSTUNPublicSocketUpdate();
|
|
||||||
|
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
||||||
|
|
||||||
|
// send any public socket changes to the data server so nodes can find us at our new IP
|
||||||
|
connect(nodeList.data(), &LimitedNodeList::publicSockAddrChanged,
|
||||||
|
this, &DomainServer::performIPAddressUpdate);
|
||||||
|
|
||||||
|
// have the LNL enable public socket updating via STUN
|
||||||
|
nodeList->startSTUNPublicSocketUpdate();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qDebug() << "Cannot enable domain-server automatic networking without a domain ID."
|
||||||
|
<< "Please add an ID to your config file or via the web interface.";
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
qDebug() << "Cannot enable domain-server automatic networking without a domain ID."
|
|
||||||
<< "Please add an ID to your config file or via the web interface.";
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainServer::setupHeartbeatToMetaverse() {
|
void DomainServer::setupHeartbeatToMetaverse() {
|
||||||
|
@ -1139,42 +1168,45 @@ void DomainServer::handleMetaverseHeartbeatError(QNetworkReply& requestReply) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if we need to force a new temporary domain name
|
// only attempt to grab a new temporary name if we're already a temporary domain server
|
||||||
switch (requestReply.error()) {
|
if (_type == MetaverseTemporaryDomain) {
|
||||||
// if we have a temporary domain with a bad token, we get a 401
|
// check if we need to force a new temporary domain name
|
||||||
case QNetworkReply::NetworkError::AuthenticationRequiredError: {
|
switch (requestReply.error()) {
|
||||||
static const QString DATA_KEY = "data";
|
// if we have a temporary domain with a bad token, we get a 401
|
||||||
static const QString TOKEN_KEY = "api_key";
|
case QNetworkReply::NetworkError::AuthenticationRequiredError: {
|
||||||
|
static const QString DATA_KEY = "data";
|
||||||
|
static const QString TOKEN_KEY = "api_key";
|
||||||
|
|
||||||
QJsonObject jsonObject = QJsonDocument::fromJson(requestReply.readAll()).object();
|
QJsonObject jsonObject = QJsonDocument::fromJson(requestReply.readAll()).object();
|
||||||
auto tokenFailure = jsonObject[DATA_KEY].toObject()[TOKEN_KEY];
|
auto tokenFailure = jsonObject[DATA_KEY].toObject()[TOKEN_KEY];
|
||||||
|
|
||||||
if (!tokenFailure.isNull()) {
|
if (!tokenFailure.isNull()) {
|
||||||
qWarning() << "Temporary domain name lacks a valid API key, and is being reset.";
|
qWarning() << "Temporary domain name lacks a valid API key, and is being reset.";
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
// if the domain does not (or no longer) exists, we get a 404
|
||||||
|
case QNetworkReply::NetworkError::ContentNotFoundError:
|
||||||
|
qWarning() << "Domain not found, getting a new temporary domain.";
|
||||||
|
break;
|
||||||
|
// otherwise, we erred on something else, and should not force a temporary domain
|
||||||
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
// if the domain does not (or no longer) exists, we get a 404
|
|
||||||
case QNetworkReply::NetworkError::ContentNotFoundError:
|
|
||||||
qWarning() << "Domain not found, getting a new temporary domain.";
|
|
||||||
break;
|
|
||||||
// otherwise, we erred on something else, and should not force a temporary domain
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// halt heartbeats until we have a token
|
// halt heartbeats until we have a token
|
||||||
_metaverseHeartbeatTimer->deleteLater();
|
_metaverseHeartbeatTimer->deleteLater();
|
||||||
_metaverseHeartbeatTimer = nullptr;
|
_metaverseHeartbeatTimer = nullptr;
|
||||||
|
|
||||||
// give up eventually to avoid flooding traffic
|
// give up eventually to avoid flooding traffic
|
||||||
static const int MAX_ATTEMPTS = 5;
|
static const int MAX_ATTEMPTS = 5;
|
||||||
static int attempt = 0;
|
static int attempt = 0;
|
||||||
if (++attempt < MAX_ATTEMPTS) {
|
if (++attempt < MAX_ATTEMPTS) {
|
||||||
// get a new temporary name and token
|
// get a new temporary name and token
|
||||||
getTemporaryName(true);
|
getTemporaryName(true);
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Already attempted too many temporary domain requests. Please set a domain ID manually or restart.";
|
qWarning() << "Already attempted too many temporary domain requests. Please set a domain ID manually or restart.";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,12 @@ public:
|
||||||
DomainServer(int argc, char* argv[]);
|
DomainServer(int argc, char* argv[]);
|
||||||
~DomainServer();
|
~DomainServer();
|
||||||
|
|
||||||
|
enum DomainType {
|
||||||
|
NonMetaverse,
|
||||||
|
MetaverseDomain,
|
||||||
|
MetaverseTemporaryDomain
|
||||||
|
};
|
||||||
|
|
||||||
static int const EXIT_CODE_REBOOT;
|
static int const EXIT_CODE_REBOOT;
|
||||||
|
|
||||||
bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler = false);
|
bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler = false);
|
||||||
|
@ -195,6 +201,8 @@ private:
|
||||||
int _numHeartbeatDenials { 0 };
|
int _numHeartbeatDenials { 0 };
|
||||||
bool _connectedToICEServer { false };
|
bool _connectedToICEServer { false };
|
||||||
|
|
||||||
|
DomainType _type { DomainType::NonMetaverse };
|
||||||
|
|
||||||
friend class DomainGatekeeper;
|
friend class DomainGatekeeper;
|
||||||
friend class DomainMetadata;
|
friend class DomainMetadata;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue