From f237b77fa7a86f8ec258c9dd592fe36ef7300e2c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 7 Feb 2014 15:26:18 -0800 Subject: [PATCH 1/2] fix a bad cast to Assignment, closes #1935 --- domain-server/resources/web/js/tables.js | 2 +- domain-server/src/DomainServer.cpp | 19 ++++++++++--------- domain-server/src/DomainServer.h | 3 +++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/domain-server/resources/web/js/tables.js b/domain-server/resources/web/js/tables.js index 390beaa89a..d0855d7967 100644 --- a/domain-server/resources/web/js/tables.js +++ b/domain-server/resources/web/js/tables.js @@ -23,8 +23,8 @@ $(document).ready(function(){ $.each(json.queued, function (uuid, data) { queuedTableBody += ""; - queuedTableBody += "" + uuid + ""; queuedTableBody += "" + data.type + ""; + queuedTableBody += "" + uuid + ""; queuedTableBody += "" + (data.pool ? data.pool : "") + ""; queuedTableBody += ""; }); diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 2a98c9b8b0..05a1b4ea65 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -374,7 +374,7 @@ void DomainServer::readAvailableDatagrams() { } } -QJsonObject jsonForSocket(const HifiSockAddr& socket) { +QJsonObject DomainServer::jsonForSocket(const HifiSockAddr& socket) { QJsonObject socketJSON; socketJSON["ip"] = socket.getAddress().toString(); @@ -388,7 +388,7 @@ const char JSON_KEY_PUBLIC_SOCKET[] = "public"; const char JSON_KEY_LOCAL_SOCKET[] = "local"; const char JSON_KEY_POOL[] = "pool"; -QJsonObject jsonObjectForNode(Node* node) { +QJsonObject DomainServer::jsonObjectForNode(const SharedNodePointer& node) { QJsonObject nodeJson; // re-format the type name so it matches the target name @@ -402,12 +402,13 @@ QJsonObject jsonObjectForNode(Node* node) { // add the node socket information nodeJson[JSON_KEY_PUBLIC_SOCKET] = jsonForSocket(node->getPublicSocket()); nodeJson[JSON_KEY_LOCAL_SOCKET] = jsonForSocket(node->getLocalSocket()); - + // if the node has pool information, add it - if (node->getLinkedData() && !((Assignment*) node->getLinkedData())->getPool().isEmpty()) { - nodeJson[JSON_KEY_POOL] = ((Assignment*) node->getLinkedData())->getPool(); + SharedAssignmentPointer matchingAssignment = _staticAssignmentHash.value(node->getUUID()); + if (matchingAssignment) { + nodeJson[JSON_KEY_POOL] = matchingAssignment->getPool(); } - + return nodeJson; } @@ -427,10 +428,10 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QString& // enumerate the NodeList to find the assigned nodes foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { - if (node->getLinkedData()) { + if (_staticAssignmentHash.value(node->getUUID())) { // add the node using the UUID as the key QString uuidString = uuidStringWithoutCurlyBraces(node->getUUID()); - assignedNodesJSON[uuidString] = jsonObjectForNode(node.data()); + assignedNodesJSON[uuidString] = jsonObjectForNode(node); } } @@ -473,7 +474,7 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QString& foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { // add the node using the UUID as the key QString uuidString = uuidStringWithoutCurlyBraces(node->getUUID()); - nodesJSON[uuidString] = jsonObjectForNode(node.data()); + nodesJSON[uuidString] = jsonObjectForNode(node); } rootJSON["nodes"] = nodesJSON; diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index 580a758df8..0646653d02 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -48,6 +48,9 @@ private: void removeMatchingAssignmentFromQueue(const SharedAssignmentPointer& removableAssignment); void refreshStaticAssignmentAndAddToQueue(SharedAssignmentPointer& assignment); + QJsonObject jsonForSocket(const HifiSockAddr& socket); + QJsonObject jsonObjectForNode(const SharedNodePointer& node); + HTTPManager _HTTPManager; QHash _staticAssignmentHash; From cf05600d73b0113195d9e1ff4e2d789138296c01 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 7 Feb 2014 15:27:44 -0800 Subject: [PATCH 2/2] fix miss of pingType in timePingReply, closes #1934 --- libraries/shared/src/NodeList.cpp | 62 +++++++++++++++---------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index 2e78537734..2672f3b27b 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -184,39 +184,37 @@ void NodeList::setDomainHostname(const QString& domainHostname) { } void NodeList::timePingReply(const QByteArray& packet, const SharedNodePointer& sendingNode) { + QDataStream packetStream(packet); + packetStream.skipRawData(numBytesForPacketHeader(packet)); - if (sendingNode) { - QDataStream packetStream(packet); - packetStream.skipRawData(numBytesForPacketHeader(packet)); - - quint64 ourOriginalTime, othersReplyTime; - - packetStream >> ourOriginalTime >> othersReplyTime; - - quint64 now = usecTimestampNow(); - int pingTime = now - ourOriginalTime; - int oneWayFlightTime = pingTime / 2; // half of the ping is our one way flight - - // The other node's expected time should be our original time plus the one way flight time - // anything other than that is clock skew - quint64 othersExprectedReply = ourOriginalTime + oneWayFlightTime; - int clockSkew = othersReplyTime - othersExprectedReply; - - sendingNode->setPingMs(pingTime / 1000); - sendingNode->setClockSkewUsec(clockSkew); - - const bool wantDebug = false; - - if (wantDebug) { - qDebug() << "PING_REPLY from node " << *sendingNode << "\n" << - " now: " << now << "\n" << - " ourTime: " << ourOriginalTime << "\n" << - " pingTime: " << pingTime << "\n" << - " oneWayFlightTime: " << oneWayFlightTime << "\n" << - " othersReplyTime: " << othersReplyTime << "\n" << - " othersExprectedReply: " << othersExprectedReply << "\n" << - " clockSkew: " << clockSkew; - } + quint8 pingType; + quint64 ourOriginalTime, othersReplyTime; + + packetStream >> pingType >> ourOriginalTime >> othersReplyTime; + + quint64 now = usecTimestampNow(); + int pingTime = now - ourOriginalTime; + int oneWayFlightTime = pingTime / 2; // half of the ping is our one way flight + + // The other node's expected time should be our original time plus the one way flight time + // anything other than that is clock skew + quint64 othersExprectedReply = ourOriginalTime + oneWayFlightTime; + int clockSkew = othersReplyTime - othersExprectedReply; + + sendingNode->setPingMs(pingTime / 1000); + sendingNode->setClockSkewUsec(clockSkew); + + const bool wantDebug = false; + + if (wantDebug) { + qDebug() << "PING_REPLY from node " << *sendingNode << "\n" << + " now: " << now << "\n" << + " ourTime: " << ourOriginalTime << "\n" << + " pingTime: " << pingTime << "\n" << + " oneWayFlightTime: " << oneWayFlightTime << "\n" << + " othersReplyTime: " << othersReplyTime << "\n" << + " othersExprectedReply: " << othersExprectedReply << "\n" << + " clockSkew: " << clockSkew; } }