From 45b48c01bfdbe90e829048fc0d449a2c48bcde01 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 19 Sep 2016 13:39:42 -0700 Subject: [PATCH] command-line arguments to control ice-server ip address and domain-server ID --- domain-server/src/DomainServer.cpp | 78 ++++++++++++++++++++++++------ domain-server/src/DomainServer.h | 6 +++ 2 files changed, 70 insertions(+), 14 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 72e9751294..654fe500c6 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -62,8 +63,11 @@ DomainServer::DomainServer(int argc, char* argv[]) : _webAuthenticationStateSet(), _cookieSessionHash(), _automaticNetworkingSetting(), - _settingsManager() + _settingsManager(), + _iceServerAddr(ICE_SERVER_DEFAULT_HOSTNAME), + _iceServerPort(ICE_SERVER_DEFAULT_PORT) { + parseCommandLine(); qInstallMessageHandler(LogHandler::verboseMessageHandler); LogUtils::init(); @@ -147,6 +151,46 @@ DomainServer::DomainServer(int argc, char* argv[]) : qDebug() << "domain-server is running"; } +void DomainServer::parseCommandLine() { + QCommandLineParser parser; + parser.setApplicationDescription("High Fidelity Domain Server"); + parser.addHelpOption(); + + const QCommandLineOption iceServerAddressOption("i", "ice-server address", "IP:PORT or HOSTNAME:PORT"); + parser.addOption(iceServerAddressOption); + + const QCommandLineOption domainIDOption("d", "domain-server uuid"); + parser.addOption(domainIDOption); + + if (!parser.parse(QCoreApplication::arguments())) { + qCritical() << parser.errorText() << endl; + parser.showHelp(); + Q_UNREACHABLE(); + } + + if (parser.isSet(iceServerAddressOption)) { + // parse the IP and port combination for this target + QString hostnamePortString = parser.value(iceServerAddressOption); + + _iceServerAddr = hostnamePortString.left(hostnamePortString.indexOf(':')); + _iceServerPort = (quint16) hostnamePortString.mid(hostnamePortString.indexOf(':') + 1).toUInt(); + if (_iceServerPort == 0) { + _iceServerPort = ICE_SERVER_DEFAULT_PORT; + } + + if (_iceServerAddr.isEmpty()) { + qCritical() << "Could not parse an IP address and port combination from" << hostnamePortString; + QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection); + } + } + + if (parser.isSet(domainIDOption)) { + _overridingDomainID = QUuid(parser.value(domainIDOption)); + _overRideDomainID = true; + qDebug() << "domain-server ID is" << _overridingDomainID; + } +} + DomainServer::~DomainServer() { // destroy the LimitedNodeList before the DomainServer QCoreApplication is down DependencyManager::destroy(); @@ -295,7 +339,7 @@ void DomainServer::handleTempDomainSuccess(QNetworkReply& requestReply) { auto domainObject = jsonObject[DATA_KEY].toObject()[DOMAIN_KEY].toObject(); if (!domainObject.isEmpty()) { - auto id = domainObject[ID_KEY].toString(); + auto id = _overRideDomainID ? _overridingDomainID.toString() : domainObject[ID_KEY].toString(); auto name = domainObject[NAME_KEY].toString(); auto key = domainObject[KEY_KEY].toString(); @@ -403,26 +447,33 @@ void DomainServer::setupNodeListAndAssignments() { quint16 localHttpsPort = DOMAIN_SERVER_HTTPS_PORT; nodeList->putLocalPortIntoSharedMemory(DOMAIN_SERVER_LOCAL_HTTPS_PORT_SMEM_KEY, this, localHttpsPort); - // set our LimitedNodeList UUID to match the UUID from our config // nodes will currently use this to add resources to data-web that relate to our domain - const QVariant* idValueVariant = valueForKeyPath(settingsMap, METAVERSE_DOMAIN_ID_KEY_PATH); - if (idValueVariant) { - nodeList->setSessionUUID(idValueVariant->toString()); + bool isMetaverseDomain = false; + if (_overRideDomainID) { + nodeList->setSessionUUID(_overridingDomainID); + isMetaverseDomain = true; // assume metaverse domain + } else { + const QVariant* idValueVariant = valueForKeyPath(settingsMap, METAVERSE_DOMAIN_ID_KEY_PATH); + if (idValueVariant) { + nodeList->setSessionUUID(idValueVariant->toString()); + isMetaverseDomain = true; // if we have an ID, we'll assume we're a metaverse domain + } else { + nodeList->setSessionUUID(QUuid::createUuid()); // Use random UUID + } + } - // 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 + if (isMetaverseDomain) { + // see if we think we're a temp domain (we have an API key) or a full domain const auto& temporaryDomainKey = DependencyManager::get()->getTemporaryDomainKey(getID()); if (temporaryDomainKey.isEmpty()) { _type = MetaverseDomain; } else { _type = MetaverseTemporaryDomain; } - - } else { - nodeList->setSessionUUID(QUuid::createUuid()); // Use random UUID } + connect(nodeList.data(), &LimitedNodeList::nodeAdded, this, &DomainServer::nodeAdded); connect(nodeList.data(), &LimitedNodeList::nodeKilled, this, &DomainServer::nodeKilled); @@ -536,7 +587,7 @@ void DomainServer::setupAutomaticNetworking() { } 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; } } @@ -594,12 +645,11 @@ void DomainServer::setupICEHeartbeatForFullNetworking() { void DomainServer::updateICEServerAddresses() { if (_iceAddressLookupID == -1) { - _iceAddressLookupID = QHostInfo::lookupHost(ICE_SERVER_DEFAULT_HOSTNAME, this, SLOT(handleICEHostInfo(QHostInfo))); + _iceAddressLookupID = QHostInfo::lookupHost(_iceServerAddr, this, SLOT(handleICEHostInfo(QHostInfo))); } } void DomainServer::parseAssignmentConfigs(QSet& excludedTypes) { - // check for configs from the command line, these take precedence const QString ASSIGNMENT_CONFIG_REGEX_STRING = "config-([\\d]+)"; QRegExp assignmentConfigRegex(ASSIGNMENT_CONFIG_REGEX_STRING); diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index e30f4515cc..de08c15468 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -105,6 +105,7 @@ signals: private: const QUuid& getID(); + void parseCommandLine(); void setupNodeListAndAssignments(); bool optionallySetupOAuth(); @@ -205,6 +206,11 @@ private: friend class DomainGatekeeper; friend class DomainMetadata; + + QString _iceServerAddr; + int _iceServerPort; + bool _overRideDomainID { false }; // should we override the domain-id from settings? + QUuid _overridingDomainID { QUuid() }; // what should we override it with? };