From c6947dd165691887ac64e0fae778be96af0d6b4e Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 9 Nov 2017 18:20:06 -0800 Subject: [PATCH 1/5] some side by side plumbing for NLPackets and NLPacketLists --- libraries/networking/src/NodeList.h | 3 ++ libraries/networking/src/PacketSender.cpp | 38 ++++++++++++---- libraries/networking/src/PacketSender.h | 5 ++- .../octree/src/OctreeEditPacketSender.cpp | 44 +++++++++++++++++-- libraries/octree/src/OctreeEditPacketSender.h | 5 ++- 5 files changed, 80 insertions(+), 15 deletions(-) diff --git a/libraries/networking/src/NodeList.h b/libraries/networking/src/NodeList.h index b3a12153e5..0ebc1f0b22 100644 --- a/libraries/networking/src/NodeList.h +++ b/libraries/networking/src/NodeList.h @@ -40,6 +40,9 @@ const quint64 DOMAIN_SERVER_CHECK_IN_MSECS = 1 * 1000; const int MAX_SILENT_DOMAIN_SERVER_CHECK_INS = 5; +using PacketOrPacketList = std::pair, std::unique_ptr>; +using NodePacketOrPacketListPair = std::pair; + using NodePacketPair = std::pair>; using NodeSharedPacketPair = std::pair>; using NodeSharedReceivedMessagePair = std::pair>; diff --git a/libraries/networking/src/PacketSender.cpp b/libraries/networking/src/PacketSender.cpp index 0cfd67cc4e..01b78585c2 100644 --- a/libraries/networking/src/PacketSender.cpp +++ b/libraries/networking/src/PacketSender.cpp @@ -53,7 +53,19 @@ void PacketSender::queuePacketForSending(const SharedNodePointer& destinationNod _totalBytesQueued += packet->getDataSize(); lock(); - _packets.push_back({destinationNode, std::move(packet)}); + _packets.push_back({destinationNode, PacketOrPacketList { std::move(packet), nullptr} }); + unlock(); + + // Make sure to wake our actual processing thread because we now have packets for it to process. + _hasPackets.wakeAll(); +} + +void PacketSender::queuePacketListForSending(const SharedNodePointer& destinationNode, std::unique_ptr packetList) { + _totalPacketsQueued += packetList->getNumPackets(); + _totalBytesQueued += packetList->getMessageSize(); + + lock(); + _packets.push_back({ destinationNode, PacketOrPacketList { nullptr, std::move(packetList)} }); unlock(); // Make sure to wake our actual processing thread because we now have packets for it to process. @@ -178,7 +190,7 @@ bool PacketSender::nonThreadedProcess() { float averagePacketsPerCall = 0; // might be less than 1, if our caller calls us more frequently than the target PPS - int packetsSentThisCall = 0; + size_t packetsSentThisCall = 0; int packetsToSendThisCall = 0; // Since we're in non-threaded mode, we need to determine how many packets to send per call to process @@ -265,23 +277,31 @@ bool PacketSender::nonThreadedProcess() { while ((packetsSentThisCall < packetsToSendThisCall) && (packetsLeft > 0)) { lock(); - NodePacketPair packetPair = std::move(_packets.front()); + NodePacketOrPacketListPair packetPair = std::move(_packets.front()); _packets.pop_front(); packetsLeft = _packets.size(); unlock(); // send the packet through the NodeList... - DependencyManager::get()->sendUnreliablePacket(*packetPair.second, *packetPair.first); + //PacketOrPacketList packetOrList = packetPair.second; + bool sendAsPacket = packetPair.second.first.get(); + if (sendAsPacket) { + DependencyManager::get()->sendUnreliablePacket(*packetPair.second.first, *packetPair.first); + } else { + DependencyManager::get()->sendPacketList(*packetPair.second.second, *packetPair.first); + } - packetsSentThisCall++; - _packetsOverCheckInterval++; - _totalPacketsSent++; + size_t packetSize = sendAsPacket ? packetPair.second.first->getDataSize() : packetPair.second.second->getMessageSize(); + size_t packetCount = sendAsPacket ? 1 : packetPair.second.second->getNumPackets(); + + packetsSentThisCall += packetCount; + _packetsOverCheckInterval += packetCount; + _totalPacketsSent += packetCount; - int packetSize = packetPair.second->getDataSize(); _totalBytesSent += packetSize; - emit packetSent(packetSize); + emit packetSent(packetSize); // FIXME should include number of packets? _lastSendTime = now; } diff --git a/libraries/networking/src/PacketSender.h b/libraries/networking/src/PacketSender.h index 68faeaca47..fead49df72 100644 --- a/libraries/networking/src/PacketSender.h +++ b/libraries/networking/src/PacketSender.h @@ -39,6 +39,7 @@ public: /// Add packet to outbound queue. void queuePacketForSending(const SharedNodePointer& destinationNode, std::unique_ptr packet); + void queuePacketListForSending(const SharedNodePointer& destinationNode, std::unique_ptr packetList); void setPacketsPerSecond(int packetsPerSecond); int getPacketsPerSecond() const { return _packetsPerSecond; } @@ -99,14 +100,14 @@ protected: SimpleMovingAverage _averageProcessCallTime; private: - std::list _packets; + std::list _packets; quint64 _lastSendTime; bool threadedProcess(); bool nonThreadedProcess(); quint64 _lastPPSCheck; - int _packetsOverCheckInterval; + size_t _packetsOverCheckInterval; quint64 _started; quint64 _totalPacketsSent; diff --git a/libraries/octree/src/OctreeEditPacketSender.cpp b/libraries/octree/src/OctreeEditPacketSender.cpp index f3c9ece9fe..7b612a828c 100644 --- a/libraries/octree/src/OctreeEditPacketSender.cpp +++ b/libraries/octree/src/OctreeEditPacketSender.cpp @@ -115,6 +115,27 @@ void OctreeEditPacketSender::queuePacketToNode(const QUuid& nodeUUID, std::uniqu }); } +// This method is called when the edit packet layer has determined that it has a fully formed packet destined for +// a known nodeID. +void OctreeEditPacketSender::queuePacketListToNode(const QUuid& nodeUUID, std::unique_ptr packetList) { + + bool wantDebug = false; + DependencyManager::get()->eachNode([&](const SharedNodePointer& node) { + // only send to the NodeTypes that are getMyNodeType() + if (node->getType() == getMyNodeType() + && ((node->getUUID() == nodeUUID) || (nodeUUID.isNull())) + && node->getActiveSocket()) { + + // NOTE: unlike packets, the packet lists don't get rewritten sequence numbers. + + // add packet to history -- we don't keep track of sent PacketLists + //_sentPacketHistories[nodeUUID].packetSent(sequence, *packet); + + queuePacketListForSending(node, std::move(packetList)); + } + }); +} + void OctreeEditPacketSender::processPreServerExistsPackets() { assert(serversExist()); // we should only be here if we have jurisdictions @@ -247,7 +268,7 @@ void OctreeEditPacketSender::queueOctreeEditMessage(PacketType type, QByteArray& }); } if (isMyJurisdiction) { - std::unique_ptr& bufferedPacket = _pendingEditPackets[nodeUUID]; + std::unique_ptr& bufferedPacket = _pendingEditPackets[nodeUUID].first; //only a NLPacket for now if (!bufferedPacket) { bufferedPacket = initializePacket(type, node->getClockSkewUsec()); @@ -291,15 +312,24 @@ void OctreeEditPacketSender::releaseQueuedMessages() { } else { _packetsQueueLock.lock(); for (auto& i : _pendingEditPackets) { - if (i.second) { + if (i.second.first) { // construct a null unique_ptr to an NL packet std::unique_ptr releasedPacket; // swap the null ptr with the packet we want to release - i.second.swap(releasedPacket); + i.second.first.swap(releasedPacket); // move and release the queued packet releaseQueuedPacket(i.first, std::move(releasedPacket)); + } else if (i.second.second) { + // construct a null unique_ptr to an NLPacketList + std::unique_ptr releasedPacketList; + + // swap the null ptr with the NLPacketList we want to release + i.second.second.swap(releasedPacketList); + + // move and release the queued NLPacketList + releaseQueuedPacketList(i.first, std::move(releasedPacketList)); } } @@ -315,6 +345,14 @@ void OctreeEditPacketSender::releaseQueuedPacket(const QUuid& nodeID, std::uniqu _releaseQueuedPacketMutex.unlock(); } +void OctreeEditPacketSender::releaseQueuedPacketList(const QUuid& nodeID, std::unique_ptr packetList) { + _releaseQueuedPacketMutex.lock(); + if (packetList->getMessageSize() > 0 && packetList->getType() != PacketType::Unknown) { + queuePacketListToNode(nodeID, std::move(packetList)); + } + _releaseQueuedPacketMutex.unlock(); +} + std::unique_ptr OctreeEditPacketSender::initializePacket(PacketType type, qint64 nodeClockSkew) { auto newPacket = NLPacket::create(type); diff --git a/libraries/octree/src/OctreeEditPacketSender.h b/libraries/octree/src/OctreeEditPacketSender.h index fd8cc85f91..79c363bec5 100644 --- a/libraries/octree/src/OctreeEditPacketSender.h +++ b/libraries/octree/src/OctreeEditPacketSender.h @@ -87,15 +87,18 @@ protected: bool _shouldSend; void queuePacketToNode(const QUuid& nodeID, std::unique_ptr packet); + void queuePacketListToNode(const QUuid& nodeUUID, std::unique_ptr packetList); + void queuePendingPacketToNodes(std::unique_ptr packet); void queuePacketToNodes(std::unique_ptr packet); std::unique_ptr initializePacket(PacketType type, qint64 nodeClockSkew); void releaseQueuedPacket(const QUuid& nodeUUID, std::unique_ptr packetBuffer); // releases specific queued packet + void releaseQueuedPacketList(const QUuid& nodeID, std::unique_ptr packetList); void processPreServerExistsPackets(); // These are packets which are destined from know servers but haven't been released because they're still too small - std::unordered_map> _pendingEditPackets; + std::unordered_map _pendingEditPackets; // These are packets that are waiting to be processed because we don't yet know if there are servers int _maxPendingMessages; From e438ac54d575583d250790a7cf805e599fe21b2f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 16 Nov 2017 13:16:23 -0800 Subject: [PATCH 2/5] make adds go over NLPacketList as reliable --- .../src/entities/EntityServer.cpp | 1 + .../octree/OctreeInboundPacketProcessor.cpp | 5 +- libraries/networking/src/PacketSender.cpp | 10 +++ .../src/ReceivedPacketProcessor.cpp | 4 + .../octree/src/OctreeEditPacketSender.cpp | 79 ++++++++++++++----- 5 files changed, 77 insertions(+), 22 deletions(-) diff --git a/assignment-client/src/entities/EntityServer.cpp b/assignment-client/src/entities/EntityServer.cpp index 995a5bad27..5417e3f6fe 100644 --- a/assignment-client/src/entities/EntityServer.cpp +++ b/assignment-client/src/entities/EntityServer.cpp @@ -72,6 +72,7 @@ void EntityServer::aboutToFinish() { } void EntityServer::handleEntityPacket(QSharedPointer message, SharedNodePointer senderNode) { + qDebug() << __FUNCTION__ << "from:" << senderNode->getUUID() << "type:" << message->getType(); if (_octreeInboundPacketProcessor) { _octreeInboundPacketProcessor->queueReceivedPacket(message, senderNode); } diff --git a/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp b/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp index bce6e7fe44..efadb5650a 100644 --- a/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp +++ b/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp @@ -76,12 +76,15 @@ void OctreeInboundPacketProcessor::midProcess() { } void OctreeInboundPacketProcessor::processPacket(QSharedPointer message, SharedNodePointer sendingNode) { + + qDebug() << __FUNCTION__ << "from:" << sendingNode->getUUID() << "type:" << message->getType(); + if (_shuttingDown) { qDebug() << "OctreeInboundPacketProcessor::processPacket() while shutting down... ignoring incoming packet"; return; } - bool debugProcessPacket = _myServer->wantsVerboseDebug(); + bool debugProcessPacket = true; // _myServer->wantsVerboseDebug(); if (debugProcessPacket) { qDebug("OctreeInboundPacketProcessor::processPacket() payload=%p payloadLength=%lld", diff --git a/libraries/networking/src/PacketSender.cpp b/libraries/networking/src/PacketSender.cpp index 01b78585c2..b7fc802883 100644 --- a/libraries/networking/src/PacketSender.cpp +++ b/libraries/networking/src/PacketSender.cpp @@ -64,6 +64,8 @@ void PacketSender::queuePacketListForSending(const SharedNodePointer& destinatio _totalPacketsQueued += packetList->getNumPackets(); _totalBytesQueued += packetList->getMessageSize(); + qDebug() << __FUNCTION__ << "to:" << destinationNode->getUUID() << "type:" << packetList->getType() << "_totalPacketsQueued:" << _totalPacketsQueued << "_totalBytesQueued:" << _totalBytesQueued; + lock(); _packets.push_back({ destinationNode, PacketOrPacketList { nullptr, std::move(packetList)} }); unlock(); @@ -287,8 +289,12 @@ bool PacketSender::nonThreadedProcess() { //PacketOrPacketList packetOrList = packetPair.second; bool sendAsPacket = packetPair.second.first.get(); if (sendAsPacket) { + + qDebug() << __FUNCTION__ << "sendUnreliablePacket() to:" << packetPair.first->getUUID() << "type:" << packetPair.second.first->getType(); DependencyManager::get()->sendUnreliablePacket(*packetPair.second.first, *packetPair.first); } else { + + qDebug() << __FUNCTION__ << "sendPacketList() to:" << packetPair.first->getUUID() << "type:" << packetPair.second.second->getType(); DependencyManager::get()->sendPacketList(*packetPair.second.second, *packetPair.first); } @@ -303,6 +309,10 @@ bool PacketSender::nonThreadedProcess() { _totalBytesSent += packetSize; emit packetSent(packetSize); // FIXME should include number of packets? + qDebug() << __FUNCTION__ << "packetsSentThisCall:" << packetsSentThisCall + << "_packetsOverCheckInterval:" << _packetsOverCheckInterval + << "_totalPacketsSent:" << _totalPacketsSent; + _lastSendTime = now; } return isStillRunning(); diff --git a/libraries/networking/src/ReceivedPacketProcessor.cpp b/libraries/networking/src/ReceivedPacketProcessor.cpp index c18d4ed1e8..9ed17ec586 100644 --- a/libraries/networking/src/ReceivedPacketProcessor.cpp +++ b/libraries/networking/src/ReceivedPacketProcessor.cpp @@ -25,6 +25,10 @@ void ReceivedPacketProcessor::terminating() { } void ReceivedPacketProcessor::queueReceivedPacket(QSharedPointer message, SharedNodePointer sendingNode) { + + qDebug() << __FUNCTION__ << "from:" << sendingNode->getUUID() << "type:" << message->getType(); + + lock(); _packets.push_back({ sendingNode, message }); _nodePacketCounts[sendingNode->getUUID()]++; diff --git a/libraries/octree/src/OctreeEditPacketSender.cpp b/libraries/octree/src/OctreeEditPacketSender.cpp index 7b612a828c..38a34d75dc 100644 --- a/libraries/octree/src/OctreeEditPacketSender.cpp +++ b/libraries/octree/src/OctreeEditPacketSender.cpp @@ -119,6 +119,8 @@ void OctreeEditPacketSender::queuePacketToNode(const QUuid& nodeUUID, std::uniqu // a known nodeID. void OctreeEditPacketSender::queuePacketListToNode(const QUuid& nodeUUID, std::unique_ptr packetList) { + qDebug() << __FUNCTION__ << "to:" << nodeUUID << "type:" << packetList->getType(); + bool wantDebug = false; DependencyManager::get()->eachNode([&](const SharedNodePointer& node) { // only send to the NodeTypes that are getMyNodeType() @@ -268,33 +270,65 @@ void OctreeEditPacketSender::queueOctreeEditMessage(PacketType type, QByteArray& }); } if (isMyJurisdiction) { - std::unique_ptr& bufferedPacket = _pendingEditPackets[nodeUUID].first; //only a NLPacket for now - if (!bufferedPacket) { - bufferedPacket = initializePacket(type, node->getClockSkewUsec()); - } else { - // If we're switching type, then we send the last one and start over - if ((type != bufferedPacket->getType() && bufferedPacket->getPayloadSize() > 0) || - (editMessage.size() >= bufferedPacket->bytesAvailableForWrite())) { + // for edit messages, we will attempt to combine multiple edit commands where possible, we + // don't do this for add because we send those reliably + if (type == PacketType::EntityAdd) { - // create the new packet and swap it with the packet in _pendingEditPackets - auto packetToRelease = initializePacket(type, node->getClockSkewUsec()); - bufferedPacket.swap(packetToRelease); + auto newPacket = NLPacketList::create(type, QByteArray(), true, true); + auto nodeClockSkew = node->getClockSkewUsec(); - // release the previously buffered packet - releaseQueuedPacket(nodeUUID, std::move(packetToRelease)); + // pack sequence number + quint16 sequence = _outgoingSequenceNumbers[nodeUUID]++; + newPacket->writePrimitive(sequence); + + // pack in timestamp + quint64 now = usecTimestampNow() + nodeClockSkew; + newPacket->writePrimitive(now); + + + // We call this virtual function that allows our specific type of EditPacketSender to + // fixup the buffer for any clock skew + if (nodeClockSkew != 0) { + adjustEditPacketForClockSkew(type, editMessage, nodeClockSkew); } - } - // This is really the first time we know which server/node this particular edit message - // is going to, so we couldn't adjust for clock skew till now. But here's our chance. - // We call this virtual function that allows our specific type of EditPacketSender to - // fixup the buffer for any clock skew - if (node->getClockSkewUsec() != 0) { - adjustEditPacketForClockSkew(type, editMessage, node->getClockSkewUsec()); - } + newPacket->write(editMessage); - bufferedPacket->write(editMessage); + // release the new packet + releaseQueuedPacketList(nodeUUID, std::move(newPacket)); + + } else { + + std::unique_ptr& bufferedPacket = _pendingEditPackets[nodeUUID].first; //only a NLPacket for now + + if (!bufferedPacket) { + bufferedPacket = initializePacket(type, node->getClockSkewUsec()); + } else { + // If we're switching type, then we send the last one and start over + if ((type != bufferedPacket->getType() && bufferedPacket->getPayloadSize() > 0) || + (editMessage.size() >= bufferedPacket->bytesAvailableForWrite())) { + + // create the new packet and swap it with the packet in _pendingEditPackets + auto packetToRelease = initializePacket(type, node->getClockSkewUsec()); + bufferedPacket.swap(packetToRelease); + + // release the previously buffered packet + releaseQueuedPacket(nodeUUID, std::move(packetToRelease)); + } + } + + // This is really the first time we know which server/node this particular edit message + // is going to, so we couldn't adjust for clock skew till now. But here's our chance. + // We call this virtual function that allows our specific type of EditPacketSender to + // fixup the buffer for any clock skew + if (node->getClockSkewUsec() != 0) { + adjustEditPacketForClockSkew(type, editMessage, node->getClockSkewUsec()); + } + + bufferedPacket->write(editMessage); + + } } } }); @@ -346,6 +380,9 @@ void OctreeEditPacketSender::releaseQueuedPacket(const QUuid& nodeID, std::uniqu } void OctreeEditPacketSender::releaseQueuedPacketList(const QUuid& nodeID, std::unique_ptr packetList) { + + qDebug() << __FUNCTION__ << "to:" << nodeID << "type:" << packetList->getType(); + _releaseQueuedPacketMutex.lock(); if (packetList->getMessageSize() > 0 && packetList->getType() != PacketType::Unknown) { queuePacketListToNode(nodeID, std::move(packetList)); From cd0fa989e1803f164679abea3f82d96dc8f22fba Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 17 Nov 2017 08:55:55 -0800 Subject: [PATCH 3/5] debugging --- assignment-client/src/entities/EntityServer.cpp | 14 ++++++++++++-- .../src/octree/OctreeInboundPacketProcessor.cpp | 7 ++++++- .../entities/src/EntityEditPacketSender.cpp | 14 ++++++++++++++ libraries/entities/src/EntityItemProperties.cpp | 9 +++++++++ libraries/networking/src/PacketSender.cpp | 17 ++++++++++++----- libraries/networking/src/ReceivedMessage.cpp | 15 +++++++++++---- libraries/networking/src/ReceivedMessage.h | 10 ++++++++++ .../networking/src/ReceivedPacketProcessor.cpp | 7 ++++++- libraries/octree/src/OctreeEditPacketSender.cpp | 4 ++-- libraries/octree/src/OctreePacketData.cpp | 17 ++++++++++++++++- libraries/octree/src/OctreePacketData.h | 9 +++++++-- 11 files changed, 105 insertions(+), 18 deletions(-) diff --git a/assignment-client/src/entities/EntityServer.cpp b/assignment-client/src/entities/EntityServer.cpp index 5417e3f6fe..43cdb6d665 100644 --- a/assignment-client/src/entities/EntityServer.cpp +++ b/assignment-client/src/entities/EntityServer.cpp @@ -41,7 +41,8 @@ EntityServer::EntityServer(ReceivedMessage& message) : DependencyManager::set(); auto& packetReceiver = DependencyManager::get()->getPacketReceiver(); - packetReceiver.registerListenerForTypes({ PacketType::EntityAdd, + packetReceiver.registerListenerForTypes({ + //PacketType::EntityAdd, PacketType::EntityEdit, PacketType::EntityErase, PacketType::EntityPhysics, @@ -51,6 +52,9 @@ EntityServer::EntityServer(ReceivedMessage& message) : this, "handleEntityPacket"); + packetReceiver.registerListener(PacketType::EntityAdd, this, "handleEntityPacket"); + + connect(&_dynamicDomainVerificationTimer, &QTimer::timeout, this, &EntityServer::startDynamicDomainVerification); _dynamicDomainVerificationTimer.setSingleShot(true); } @@ -72,7 +76,13 @@ void EntityServer::aboutToFinish() { } void EntityServer::handleEntityPacket(QSharedPointer message, SharedNodePointer senderNode) { - qDebug() << __FUNCTION__ << "from:" << senderNode->getUUID() << "type:" << message->getType(); + qDebug() << __FUNCTION__ << "from:" << senderNode->getUUID() << "type:" << message->getType() + << "getNumPackets:" << message->getNumPackets() + << "getSize:" << message->getSize() + << "isFromPacketList:" << message->isFromPacketList() + << "isComplete:" << message->isComplete() + ; + if (_octreeInboundPacketProcessor) { _octreeInboundPacketProcessor->queueReceivedPacket(message, senderNode); } diff --git a/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp b/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp index efadb5650a..d2723e936f 100644 --- a/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp +++ b/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp @@ -77,7 +77,12 @@ void OctreeInboundPacketProcessor::midProcess() { void OctreeInboundPacketProcessor::processPacket(QSharedPointer message, SharedNodePointer sendingNode) { - qDebug() << __FUNCTION__ << "from:" << sendingNode->getUUID() << "type:" << message->getType(); + qDebug() << __FUNCTION__ << "from:" << sendingNode->getUUID() << "type:" << message->getType() + << "getNumPackets:" << message->getNumPackets() + << "getSize:" << message->getSize() + << "isFromPacketList:" << message->isFromPacketList() + << "isComplete:" << message->isComplete() + ; if (_shuttingDown) { qDebug() << "OctreeInboundPacketProcessor::processPacket() while shutting down... ignoring incoming packet"; diff --git a/libraries/entities/src/EntityEditPacketSender.cpp b/libraries/entities/src/EntityEditPacketSender.cpp index 168b0cd446..42c13119b5 100644 --- a/libraries/entities/src/EntityEditPacketSender.cpp +++ b/libraries/entities/src/EntityEditPacketSender.cpp @@ -81,6 +81,9 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityTreePointer entityTree, EntityItemID entityItemID, const EntityItemProperties& properties) { + + qDebug() << __FUNCTION__ << "type:" << type; + if (!_shouldSend) { return; // bail early } @@ -93,6 +96,14 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type, QByteArray bufferOut(NLPacket::maxPayloadSize(type), 0); + if (type == PacketType::EntityAdd) { + auto MAX_ADD_DATA_SIZE = NLPacket::maxPayloadSize(type) * 10; // a really big packet + bufferOut.resize(MAX_ADD_DATA_SIZE); + } + + qDebug() << __FUNCTION__ << "bufferOut.size():" << bufferOut.size(); + + OctreeElement::AppendState encodeResult = OctreeElement::PARTIAL; // start the loop assuming there's more to send auto nodeList = DependencyManager::get(); @@ -115,6 +126,9 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type, qCDebug(entities) << " id:" << entityItemID; qCDebug(entities) << " properties:" << properties; #endif + + qDebug() << __FUNCTION__ << "about to call queueOctreeEditMessage() --- bufferOut.size():" << bufferOut.size(); + queueOctreeEditMessage(type, bufferOut); if (type == PacketType::EntityAdd && !properties.getCertificateID().isEmpty()) { emit addingEntityWithCertificate(properties.getCertificateID(), DependencyManager::get()->getPlaceName()); diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 108fc14e30..2302765b1a 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -1227,6 +1227,9 @@ OctreeElement::AppendState EntityItemProperties::encodeEntityEditPacket(PacketTy OctreePacketData ourDataPacket(false, buffer.size()); // create a packetData object to add out packet details too. OctreePacketData* packetData = &ourDataPacket; // we want a pointer to this so we can use our APPEND_ENTITY_PROPERTY macro + qDebug() << __FUNCTION__ << "OctreePacketData::getBytesAvailable():" << packetData->getBytesAvailable(); + + bool success = true; // assume the best OctreeElement::AppendState appendState = OctreeElement::COMPLETED; // assume the best @@ -1525,9 +1528,15 @@ OctreeElement::AppendState EntityItemProperties::encodeEntityEditPacket(PacketTy const char* finalizedData = reinterpret_cast(packetData->getFinalizedData()); int finalizedSize = packetData->getFinalizedSize(); + qDebug() << __FUNCTION__ << "packetData->getFinalizedSize():" << packetData->getFinalizedSize(); + qDebug() << __FUNCTION__ << "packetData->getUncompressedSize():" << packetData->getUncompressedSize(); + qDebug() << __FUNCTION__ << "buffer.size():" << buffer.size(); + if (finalizedSize <= buffer.size()) { buffer.replace(0, finalizedSize, finalizedData, finalizedSize); buffer.resize(finalizedSize); + qDebug() << __FUNCTION__ << "replaced with finalized data size:" << buffer.size(); + } else { qCDebug(entities) << "ERROR - encoded edit message doesn't fit in output buffer."; success = false; diff --git a/libraries/networking/src/PacketSender.cpp b/libraries/networking/src/PacketSender.cpp index b7fc802883..2ccd9094ed 100644 --- a/libraries/networking/src/PacketSender.cpp +++ b/libraries/networking/src/PacketSender.cpp @@ -64,7 +64,8 @@ void PacketSender::queuePacketListForSending(const SharedNodePointer& destinatio _totalPacketsQueued += packetList->getNumPackets(); _totalBytesQueued += packetList->getMessageSize(); - qDebug() << __FUNCTION__ << "to:" << destinationNode->getUUID() << "type:" << packetList->getType() << "_totalPacketsQueued:" << _totalPacketsQueued << "_totalBytesQueued:" << _totalBytesQueued; + qDebug() << __FUNCTION__ << "to:" << destinationNode->getUUID() << "type:" << packetList->getType() << "size:" << packetList->getDataSize() + << "_totalPacketsQueued:" << _totalPacketsQueued << "_totalBytesQueued:" << _totalBytesQueued; lock(); _packets.push_back({ destinationNode, PacketOrPacketList { nullptr, std::move(packetList)} }); @@ -288,18 +289,22 @@ bool PacketSender::nonThreadedProcess() { // send the packet through the NodeList... //PacketOrPacketList packetOrList = packetPair.second; bool sendAsPacket = packetPair.second.first.get(); + size_t packetSize = sendAsPacket ? packetPair.second.first->getDataSize() : packetPair.second.second->getMessageSize(); + size_t packetCount = sendAsPacket ? 1 : packetPair.second.second->getNumPackets(); + if (sendAsPacket) { qDebug() << __FUNCTION__ << "sendUnreliablePacket() to:" << packetPair.first->getUUID() << "type:" << packetPair.second.first->getType(); DependencyManager::get()->sendUnreliablePacket(*packetPair.second.first, *packetPair.first); } else { - qDebug() << __FUNCTION__ << "sendPacketList() to:" << packetPair.first->getUUID() << "type:" << packetPair.second.second->getType(); + qDebug() << __FUNCTION__ << "sendPacketList() to:" << packetPair.first->getUUID() << "type:" << packetPair.second.second->getType() + << "getMessageSize:" << packetPair.second.second->getMessageSize() + << "getDataSize:" << packetPair.second.second->getDataSize(); + DependencyManager::get()->sendPacketList(*packetPair.second.second, *packetPair.first); } - size_t packetSize = sendAsPacket ? packetPair.second.first->getDataSize() : packetPair.second.second->getMessageSize(); - size_t packetCount = sendAsPacket ? 1 : packetPair.second.second->getNumPackets(); packetsSentThisCall += packetCount; _packetsOverCheckInterval += packetCount; @@ -311,7 +316,9 @@ bool PacketSender::nonThreadedProcess() { qDebug() << __FUNCTION__ << "packetsSentThisCall:" << packetsSentThisCall << "_packetsOverCheckInterval:" << _packetsOverCheckInterval - << "_totalPacketsSent:" << _totalPacketsSent; + << "_totalPacketsSent:" << _totalPacketsSent + << "packetSize:" << packetSize + << "_totalBytesSent:" << _totalBytesSent; _lastSendTime = now; } diff --git a/libraries/networking/src/ReceivedMessage.cpp b/libraries/networking/src/ReceivedMessage.cpp index 6ca249fb22..8a3322ce20 100644 --- a/libraries/networking/src/ReceivedMessage.cpp +++ b/libraries/networking/src/ReceivedMessage.cpp @@ -26,8 +26,10 @@ ReceivedMessage::ReceivedMessage(const NLPacketList& packetList) _sourceID(packetList.getSourceID()), _packetType(packetList.getType()), _packetVersion(packetList.getVersion()), - _senderSockAddr(packetList.getSenderSockAddr()) + _senderSockAddr(packetList.getSenderSockAddr()), + _fromPacketList(true) { + qDebug() << __FUNCTION__ << "(const NLPacketList& packetList) _fromPacketList:" << _fromPacketList; } ReceivedMessage::ReceivedMessage(NLPacket& packet) @@ -38,8 +40,12 @@ ReceivedMessage::ReceivedMessage(NLPacket& packet) _packetType(packet.getType()), _packetVersion(packet.getVersion()), _senderSockAddr(packet.getSenderSockAddr()), - _isComplete(packet.getPacketPosition() == NLPacket::ONLY) + _isComplete(packet.getPacketPosition() == NLPacket::ONLY), + _fromPacket(true) { + if (packet.getType() == PacketType::EntityAdd) { + qDebug() << __FUNCTION__ << "(NLPacket& packet) _fromPacketList:" << _fromPacketList << "packet.getType():" << packet.getType(); + } } ReceivedMessage::ReceivedMessage(QByteArray byteArray, PacketType packetType, PacketVersion packetVersion, @@ -51,9 +57,10 @@ ReceivedMessage::ReceivedMessage(QByteArray byteArray, PacketType packetType, Pa _packetType(packetType), _packetVersion(packetVersion), _senderSockAddr(senderSockAddr), - _isComplete(true) + _isComplete(true), + _fromByteArray(true) { - + qDebug() << __FUNCTION__ << "(QByteArray byteArray)... _fromPacketList:" << _fromPacketList; } void ReceivedMessage::setFailed() { diff --git a/libraries/networking/src/ReceivedMessage.h b/libraries/networking/src/ReceivedMessage.h index ae51e7592a..2af4798bc3 100644 --- a/libraries/networking/src/ReceivedMessage.h +++ b/libraries/networking/src/ReceivedMessage.h @@ -79,6 +79,10 @@ public: template qint64 readHeadPrimitive(T* data); + bool isFromPacketList() const { return _fromPacketList; }; + bool isFromPacket() const { return _fromPacket; }; + bool isFromByteArray() const { return _fromByteArray; }; + signals: void progress(qint64 size); void completed(); @@ -100,6 +104,12 @@ private: std::atomic _isComplete { true }; std::atomic _failed { false }; + + std::atomic _fromPacketList { false }; + std::atomic _fromPacket { false }; + std::atomic _fromByteArray { false }; + + }; Q_DECLARE_METATYPE(ReceivedMessage*) diff --git a/libraries/networking/src/ReceivedPacketProcessor.cpp b/libraries/networking/src/ReceivedPacketProcessor.cpp index 9ed17ec586..eda5109279 100644 --- a/libraries/networking/src/ReceivedPacketProcessor.cpp +++ b/libraries/networking/src/ReceivedPacketProcessor.cpp @@ -26,7 +26,12 @@ void ReceivedPacketProcessor::terminating() { void ReceivedPacketProcessor::queueReceivedPacket(QSharedPointer message, SharedNodePointer sendingNode) { - qDebug() << __FUNCTION__ << "from:" << sendingNode->getUUID() << "type:" << message->getType(); + qDebug() << __FUNCTION__ << "from:" << sendingNode->getUUID() << "type:" << message->getType() + << "getNumPackets:" << message->getNumPackets() + << "getSize:" << message->getSize() + << "isFromPacketList:" << message->isFromPacketList() + << "isComplete:" << message->isComplete() + ; lock(); diff --git a/libraries/octree/src/OctreeEditPacketSender.cpp b/libraries/octree/src/OctreeEditPacketSender.cpp index 38a34d75dc..7e04fa6630 100644 --- a/libraries/octree/src/OctreeEditPacketSender.cpp +++ b/libraries/octree/src/OctreeEditPacketSender.cpp @@ -119,7 +119,7 @@ void OctreeEditPacketSender::queuePacketToNode(const QUuid& nodeUUID, std::uniqu // a known nodeID. void OctreeEditPacketSender::queuePacketListToNode(const QUuid& nodeUUID, std::unique_ptr packetList) { - qDebug() << __FUNCTION__ << "to:" << nodeUUID << "type:" << packetList->getType(); + qDebug() << __FUNCTION__ << "to:" << nodeUUID << "type:" << packetList->getType() << "size:" << packetList->getDataSize(); bool wantDebug = false; DependencyManager::get()->eachNode([&](const SharedNodePointer& node) { @@ -381,7 +381,7 @@ void OctreeEditPacketSender::releaseQueuedPacket(const QUuid& nodeID, std::uniqu void OctreeEditPacketSender::releaseQueuedPacketList(const QUuid& nodeID, std::unique_ptr packetList) { - qDebug() << __FUNCTION__ << "to:" << nodeID << "type:" << packetList->getType(); + qDebug() << __FUNCTION__ << "to:" << nodeID << "type:" << packetList->getType() << "size:" << packetList->getDataSize(); _releaseQueuedPacketMutex.lock(); if (packetList->getMessageSize() > 0 && packetList->getType() != PacketType::Unknown) { diff --git a/libraries/octree/src/OctreePacketData.cpp b/libraries/octree/src/OctreePacketData.cpp index b5b4a161ef..5b3e68c0a1 100644 --- a/libraries/octree/src/OctreePacketData.cpp +++ b/libraries/octree/src/OctreePacketData.cpp @@ -35,7 +35,14 @@ OctreePacketData::OctreePacketData(bool enableCompression, int targetSize) { void OctreePacketData::changeSettings(bool enableCompression, unsigned int targetSize) { _enableCompression = enableCompression; - _targetSize = std::min(MAX_OCTREE_UNCOMRESSED_PACKET_SIZE, targetSize); + _targetSize = targetSize; // std::min(MAX_OCTREE_UNCOMRESSED_PACKET_SIZE, targetSize); + + _uncompressedByteArray.resize(_targetSize); + _compressedByteArray.resize(_targetSize); + + _uncompressed = (unsigned char*)_uncompressedByteArray.data(); + _compressed = (unsigned char*)_compressedByteArray.data(); + reset(); } @@ -689,6 +696,8 @@ int OctreePacketData::unpackDataFromBytes(const unsigned char *dataBytes, QVecto uint16_t length; memcpy(&length, dataBytes, sizeof(uint16_t)); dataBytes += sizeof(length); + + // FIXME - this size check is wrong if we allow larger packets if (length * sizeof(glm::vec3) > MAX_OCTREE_UNCOMRESSED_PACKET_SIZE) { result.resize(0); return sizeof(uint16_t); @@ -702,6 +711,8 @@ int OctreePacketData::unpackDataFromBytes(const unsigned char *dataBytes, QVecto uint16_t length; memcpy(&length, dataBytes, sizeof(uint16_t)); dataBytes += sizeof(length); + + // FIXME - this size check is wrong if we allow larger packets if (length * sizeof(glm::quat) > MAX_OCTREE_UNCOMRESSED_PACKET_SIZE) { result.resize(0); return sizeof(uint16_t); @@ -720,6 +731,8 @@ int OctreePacketData::unpackDataFromBytes(const unsigned char* dataBytes, QVecto uint16_t length; memcpy(&length, dataBytes, sizeof(uint16_t)); dataBytes += sizeof(length); + + // FIXME - this size check is wrong if we allow larger packets if (length * sizeof(float) > MAX_OCTREE_UNCOMRESSED_PACKET_SIZE) { result.resize(0); return sizeof(uint16_t); @@ -733,6 +746,8 @@ int OctreePacketData::unpackDataFromBytes(const unsigned char* dataBytes, QVecto uint16_t length; memcpy(&length, dataBytes, sizeof(uint16_t)); dataBytes += sizeof(length); + + // FIXME - this size check is wrong if we allow larger packets if (length / 8 > MAX_OCTREE_UNCOMRESSED_PACKET_SIZE) { result.resize(0); return sizeof(uint16_t); diff --git a/libraries/octree/src/OctreePacketData.h b/libraries/octree/src/OctreePacketData.h index 37c171504b..0c582f4ed6 100644 --- a/libraries/octree/src/OctreePacketData.h +++ b/libraries/octree/src/OctreePacketData.h @@ -279,7 +279,10 @@ private: unsigned int _targetSize; bool _enableCompression; - unsigned char _uncompressed[MAX_OCTREE_UNCOMRESSED_PACKET_SIZE]; + //unsigned char _uncompressed[MAX_OCTREE_UNCOMRESSED_PACKET_SIZE]; + + QByteArray _uncompressedByteArray; + unsigned char* _uncompressed { nullptr }; int _bytesInUse; int _bytesAvailable; int _subTreeAt; @@ -288,7 +291,9 @@ private: bool compressContent(); - unsigned char _compressed[MAX_OCTREE_UNCOMRESSED_PACKET_SIZE]; + //unsigned char _compressed[MAX_OCTREE_UNCOMRESSED_PACKET_SIZE]; + QByteArray _compressedByteArray; + unsigned char* _compressed { nullptr }; int _compressedBytes; int _bytesInUseLastCheck; bool _dirty; From 71a46a33745f828d1d1ebb33e991832e1e230082 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 17 Nov 2017 13:03:04 -0800 Subject: [PATCH 4/5] cleanup --- .../src/entities/EntityServer.cpp | 13 +------------ .../octree/OctreeInboundPacketProcessor.cpp | 10 +--------- .../entities/src/EntityEditPacketSender.cpp | 10 +--------- .../entities/src/EntityItemProperties.cpp | 9 --------- libraries/networking/src/PacketSender.cpp | 19 +------------------ libraries/networking/src/ReceivedMessage.cpp | 14 +++----------- libraries/networking/src/ReceivedMessage.h | 10 ---------- .../src/ReceivedPacketProcessor.cpp | 9 --------- .../octree/src/OctreeEditPacketSender.cpp | 11 +---------- libraries/octree/src/OctreePacketData.cpp | 3 +-- libraries/octree/src/OctreePacketData.h | 3 --- 11 files changed, 9 insertions(+), 102 deletions(-) diff --git a/assignment-client/src/entities/EntityServer.cpp b/assignment-client/src/entities/EntityServer.cpp index 43cdb6d665..995a5bad27 100644 --- a/assignment-client/src/entities/EntityServer.cpp +++ b/assignment-client/src/entities/EntityServer.cpp @@ -41,8 +41,7 @@ EntityServer::EntityServer(ReceivedMessage& message) : DependencyManager::set(); auto& packetReceiver = DependencyManager::get()->getPacketReceiver(); - packetReceiver.registerListenerForTypes({ - //PacketType::EntityAdd, + packetReceiver.registerListenerForTypes({ PacketType::EntityAdd, PacketType::EntityEdit, PacketType::EntityErase, PacketType::EntityPhysics, @@ -52,9 +51,6 @@ EntityServer::EntityServer(ReceivedMessage& message) : this, "handleEntityPacket"); - packetReceiver.registerListener(PacketType::EntityAdd, this, "handleEntityPacket"); - - connect(&_dynamicDomainVerificationTimer, &QTimer::timeout, this, &EntityServer::startDynamicDomainVerification); _dynamicDomainVerificationTimer.setSingleShot(true); } @@ -76,13 +72,6 @@ void EntityServer::aboutToFinish() { } void EntityServer::handleEntityPacket(QSharedPointer message, SharedNodePointer senderNode) { - qDebug() << __FUNCTION__ << "from:" << senderNode->getUUID() << "type:" << message->getType() - << "getNumPackets:" << message->getNumPackets() - << "getSize:" << message->getSize() - << "isFromPacketList:" << message->isFromPacketList() - << "isComplete:" << message->isComplete() - ; - if (_octreeInboundPacketProcessor) { _octreeInboundPacketProcessor->queueReceivedPacket(message, senderNode); } diff --git a/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp b/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp index d2723e936f..bce6e7fe44 100644 --- a/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp +++ b/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp @@ -76,20 +76,12 @@ void OctreeInboundPacketProcessor::midProcess() { } void OctreeInboundPacketProcessor::processPacket(QSharedPointer message, SharedNodePointer sendingNode) { - - qDebug() << __FUNCTION__ << "from:" << sendingNode->getUUID() << "type:" << message->getType() - << "getNumPackets:" << message->getNumPackets() - << "getSize:" << message->getSize() - << "isFromPacketList:" << message->isFromPacketList() - << "isComplete:" << message->isComplete() - ; - if (_shuttingDown) { qDebug() << "OctreeInboundPacketProcessor::processPacket() while shutting down... ignoring incoming packet"; return; } - bool debugProcessPacket = true; // _myServer->wantsVerboseDebug(); + bool debugProcessPacket = _myServer->wantsVerboseDebug(); if (debugProcessPacket) { qDebug("OctreeInboundPacketProcessor::processPacket() payload=%p payloadLength=%lld", diff --git a/libraries/entities/src/EntityEditPacketSender.cpp b/libraries/entities/src/EntityEditPacketSender.cpp index 42c13119b5..90740948ce 100644 --- a/libraries/entities/src/EntityEditPacketSender.cpp +++ b/libraries/entities/src/EntityEditPacketSender.cpp @@ -81,9 +81,6 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityTreePointer entityTree, EntityItemID entityItemID, const EntityItemProperties& properties) { - - qDebug() << __FUNCTION__ << "type:" << type; - if (!_shouldSend) { return; // bail early } @@ -97,13 +94,10 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type, QByteArray bufferOut(NLPacket::maxPayloadSize(type), 0); if (type == PacketType::EntityAdd) { - auto MAX_ADD_DATA_SIZE = NLPacket::maxPayloadSize(type) * 10; // a really big packet + auto MAX_ADD_DATA_SIZE = NLPacket::maxPayloadSize(type) * 10; // a really big buffer bufferOut.resize(MAX_ADD_DATA_SIZE); } - qDebug() << __FUNCTION__ << "bufferOut.size():" << bufferOut.size(); - - OctreeElement::AppendState encodeResult = OctreeElement::PARTIAL; // start the loop assuming there's more to send auto nodeList = DependencyManager::get(); @@ -127,8 +121,6 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type, qCDebug(entities) << " properties:" << properties; #endif - qDebug() << __FUNCTION__ << "about to call queueOctreeEditMessage() --- bufferOut.size():" << bufferOut.size(); - queueOctreeEditMessage(type, bufferOut); if (type == PacketType::EntityAdd && !properties.getCertificateID().isEmpty()) { emit addingEntityWithCertificate(properties.getCertificateID(), DependencyManager::get()->getPlaceName()); diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 2302765b1a..108fc14e30 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -1227,9 +1227,6 @@ OctreeElement::AppendState EntityItemProperties::encodeEntityEditPacket(PacketTy OctreePacketData ourDataPacket(false, buffer.size()); // create a packetData object to add out packet details too. OctreePacketData* packetData = &ourDataPacket; // we want a pointer to this so we can use our APPEND_ENTITY_PROPERTY macro - qDebug() << __FUNCTION__ << "OctreePacketData::getBytesAvailable():" << packetData->getBytesAvailable(); - - bool success = true; // assume the best OctreeElement::AppendState appendState = OctreeElement::COMPLETED; // assume the best @@ -1528,15 +1525,9 @@ OctreeElement::AppendState EntityItemProperties::encodeEntityEditPacket(PacketTy const char* finalizedData = reinterpret_cast(packetData->getFinalizedData()); int finalizedSize = packetData->getFinalizedSize(); - qDebug() << __FUNCTION__ << "packetData->getFinalizedSize():" << packetData->getFinalizedSize(); - qDebug() << __FUNCTION__ << "packetData->getUncompressedSize():" << packetData->getUncompressedSize(); - qDebug() << __FUNCTION__ << "buffer.size():" << buffer.size(); - if (finalizedSize <= buffer.size()) { buffer.replace(0, finalizedSize, finalizedData, finalizedSize); buffer.resize(finalizedSize); - qDebug() << __FUNCTION__ << "replaced with finalized data size:" << buffer.size(); - } else { qCDebug(entities) << "ERROR - encoded edit message doesn't fit in output buffer."; success = false; diff --git a/libraries/networking/src/PacketSender.cpp b/libraries/networking/src/PacketSender.cpp index 2ccd9094ed..657a122cbe 100644 --- a/libraries/networking/src/PacketSender.cpp +++ b/libraries/networking/src/PacketSender.cpp @@ -64,9 +64,6 @@ void PacketSender::queuePacketListForSending(const SharedNodePointer& destinatio _totalPacketsQueued += packetList->getNumPackets(); _totalBytesQueued += packetList->getMessageSize(); - qDebug() << __FUNCTION__ << "to:" << destinationNode->getUUID() << "type:" << packetList->getType() << "size:" << packetList->getDataSize() - << "_totalPacketsQueued:" << _totalPacketsQueued << "_totalBytesQueued:" << _totalBytesQueued; - lock(); _packets.push_back({ destinationNode, PacketOrPacketList { nullptr, std::move(packetList)} }); unlock(); @@ -293,16 +290,9 @@ bool PacketSender::nonThreadedProcess() { size_t packetCount = sendAsPacket ? 1 : packetPair.second.second->getNumPackets(); if (sendAsPacket) { - - qDebug() << __FUNCTION__ << "sendUnreliablePacket() to:" << packetPair.first->getUUID() << "type:" << packetPair.second.first->getType(); DependencyManager::get()->sendUnreliablePacket(*packetPair.second.first, *packetPair.first); } else { - - qDebug() << __FUNCTION__ << "sendPacketList() to:" << packetPair.first->getUUID() << "type:" << packetPair.second.second->getType() - << "getMessageSize:" << packetPair.second.second->getMessageSize() - << "getDataSize:" << packetPair.second.second->getDataSize(); - - DependencyManager::get()->sendPacketList(*packetPair.second.second, *packetPair.first); + DependencyManager::get()->sendPacketList(std::move(packetPair.second.second), *packetPair.first); } @@ -313,13 +303,6 @@ bool PacketSender::nonThreadedProcess() { _totalBytesSent += packetSize; emit packetSent(packetSize); // FIXME should include number of packets? - - qDebug() << __FUNCTION__ << "packetsSentThisCall:" << packetsSentThisCall - << "_packetsOverCheckInterval:" << _packetsOverCheckInterval - << "_totalPacketsSent:" << _totalPacketsSent - << "packetSize:" << packetSize - << "_totalBytesSent:" << _totalBytesSent; - _lastSendTime = now; } return isStillRunning(); diff --git a/libraries/networking/src/ReceivedMessage.cpp b/libraries/networking/src/ReceivedMessage.cpp index 8a3322ce20..00b16908ce 100644 --- a/libraries/networking/src/ReceivedMessage.cpp +++ b/libraries/networking/src/ReceivedMessage.cpp @@ -26,10 +26,8 @@ ReceivedMessage::ReceivedMessage(const NLPacketList& packetList) _sourceID(packetList.getSourceID()), _packetType(packetList.getType()), _packetVersion(packetList.getVersion()), - _senderSockAddr(packetList.getSenderSockAddr()), - _fromPacketList(true) + _senderSockAddr(packetList.getSenderSockAddr()) { - qDebug() << __FUNCTION__ << "(const NLPacketList& packetList) _fromPacketList:" << _fromPacketList; } ReceivedMessage::ReceivedMessage(NLPacket& packet) @@ -40,12 +38,8 @@ ReceivedMessage::ReceivedMessage(NLPacket& packet) _packetType(packet.getType()), _packetVersion(packet.getVersion()), _senderSockAddr(packet.getSenderSockAddr()), - _isComplete(packet.getPacketPosition() == NLPacket::ONLY), - _fromPacket(true) + _isComplete(packet.getPacketPosition() == NLPacket::ONLY) { - if (packet.getType() == PacketType::EntityAdd) { - qDebug() << __FUNCTION__ << "(NLPacket& packet) _fromPacketList:" << _fromPacketList << "packet.getType():" << packet.getType(); - } } ReceivedMessage::ReceivedMessage(QByteArray byteArray, PacketType packetType, PacketVersion packetVersion, @@ -57,10 +51,8 @@ ReceivedMessage::ReceivedMessage(QByteArray byteArray, PacketType packetType, Pa _packetType(packetType), _packetVersion(packetVersion), _senderSockAddr(senderSockAddr), - _isComplete(true), - _fromByteArray(true) + _isComplete(true) { - qDebug() << __FUNCTION__ << "(QByteArray byteArray)... _fromPacketList:" << _fromPacketList; } void ReceivedMessage::setFailed() { diff --git a/libraries/networking/src/ReceivedMessage.h b/libraries/networking/src/ReceivedMessage.h index 2af4798bc3..ae51e7592a 100644 --- a/libraries/networking/src/ReceivedMessage.h +++ b/libraries/networking/src/ReceivedMessage.h @@ -79,10 +79,6 @@ public: template qint64 readHeadPrimitive(T* data); - bool isFromPacketList() const { return _fromPacketList; }; - bool isFromPacket() const { return _fromPacket; }; - bool isFromByteArray() const { return _fromByteArray; }; - signals: void progress(qint64 size); void completed(); @@ -104,12 +100,6 @@ private: std::atomic _isComplete { true }; std::atomic _failed { false }; - - std::atomic _fromPacketList { false }; - std::atomic _fromPacket { false }; - std::atomic _fromByteArray { false }; - - }; Q_DECLARE_METATYPE(ReceivedMessage*) diff --git a/libraries/networking/src/ReceivedPacketProcessor.cpp b/libraries/networking/src/ReceivedPacketProcessor.cpp index eda5109279..c18d4ed1e8 100644 --- a/libraries/networking/src/ReceivedPacketProcessor.cpp +++ b/libraries/networking/src/ReceivedPacketProcessor.cpp @@ -25,15 +25,6 @@ void ReceivedPacketProcessor::terminating() { } void ReceivedPacketProcessor::queueReceivedPacket(QSharedPointer message, SharedNodePointer sendingNode) { - - qDebug() << __FUNCTION__ << "from:" << sendingNode->getUUID() << "type:" << message->getType() - << "getNumPackets:" << message->getNumPackets() - << "getSize:" << message->getSize() - << "isFromPacketList:" << message->isFromPacketList() - << "isComplete:" << message->isComplete() - ; - - lock(); _packets.push_back({ sendingNode, message }); _nodePacketCounts[sendingNode->getUUID()]++; diff --git a/libraries/octree/src/OctreeEditPacketSender.cpp b/libraries/octree/src/OctreeEditPacketSender.cpp index 7e04fa6630..a880b44074 100644 --- a/libraries/octree/src/OctreeEditPacketSender.cpp +++ b/libraries/octree/src/OctreeEditPacketSender.cpp @@ -118,9 +118,6 @@ void OctreeEditPacketSender::queuePacketToNode(const QUuid& nodeUUID, std::uniqu // This method is called when the edit packet layer has determined that it has a fully formed packet destined for // a known nodeID. void OctreeEditPacketSender::queuePacketListToNode(const QUuid& nodeUUID, std::unique_ptr packetList) { - - qDebug() << __FUNCTION__ << "to:" << nodeUUID << "type:" << packetList->getType() << "size:" << packetList->getDataSize(); - bool wantDebug = false; DependencyManager::get()->eachNode([&](const SharedNodePointer& node) { // only send to the NodeTypes that are getMyNodeType() @@ -129,10 +126,7 @@ void OctreeEditPacketSender::queuePacketListToNode(const QUuid& nodeUUID, std::u && node->getActiveSocket()) { // NOTE: unlike packets, the packet lists don't get rewritten sequence numbers. - - // add packet to history -- we don't keep track of sent PacketLists - //_sentPacketHistories[nodeUUID].packetSent(sequence, *packet); - + // or do history for resend queuePacketListForSending(node, std::move(packetList)); } }); @@ -380,9 +374,6 @@ void OctreeEditPacketSender::releaseQueuedPacket(const QUuid& nodeID, std::uniqu } void OctreeEditPacketSender::releaseQueuedPacketList(const QUuid& nodeID, std::unique_ptr packetList) { - - qDebug() << __FUNCTION__ << "to:" << nodeID << "type:" << packetList->getType() << "size:" << packetList->getDataSize(); - _releaseQueuedPacketMutex.lock(); if (packetList->getMessageSize() > 0 && packetList->getType() != PacketType::Unknown) { queuePacketListToNode(nodeID, std::move(packetList)); diff --git a/libraries/octree/src/OctreePacketData.cpp b/libraries/octree/src/OctreePacketData.cpp index 5b3e68c0a1..a2aad33058 100644 --- a/libraries/octree/src/OctreePacketData.cpp +++ b/libraries/octree/src/OctreePacketData.cpp @@ -35,8 +35,7 @@ OctreePacketData::OctreePacketData(bool enableCompression, int targetSize) { void OctreePacketData::changeSettings(bool enableCompression, unsigned int targetSize) { _enableCompression = enableCompression; - _targetSize = targetSize; // std::min(MAX_OCTREE_UNCOMRESSED_PACKET_SIZE, targetSize); - + _targetSize = targetSize; _uncompressedByteArray.resize(_targetSize); _compressedByteArray.resize(_targetSize); diff --git a/libraries/octree/src/OctreePacketData.h b/libraries/octree/src/OctreePacketData.h index 0c582f4ed6..09eb134124 100644 --- a/libraries/octree/src/OctreePacketData.h +++ b/libraries/octree/src/OctreePacketData.h @@ -279,8 +279,6 @@ private: unsigned int _targetSize; bool _enableCompression; - //unsigned char _uncompressed[MAX_OCTREE_UNCOMRESSED_PACKET_SIZE]; - QByteArray _uncompressedByteArray; unsigned char* _uncompressed { nullptr }; int _bytesInUse; @@ -291,7 +289,6 @@ private: bool compressContent(); - //unsigned char _compressed[MAX_OCTREE_UNCOMRESSED_PACKET_SIZE]; QByteArray _compressedByteArray; unsigned char* _compressed { nullptr }; int _compressedBytes; From 66454e72887ea608708fd3afac1401aa9ad0845c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 17 Nov 2017 16:33:43 -0800 Subject: [PATCH 5/5] fix unix warnings --- libraries/networking/src/PacketSender.cpp | 2 +- libraries/octree/src/OctreeEditPacketSender.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/networking/src/PacketSender.cpp b/libraries/networking/src/PacketSender.cpp index 657a122cbe..02c4815f1f 100644 --- a/libraries/networking/src/PacketSender.cpp +++ b/libraries/networking/src/PacketSender.cpp @@ -191,7 +191,7 @@ bool PacketSender::nonThreadedProcess() { float averagePacketsPerCall = 0; // might be less than 1, if our caller calls us more frequently than the target PPS size_t packetsSentThisCall = 0; - int packetsToSendThisCall = 0; + size_t packetsToSendThisCall = 0; // Since we're in non-threaded mode, we need to determine how many packets to send per call to process // based on how often we get called... We do this by keeping a running average of our call times, and we determine diff --git a/libraries/octree/src/OctreeEditPacketSender.cpp b/libraries/octree/src/OctreeEditPacketSender.cpp index a880b44074..9cb383df41 100644 --- a/libraries/octree/src/OctreeEditPacketSender.cpp +++ b/libraries/octree/src/OctreeEditPacketSender.cpp @@ -118,7 +118,6 @@ void OctreeEditPacketSender::queuePacketToNode(const QUuid& nodeUUID, std::uniqu // This method is called when the edit packet layer has determined that it has a fully formed packet destined for // a known nodeID. void OctreeEditPacketSender::queuePacketListToNode(const QUuid& nodeUUID, std::unique_ptr packetList) { - bool wantDebug = false; DependencyManager::get()->eachNode([&](const SharedNodePointer& node) { // only send to the NodeTypes that are getMyNodeType() if (node->getType() == getMyNodeType()