handle automatic networking changes with data-server

This commit is contained in:
Stephen Birarda 2014-10-01 16:38:44 -07:00
parent 15156519b3
commit d6572c3e2e
3 changed files with 32 additions and 12 deletions

View file

@ -29,7 +29,7 @@
"label": "IP Only: update just my IP address, I will open the port manually" "label": "IP Only: update just my IP address, I will open the port manually"
}, },
{ {
"value": "none", "value": "disabled",
"label": "None: use the network information I have entered for this domain at data.highfidelity.io" "label": "None: use the network information I have entered for this domain at data.highfidelity.io"
} }
] ]

View file

@ -74,7 +74,7 @@ DomainServer::DomainServer(int argc, char* argv[]) :
loadExistingSessionsFromSettings(); loadExistingSessionsFromSettings();
// check if we have the flag that enables dynamic IP // setup automatic networking settings with data server
setupAutomaticNetworking(); setupAutomaticNetworking();
} }
} }
@ -310,22 +310,24 @@ bool DomainServer::optionallySetupAssignmentPayment() {
return true; return true;
} }
const QString FULL_AUTOMATIC_NETWORKING_VALUE = "full";
const QString IP_ONLY_AUTOMATIC_NETWORKING_VALUE = "ip";
const QString DISABLED_AUTOMATIC_NETWORKING_VALUE = "disabled";
void DomainServer::setupAutomaticNetworking() { void DomainServer::setupAutomaticNetworking() {
const QString METAVERSE_AUTOMATIC_NETWORKING_KEY_PATH = "metaverse.automatic_networking"; const QString METAVERSE_AUTOMATIC_NETWORKING_KEY_PATH = "metaverse.automatic_networking";
const QString FULL_AUTOMATIC_NETWORKING_VALUE = "full"; if (!didSetupAccountManagerWithAccessToken()) {
const QString IP_ONLY_AUTOMATIC_NETWORKING_VALUE = "ip"; qDebug() << "Cannot setup 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 = QString automaticNetworkValue =
_settingsManager.valueOrDefaultValueForKeyPath(METAVERSE_AUTOMATIC_NETWORKING_KEY_PATH).toString(); _settingsManager.valueOrDefaultValueForKeyPath(METAVERSE_AUTOMATIC_NETWORKING_KEY_PATH).toString();
if (automaticNetworkValue == IP_ONLY_AUTOMATIC_NETWORKING_VALUE) { 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;
}
LimitedNodeList* nodeList = LimitedNodeList::getInstance(); LimitedNodeList* nodeList = LimitedNodeList::getInstance();
const QUuid& domainID = nodeList->getSessionUUID(); const QUuid& domainID = nodeList->getSessionUUID();
@ -353,6 +355,8 @@ void DomainServer::setupAutomaticNetworking() {
return; return;
} }
} else {
updateNetworkingInfoWithDataServer(automaticNetworkValue);
} }
} }
@ -933,7 +937,13 @@ QJsonObject jsonForDomainSocketUpdate(const HifiSockAddr& socket) {
return socketObject; return socketObject;
} }
const QString DOMAIN_UPDATE_AUTOMATIC_NETWORKING_KEY = "automatic_networking";
void DomainServer::performIPAddressUpdate(const HifiSockAddr& newPublicSockAddr) { void DomainServer::performIPAddressUpdate(const HifiSockAddr& newPublicSockAddr) {
updateNetworkingInfoWithDataServer(IP_ONLY_AUTOMATIC_NETWORKING_VALUE, newPublicSockAddr.getAddress().toString());
}
void DomainServer::updateNetworkingInfoWithDataServer(const QString& newSetting, const QString& networkAddress) {
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();
@ -941,8 +951,16 @@ void DomainServer::performIPAddressUpdate(const HifiSockAddr& newPublicSockAddr)
const QString PUBLIC_NETWORK_ADDRESS_KEY = "network_address"; const QString PUBLIC_NETWORK_ADDRESS_KEY = "network_address";
const QString AUTOMATIC_NETWORKING_KEY = "automatic_networking"; const QString AUTOMATIC_NETWORKING_KEY = "automatic_networking";
const QString DOMAIN_JSON_OBJECT = "{\"domain\": { \"network_address\": \"%1\", \"automatic_networking\": \"ip\" }"; QJsonObject domainObject;
QString domainUpdateJSON = DOMAIN_JSON_OBJECT.arg(newPublicSockAddr.getAddress().toString()); if (!networkAddress.isEmpty()) {
domainObject[PUBLIC_NETWORK_ADDRESS_KEY] = networkAddress;
}
qDebug() << "Updating automatic networking setting in domain-server to" << newSetting;
domainObject[AUTOMATIC_NETWORKING_KEY] = newSetting;
QString domainUpdateJSON = QString("{\"domain\": %1 }").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,

View file

@ -70,7 +70,9 @@ private:
bool optionallyReadX509KeyAndCertificate(); bool optionallyReadX509KeyAndCertificate();
bool didSetupAccountManagerWithAccessToken(); bool didSetupAccountManagerWithAccessToken();
bool optionallySetupAssignmentPayment(); bool optionallySetupAssignmentPayment();
void setupAutomaticNetworking(); void setupAutomaticNetworking();
void updateNetworkingInfoWithDataServer(const QString& newSetting, const QString& networkAddress = QString());
void processDatagram(const QByteArray& receivedPacket, const HifiSockAddr& senderSockAddr); void processDatagram(const QByteArray& receivedPacket, const HifiSockAddr& senderSockAddr);