From cfc7309c96f9ac3867a77145673853163c600258 Mon Sep 17 00:00:00 2001 From: Kalila L Date: Fri, 20 Nov 2020 03:19:19 -0500 Subject: [PATCH 1/5] Send address and port with each metaverse heartbeat. --- .../resources/describe-settings.json | 17 +++++++++ domain-server/resources/web/js/shared.js | 7 ++-- domain-server/src/DomainServer.cpp | 36 ++++++++++++++++--- domain-server/src/DomainServer.h | 4 +-- 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/domain-server/resources/describe-settings.json b/domain-server/resources/describe-settings.json index 42b15adefe3..2cef93ad539 100644 --- a/domain-server/resources/describe-settings.json +++ b/domain-server/resources/describe-settings.json @@ -2013,6 +2013,23 @@ } ] }, + { + "name": "domain_server", + "label": "Setup Domain Server", + "restart": false, + "hidden": true, + "settings": [ + { + "name": "network_address", + "default": "" + }, + { + "name": "port", + "type": "int", + "default": 0 + } + ] + }, { "name": "installed_content", "label": "Installed Content", diff --git a/domain-server/resources/web/js/shared.js b/domain-server/resources/web/js/shared.js index bffd5128900..542771c60e2 100644 --- a/domain-server/resources/web/js/shared.js +++ b/domain-server/resources/web/js/shared.js @@ -129,9 +129,10 @@ function getCurrentDomainIDType() { return DOMAIN_ID_TYPE_UNKNOWN; } if (DomainInfo !== null) { - if (DomainInfo.name !== undefined) { - return DOMAIN_ID_TYPE_TEMP; - } + // Disabled because detecting as temp domain... and we're not even using temp domains right now. + // if (DomainInfo.name !== undefined) { + // return DOMAIN_ID_TYPE_TEMP; + // } return DOMAIN_ID_TYPE_FULL; } return DOMAIN_ID_TYPE_UNKNOWN; diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index f26dc4ac27e..80458e7ad0b 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -1507,10 +1507,23 @@ QJsonObject jsonForDomainSocketUpdate(const HifiSockAddr& socket) { const QString DOMAIN_UPDATE_AUTOMATIC_NETWORKING_KEY = "automatic_networking"; void DomainServer::performIPAddressUpdate(const HifiSockAddr& newPublicSockAddr) { - sendHeartbeatToMetaverse(newPublicSockAddr.getAddress().toString()); + static const QString PUBLIC_SOCKET_ADDRESS_KEY = "network_address"; + static const QString PUBLIC_SOCKET_PORT_KEY = "port"; + const QString& publicSocketAddress = newPublicSockAddr.getAddress().toString(); + const int publicSocketPort = newPublicSockAddr.getPort(); + + sendHeartbeatToMetaverse(publicSocketAddress, publicSocketPort); + + QString newSettingsJSON = QString("{\"domain_server\": { \"%1\": \"%2\", \"%3\": %4}}") + .arg(PUBLIC_SOCKET_ADDRESS_KEY) + .arg(publicSocketAddress) + .arg(PUBLIC_SOCKET_PORT_KEY) + .arg(publicSocketPort); + auto settingsDocument = QJsonDocument::fromJson(newSettingsJSON.toUtf8()); + _settingsManager.recurseJSONObjectAndOverwriteSettings(settingsDocument.object(), DomainSettings); } -void DomainServer::sendHeartbeatToMetaverse(const QString& networkAddress) { +void DomainServer::sendHeartbeatToMetaverse(const QString& networkAddress, const int port) { // Setup the domain object to send to the data server QJsonObject domainObject; @@ -1520,10 +1533,23 @@ void DomainServer::sendHeartbeatToMetaverse(const QString& networkAddress) { static const QString PROTOCOL_VERSION_KEY = "protocol"; domainObject[PROTOCOL_VERSION_KEY] = protocolVersionsSignatureBase64(); - // add networking + static const QString PUBLIC_SOCKET_ADDRESS_KEY = "network_address"; + static const QString PUBLIC_SOCKET_PORT_KEY = "port"; + + static const QString NETWORK_ADDRESS_SETTINGS_KEY = "domain_server." + PUBLIC_SOCKET_ADDRESS_KEY; + const QString networkAddressFromSettings = _settingsManager.valueForKeyPath(NETWORK_ADDRESS_SETTINGS_KEY).toString(); if (!networkAddress.isEmpty()) { - static const QString PUBLIC_NETWORK_ADDRESS_KEY = "network_address"; - domainObject[PUBLIC_NETWORK_ADDRESS_KEY] = networkAddress; + domainObject[PUBLIC_SOCKET_ADDRESS_KEY] = networkAddress; + } else if (!networkAddressFromSettings.isEmpty()) { + domainObject[PUBLIC_SOCKET_ADDRESS_KEY] = networkAddressFromSettings; + } + + static const QString PORT_SETTINGS_KEY = "domain_server." + PUBLIC_SOCKET_PORT_KEY; + const int portFromSettings = _settingsManager.valueForKeyPath(PORT_SETTINGS_KEY).toInt(); + if (port != NULL) { + domainObject[PUBLIC_SOCKET_PORT_KEY] = port; + } else if (portFromSettings != NULL) { + domainObject[PUBLIC_SOCKET_PORT_KEY] = portFromSettings; } static const QString AUTOMATIC_NETWORKING_KEY = "automatic_networking"; diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index 7a09141db60..69c99e5cf43 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -113,7 +113,7 @@ private slots: void sendPendingTransactionsToServer(); void performIPAddressUpdate(const HifiSockAddr& newPublicSockAddr); - void sendHeartbeatToMetaverse() { sendHeartbeatToMetaverse(QString()); } + void sendHeartbeatToMetaverse() { sendHeartbeatToMetaverse(QString(), int()); } void sendHeartbeatToIceServer(); void nodePingMonitor(); @@ -176,7 +176,7 @@ private slots: void setupAutomaticNetworking(); void setupICEHeartbeatForFullNetworking(); void setupHeartbeatToMetaverse(); - void sendHeartbeatToMetaverse(const QString& networkAddress); + void sendHeartbeatToMetaverse(const QString& networkAddress, const int port); void randomizeICEServerAddress(bool shouldTriggerHostLookup); From 97681786cdfbc019e6bfa06480575fcb4416d6c0 Mon Sep 17 00:00:00 2001 From: Kalila L Date: Wed, 25 Nov 2020 04:54:47 -0500 Subject: [PATCH 2/5] Potentially fix STUN IP+Port init for heartbeat issue? --- domain-server/src/DomainServer.cpp | 13 ++++++------- domain-server/src/DomainServer.h | 2 +- libraries/networking/src/LimitedNodeList.cpp | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 80458e7ad0b..66bb06b2d62 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -901,14 +901,13 @@ void DomainServer::setupAutomaticNetworking() { qDebug() << "domain-server" << _automaticNetworkingSetting << "automatic networking enabled for ID" << uuidStringWithoutCurlyBraces(domainID) << "via" << _oauthProviderURL.toString(); - if (_automaticNetworkingSetting == IP_ONLY_AUTOMATIC_NETWORKING_VALUE) { - - auto nodeList = DependencyManager::get(); + auto nodeList = DependencyManager::get(); - // 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); + // 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::performIPAddressPortUpdate); + if (_automaticNetworkingSetting == IP_ONLY_AUTOMATIC_NETWORKING_VALUE) { // have the LNL enable public socket updating via STUN nodeList->startSTUNPublicSocketUpdate(); } @@ -1506,7 +1505,7 @@ QJsonObject jsonForDomainSocketUpdate(const HifiSockAddr& socket) { const QString DOMAIN_UPDATE_AUTOMATIC_NETWORKING_KEY = "automatic_networking"; -void DomainServer::performIPAddressUpdate(const HifiSockAddr& newPublicSockAddr) { +void DomainServer::performIPAddressPortUpdate(const HifiSockAddr& newPublicSockAddr) { static const QString PUBLIC_SOCKET_ADDRESS_KEY = "network_address"; static const QString PUBLIC_SOCKET_PORT_KEY = "port"; const QString& publicSocketAddress = newPublicSockAddr.getAddress().toString(); diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index 69c99e5cf43..24d26540c15 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -112,7 +112,7 @@ private slots: void setupPendingAssignmentCredits(); void sendPendingTransactionsToServer(); - void performIPAddressUpdate(const HifiSockAddr& newPublicSockAddr); + void performIPAddressPortUpdate(const HifiSockAddr& newPublicSockAddr); void sendHeartbeatToMetaverse() { sendHeartbeatToMetaverse(QString(), int()); } void sendHeartbeatToIceServer(); void nodePingMonitor(); diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index d867b49b30d..3da5b53dcb5 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -1197,7 +1197,7 @@ void LimitedNodeList::stopInitialSTUNUpdate(bool success) { } // We now setup a timer here to fire every so often to check that our IP address has not changed. - // Or, if we failed - if will check if we can eventually get a public socket + // Or, if we failed - it will check if we can eventually get a public socket const int STUN_IP_ADDRESS_CHECK_INTERVAL_MSECS = 10 * 1000; QTimer* stunOccasionalTimer = new QTimer { this }; From cec112dd286c034d2f078262e9a90415cbcf587f Mon Sep 17 00:00:00 2001 From: Kalila L Date: Wed, 25 Nov 2020 15:19:35 -0500 Subject: [PATCH 3/5] "port" -> "network_port" --- domain-server/resources/describe-settings.json | 2 +- domain-server/src/DomainServer.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/domain-server/resources/describe-settings.json b/domain-server/resources/describe-settings.json index 2cef93ad539..bb7acf344c3 100644 --- a/domain-server/resources/describe-settings.json +++ b/domain-server/resources/describe-settings.json @@ -2024,7 +2024,7 @@ "default": "" }, { - "name": "port", + "name": "network_port", "type": "int", "default": 0 } diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 66bb06b2d62..9f5c7e0bb05 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -1507,7 +1507,7 @@ const QString DOMAIN_UPDATE_AUTOMATIC_NETWORKING_KEY = "automatic_networking"; void DomainServer::performIPAddressPortUpdate(const HifiSockAddr& newPublicSockAddr) { static const QString PUBLIC_SOCKET_ADDRESS_KEY = "network_address"; - static const QString PUBLIC_SOCKET_PORT_KEY = "port"; + static const QString PUBLIC_SOCKET_PORT_KEY = "network_port"; const QString& publicSocketAddress = newPublicSockAddr.getAddress().toString(); const int publicSocketPort = newPublicSockAddr.getPort(); @@ -1533,7 +1533,7 @@ void DomainServer::sendHeartbeatToMetaverse(const QString& networkAddress, const domainObject[PROTOCOL_VERSION_KEY] = protocolVersionsSignatureBase64(); static const QString PUBLIC_SOCKET_ADDRESS_KEY = "network_address"; - static const QString PUBLIC_SOCKET_PORT_KEY = "port"; + static const QString PUBLIC_SOCKET_PORT_KEY = "network_port"; static const QString NETWORK_ADDRESS_SETTINGS_KEY = "domain_server." + PUBLIC_SOCKET_ADDRESS_KEY; const QString networkAddressFromSettings = _settingsManager.valueForKeyPath(NETWORK_ADDRESS_SETTINGS_KEY).toString(); From 0468c98c30eb8bba6e32c7a4531de18b9e4241d1 Mon Sep 17 00:00:00 2001 From: Kalila L Date: Fri, 11 Dec 2020 15:55:24 -0500 Subject: [PATCH 4/5] CR, move duplicate consts to top of file. --- domain-server/src/DomainServer.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 9f5c7e0bb05..5d72f717979 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -68,6 +68,9 @@ Q_LOGGING_CATEGORY(domain_server_ice, "hifi.domain_server.ice") const QString ACCESS_TOKEN_KEY_PATH = "metaverse.access_token"; const QString DomainServer::REPLACEMENT_FILE_EXTENSION = ".replace"; +const QString PUBLIC_SOCKET_ADDRESS_KEY = "network_address"; +const QString PUBLIC_SOCKET_PORT_KEY = "network_port"; +const QString DOMAIN_UPDATE_AUTOMATIC_NETWORKING_KEY = "automatic_networking"; const int MIN_PORT = 1; const int MAX_PORT = 65535; @@ -1503,11 +1506,7 @@ QJsonObject jsonForDomainSocketUpdate(const HifiSockAddr& socket) { return socketObject; } -const QString DOMAIN_UPDATE_AUTOMATIC_NETWORKING_KEY = "automatic_networking"; - void DomainServer::performIPAddressPortUpdate(const HifiSockAddr& newPublicSockAddr) { - static const QString PUBLIC_SOCKET_ADDRESS_KEY = "network_address"; - static const QString PUBLIC_SOCKET_PORT_KEY = "network_port"; const QString& publicSocketAddress = newPublicSockAddr.getAddress().toString(); const int publicSocketPort = newPublicSockAddr.getPort(); @@ -1532,9 +1531,6 @@ void DomainServer::sendHeartbeatToMetaverse(const QString& networkAddress, const static const QString PROTOCOL_VERSION_KEY = "protocol"; domainObject[PROTOCOL_VERSION_KEY] = protocolVersionsSignatureBase64(); - static const QString PUBLIC_SOCKET_ADDRESS_KEY = "network_address"; - static const QString PUBLIC_SOCKET_PORT_KEY = "network_port"; - static const QString NETWORK_ADDRESS_SETTINGS_KEY = "domain_server." + PUBLIC_SOCKET_ADDRESS_KEY; const QString networkAddressFromSettings = _settingsManager.valueForKeyPath(NETWORK_ADDRESS_SETTINGS_KEY).toString(); if (!networkAddress.isEmpty()) { From 5c9b1edb86bb435c1c41053b614a61073319065a Mon Sep 17 00:00:00 2001 From: Kalila L Date: Mon, 14 Dec 2020 01:03:36 -0500 Subject: [PATCH 5/5] Convert QString to QJsonObject. --- domain-server/src/DomainServer.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 5d72f717979..1d7ef7fcfcc 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -1507,18 +1507,19 @@ QJsonObject jsonForDomainSocketUpdate(const HifiSockAddr& socket) { } void DomainServer::performIPAddressPortUpdate(const HifiSockAddr& newPublicSockAddr) { + const QString& DOMAIN_SERVER_SETTINGS_KEY = "domain_server"; const QString& publicSocketAddress = newPublicSockAddr.getAddress().toString(); const int publicSocketPort = newPublicSockAddr.getPort(); sendHeartbeatToMetaverse(publicSocketAddress, publicSocketPort); - QString newSettingsJSON = QString("{\"domain_server\": { \"%1\": \"%2\", \"%3\": %4}}") - .arg(PUBLIC_SOCKET_ADDRESS_KEY) - .arg(publicSocketAddress) - .arg(PUBLIC_SOCKET_PORT_KEY) - .arg(publicSocketPort); - auto settingsDocument = QJsonDocument::fromJson(newSettingsJSON.toUtf8()); - _settingsManager.recurseJSONObjectAndOverwriteSettings(settingsDocument.object(), DomainSettings); + QJsonObject rootObject; + QJsonObject domainServerObject; + domainServerObject.insert(PUBLIC_SOCKET_ADDRESS_KEY, publicSocketAddress); + domainServerObject.insert(PUBLIC_SOCKET_PORT_KEY, publicSocketPort); + rootObject.insert(DOMAIN_SERVER_SETTINGS_KEY, domainServerObject); + QJsonDocument doc(rootObject); + _settingsManager.recurseJSONObjectAndOverwriteSettings(rootObject, DomainSettings); } void DomainServer::sendHeartbeatToMetaverse(const QString& networkAddress, const int port) {