Skip to content

Commit

Permalink
Merge pull request #877 from vircadia/feature/domain-server-reporting…
Browse files Browse the repository at this point in the history
…-socket

Send address and port with each metaverse heartbeat.
  • Loading branch information
daleglass authored Dec 26, 2020
2 parents df1feaf + 5c9b1ed commit f894a0a
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 20 deletions.
17 changes: 17 additions & 0 deletions domain-server/resources/describe-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2013,6 +2013,23 @@
}
]
},
{
"name": "domain_server",
"label": "Setup Domain Server",
"restart": false,
"hidden": true,
"settings": [
{
"name": "network_address",
"default": ""
},
{
"name": "network_port",
"type": "int",
"default": 0
}
]
},
{
"name": "installed_content",
"label": "Installed Content",
Expand Down
7 changes: 4 additions & 3 deletions domain-server/resources/web/js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
48 changes: 35 additions & 13 deletions domain-server/src/DomainServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -901,14 +904,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<LimitedNodeList>();
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);
// 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();
}
Expand Down Expand Up @@ -1504,13 +1506,23 @@ QJsonObject jsonForDomainSocketUpdate(const HifiSockAddr& socket) {
return socketObject;
}

const QString DOMAIN_UPDATE_AUTOMATIC_NETWORKING_KEY = "automatic_networking";
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);

void DomainServer::performIPAddressUpdate(const HifiSockAddr& newPublicSockAddr) {
sendHeartbeatToMetaverse(newPublicSockAddr.getAddress().toString());
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) {
void DomainServer::sendHeartbeatToMetaverse(const QString& networkAddress, const int port) {
// Setup the domain object to send to the data server
QJsonObject domainObject;

Expand All @@ -1520,10 +1532,20 @@ void DomainServer::sendHeartbeatToMetaverse(const QString& networkAddress) {
static const QString PROTOCOL_VERSION_KEY = "protocol";
domainObject[PROTOCOL_VERSION_KEY] = protocolVersionsSignatureBase64();

// add networking
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";
Expand Down
6 changes: 3 additions & 3 deletions domain-server/src/DomainServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ private slots:
void setupPendingAssignmentCredits();
void sendPendingTransactionsToServer();

void performIPAddressUpdate(const HifiSockAddr& newPublicSockAddr);
void sendHeartbeatToMetaverse() { sendHeartbeatToMetaverse(QString()); }
void performIPAddressPortUpdate(const HifiSockAddr& newPublicSockAddr);
void sendHeartbeatToMetaverse() { sendHeartbeatToMetaverse(QString(), int()); }
void sendHeartbeatToIceServer();
void nodePingMonitor();

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion libraries/networking/src/LimitedNodeList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down

0 comments on commit f894a0a

Please sign in to comment.