mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 08:23:04 +02:00
update domain network address updating for IP auto networking
This commit is contained in:
parent
d5b0904d7a
commit
3292808342
4 changed files with 74 additions and 60 deletions
|
@ -75,7 +75,7 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
||||||
loadExistingSessionsFromSettings();
|
loadExistingSessionsFromSettings();
|
||||||
|
|
||||||
// check if we have the flag that enables dynamic IP
|
// check if we have the flag that enables dynamic IP
|
||||||
setupDynamicSocketUpdating();
|
setupAutomaticNetworking();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,54 +305,48 @@ bool DomainServer::optionallySetupAssignmentPayment() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainServer::setupDynamicSocketUpdating() {
|
void DomainServer::setupAutomaticNetworking() {
|
||||||
const QString METAVERSE_AUTOMATIC_NETWORKING_KEY_PATH = "metaverse.automatic_networking";
|
const QString METAVERSE_AUTOMATIC_NETWORKING_KEY_PATH = "metaverse.automatic_networking";
|
||||||
|
|
||||||
const QVariant* automaticNetworkVariant = valueForKeyPath(_settingsManager.getSettingsMap(),
|
|
||||||
METAVERSE_AUTOMATIC_NETWORKING_KEY_PATH);
|
|
||||||
|
|
||||||
const QString FULL_AUTOMATIC_NETWORKING_VALUE = "full";
|
const QString FULL_AUTOMATIC_NETWORKING_VALUE = "full";
|
||||||
const QString IP_ONLY_AUTOMATIC_NETWORKING_VALUE = "ip";
|
const QString IP_ONLY_AUTOMATIC_NETWORKING_VALUE = "ip";
|
||||||
|
|
||||||
if (automaticNetworkVariant) {
|
QString automaticNetworkValue =
|
||||||
|
_settingsManager.valueOrDefaultValueForKeyPath(METAVERSE_AUTOMATIC_NETWORKING_KEY_PATH).toString();
|
||||||
|
|
||||||
|
if (automaticNetworkValue == IP_ONLY_AUTOMATIC_NETWORKING_VALUE) {
|
||||||
|
if (!didSetupAccountManagerWithAccessToken()) {
|
||||||
|
qDebug() << "Cannot enable domain-server automatic networking without an access token.";
|
||||||
|
qDebug() << "Please add an access token to your config file or via the web interface.";
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QString automaticNetworkValue = automaticNetworkVariant->toString();
|
LimitedNodeList* nodeList = LimitedNodeList::getInstance();
|
||||||
if ((automaticNetworkValue == FULL_AUTOMATIC_NETWORKING_VALUE
|
const QUuid& domainID = nodeList->getSessionUUID();
|
||||||
|| automaticNetworkValue == IP_ONLY_AUTOMATIC_NETWORKING_VALUE)) {
|
|
||||||
|
if (!domainID.isNull()) {
|
||||||
|
qDebug() << "domain-server" << automaticNetworkValue << "automatic networking enabled for ID"
|
||||||
|
<< uuidStringWithoutCurlyBraces(domainID) << "via" << _oauthProviderURL.toString();
|
||||||
|
|
||||||
if (!didSetupAccountManagerWithAccessToken()) {
|
const int STUN_IP_ADDRESS_CHECK_INTERVAL_MSECS = 30 * 1000;
|
||||||
qDebug() << "Cannot enable domain-server automatic networking without an access token.";
|
|
||||||
qDebug() << "Please add an access token to your config file or via the web interface.";
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
LimitedNodeList* nodeList = LimitedNodeList::getInstance();
|
// setup our timer to check our IP via stun every 30 seconds
|
||||||
const QUuid& domainID = nodeList->getSessionUUID();
|
QTimer* dynamicIPTimer = new QTimer(this);
|
||||||
|
connect(dynamicIPTimer, &QTimer::timeout, this, &DomainServer::requestCurrentPublicSocketViaSTUN);
|
||||||
|
dynamicIPTimer->start(STUN_IP_ADDRESS_CHECK_INTERVAL_MSECS);
|
||||||
|
|
||||||
if (!domainID.isNull()) {
|
// send public socket changes to the data server so nodes can find us at our new IP
|
||||||
qDebug() << "domain-server" << automaticNetworkValue << "automatic networking enabled for ID"
|
connect(nodeList, &LimitedNodeList::publicSockAddrChanged, this, &DomainServer::performIPAddressUpdate);
|
||||||
<< uuidStringWithoutCurlyBraces(domainID) << "via" << _oauthProviderURL.toString();
|
|
||||||
|
// attempt to update our sockets now
|
||||||
const int STUN_IP_ADDRESS_CHECK_INTERVAL_MSECS = 30 * 1000;
|
requestCurrentPublicSocketViaSTUN();
|
||||||
|
|
||||||
// setup our timer to check our IP via stun every 30 seconds
|
} else {
|
||||||
QTimer* dynamicIPTimer = new QTimer(this);
|
qDebug() << "Cannot enable domain-server automatic networking without a domain ID."
|
||||||
connect(dynamicIPTimer, &QTimer::timeout, this, &DomainServer::requestCurrentPublicSocketViaSTUN);
|
<< "Please add an ID to your config file or via the web interface.";
|
||||||
dynamicIPTimer->start(STUN_IP_ADDRESS_CHECK_INTERVAL_MSECS);
|
|
||||||
|
return;
|
||||||
// send public socket changes to the data server so nodes can find us at our new IP
|
|
||||||
connect(nodeList, &LimitedNodeList::publicSockAddrChanged, this, &DomainServer::sendNewSocketsToDataServer);
|
|
||||||
|
|
||||||
// attempt to update our sockets now
|
|
||||||
requestCurrentPublicSocketViaSTUN();
|
|
||||||
|
|
||||||
} 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -934,25 +928,16 @@ QJsonObject jsonForDomainSocketUpdate(const HifiSockAddr& socket) {
|
||||||
return socketObject;
|
return socketObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainServer::sendNewSocketsToDataServer(const HifiSockAddr& newPublicSockAddr) {
|
void DomainServer::performIPAddressUpdate(const HifiSockAddr& newPublicSockAddr) {
|
||||||
const QString DOMAIN_UPDATE = "/api/v1/domains/%1";
|
const QString DOMAIN_UPDATE = "/api/v1/domains/%1";
|
||||||
const QUuid& domainID = LimitedNodeList::getInstance()->getSessionUUID();
|
const QUuid& domainID = LimitedNodeList::getInstance()->getSessionUUID();
|
||||||
|
|
||||||
// we're not mointoring for local socket changes yet
|
|
||||||
// the first time this is called grab whatever it is and assume it'll stay the same
|
|
||||||
static HifiSockAddr localSockAddr = HifiSockAddr(QHostAddress(getHostOrderLocalAddress()),
|
|
||||||
LimitedNodeList::getInstance()->getNodeSocket().localPort());
|
|
||||||
|
|
||||||
// setup the domain object to send to the data server
|
// setup the domain object to send to the data server
|
||||||
const QString PUBLIC_SOCKET_ATTRIBUTES_KEY = "public_socket_attributes";
|
const QString PUBLIC_NETWORK_ADDRESS_KEY = "network_address";
|
||||||
const QString LOCAL_SOCKET_ATTRIBUTES_KEY = "local_socket_attributes";
|
const QString AUTOMATIC_NETWORKING_KEY = "automatic_networking";
|
||||||
|
|
||||||
QJsonObject domainObject;
|
const QString DOMAIN_JSON_OBJECT = "{\"domain\": { \"network_address\": \"%1\", \"automatic_networking\": \"ip\" }";
|
||||||
domainObject[PUBLIC_SOCKET_ATTRIBUTES_KEY] = jsonForDomainSocketUpdate(newPublicSockAddr);
|
QString domainUpdateJSON = DOMAIN_JSON_OBJECT.arg(newPublicSockAddr.getAddress().toString());
|
||||||
domainObject[LOCAL_SOCKET_ATTRIBUTES_KEY] = jsonForDomainSocketUpdate(localSockAddr);
|
|
||||||
|
|
||||||
const QString DOMAIN_JSON_OBJECT = "{\"domain\":%1}";
|
|
||||||
QString domainUpdateJSON = DOMAIN_JSON_OBJECT.arg(QString(QJsonDocument(domainObject).toJson()));
|
|
||||||
|
|
||||||
AccountManager::getInstance().authenticatedRequest(DOMAIN_UPDATE.arg(uuidStringWithoutCurlyBraces(domainID)),
|
AccountManager::getInstance().authenticatedRequest(DOMAIN_UPDATE.arg(uuidStringWithoutCurlyBraces(domainID)),
|
||||||
QNetworkAccessManager::PutOperation,
|
QNetworkAccessManager::PutOperation,
|
||||||
|
|
|
@ -63,14 +63,14 @@ private slots:
|
||||||
void sendPendingTransactionsToServer();
|
void sendPendingTransactionsToServer();
|
||||||
|
|
||||||
void requestCurrentPublicSocketViaSTUN();
|
void requestCurrentPublicSocketViaSTUN();
|
||||||
void sendNewSocketsToDataServer(const HifiSockAddr& newPublicSockAddr);
|
void performIPAddressUpdate(const HifiSockAddr& newPublicSockAddr);
|
||||||
private:
|
private:
|
||||||
void setupNodeListAndAssignments(const QUuid& sessionUUID = QUuid::createUuid());
|
void setupNodeListAndAssignments(const QUuid& sessionUUID = QUuid::createUuid());
|
||||||
bool optionallySetupOAuth();
|
bool optionallySetupOAuth();
|
||||||
bool optionallyReadX509KeyAndCertificate();
|
bool optionallyReadX509KeyAndCertificate();
|
||||||
bool didSetupAccountManagerWithAccessToken();
|
bool didSetupAccountManagerWithAccessToken();
|
||||||
bool optionallySetupAssignmentPayment();
|
bool optionallySetupAssignmentPayment();
|
||||||
void setupDynamicSocketUpdating();
|
void setupAutomaticNetworking();
|
||||||
|
|
||||||
void processDatagram(const QByteArray& receivedPacket, const HifiSockAddr& senderSockAddr);
|
void processDatagram(const QByteArray& receivedPacket, const HifiSockAddr& senderSockAddr);
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,10 @@
|
||||||
|
|
||||||
const QString SETTINGS_DESCRIPTION_RELATIVE_PATH = "/resources/describe-settings.json";
|
const QString SETTINGS_DESCRIPTION_RELATIVE_PATH = "/resources/describe-settings.json";
|
||||||
|
|
||||||
|
const QString DESCRIPTION_SETTINGS_KEY = "settings";
|
||||||
|
const QString SETTING_DEFAULT_KEY = "default";
|
||||||
|
const QString DESCRIPTION_NAME_KEY = "name";
|
||||||
|
|
||||||
DomainServerSettingsManager::DomainServerSettingsManager() :
|
DomainServerSettingsManager::DomainServerSettingsManager() :
|
||||||
_descriptionArray(),
|
_descriptionArray(),
|
||||||
_configMap()
|
_configMap()
|
||||||
|
@ -63,6 +67,34 @@ void DomainServerSettingsManager::setupConfigMap(const QStringList& argumentList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant DomainServerSettingsManager::valueOrDefaultValueForKeyPath(const QString &keyPath) {
|
||||||
|
const QVariant* foundValue = valueForKeyPath(_configMap.getMergedConfig(), keyPath);
|
||||||
|
|
||||||
|
if (foundValue) {
|
||||||
|
return *foundValue;
|
||||||
|
} else {
|
||||||
|
int dotIndex = keyPath.indexOf('.');
|
||||||
|
|
||||||
|
QString groupKey = keyPath.mid(0, dotIndex);
|
||||||
|
QString settingKey = keyPath.mid(dotIndex);
|
||||||
|
|
||||||
|
foreach(const QVariant& group, _descriptionArray.toVariantList()) {
|
||||||
|
QVariantMap groupMap = group.toMap();
|
||||||
|
|
||||||
|
if (groupMap[DESCRIPTION_NAME_KEY].toString() == groupKey) {
|
||||||
|
foreach(const QVariant& setting, groupMap[DESCRIPTION_SETTINGS_KEY].toList()) {
|
||||||
|
QVariantMap settingMap = setting.toMap();
|
||||||
|
if (settingMap[DESCRIPTION_NAME_KEY].toString() == settingKey) {
|
||||||
|
return settingMap[SETTING_DEFAULT_KEY];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return *foundValue;
|
||||||
|
}
|
||||||
|
|
||||||
const QString SETTINGS_PATH = "/settings.json";
|
const QString SETTINGS_PATH = "/settings.json";
|
||||||
|
|
||||||
bool DomainServerSettingsManager::handlePublicHTTPRequest(HTTPConnection* connection, const QUrl &url) {
|
bool DomainServerSettingsManager::handlePublicHTTPRequest(HTTPConnection* connection, const QUrl &url) {
|
||||||
|
@ -127,10 +159,6 @@ bool DomainServerSettingsManager::handleAuthenticatedHTTPRequest(HTTPConnection
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString DESCRIPTION_SETTINGS_KEY = "settings";
|
|
||||||
const QString SETTING_DEFAULT_KEY = "default";
|
|
||||||
const QString DESCRIPTION_NAME_KEY = "name";
|
|
||||||
|
|
||||||
QJsonObject DomainServerSettingsManager::responseObjectForType(const QString& typeValue, bool isAuthenticated) {
|
QJsonObject DomainServerSettingsManager::responseObjectForType(const QString& typeValue, bool isAuthenticated) {
|
||||||
QJsonObject responseObject;
|
QJsonObject responseObject;
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ public:
|
||||||
bool handleAuthenticatedHTTPRequest(HTTPConnection* connection, const QUrl& url);
|
bool handleAuthenticatedHTTPRequest(HTTPConnection* connection, const QUrl& url);
|
||||||
|
|
||||||
void setupConfigMap(const QStringList& argumentList);
|
void setupConfigMap(const QStringList& argumentList);
|
||||||
|
QVariant valueOrDefaultValueForKeyPath(const QString& keyPath);
|
||||||
|
|
||||||
QVariantMap& getSettingsMap() { return _configMap.getMergedConfig(); }
|
QVariantMap& getSettingsMap() { return _configMap.getMergedConfig(); }
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue