From fb8d2e34fb46bea9e9b483ed6e05a061a1c60371 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 23 Jan 2017 13:14:53 -0800 Subject: [PATCH 1/2] fix needless reinterpret_cast for DomainServerNodeData --- domain-server/src/DomainGatekeeper.cpp | 12 ++++++------ domain-server/src/DomainServer.cpp | 14 +++++++------- domain-server/src/DomainServerSettingsManager.cpp | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/domain-server/src/DomainGatekeeper.cpp b/domain-server/src/DomainGatekeeper.cpp index 97f3e1a697..3d4e48f94a 100644 --- a/domain-server/src/DomainGatekeeper.cpp +++ b/domain-server/src/DomainGatekeeper.cpp @@ -107,7 +107,7 @@ void DomainGatekeeper::processConnectRequestPacket(QSharedPointer(node->getLinkedData()); + DomainServerNodeData* nodeData = static_cast(node->getLinkedData()); nodeData->setSendingSockAddr(message->getSenderSockAddr()); // guard against patched agents asking to hear about other agents @@ -128,12 +128,12 @@ void DomainGatekeeper::processConnectRequestPacket(QSharedPointergetSenderSockAddr() - << "with hardware address" << nodeConnection.hardwareAddress + << "with hardware address" << nodeConnection.hardwareAddress << "and machine fingerprint" << nodeConnection.machineFingerprint; } } -NodePermissions DomainGatekeeper::setPermissionsForUser(bool isLocalUser, QString verifiedUsername, const QHostAddress& senderAddress, +NodePermissions DomainGatekeeper::setPermissionsForUser(bool isLocalUser, QString verifiedUsername, const QHostAddress& senderAddress, const QString& hardwareAddress, const QUuid& machineFingerprint) { NodePermissions userPerms; @@ -283,7 +283,7 @@ void DomainGatekeeper::updateNodePermissions() { QString hardwareAddress; QUuid machineFingerprint; - DomainServerNodeData* nodeData = reinterpret_cast(node->getLinkedData()); + DomainServerNodeData* nodeData = static_cast(node->getLinkedData()); if (nodeData) { hardwareAddress = nodeData->getHardwareAddress(); machineFingerprint = nodeData->getMachineFingerprint(); @@ -336,7 +336,7 @@ SharedNodePointer DomainGatekeeper::processAssignmentConnectRequest(const NodeCo // add the new node SharedNodePointer newNode = addVerifiedNodeFromConnectRequest(nodeConnection); - DomainServerNodeData* nodeData = reinterpret_cast(newNode->getLinkedData()); + DomainServerNodeData* nodeData = static_cast(newNode->getLinkedData()); // set assignment related data on the linked data for this node nodeData->setAssignmentUUID(matchingQueuedAssignment->getUUID()); @@ -458,7 +458,7 @@ SharedNodePointer DomainGatekeeper::processAgentConnectRequest(const NodeConnect newNode->setPermissions(userPerms); // grab the linked data for our new node so we can set the username - DomainServerNodeData* nodeData = reinterpret_cast(newNode->getLinkedData()); + DomainServerNodeData* nodeData = static_cast(newNode->getLinkedData()); // if we have a username from the connect request, set it on the DomainServerNodeData nodeData->setUsername(username); diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 0f7923519b..aebec1e317 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -841,7 +841,7 @@ void DomainServer::processListRequestPacket(QSharedPointer mess sendingNode->setLocalSocket(nodeRequestData.localSockAddr); // update the NodeInterestSet in case there have been any changes - DomainServerNodeData* nodeData = reinterpret_cast(sendingNode->getLinkedData()); + DomainServerNodeData* nodeData = static_cast(sendingNode->getLinkedData()); // guard against patched agents asking to hear about other agents auto safeInterestSet = nodeRequestData.interestList.toSet(); @@ -945,7 +945,7 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif // always send the node their own UUID back QDataStream domainListStream(domainListPackets.get()); - DomainServerNodeData* nodeData = reinterpret_cast(node->getLinkedData()); + DomainServerNodeData* nodeData = static_cast(node->getLinkedData()); // store the nodeInterestSet on this DomainServerNodeData, in case it has changed auto& nodeInterestSet = nodeData->getNodeInterestSet(); @@ -994,7 +994,7 @@ QUuid DomainServer::connectionSecretForNodes(const SharedNodePointer& nodeA, con secretUUID = QUuid::createUuid(); // set it on the other Node's sessionSecretHash - reinterpret_cast(nodeBData)->getSessionSecretHash().insert(nodeA->getUUID(), secretUUID); + static_cast(nodeBData)->getSessionSecretHash().insert(nodeA->getUUID(), secretUUID); } return secretUUID; @@ -1124,7 +1124,7 @@ void DomainServer::processRequestAssignmentPacket(QSharedPointer()->eachNode([&](const SharedNodePointer& node){ - DomainServerNodeData* nodeData = reinterpret_cast(node->getLinkedData()); + DomainServerNodeData* nodeData = static_cast(node->getLinkedData()); if (!nodeData->getAssignmentUUID().isNull() && !nodeData->getWalletUUID().isNull()) { // check if we have a non-finalized transaction for this node to add this amount to @@ -1556,7 +1556,7 @@ QJsonObject DomainServer::jsonObjectForNode(const SharedNodePointer& node) { nodeJson[JSON_KEY_UPTIME] = QString::number(double(QDateTime::currentMSecsSinceEpoch() - node->getWakeTimestamp()) / 1000.0); // if the node has pool information, add it - DomainServerNodeData* nodeData = reinterpret_cast(node->getLinkedData()); + DomainServerNodeData* nodeData = static_cast(node->getLinkedData()); // add the node username, if it exists nodeJson[JSON_KEY_USERNAME] = nodeData->getUsername(); @@ -1687,7 +1687,7 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url // enumerate the NodeList to find the assigned nodes nodeList->eachNode([this, &assignedNodesJSON](const SharedNodePointer& node){ - DomainServerNodeData* nodeData = reinterpret_cast(node->getLinkedData()); + DomainServerNodeData* nodeData = static_cast(node->getLinkedData()); if (!nodeData->getAssignmentUUID().isNull()) { // add the node using the UUID as the key @@ -1775,7 +1775,7 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url if (matchingNode) { // create a QJsonDocument with the stats QJsonObject QJsonObject statsObject = - reinterpret_cast(matchingNode->getLinkedData())->getStatsJSONObject(); + static_cast(matchingNode->getLinkedData())->getStatsJSONObject(); // add the node type to the JSON data for output purposes statsObject["node_type"] = NodeType::getNodeTypeName(matchingNode->getType()).toLower().replace(' ', '-'); diff --git a/domain-server/src/DomainServerSettingsManager.cpp b/domain-server/src/DomainServerSettingsManager.cpp index 5e1d747604..a0b80875b0 100644 --- a/domain-server/src/DomainServerSettingsManager.cpp +++ b/domain-server/src/DomainServerSettingsManager.cpp @@ -725,7 +725,7 @@ void DomainServerSettingsManager::processNodeKickRequestPacket(QSharedPointer(matchingNode->getLinkedData()); + DomainServerNodeData* nodeData = static_cast(matchingNode->getLinkedData()); if (nodeData) { // mac address first NodePermissionsKey macAddressKey(nodeData->getHardwareAddress(), 0); @@ -807,7 +807,7 @@ void DomainServerSettingsManager::processUsernameFromIDRequestPacket(QSharedPoin usernameFromIDReplyPacket->writeString(verifiedUsername); // now put in the machine fingerprint - DomainServerNodeData* nodeData = reinterpret_cast(matchingNode->getLinkedData()); + DomainServerNodeData* nodeData = static_cast(matchingNode->getLinkedData()); machineFingerprint = nodeData ? nodeData->getMachineFingerprint() : QUuid(); usernameFromIDReplyPacket->write(machineFingerprint.toRfc4122()); } else { From 1802e1520db6fe59809f2a5f10a3417d7240e1ed Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 23 Jan 2017 13:15:48 -0800 Subject: [PATCH 2/2] change some dynamic_cast to static_cast for DomainServerNodeData --- domain-server/src/DomainServer.cpp | 60 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index aebec1e317..7f142b6ef8 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -107,7 +107,7 @@ DomainServer::DomainServer(int argc, char* argv[]) : qRegisterMetaType("DomainServerWebSessionData"); qRegisterMetaTypeStreamOperators("DomainServerWebSessionData"); - + // make sure we hear about newly connected nodes from our gatekeeper connect(&_gatekeeper, &DomainGatekeeper::connectedNode, this, &DomainServer::handleConnectedNode); @@ -281,7 +281,7 @@ bool DomainServer::optionallyReadX509KeyAndCertificate() { QString keyPassphraseString = QProcessEnvironment::systemEnvironment().value(X509_KEY_PASSPHRASE_ENV); qDebug() << "Reading certificate file at" << certPath << "for HTTPS."; - qDebug() << "Reading key file at" << keyPath << "for HTTPS."; + qDebug() << "Reading key file at" << keyPath << "for HTTPS."; QFile certFile(certPath); certFile.open(QIODevice::ReadOnly); @@ -528,12 +528,12 @@ void DomainServer::setupNodeListAndAssignments() { packetReceiver.registerListener(PacketType::DomainServerPathQuery, this, "processPathQueryPacket"); packetReceiver.registerListener(PacketType::NodeJsonStats, this, "processNodeJSONStatsPacket"); packetReceiver.registerListener(PacketType::DomainDisconnectRequest, this, "processNodeDisconnectRequestPacket"); - + // NodeList won't be available to the settings manager when it is created, so call registerListener here packetReceiver.registerListener(PacketType::DomainSettingsRequest, &_settingsManager, "processSettingsRequestPacket"); packetReceiver.registerListener(PacketType::NodeKickRequest, &_settingsManager, "processNodeKickRequestPacket"); packetReceiver.registerListener(PacketType::UsernameFromIDRequest, &_settingsManager, "processUsernameFromIDRequestPacket"); - + // register the gatekeeper for the packets it needs to receive packetReceiver.registerListener(PacketType::DomainConnectRequest, &_gatekeeper, "processConnectRequestPacket"); packetReceiver.registerListener(PacketType::ICEPing, &_gatekeeper, "processICEPingPacket"); @@ -542,7 +542,7 @@ void DomainServer::setupNodeListAndAssignments() { packetReceiver.registerListener(PacketType::ICEServerHeartbeatDenied, this, "processICEServerHeartbeatDenialPacket"); packetReceiver.registerListener(PacketType::ICEServerHeartbeatACK, this, "processICEServerHeartbeatACK"); - + // add whatever static assignments that have been parsed to the queue addStaticAssignmentsToQueue(); @@ -811,18 +811,18 @@ void DomainServer::populateDefaultStaticAssignmentsExcludingTypes(const QSet mess // update this node's sockets in case they have changed sendingNode->setPublicSocket(nodeRequestData.publicSockAddr); sendingNode->setLocalSocket(nodeRequestData.localSockAddr); - + // update the NodeInterestSet in case there have been any changes DomainServerNodeData* nodeData = static_cast(sendingNode->getLinkedData()); @@ -928,14 +928,14 @@ void DomainServer::handleConnectedNode(SharedNodePointer newNode) { void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const HifiSockAddr &senderSockAddr) { const int NUM_DOMAIN_LIST_EXTENDED_HEADER_BYTES = NUM_BYTES_RFC4122_UUID + NUM_BYTES_RFC4122_UUID + 2; - + // setup the extended header for the domain list packets // this data is at the beginning of each of the domain list packets QByteArray extendedHeader(NUM_DOMAIN_LIST_EXTENDED_HEADER_BYTES, 0); QDataStream extendedHeaderStream(&extendedHeader, QIODevice::WriteOnly); - + auto limitedNodeList = DependencyManager::get(); - + extendedHeaderStream << limitedNodeList->getSessionUUID(); extendedHeaderStream << node->getUUID(); extendedHeaderStream << node->getPermissions(); @@ -958,7 +958,7 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif limitedNodeList->eachNode([&](const SharedNodePointer& otherNode){ if (otherNode->getUUID() != node->getUUID() && nodeInterestSet.contains(otherNode->getType())) { - + // since we're about to add a node to the packet we start a segment domainListPackets->startSegment(); @@ -974,7 +974,7 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif }); } } - + // send an empty list to the node, in case there were no other nodes domainListPackets->closeCurrentPacket(true); @@ -983,8 +983,8 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif } QUuid DomainServer::connectionSecretForNodes(const SharedNodePointer& nodeA, const SharedNodePointer& nodeB) { - DomainServerNodeData* nodeAData = dynamic_cast(nodeA->getLinkedData()); - DomainServerNodeData* nodeBData = dynamic_cast(nodeB->getLinkedData()); + DomainServerNodeData* nodeAData = static_cast(nodeA->getLinkedData()); + DomainServerNodeData* nodeBData = static_cast(nodeB->getLinkedData()); if (nodeAData && nodeBData) { QUuid& secretUUID = nodeAData->getSessionSecretHash()[nodeB->getUUID()]; @@ -1020,7 +1020,7 @@ void DomainServer::broadcastNewNode(const SharedNodePointer& addedNode) { [&](const SharedNodePointer& node)->bool { if (node->getLinkedData() && node->getActiveSocket() && node != addedNode) { // is the added Node in this node's interest list? - DomainServerNodeData* nodeData = dynamic_cast(node->getLinkedData()); + DomainServerNodeData* nodeData = static_cast(node->getLinkedData()); return nodeData->getNodeInterestSet().contains(addedNode->getType()); } else { return false; @@ -1510,7 +1510,7 @@ void DomainServer::sendHeartbeatToIceServer() { } void DomainServer::processNodeJSONStatsPacket(QSharedPointer packetList, SharedNodePointer sendingNode) { - auto nodeData = dynamic_cast(sendingNode->getLinkedData()); + auto nodeData = static_cast(sendingNode->getLinkedData()); if (nodeData) { nodeData->updateJSONStats(packetList->getMessage()); } @@ -1624,23 +1624,23 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url if (connection->requestOperation() == QNetworkAccessManager::GetOperation && assignmentRegex.indexIn(url.path()) != -1) { QUuid nodeUUID = QUuid(assignmentRegex.cap(1)); - + auto matchingNode = nodeList->nodeWithUUID(nodeUUID); - + // don't handle if we don't have a matching node if (!matchingNode) { return false; } - - auto nodeData = dynamic_cast(matchingNode->getLinkedData()); - + + auto nodeData = static_cast(matchingNode->getLinkedData()); + // don't handle if we don't have node data for this node if (!nodeData) { return false; } - + SharedAssignmentPointer matchingAssignment = _allAssignments.value(nodeData->getAssignmentUUID()); - + // check if we have an assignment that matches this temp UUID, and it is a scripted assignment if (matchingAssignment && matchingAssignment->getType() == Assignment::AgentType) { // we have a matching assignment and it is for the right type, have the HTTP manager handle it @@ -1655,7 +1655,7 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url return true; } - + // request not handled return false; } @@ -2247,7 +2247,7 @@ void DomainServer::addStaticAssignmentsToQueue() { // if the domain-server has just restarted, // check if there are static assignments that we need to throw into the assignment queue auto sharedAssignments = _allAssignments.values(); - + // sort the assignments to put the server/mixer assignments first qSort(sharedAssignments.begin(), sharedAssignments.end(), [](SharedAssignmentPointer a, SharedAssignmentPointer b){ if (a->getType() == b->getType()) { @@ -2258,9 +2258,9 @@ void DomainServer::addStaticAssignmentsToQueue() { return a->getType() != Assignment::AgentType; } }); - + auto staticAssignment = sharedAssignments.begin(); - + while (staticAssignment != sharedAssignments.end()) { // add any of the un-matched static assignments to the queue @@ -2385,7 +2385,7 @@ void DomainServer::handleKillNode(SharedNodePointer nodeToKill) { // broadcast out the DomainServerRemovedNode message limitedNodeList->eachMatchingNode([&nodeType](const SharedNodePointer& otherNode) -> bool { // only send the removed node packet to nodes that care about the type of node this was - auto nodeLinkedData = dynamic_cast(otherNode->getLinkedData()); + auto nodeLinkedData = static_cast(otherNode->getLinkedData()); return (nodeLinkedData != nullptr) && nodeLinkedData->getNodeInterestSet().contains(nodeType); }, [&limitedNodeList](const SharedNodePointer& otherNode){ limitedNodeList->sendUnreliablePacket(*removedNodePacket, *otherNode);