From 09ffcbb2e88f35a48ba7e46138cabbe4fa08e2c9 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 24 Feb 2015 12:30:40 -0800 Subject: [PATCH] Revert "Merge pull request #4324 from sethalves/assignment-client-keep-a-spare" This reverts commit 087e2babde1329c242484e0e7f4ffbfa3e3206ea, reversing changes made to 5202d2136a0adfb2cf2558847b85a1f7ec94457d. --- assignment-client/src/AssignmentClient.cpp | 87 +++------- assignment-client/src/AssignmentClient.h | 11 +- assignment-client/src/AssignmentClientApp.cpp | 66 -------- assignment-client/src/AssignmentClientApp.h | 18 -- .../src/AssignmentClientChildData.cpp | 8 - .../src/AssignmentClientChildData.h | 32 ---- .../src/AssignmentClientMonitor.cpp | 158 ++++-------------- .../src/AssignmentClientMonitor.h | 13 +- assignment-client/src/main.cpp | 30 +++- domain-server/src/DomainServer.cpp | 14 +- libraries/networking/src/AddressManager.cpp | 4 +- libraries/networking/src/LimitedNodeList.cpp | 38 ----- libraries/networking/src/LimitedNodeList.h | 9 - libraries/networking/src/Node.cpp | 7 +- libraries/networking/src/NodeList.cpp | 8 +- libraries/networking/src/NodeList.h | 1 - libraries/networking/src/PacketHeaders.cpp | 3 - libraries/networking/src/PacketHeaders.h | 4 +- 18 files changed, 108 insertions(+), 403 deletions(-) delete mode 100644 assignment-client/src/AssignmentClientApp.cpp delete mode 100644 assignment-client/src/AssignmentClientApp.h delete mode 100644 assignment-client/src/AssignmentClientChildData.cpp delete mode 100644 assignment-client/src/AssignmentClientChildData.h diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index 2dfc3787de..bf67d4d597 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -18,10 +18,10 @@ #include #include #include +#include #include #include #include -#include #include #include #include @@ -43,8 +43,7 @@ int hifiSockAddrMeta = qRegisterMetaType("HifiSockAddr"); AssignmentClient::AssignmentClient(int &argc, char **argv) : QCoreApplication(argc, argv), _assignmentServerHostname(DEFAULT_ASSIGNMENT_SERVER_HOSTNAME), - _localASPortSharedMem(NULL), - _localACMPortSharedMem(NULL) + _localASPortSharedMem(NULL) { LogUtils::init(); @@ -57,11 +56,7 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) : DependencyManager::registerInheritance(); auto addressManager = DependencyManager::set(); auto nodeList = DependencyManager::set(NodeType::Unassigned); - - // make up a uuid for this child so the parent can tell us apart. This id will be changed - // when the domain server hands over an assignment. - QUuid nodeUUID = QUuid::createUuid(); - nodeList->setSessionUUID(nodeUUID); + auto avatarHashMap = DependencyManager::set(); // setup a shutdown event listener to handle SIGTERM or WM_CLOSE for us #ifdef _WIN32 @@ -128,8 +123,9 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) : // call a timer function every ASSIGNMENT_REQUEST_INTERVAL_MSECS to ask for assignment, if required qDebug() << "Waiting for assignment -" << _requestAssignment; - connect(&_requestTimer, SIGNAL(timeout()), SLOT(sendAssignmentRequest())); - _requestTimer.start(ASSIGNMENT_REQUEST_INTERVAL_MSECS); + QTimer* timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), SLOT(sendAssignmentRequest())); + timer->start(ASSIGNMENT_REQUEST_INTERVAL_MSECS); // connect our readPendingDatagrams method to the readyRead() signal of the socket connect(&nodeList->getNodeSocket(), &QUdpSocket::readyRead, this, &AssignmentClient::readPendingDatagrams); @@ -140,45 +136,6 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) : // Create Singleton objects on main thread NetworkAccessManager::getInstance(); - - // Hook up a timer to send this child's status to the Monitor once per second - setUpStatsToMonitor(); -} - - -void AssignmentClient::stopAssignmentClient() { - qDebug() << "Exiting."; - _requestTimer.stop(); - _statsTimerACM.stop(); - quit(); -} - - -void AssignmentClient::setUpStatsToMonitor() { - // Figure out the address to send out stats to - quint16 localMonitorServerPort = DEFAULT_ASSIGNMENT_CLIENT_MONITOR_PORT; - auto nodeList = DependencyManager::get(); - - nodeList->getLocalServerPortFromSharedMemory(ASSIGNMENT_CLIENT_MONITOR_LOCAL_PORT_SMEM_KEY, - _localACMPortSharedMem, localMonitorServerPort); - _assignmentClientMonitorSocket = HifiSockAddr(DEFAULT_ASSIGNMENT_CLIENT_MONITOR_HOSTNAME, localMonitorServerPort, true); - - // send a stats packet every 1 seconds - connect(&_statsTimerACM, &QTimer::timeout, this, &AssignmentClient::sendStatsPacketToACM); - _statsTimerACM.start(1000); -} - -void AssignmentClient::sendStatsPacketToACM() { - // tell the assignment client monitor what this assignment client is doing (if anything) - QJsonObject statsObject; - auto nodeList = DependencyManager::get(); - - if (_currentAssignment) { - statsObject["assignment_type"] = _currentAssignment->getTypeName(); - } else { - statsObject["assignment_type"] = "none"; - } - nodeList->sendStats(statsObject, _assignmentClientMonitorSocket); } void AssignmentClient::sendAssignmentRequest() { @@ -188,9 +145,23 @@ void AssignmentClient::sendAssignmentRequest() { if (_assignmentServerHostname == "localhost") { // we want to check again for the local domain-server port in case the DS has restarted - quint16 localAssignmentServerPort; - if (nodeList->getLocalServerPortFromSharedMemory(DOMAIN_SERVER_LOCAL_PORT_SMEM_KEY, _localASPortSharedMem, - localAssignmentServerPort)) { + if (!_localASPortSharedMem) { + _localASPortSharedMem = new QSharedMemory(DOMAIN_SERVER_LOCAL_PORT_SMEM_KEY, this); + + if (!_localASPortSharedMem->attach(QSharedMemory::ReadOnly)) { + qWarning() << "Could not attach to shared memory at key" << DOMAIN_SERVER_LOCAL_PORT_SMEM_KEY + << "- will attempt to connect to domain-server on" << _assignmentServerSocket.getPort(); + } + } + + if (_localASPortSharedMem->isAttached()) { + _localASPortSharedMem->lock(); + + quint16 localAssignmentServerPort; + memcpy(&localAssignmentServerPort, _localASPortSharedMem->data(), sizeof(localAssignmentServerPort)); + + _localASPortSharedMem->unlock(); + if (localAssignmentServerPort != _assignmentServerSocket.getPort()) { qDebug() << "Port for local assignment server read from shared memory is" << localAssignmentServerPort; @@ -199,9 +170,7 @@ void AssignmentClient::sendAssignmentRequest() { nodeList->setAssignmentServerSocket(_assignmentServerSocket); } } - else { - qDebug () << "- will attempt to connect to domain-server on" << _assignmentServerSocket.getPort(); - } + } nodeList->sendAssignment(_requestAssignment); @@ -258,14 +227,6 @@ void AssignmentClient::readPendingDatagrams() { } else { qDebug() << "Received an assignment that could not be unpacked. Re-requesting."; } - } else if (packetTypeForPacket(receivedPacket) == PacketTypeStopNode) { - if (senderSockAddr.getAddress() == QHostAddress::LocalHost || - senderSockAddr.getAddress() == QHostAddress::LocalHostIPv6) { - qDebug() << "Network told me to exit."; - emit stopAssignmentClient(); - } else { - qDebug() << "Got a stop packet from other than localhost."; - } } else { // have the NodeList attempt to handle it nodeList->processNodeData(senderSockAddr, receivedPacket); diff --git a/assignment-client/src/AssignmentClient.h b/assignment-client/src/AssignmentClient.h index e105309e10..053458f136 100644 --- a/assignment-client/src/AssignmentClient.h +++ b/assignment-client/src/AssignmentClient.h @@ -29,22 +29,13 @@ private slots: void readPendingDatagrams(); void assignmentCompleted(); void handleAuthenticationRequest(); - void sendStatsPacketToACM(); - void stopAssignmentClient(); private: - void setUpStatsToMonitor(); Assignment _requestAssignment; static SharedAssignmentPointer _currentAssignment; QString _assignmentServerHostname; HifiSockAddr _assignmentServerSocket; - QSharedMemory* _localASPortSharedMem; // memory shared with domain server - QSharedMemory* _localACMPortSharedMem; // memory shared with assignment client monitor - QTimer _requestTimer; // timer for requesting and assignment - QTimer _statsTimerACM; // timer for sending stats to assignment client monitor - - protected: - HifiSockAddr _assignmentClientMonitorSocket; + QSharedMemory* _localASPortSharedMem; }; #endif // hifi_AssignmentClient_h diff --git a/assignment-client/src/AssignmentClientApp.cpp b/assignment-client/src/AssignmentClientApp.cpp deleted file mode 100644 index 477f1a2cf8..0000000000 --- a/assignment-client/src/AssignmentClientApp.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// -// AssignmentClientapp.cpp -// assignment-client/src -// -// Created by Seth Alves on 2/19/15. -// Copyright 2015 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#include - -#include -#include - -#include "Assignment.h" -#include "AssignmentClient.h" -#include "AssignmentClientMonitor.h" -#include "AssignmentClientApp.h" - - -AssignmentClientApp::AssignmentClientApp(int argc, char* argv[]) : - QCoreApplication(argc, argv) -{ -# ifndef WIN32 - setvbuf(stdout, NULL, _IOLBF, 0); -# endif - - // use the verbose message handler in Logging - qInstallMessageHandler(LogHandler::verboseMessageHandler); - - // parse command-line - QCommandLineParser parser; - parser.setApplicationDescription("High Fidelity Assignment Client"); - parser.addHelpOption(); - - const QCommandLineOption helpOption = parser.addHelpOption(); - - const QCommandLineOption numChildsOption("n", "number of children to fork", "child-count"); - parser.addOption(numChildsOption); - - if (!parser.parse(QCoreApplication::arguments())) { - qCritical() << parser.errorText() << endl; - parser.showHelp(); - Q_UNREACHABLE(); - } - - if (parser.isSet(helpOption)) { - parser.showHelp(); - Q_UNREACHABLE(); - } - - unsigned int numForks = 0; - if (parser.isSet(numChildsOption)) { - numForks = parser.value(numChildsOption).toInt(); - } - - if (numForks) { - AssignmentClientMonitor monitor(argc, argv, numForks); - monitor.exec(); - } else { - AssignmentClient client(argc, argv); - client.exec(); - } -} diff --git a/assignment-client/src/AssignmentClientApp.h b/assignment-client/src/AssignmentClientApp.h deleted file mode 100644 index c5099ff25c..0000000000 --- a/assignment-client/src/AssignmentClientApp.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// AssignmentClientapp.h -// assignment-client/src -// -// Created by Seth Alves on 2/19/15. -// Copyright 2015 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#include - -class AssignmentClientApp : public QCoreApplication { - Q_OBJECT -public: - AssignmentClientApp(int argc, char* argv[]); -}; diff --git a/assignment-client/src/AssignmentClientChildData.cpp b/assignment-client/src/AssignmentClientChildData.cpp deleted file mode 100644 index de34613ec9..0000000000 --- a/assignment-client/src/AssignmentClientChildData.cpp +++ /dev/null @@ -1,8 +0,0 @@ - -#include "AssignmentClientChildData.h" - - -AssignmentClientChildData::AssignmentClientChildData(QString childType) : - _childType(childType) -{ -} diff --git a/assignment-client/src/AssignmentClientChildData.h b/assignment-client/src/AssignmentClientChildData.h deleted file mode 100644 index 6fd5f72f7f..0000000000 --- a/assignment-client/src/AssignmentClientChildData.h +++ /dev/null @@ -1,32 +0,0 @@ -// -// AssignmentClientChildData.h -// assignment-client/src -// -// Created by Seth Alves on 2/23/2015. -// Copyright 2015 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_AssignmentClientChildData_h -#define hifi_AssignmentClientChildData_h - -#include - - -class AssignmentClientChildData : public NodeData { - public: - AssignmentClientChildData(QString childType); - - QString getChildType() { return _childType; } - void setChildType(QString childType) { _childType = childType; } - - // implement parseData to return 0 so we can be a subclass of NodeData - int parseData(const QByteArray& packet) { return 0; } - - private: - QString _childType; -}; - -#endif // hifi_AssignmentClientChildData_h diff --git a/assignment-client/src/AssignmentClientMonitor.cpp b/assignment-client/src/AssignmentClientMonitor.cpp index 803c7fd5c7..45e1f56d53 100644 --- a/assignment-client/src/AssignmentClientMonitor.cpp +++ b/assignment-client/src/AssignmentClientMonitor.cpp @@ -13,18 +13,14 @@ #include #include -#include #include "AssignmentClientMonitor.h" -#include "AssignmentClientChildData.h" -#include "PacketHeaders.h" -#include "SharedUtil.h" const char* NUM_FORKS_PARAMETER = "-n"; const QString ASSIGNMENT_CLIENT_MONITOR_TARGET_NAME = "assignment-client-monitor"; -AssignmentClientMonitor::AssignmentClientMonitor(int &argc, char **argv, const unsigned int numAssignmentClientForks) : +AssignmentClientMonitor::AssignmentClientMonitor(int &argc, char **argv, int numAssignmentClientForks) : QCoreApplication(argc, argv) { // start the Logging class with the parent's target name @@ -45,25 +41,11 @@ AssignmentClientMonitor::AssignmentClientMonitor(int &argc, char **argv, const u // this removes both the "-n" parameter and the number of forks passed _childArguments.removeAt(forksParameterIndex); _childArguments.removeAt(forksParameterIndex); - - - // create a NodeList so we can receive stats from children - DependencyManager::registerInheritance(); - auto addressManager = DependencyManager::set(); - auto nodeList = DependencyManager::set(DEFAULT_ASSIGNMENT_CLIENT_MONITOR_PORT, - DEFAULT_ASSIGNMENT_CLIENT_MONITOR_DTLS_PORT); - - connect(&nodeList->getNodeSocket(), &QUdpSocket::readyRead, this, &AssignmentClientMonitor::readPendingDatagrams); - - nodeList->putLocalPortIntoSharedMemory(ASSIGNMENT_CLIENT_MONITOR_LOCAL_PORT_SMEM_KEY, this); // use QProcess to fork off a process for each of the child assignment clients - for (unsigned int i = 0; i < numAssignmentClientForks; i++) { + for (int i = 0; i < numAssignmentClientForks; i++) { spawnChildClient(); } - - connect(&_checkSparesTimer, SIGNAL(timeout()), SLOT(checkSpares())); - _checkSparesTimer.start(NODE_SILENCE_THRESHOLD_MSECS * 3); } AssignmentClientMonitor::~AssignmentClientMonitor() { @@ -71,122 +53,46 @@ AssignmentClientMonitor::~AssignmentClientMonitor() { } void AssignmentClientMonitor::stopChildProcesses() { - auto nodeList = DependencyManager::get(); - - nodeList->eachNode([&](const SharedNodePointer& node) { - qDebug() << "asking child" << node->getUUID() << "to exit."; - node->activateLocalSocket(); - QByteArray diePacket = byteArrayWithPopulatedHeader(PacketTypeStopNode); - nodeList->writeUnverifiedDatagram(diePacket, *node->getActiveSocket()); - }); + + QList >::Iterator it = _childProcesses.begin(); + while (it != _childProcesses.end()) { + if (!it->isNull()) { + qDebug() << "Monitor is terminating child process" << it->data(); + + // don't re-spawn this child when it goes down + disconnect(it->data(), 0, this, 0); + + it->data()->terminate(); + it->data()->waitForFinished(); + } + + it = _childProcesses.erase(it); + } } void AssignmentClientMonitor::spawnChildClient() { QProcess *assignmentClient = new QProcess(this); + _childProcesses.append(QPointer(assignmentClient)); + // make sure that the output from the child process appears in our output assignmentClient->setProcessChannelMode(QProcess::ForwardedChannels); assignmentClient->start(applicationFilePath(), _childArguments); - + + // link the child processes' finished slot to our childProcessFinished slot + connect(assignmentClient, SIGNAL(finished(int, QProcess::ExitStatus)), this, + SLOT(childProcessFinished(int, QProcess::ExitStatus))); + qDebug() << "Spawned a child client with PID" << assignmentClient->pid(); } - - -void AssignmentClientMonitor::checkSpares() { - auto nodeList = DependencyManager::get(); - QUuid aSpareId = ""; - unsigned int spareCount = 0; - - nodeList->removeSilentNodes(); - - nodeList->eachNode([&](const SharedNodePointer& node) { - AssignmentClientChildData *childData = static_cast(node->getLinkedData()); - if (childData->getChildType() == "none") { - spareCount ++; - aSpareId = node->getUUID(); - } - }); - - if (spareCount != 1) { - qDebug() << "spare count is" << spareCount; - } - - if (spareCount < 1) { - spawnChildClient(); - } - - if (spareCount > 1) { - // kill aSpareId - qDebug() << "asking child" << aSpareId << "to exit."; - SharedNodePointer childNode = nodeList->nodeWithUUID(aSpareId); - childNode->activateLocalSocket(); - QByteArray diePacket = byteArrayWithPopulatedHeader(PacketTypeStopNode); - nodeList->writeUnverifiedDatagram(diePacket, childNode); - } +void AssignmentClientMonitor::childProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) { + qDebug("Replacing dead child assignment client with a new one"); + + // remove the old process from our list of child processes + qDebug() << "need to remove" << QPointer(qobject_cast(sender())); + _childProcesses.removeOne(QPointer(qobject_cast(sender()))); + + spawnChildClient(); } - - -void AssignmentClientMonitor::readPendingDatagrams() { - auto nodeList = DependencyManager::get(); - - QByteArray receivedPacket; - HifiSockAddr senderSockAddr; - - while (nodeList->getNodeSocket().hasPendingDatagrams()) { - receivedPacket.resize(nodeList->getNodeSocket().pendingDatagramSize()); - nodeList->getNodeSocket().readDatagram(receivedPacket.data(), receivedPacket.size(), - senderSockAddr.getAddressPointer(), senderSockAddr.getPortPointer()); - - if (nodeList->packetVersionAndHashMatch(receivedPacket)) { - if (packetTypeForPacket(receivedPacket) == PacketTypeNodeJsonStats) { - QUuid packetUUID = uuidFromPacketHeader(receivedPacket); - SharedNodePointer matchingNode = nodeList->sendingNodeForPacket(receivedPacket); - if (!matchingNode) { - // The parent only expects to be talking with prorams running on this same machine. - if (senderSockAddr.getAddress() == QHostAddress::LocalHost || - senderSockAddr.getAddress() == QHostAddress::LocalHostIPv6) { - if (!packetUUID.isNull()) { - matchingNode = DependencyManager::get()->addOrUpdateNode - (packetUUID, NodeType::Unassigned, senderSockAddr, senderSockAddr, false); - AssignmentClientChildData *childData = new AssignmentClientChildData("unknown"); - matchingNode->setLinkedData(childData); - } else { - // tell unknown assignment-client child to exit. - qDebug() << "asking unknown child to exit."; - QByteArray diePacket = byteArrayWithPopulatedHeader(PacketTypeStopNode); - nodeList->writeUnverifiedDatagram(diePacket, senderSockAddr); - } - } - } - - if (matchingNode) { - // update our records about how to reach this child - matchingNode->setLocalSocket(senderSockAddr); - - // push past the packet header - QDataStream packetStream(receivedPacket); - packetStream.skipRawData(numBytesForPacketHeader(receivedPacket)); - // decode json - QVariantMap unpackedVariantMap; - packetStream >> unpackedVariantMap; - QJsonObject unpackedStatsJSON = QJsonObject::fromVariantMap(unpackedVariantMap); - - // get child's assignment type out of the decoded json - QString childType = unpackedStatsJSON["assignment_type"].toString(); - AssignmentClientChildData *childData = - static_cast(matchingNode->getLinkedData()); - childData->setChildType(childType); - // note when this child talked - matchingNode->setLastHeardMicrostamp(usecTimestampNow()); - } - } else { - // have the NodeList attempt to handle it - nodeList->processNodeData(senderSockAddr, receivedPacket); - } - } - } -} - - diff --git a/assignment-client/src/AssignmentClientMonitor.h b/assignment-client/src/AssignmentClientMonitor.h index 71ae34bc8c..9a7bca9cb3 100644 --- a/assignment-client/src/AssignmentClientMonitor.h +++ b/assignment-client/src/AssignmentClientMonitor.h @@ -15,30 +15,25 @@ #include #include #include -#include #include -#include "AssignmentClientChildData.h" - extern const char* NUM_FORKS_PARAMETER; - class AssignmentClientMonitor : public QCoreApplication { Q_OBJECT public: - AssignmentClientMonitor(int &argc, char **argv, const unsigned int numAssignmentClientForks); + AssignmentClientMonitor(int &argc, char **argv, int numAssignmentClientForks); ~AssignmentClientMonitor(); void stopChildProcesses(); private slots: - void readPendingDatagrams(); - void checkSpares(); - + void childProcessFinished(int exitCode, QProcess::ExitStatus exitStatus); private: void spawnChildClient(); + QList > _childProcesses; + QStringList _childArguments; - QTimer _checkSparesTimer; // every few seconds see if it need fewer or more spare children }; #endif // hifi_AssignmentClientMonitor_h diff --git a/assignment-client/src/main.cpp b/assignment-client/src/main.cpp index 81a12526bf..3bf6990a74 100644 --- a/assignment-client/src/main.cpp +++ b/assignment-client/src/main.cpp @@ -9,10 +9,34 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include +#include -#include "AssignmentClientApp.h" +#include "Assignment.h" +#include "AssignmentClient.h" +#include "AssignmentClientMonitor.h" int main(int argc, char* argv[]) { - AssignmentClientApp app(argc, argv); - return 0; +#ifndef WIN32 + setvbuf(stdout, NULL, _IOLBF, 0); +#endif + + // use the verbose message handler in Logging + qInstallMessageHandler(LogHandler::verboseMessageHandler); + + const char* numForksString = getCmdOption(argc, (const char**)argv, NUM_FORKS_PARAMETER); + + int numForks = 0; + + if (numForksString) { + numForks = atoi(numForksString); + } + + if (numForks) { + AssignmentClientMonitor monitor(argc, argv, numForks); + return monitor.exec(); + } else { + AssignmentClient client(argc, argv); + return client.exec(); + } } diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 64e0d335b1..f84722a438 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -246,7 +246,19 @@ void DomainServer::setupNodeListAndAssignments(const QUuid& sessionUUID) { auto nodeList = DependencyManager::set(domainServerPort, domainServerDTLSPort); // no matter the local port, save it to shared mem so that local assignment clients can ask what it is - nodeList->putLocalPortIntoSharedMemory(DOMAIN_SERVER_LOCAL_PORT_SMEM_KEY, this); + QSharedMemory* sharedPortMem = new QSharedMemory(DOMAIN_SERVER_LOCAL_PORT_SMEM_KEY, this); + quint16 localPort = nodeList->getNodeSocket().localPort(); + + // attempt to create the shared memory segment + if (sharedPortMem->create(sizeof(localPort)) || sharedPortMem->attach()) { + sharedPortMem->lock(); + memcpy(sharedPortMem->data(), &localPort, sizeof(localPort)); + sharedPortMem->unlock(); + + qDebug() << "Wrote local listening port" << localPort << "to shared memory at key" << DOMAIN_SERVER_LOCAL_PORT_SMEM_KEY; + } else { + qWarning() << "Failed to create and attach to shared memory to share local port with assignment-client children."; + } // 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 diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index f67abdca2b..9bcdcbe9a4 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -76,7 +76,7 @@ const QString AddressManager::currentPath(bool withOrientation) const { pathString += "/" + orientationString; } else { qDebug() << "Cannot add orientation to path without a getter for position." - << "Call AddressManager::setOrientationGetter to pass a function that will return a glm::quat"; + << "Call AdressManager::setOrientationGetter to pass a function that will return a glm::quat"; } } @@ -84,7 +84,7 @@ const QString AddressManager::currentPath(bool withOrientation) const { return pathString; } else { qDebug() << "Cannot create address path without a getter for position." - << "Call AddressManager::setPositionGetter to pass a function that will return a const glm::vec3&"; + << "Call AdressManager::setPositionGetter to pass a function that will return a const glm::vec3&"; return QString(); } } diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index b240f0df9e..c8c454ff14 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -669,41 +669,3 @@ void LimitedNodeList::sendHeartbeatToIceServer(const HifiSockAddr& iceServerSock writeUnverifiedDatagram(iceRequestByteArray, iceServerSockAddr); } - -void LimitedNodeList::putLocalPortIntoSharedMemory(const QString key, QObject* parent) { - // save our local port to shared memory so that assignment client children know how to talk to this parent - QSharedMemory* sharedPortMem = new QSharedMemory(key, parent); - quint16 localPort = getNodeSocket().localPort(); - - // attempt to create the shared memory segment - if (sharedPortMem->create(sizeof(localPort)) || sharedPortMem->attach()) { - sharedPortMem->lock(); - memcpy(sharedPortMem->data(), &localPort, sizeof(localPort)); - sharedPortMem->unlock(); - - qDebug() << "Wrote local listening port" << localPort << "to shared memory at key" << key; - } else { - qWarning() << "Failed to create and attach to shared memory to share local port with assignment-client children."; - } -} - - -bool LimitedNodeList::getLocalServerPortFromSharedMemory(const QString key, QSharedMemory*& sharedMem, - quint16& localPort) { - if (!sharedMem) { - sharedMem = new QSharedMemory(key, this); - - if (!sharedMem->attach(QSharedMemory::ReadOnly)) { - qWarning() << "Could not attach to shared memory at key" << key; - } - } - - if (sharedMem->isAttached()) { - sharedMem->lock(); - memcpy(&localPort, sharedMem->data(), sizeof(localPort)); - sharedMem->unlock(); - return true; - } - - return false; -} diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index 02234ee4f7..72aefdb2b3 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -26,7 +26,6 @@ #include #include #include -#include #include @@ -50,11 +49,6 @@ const char STUN_SERVER_HOSTNAME[] = "stun.highfidelity.io"; const unsigned short STUN_SERVER_PORT = 3478; const QString DOMAIN_SERVER_LOCAL_PORT_SMEM_KEY = "domain-server.local-port"; -const QString ASSIGNMENT_CLIENT_MONITOR_LOCAL_PORT_SMEM_KEY = "assignment-client-monitor.local-port"; - -const char DEFAULT_ASSIGNMENT_CLIENT_MONITOR_HOSTNAME[] = "localhost"; -const unsigned short DEFAULT_ASSIGNMENT_CLIENT_MONITOR_PORT = 40104; -const unsigned short DEFAULT_ASSIGNMENT_CLIENT_MONITOR_DTLS_PORT = 40105; class HifiSockAddr; @@ -174,9 +168,6 @@ public: return SharedNodePointer(); } - - void putLocalPortIntoSharedMemory(const QString key, QObject* parent); - bool getLocalServerPortFromSharedMemory(const QString key, QSharedMemory*& sharedMem, quint16& localPort); public slots: void reset(); diff --git a/libraries/networking/src/Node.cpp b/libraries/networking/src/Node.cpp index 2a38799707..2bf792c6ee 100644 --- a/libraries/networking/src/Node.cpp +++ b/libraries/networking/src/Node.cpp @@ -149,12 +149,7 @@ QDataStream& operator>>(QDataStream& in, Node& node) { } QDebug operator<<(QDebug debug, const Node &node) { - debug.nospace() << NodeType::getNodeTypeName(node.getType()); - if (node.getType() == NodeType::Unassigned) { - debug.nospace() << " (1)"; - } else { - debug.nospace() << " (" << node.getType() << ")"; - } + debug.nospace() << NodeType::getNodeTypeName(node.getType()) << " (" << node.getType() << ")"; debug << " " << node.getUUID().toString().toLocal8Bit().constData() << " "; debug.nospace() << node.getPublicSocket() << "/" << node.getLocalSocket(); return debug.nospace(); diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index e63f230f6e..f70c2d9b3c 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -62,17 +62,13 @@ NodeList::NodeList(char newOwnerType, unsigned short socketListenPort, unsigned connect(&AccountManager::getInstance(), &AccountManager::logoutComplete , this, &NodeList::reset); } -qint64 NodeList::sendStats(const QJsonObject& statsObject, HifiSockAddr destination) { +qint64 NodeList::sendStatsToDomainServer(const QJsonObject& statsObject) { QByteArray statsPacket = byteArrayWithPopulatedHeader(PacketTypeNodeJsonStats); QDataStream statsPacketStream(&statsPacket, QIODevice::Append); statsPacketStream << statsObject.toVariantMap(); - return writeUnverifiedDatagram(statsPacket, destination); -} - -qint64 NodeList::sendStatsToDomainServer(const QJsonObject& statsObject) { - return sendStats(statsObject, _domainHandler.getSockAddr()); + return writeUnverifiedDatagram(statsPacket, _domainHandler.getSockAddr()); } void NodeList::timePingReply(const QByteArray& packet, const SharedNodePointer& sendingNode) { diff --git a/libraries/networking/src/NodeList.h b/libraries/networking/src/NodeList.h index 1c6de4bb6c..907fccfcac 100644 --- a/libraries/networking/src/NodeList.h +++ b/libraries/networking/src/NodeList.h @@ -47,7 +47,6 @@ public: NodeType_t getOwnerType() const { return _ownerType; } void setOwnerType(NodeType_t ownerType) { _ownerType = ownerType; } - qint64 sendStats(const QJsonObject& statsObject, HifiSockAddr destination); qint64 sendStatsToDomainServer(const QJsonObject& statsObject); int getNumNoReplyDomainCheckIns() const { return _numNoReplyDomainCheckIns; } diff --git a/libraries/networking/src/PacketHeaders.cpp b/libraries/networking/src/PacketHeaders.cpp index db97e216ee..2eee540fff 100644 --- a/libraries/networking/src/PacketHeaders.cpp +++ b/libraries/networking/src/PacketHeaders.cpp @@ -70,8 +70,6 @@ PacketVersion versionForPacketType(PacketType type) { return 2; case PacketTypeOctreeStats: return 1; - case PacketTypeStopNode: - return 1; case PacketTypeEntityAddOrEdit: case PacketTypeEntityData: return VERSION_MODEL_ENTITIES_SUPPORT_SHAPE_TYPE; @@ -126,7 +124,6 @@ QString nameForPacketType(PacketType type) { PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityErase); PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityAddResponse); PACKET_TYPE_NAME_LOOKUP(PacketTypeOctreeDataNack); - PACKET_TYPE_NAME_LOOKUP(PacketTypeStopNode); PACKET_TYPE_NAME_LOOKUP(PacketTypeAudioEnvironment); PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityEditNack); PACKET_TYPE_NAME_LOOKUP(PacketTypeSignedTransactionPayment); diff --git a/libraries/networking/src/PacketHeaders.h b/libraries/networking/src/PacketHeaders.h index 32f33c01d9..e593955b51 100644 --- a/libraries/networking/src/PacketHeaders.h +++ b/libraries/networking/src/PacketHeaders.h @@ -67,7 +67,7 @@ enum PacketType { PacketTypeEntityErase, PacketTypeEntityAddResponse, PacketTypeOctreeDataNack, // 45 - PacketTypeStopNode, + UNUSED_10, PacketTypeAudioEnvironment, PacketTypeEntityEditNack, PacketTypeSignedTransactionPayment, @@ -86,7 +86,7 @@ const QSet NON_VERIFIED_PACKETS = QSet() << PacketTypeNodeJsonStats << PacketTypeEntityQuery << PacketTypeOctreeDataNack << PacketTypeEntityEditNack << PacketTypeIceServerHeartbeat << PacketTypeIceServerHeartbeatResponse - << PacketTypeUnverifiedPing << PacketTypeUnverifiedPingReply << PacketTypeStopNode; + << PacketTypeUnverifiedPing << PacketTypeUnverifiedPingReply; const int NUM_BYTES_MD5_HASH = 16; const int NUM_STATIC_HEADER_BYTES = sizeof(PacketVersion) + NUM_BYTES_RFC4122_UUID;