diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index b6bc2c8d01..9a3896f0ac 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -63,12 +63,12 @@ void Agent::handleOctreePacket(QSharedPointer message, SharedNo if (packetType == PacketType::OctreeStats) { int statsMessageLength = OctreeHeadlessViewer::parseOctreeStats(message, senderNode); - if (message->getPayloadSize() > statsMessageLength) { + if (message->getSize() > statsMessageLength) { // pull out the piggybacked packet and create a new QSharedPointer for it - int piggyBackedSizeWithHeader = message->getPayloadSize() - statsMessageLength; + int piggyBackedSizeWithHeader = message->getSize() - statsMessageLength; auto buffer = std::unique_ptr(new char[piggyBackedSizeWithHeader]); - memcpy(buffer.get(), message->getPayload() + statsMessageLength, piggyBackedSizeWithHeader); + memcpy(buffer.get(), message->getRawMessage() + statsMessageLength, piggyBackedSizeWithHeader); auto newPacket = NLPacket::fromReceivedPacket(std::move(buffer), piggyBackedSizeWithHeader, message->getSenderSockAddr()); message = QSharedPointer(new ReceivedMessage(*newPacket)); diff --git a/assignment-client/src/assets/AssetServer.cpp b/assignment-client/src/assets/AssetServer.cpp index da1addf174..2f9e7ee1e6 100644 --- a/assignment-client/src/assets/AssetServer.cpp +++ b/assignment-client/src/assets/AssetServer.cpp @@ -40,7 +40,7 @@ AssetServer::AssetServer(ReceivedMessage& message) : auto& packetReceiver = DependencyManager::get()->getPacketReceiver(); packetReceiver.registerListener(PacketType::AssetGet, this, "handleAssetGet"); packetReceiver.registerListener(PacketType::AssetGetInfo, this, "handleAssetGetInfo"); - packetReceiver.registerMessageListener(PacketType::AssetUpload, this, "handleAssetUpload"); + packetReceiver.registerListener(PacketType::AssetUpload, this, "handleAssetUpload"); } void AssetServer::run() { @@ -89,7 +89,7 @@ void AssetServer::handleAssetGetInfo(QSharedPointer message, Sh MessageID messageID; uint8_t extensionLength; - if (message->getPayloadSize() < qint64(SHA256_HASH_LENGTH + sizeof(messageID) + sizeof(extensionLength))) { + if (message->getSize() < qint64(SHA256_HASH_LENGTH + sizeof(messageID) + sizeof(extensionLength))) { qDebug() << "ERROR bad file request"; return; } @@ -126,7 +126,7 @@ void AssetServer::handleAssetGet(QSharedPointer message, Shared auto minSize = qint64(sizeof(MessageID) + SHA256_HASH_LENGTH + sizeof(uint8_t) + sizeof(DataOffset) + sizeof(DataOffset)); - if (message->getPayloadSize() < minSize) { + if (message->getSize() < minSize) { qDebug() << "ERROR bad file request"; return; } diff --git a/assignment-client/src/audio/AudioMixer.cpp b/assignment-client/src/audio/AudioMixer.cpp index e09564634c..1cc686039f 100644 --- a/assignment-client/src/audio/AudioMixer.cpp +++ b/assignment-client/src/audio/AudioMixer.cpp @@ -549,9 +549,9 @@ void AudioMixer::handleMuteEnvironmentPacket(QSharedPointer mes auto nodeList = DependencyManager::get(); if (sendingNode->getCanAdjustLocks()) { - auto newPacket = NLPacket::create(PacketType::MuteEnvironment, message->getPayloadSize()); + auto newPacket = NLPacket::create(PacketType::MuteEnvironment, message->getSize()); // Copy payload - newPacket->write(message->getPayload(), message->getPayloadSize()); + newPacket->write(message->getRawMessage(), message->getSize()); nodeList->eachNode([&](const SharedNodePointer& node){ if (node->getType() == NodeType::Agent && node->getActiveSocket() && diff --git a/assignment-client/src/audio/AudioMixerClientData.cpp b/assignment-client/src/audio/AudioMixerClientData.cpp index 63ee88f2ef..729e9fa633 100644 --- a/assignment-client/src/audio/AudioMixerClientData.cpp +++ b/assignment-client/src/audio/AudioMixerClientData.cpp @@ -60,7 +60,7 @@ int AudioMixerClientData::parseData(ReceivedMessage& message) { // read the downstream audio stream stats message.readPrimitive(&_downstreamAudioStreamStats); - return message.pos(); + return message.getPosition(); } else { PositionalAudioStream* matchingStream = NULL; diff --git a/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp b/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp index cee1d9ba0f..ce67fdb030 100644 --- a/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp +++ b/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp @@ -84,8 +84,8 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer if (debugProcessPacket) { qDebug("OctreeInboundPacketProcessor::processPacket() payload=%p payloadLength=%lld", - message->getPayload(), - message->getPayloadSize()); + message->getRawMessage(), + message->getSize()); } // Ask our tree subclass if it can handle the incoming packet... @@ -117,7 +117,7 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer if (debugProcessPacket || _myServer->wantsDebugReceiving()) { qDebug() << "PROCESSING THREAD: got '" << packetType << "' packet - " << _receivedPacketCount << " command from client"; - qDebug() << " receivedBytes=" << message->getDataSize(); + qDebug() << " receivedBytes=" << message->getSize(); qDebug() << " sequence=" << sequence; qDebug() << " sentAt=" << sentAt << " usecs"; qDebug() << " arrivedAt=" << arrivedAt << " usecs"; @@ -131,8 +131,8 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer qDebug() << " numBytesPacketHeader=" << NLPacket::totalHeaderSize(packetType); qDebug() << " sizeof(sequence)=" << sizeof(sequence); qDebug() << " sizeof(sentAt)=" << sizeof(sentAt); - qDebug() << " atByte (in payload)=" << message->pos(); - qDebug() << " payload size=" << message->getPayloadSize(); + qDebug() << " atByte (in payload)=" << message->getPosition(); + qDebug() << " payload size=" << message->getSize(); if (!message->getBytesLeftToRead()) { qDebug() << " ----- UNEXPECTED ---- got a packet without any edit details!!!! --------"; @@ -143,7 +143,7 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer while (message->getBytesLeftToRead() > 0) { - editData = reinterpret_cast(message->getPayload() + message->pos()); + editData = reinterpret_cast(message->getRawMessage() + message->getPosition()); int maxSize = message->getBytesLeftToRead(); @@ -152,8 +152,8 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer qDebug() << " maxSize=" << maxSize; qDebug("OctreeInboundPacketProcessor::processPacket() %hhu " "payload=%p payloadLength=%lld editData=%p payloadPosition=%lld maxSize=%d", - packetType, message->getPayload(), message->getPayloadSize(), editData, - message->pos(), maxSize); + packetType, message->getRawMessage(), message->getSize(), editData, + message->getPosition(), maxSize); } quint64 startProcess, startLock = usecTimestampNow(); @@ -177,12 +177,12 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer lockWaitTime += thisLockWaitTime; // skip to next edit record in the packet - message->seek(message->pos() + editDataBytesRead); + message->seek(message->getPosition() + editDataBytesRead); if (debugProcessPacket) { qDebug() << " editDataBytesRead=" << editDataBytesRead; - qDebug() << " AFTER processEditPacketData payload position=" << message->pos(); - qDebug() << " AFTER processEditPacketData payload size=" << message->getPayloadSize(); + qDebug() << " AFTER processEditPacketData payload position=" << message->getPosition(); + qDebug() << " AFTER processEditPacketData payload size=" << message->getSize(); } } @@ -190,7 +190,7 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer if (debugProcessPacket) { qDebug("OctreeInboundPacketProcessor::processPacket() DONE LOOPING FOR %hhu " "payload=%p payloadLength=%lld editData=%p payloadPosition=%lld", - packetType, message->getPayload(), message->getPayloadSize(), editData, message->pos()); + packetType, message->getRawMessage(), message->getSize(), editData, message->getPosition()); } // Make sure our Node and NodeList knows we've heard from this node. diff --git a/domain-server/src/DomainGatekeeper.cpp b/domain-server/src/DomainGatekeeper.cpp index 1048d2665e..714d840baa 100644 --- a/domain-server/src/DomainGatekeeper.cpp +++ b/domain-server/src/DomainGatekeeper.cpp @@ -51,7 +51,7 @@ const NodeSet STATICALLY_ASSIGNED_NODES = NodeSet() << NodeType::AudioMixer << NodeType::AssetServer; void DomainGatekeeper::processConnectRequestPacket(QSharedPointer message) { - if (message->getPayloadSize() == 0) { + if (message->getSize() == 0) { return; } diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 80529ac116..ec8ad16ae8 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -267,7 +267,7 @@ void DomainServer::setupNodeListAndAssignments(const QUuid& sessionUUID) { packetReceiver.registerListener(PacketType::RequestAssignment, this, "processRequestAssignmentPacket"); packetReceiver.registerListener(PacketType::DomainListRequest, this, "processListRequestPacket"); packetReceiver.registerListener(PacketType::DomainServerPathQuery, this, "processPathQueryPacket"); - packetReceiver.registerMessageListener(PacketType::NodeJsonStats, this, "processNodeJSONStatsPacket"); + packetReceiver.registerListener(PacketType::NodeJsonStats, this, "processNodeJSONStatsPacket"); // NodeList won't be available to the settings manager when it is created, so call registerListener here packetReceiver.registerListener(PacketType::DomainSettingsRequest, &_settingsManager, "processSettingsRequestPacket"); @@ -1763,7 +1763,7 @@ void DomainServer::processPathQueryPacket(QSharedPointer messag if (numPathBytes <= message->getBytesLeftToRead()) { // the number of path bytes makes sense for the sent packet - pull out the path - QString pathQuery = QString::fromUtf8(message->getPayload() + message->pos(), numPathBytes); + QString pathQuery = QString::fromUtf8(message->getRawMessage() + message->getPosition(), numPathBytes); // our settings contain paths that start with a leading slash, so make sure this query has that if (!pathQuery.startsWith("/")) { diff --git a/interface/src/octree/OctreePacketProcessor.cpp b/interface/src/octree/OctreePacketProcessor.cpp index 1538c4eb65..b565bdfd88 100644 --- a/interface/src/octree/OctreePacketProcessor.cpp +++ b/interface/src/octree/OctreePacketProcessor.cpp @@ -48,12 +48,12 @@ void OctreePacketProcessor::processPacket(QSharedPointer messag int statsMessageLength = qApp->processOctreeStats(*message, sendingNode); wasStatsPacket = true; - int piggybackBytes = message->getPayloadSize() - statsMessageLength; + int piggybackBytes = message->getSize() - statsMessageLength; if (piggybackBytes) { // construct a new packet from the piggybacked one auto buffer = std::unique_ptr(new char[piggybackBytes]); - memcpy(buffer.get(), message->getPayload() + statsMessageLength, piggybackBytes); + memcpy(buffer.get(), message->getRawMessage() + statsMessageLength, piggybackBytes); qDebug() << "Got piggyback, read " << piggybackBytes << " bytes"; auto newPacket = NLPacket::fromReceivedPacket(std::move(buffer), piggybackBytes, message->getSenderSockAddr()); diff --git a/libraries/audio/src/InboundAudioStream.cpp b/libraries/audio/src/InboundAudioStream.cpp index f2aa91aae1..8b32ada296 100644 --- a/libraries/audio/src/InboundAudioStream.cpp +++ b/libraries/audio/src/InboundAudioStream.cpp @@ -111,7 +111,7 @@ int InboundAudioStream::parseData(ReceivedMessage& message) { int networkSamples; // parse the info after the seq number and before the audio data (the stream properties) - int prePropertyPosition = message.pos(); + int prePropertyPosition = message.getPosition(); int propertyBytes = parseStreamProperties(message.getType(), message.readWithoutCopy(message.getBytesLeftToRead()), networkSamples); message.seek(prePropertyPosition + propertyBytes); @@ -161,7 +161,7 @@ int InboundAudioStream::parseData(ReceivedMessage& message) { framesAvailableChanged(); - return message.pos(); + return message.getPosition(); } int InboundAudioStream::parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& numAudioSamples) { diff --git a/libraries/avatars/src/AvatarHashMap.cpp b/libraries/avatars/src/AvatarHashMap.cpp index 0a46fec3bc..8befede6c8 100644 --- a/libraries/avatars/src/AvatarHashMap.cpp +++ b/libraries/avatars/src/AvatarHashMap.cpp @@ -55,7 +55,7 @@ void AvatarHashMap::processAvatarDataPacket(QSharedPointer mess while (message->getBytesLeftToRead()) { QUuid sessionUUID = QUuid::fromRfc4122(message->readWithoutCopy(NUM_BYTES_RFC4122_UUID)); - int positionBeforeRead = message->pos(); + int positionBeforeRead = message->getPosition(); QByteArray byteArray = message->readWithoutCopy(message->getBytesLeftToRead()); diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 0f76f76094..99331774a8 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -877,7 +877,7 @@ int EntityTree::processEraseMessage(ReceivedMessage& message, const SharedNodePo deleteEntities(entityItemIDsToDelete, true, true); } }); - return message.pos(); + return message.getPosition(); } // This version skips over the header diff --git a/libraries/networking/src/AssetClient.cpp b/libraries/networking/src/AssetClient.cpp index 623d1d86eb..ecf138ba5f 100644 --- a/libraries/networking/src/AssetClient.cpp +++ b/libraries/networking/src/AssetClient.cpp @@ -38,9 +38,9 @@ AssetClient::AssetClient() { auto nodeList = DependencyManager::get(); auto& packetReceiver = nodeList->getPacketReceiver(); - packetReceiver.registerMessageListener(PacketType::AssetGetInfoReply, this, "handleAssetGetInfoReply"); - packetReceiver.registerMessageListener(PacketType::AssetGetReply, this, "handleAssetGetReply", true); - packetReceiver.registerMessageListener(PacketType::AssetUploadReply, this, "handleAssetUploadReply"); + packetReceiver.registerListener(PacketType::AssetGetInfoReply, this, "handleAssetGetInfoReply"); + packetReceiver.registerListener(PacketType::AssetGetReply, this, "handleAssetGetReply", true); + packetReceiver.registerListener(PacketType::AssetUploadReply, this, "handleAssetUploadReply"); connect(nodeList.data(), &LimitedNodeList::nodeKilled, this, &AssetClient::handleNodeKilled); } @@ -242,7 +242,7 @@ void AssetClient::handleAssetGetReply(QSharedPointer message, S } else { connect(message.data(), &ReceivedMessage::progress, this, [this, length, message, callbacks](ReceivedMessage* msg) { //qDebug() << "Progress: " << msg->getDataSize(); - callbacks.progressCallback(msg->getDataSize(), length); + callbacks.progressCallback(msg->getSize(), length); }); connect(message.data(), &ReceivedMessage::completed, this, [this, message, error, callbacks](ReceivedMessage* msg) { callbacks.completeCallback(true, error, message->readAll()); diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 91cff1ad0b..0827252599 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -100,11 +100,6 @@ LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short _packetReceiver->handleVerifiedMessagePacket(std::move(packet)); } ); - _nodeSocket.setPacketListHandler( - [this](std::unique_ptr packetList) { - _packetReceiver->handleVerifiedPacketList(std::move(packetList)); - } - ); // set our isPacketVerified method as the verify operator for the udt::Socket using std::placeholders::_1; @@ -554,7 +549,7 @@ std::unique_ptr LimitedNodeList::constructICEPingReplyPacket(ReceivedM // pull out the ping type so we can reply back with that PingType_t pingType; - memcpy(&pingType, message.getPayload() + NUM_BYTES_RFC4122_UUID, sizeof(PingType_t)); + memcpy(&pingType, message.getRawMessage() + NUM_BYTES_RFC4122_UUID, sizeof(PingType_t)); int packetSize = NUM_BYTES_RFC4122_UUID + sizeof(PingType_t); auto icePingReplyPacket = NLPacket::create(PacketType::ICEPingReply, packetSize); diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 00d6a503a7..ddec52aa2f 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -98,7 +98,7 @@ NodeList::NodeList(char newOwnerType, unsigned short socketListenPort, unsigned packetReceiver.registerListener(PacketType::ICEPing, this, "processICEPingPacket"); packetReceiver.registerListener(PacketType::DomainServerAddedNode, this, "processDomainServerAddedNode"); packetReceiver.registerListener(PacketType::DomainServerConnectionToken, this, "processDomainServerConnectionTokenPacket"); - packetReceiver.registerMessageListener(PacketType::DomainSettings, &_domainHandler, "processSettingsPacketList"); + packetReceiver.registerListener(PacketType::DomainSettings, &_domainHandler, "processSettingsPacketList"); packetReceiver.registerListener(PacketType::ICEServerPeerInformation, &_domainHandler, "processICEResponsePacket"); packetReceiver.registerListener(PacketType::DomainServerRequireDTLS, &_domainHandler, "processDTLSRequirementPacket"); packetReceiver.registerListener(PacketType::ICEPingReply, &_domainHandler, "processICEPingReplyPacket"); @@ -378,8 +378,8 @@ void NodeList::processDomainServerPathResponse(QSharedPointer m return; } - QString pathQuery = QString::fromUtf8(message->getPayload() + message->pos(), numPathBytes); - message->seek(message->pos() + numPathBytes); + QString pathQuery = QString::fromUtf8(message->getRawMessage() + message->getPosition(), numPathBytes); + message->seek(message->getPosition() + numPathBytes); // figure out how many bytes the viewpoint is quint16 numViewpointBytes; @@ -391,7 +391,7 @@ void NodeList::processDomainServerPathResponse(QSharedPointer m } // pull the viewpoint from the packet - QString viewpoint = QString::fromUtf8(message->getPayload() + message->pos(), numViewpointBytes); + QString viewpoint = QString::fromUtf8(message->getRawMessage() + message->getPosition(), numViewpointBytes); // Hand it off to the AddressManager so it can handle it as a relative viewpoint if (DependencyManager::get()->goToViewpointForPath(viewpoint, pathQuery)) { @@ -500,7 +500,7 @@ void NodeList::processDomainServerList(QSharedPointer message) setThisNodeCanRez((bool) thisNodeCanRez); // pull each node in the packet - while (packetStream.device()->pos() < message->getPayloadSize()) { + while (packetStream.device()->pos() < message->getSize()) { parseNodeFromPacketStream(packetStream); } } diff --git a/libraries/networking/src/PacketReceiver.cpp b/libraries/networking/src/PacketReceiver.cpp index a95ba12047..1b2a966b70 100644 --- a/libraries/networking/src/PacketReceiver.cpp +++ b/libraries/networking/src/PacketReceiver.cpp @@ -94,7 +94,7 @@ void PacketReceiver::registerDirectListenerForTypes(PacketTypeList types, } } -bool PacketReceiver::registerMessageListener(PacketType type, QObject* listener, const char* slot, +bool PacketReceiver::registerListener(PacketType type, QObject* listener, const char* slot, bool deliverPending) { Q_ASSERT_X(listener, "PacketReceiver::registerMessageListener", "No object to register"); Q_ASSERT_X(slot, "PacketReceiver::registerMessageListener", "No slot to register"); @@ -102,22 +102,15 @@ bool PacketReceiver::registerMessageListener(PacketType type, QObject* listener, QMetaMethod matchingMethod = matchingMethodForListener(type, listener, slot); if (matchingMethod.isValid()) { - QMutexLocker locker(&_packetListenerLock); - - if (_messageListenerMap.contains(type)) { - qCWarning(networking) << "Registering a packet listener for packet type" << type - << "that will remove a previously registered listener"; - } - - // add the mapping - _messageListenerMap[type] = { QPointer(listener), matchingMethod, deliverPending }; - + qDebug() << "Found: " << matchingMethod.methodSignature(); + registerVerifiedListener(type, listener, matchingMethod); return true; } else { return false; } } +/* bool PacketReceiver::registerListener(PacketType type, QObject* listener, const char* slot) { Q_ASSERT_X(listener, "PacketReceiver::registerListener", "No object to register"); Q_ASSERT_X(slot, "PacketReceiver::registerListener", "No slot to register"); @@ -132,6 +125,7 @@ bool PacketReceiver::registerListener(PacketType type, QObject* listener, const return false; } } +*/ QMetaMethod PacketReceiver::matchingMethodForListener(PacketType type, QObject* object, const char* slot) const { Q_ASSERT_X(object, "PacketReceiver::matchingMethodForListener", "No object to call"); @@ -140,27 +134,20 @@ QMetaMethod PacketReceiver::matchingMethodForListener(PacketType type, QObject* // normalize the slot with the expected parameters static const QString SIGNATURE_TEMPLATE("%1(%2)"); - // static const QString NON_SOURCED_PACKET_LISTENER_PARAMETERS = "QSharedPointer"; - static const QString NON_SOURCED_PACKETLIST_LISTENER_PARAMETERS = "QSharedPointer"; + static const QString NON_SOURCED_MESSAGE_LISTENER_PARAMETERS = "QSharedPointer"; QSet possibleSignatures { - // SIGNATURE_TEMPLATE.arg(slot, NON_SOURCED_PACKET_LISTENER_PARAMETERS), - SIGNATURE_TEMPLATE.arg(slot, NON_SOURCED_PACKETLIST_LISTENER_PARAMETERS) + SIGNATURE_TEMPLATE.arg(slot, NON_SOURCED_MESSAGE_LISTENER_PARAMETERS) }; if (!NON_SOURCED_PACKETS.contains(type)) { - // static const QString SOURCED_PACKET_LISTENER_PARAMETERS = "QSharedPointer,QSharedPointer"; - // static const QString TYPEDEF_SOURCED_PACKET_LISTENER_PARAMETERS = "QSharedPointer,SharedNodePointer"; - static const QString SOURCED_PACKETLIST_LISTENER_PARAMETERS = "QSharedPointer,QSharedPointer"; - static const QString TYPEDEF_SOURCED_PACKETLIST_LISTENER_PARAMETERS = "QSharedPointer,SharedNodePointer"; + static const QString SOURCED_MESSAGE_LISTENER_PARAMETERS = "QSharedPointer,QSharedPointer"; + static const QString TYPEDEF_SOURCED_MESSAGE_LISTENER_PARAMETERS = "QSharedPointer,SharedNodePointer"; - // a sourced packet must take the shared pointer to the packet but optionally could include + // a sourced packet must take the shared pointer to the ReceivedMessage but optionally could include // a shared pointer to the node - - // possibleSignatures << SIGNATURE_TEMPLATE.arg(slot, TYPEDEF_SOURCED_PACKET_LISTENER_PARAMETERS); - // possibleSignatures << SIGNATURE_TEMPLATE.arg(slot, SOURCED_PACKET_LISTENER_PARAMETERS); - possibleSignatures << SIGNATURE_TEMPLATE.arg(slot, TYPEDEF_SOURCED_PACKETLIST_LISTENER_PARAMETERS); - possibleSignatures << SIGNATURE_TEMPLATE.arg(slot, SOURCED_PACKETLIST_LISTENER_PARAMETERS); + possibleSignatures << SIGNATURE_TEMPLATE.arg(slot, TYPEDEF_SOURCED_MESSAGE_LISTENER_PARAMETERS); + possibleSignatures << SIGNATURE_TEMPLATE.arg(slot, SOURCED_MESSAGE_LISTENER_PARAMETERS); } int methodIndex = -1; @@ -244,17 +231,22 @@ void PacketReceiver::handleVerifiedPacket(std::unique_ptr packet) { auto nlPacket = NLPacket::fromBase(std::move(packet)); auto receivedMessage = QSharedPointer(new ReceivedMessage(*nlPacket.get())); + _inPacketCount += 1; + _inByteCount += nlPacket->size(); + handleVerifiedMessage(receivedMessage, true); } void PacketReceiver::handleVerifiedMessagePacket(std::unique_ptr packet) { - qDebug() << "Got message packet"; auto nlPacket = NLPacket::fromBase(std::move(packet)); + _inPacketCount += 1; _inByteCount += nlPacket->size(); + auto key = std::pair(nlPacket->getSenderSockAddr(), nlPacket->getMessageNumber()); auto it = _pendingMessages.find(key); QSharedPointer message; + if (it == _pendingMessages.end()) { // Create message message = QSharedPointer(new ReceivedMessage(*nlPacket.release())); @@ -273,26 +265,9 @@ void PacketReceiver::handleVerifiedMessagePacket(std::unique_ptr pa } } -void PacketReceiver::handleVerifiedPacketList(std::unique_ptr packetList) { - // if we're supposed to drop this packet then break out here - if (_shouldDropPackets) { - return; - } - - // setup an NLPacketList from the PacketList we were passed - auto nlPacketList = NLPacketList::fromPacketList(std::move(packetList)); - auto receivedMessage = QSharedPointer(new ReceivedMessage(*nlPacketList.release())); - - handleVerifiedMessage(receivedMessage, true); -} - void PacketReceiver::handleVerifiedMessage(QSharedPointer receivedMessage, bool justReceived) { - auto nodeList = DependencyManager::get(); - _inPacketCount += receivedMessage->getNumPackets(); - _inByteCount += receivedMessage->size(); - SharedNodePointer matchingNode; if (!receivedMessage->getSourceID().isNull()) { @@ -328,14 +303,12 @@ void PacketReceiver::handleVerifiedMessage(QSharedPointer recei PacketType packetType = receivedMessage->getType(); if (matchingNode) { - emit dataReceived(matchingNode->getType(), receivedMessage->size()); - matchingNode->recordBytesReceived(receivedMessage->size()); + emit dataReceived(matchingNode->getType(), receivedMessage->getSize()); + matchingNode->recordBytesReceived(receivedMessage->getSize()); Node* n = matchingNode.data(); auto addr = n->getActiveSocket(); QMetaMethod metaMethod = listener.method; - - // qDebug() << "Got verified packet list: " << QString(receivedMessage->getMessage()); static const QByteArray QSHAREDPOINTER_NODE_NORMALIZED = QMetaObject::normalizedType("QSharedPointer"); static const QByteArray SHARED_NODE_NORMALIZED = QMetaObject::normalizedType("SharedNodePointer"); @@ -364,7 +337,7 @@ void PacketReceiver::handleVerifiedMessage(QSharedPointer recei } } else { // qDebug() << "Got verified unsourced packet list: " << QString(nlPacketList->getMessage()); - emit dataReceived(NodeType::Unassigned, receivedMessage->size()); + emit dataReceived(NodeType::Unassigned, receivedMessage->getSize()); // one final check on the QPointer before we invoke if (listener.object) { diff --git a/libraries/networking/src/PacketReceiver.h b/libraries/networking/src/PacketReceiver.h index b27abdc084..4a3f32f99c 100644 --- a/libraries/networking/src/PacketReceiver.h +++ b/libraries/networking/src/PacketReceiver.h @@ -57,15 +57,14 @@ public: void resetCounters() { _inPacketCount = 0; _inByteCount = 0; } + // If deliverPending is false, ReceivedMessage will only be delivered once all packets for the message have + // been received. If deliverPending is true, ReceivedMessage will be delivered as soon as the first packet + // for the message is received. + bool registerListener(PacketType type, QObject* listener, const char* slot, bool deliverPending = false); bool registerListenerForTypes(PacketTypeList types, QObject* listener, const char* slot); - bool registerMessageListener(PacketType type, QObject* listener, const char* slot, bool deliverPending = false); - bool registerListener(PacketType type, QObject* listener, const char* slot); void unregisterListener(QObject* listener); void handleVerifiedPacket(std::unique_ptr packet); - void handleVerifiedPacketList(std::unique_ptr packetList); - void handleVerifiedMessage(QSharedPointer message, bool justReceived); - void handleVerifiedMessagePacket(std::unique_ptr message); signals: @@ -78,6 +77,8 @@ private: bool deliverPending; }; + void handleVerifiedMessage(QSharedPointer message, bool justReceived); + // these are brutal hacks for now - ideally GenericThread / ReceivedPacketProcessor // should be changed to have a true event loop and be able to handle our QMetaMethod::invoke void registerDirectListenerForTypes(PacketTypeList types, QObject* listener, const char* slot); diff --git a/libraries/networking/src/ReceivedMessage.h b/libraries/networking/src/ReceivedMessage.h index bd92205d5a..8ab254e8e4 100644 --- a/libraries/networking/src/ReceivedMessage.h +++ b/libraries/networking/src/ReceivedMessage.h @@ -27,8 +27,9 @@ public: ReceivedMessage(const NLPacketList& packetList); ReceivedMessage(NLPacket& packet); - const char* getPayload() const { return _data.constData(); } QByteArray getMessage() const { return _data; } + const char* getRawMessage() const { return _data.constData(); } + PacketType getType() const { return _packetType; } PacketVersion getVersion() const { return _packetVersion; } @@ -39,18 +40,18 @@ public: const QUuid& getSourceID() const { return _sourceID; } const HifiSockAddr& getSenderSockAddr() { return _senderSockAddr; } - void seek(qint64 position) { _position = position; } - qint64 pos() const { return _position; } - qint64 size() const { return _data.size(); } + qint64 getPosition() const { return _position; } + //qint64 size() const { return _data.size(); } // Get the number of packets that were used to send this message qint64 getNumPackets() const { return _numPackets; } - qint64 getDataSize() const { return _data.size(); } - qint64 getPayloadSize() const { return _data.size(); } + qint64 getSize() const { return _data.size(); } qint64 getBytesLeftToRead() const { return _data.size() - _position; } + void seek(qint64 position) { _position = position; } + qint64 peek(char* data, qint64 size); qint64 read(char* data, qint64 size); diff --git a/libraries/octree/src/JurisdictionMap.cpp b/libraries/octree/src/JurisdictionMap.cpp index 2b38a98bf6..d473b3973e 100644 --- a/libraries/octree/src/JurisdictionMap.cpp +++ b/libraries/octree/src/JurisdictionMap.cpp @@ -329,5 +329,5 @@ int JurisdictionMap::unpackFromPacket(ReceivedMessage& message) { } } - return message.pos(); // excludes header + return message.getPosition(); // excludes header } diff --git a/libraries/octree/src/OctreeQuery.cpp b/libraries/octree/src/OctreeQuery.cpp index 9472ce465b..2b2c53e355 100644 --- a/libraries/octree/src/OctreeQuery.cpp +++ b/libraries/octree/src/OctreeQuery.cpp @@ -66,7 +66,7 @@ int OctreeQuery::getBroadcastData(unsigned char* destinationBuffer) { // called on the other nodes - assigns it to my views of the others int OctreeQuery::parseData(ReceivedMessage& message) { - const unsigned char* startPosition = reinterpret_cast(message.getPayload()); + const unsigned char* startPosition = reinterpret_cast(message.getRawMessage()); const unsigned char* sourceBuffer = startPosition; // camera details diff --git a/libraries/octree/src/OctreeRenderer.cpp b/libraries/octree/src/OctreeRenderer.cpp index 526ecb2d8a..8a8353ee1d 100644 --- a/libraries/octree/src/OctreeRenderer.cpp +++ b/libraries/octree/src/OctreeRenderer.cpp @@ -83,7 +83,7 @@ void OctreeRenderer::processDatagram(ReceivedMessage& message, SharedNodePointer qCDebug(octree, "OctreeRenderer::processDatagram() ... Got Packet Section" " color:%s compressed:%s sequence: %u flight:%d usec size:%lld data:%lld", debug::valueOf(packetIsColored), debug::valueOf(packetIsCompressed), - sequence, flightTime, message.getDataSize(), message.getBytesLeftToRead()); + sequence, flightTime, message.getSize(), message.getBytesLeftToRead()); } _packetsInLastWindow++; @@ -125,14 +125,14 @@ void OctreeRenderer::processDatagram(ReceivedMessage& message, SharedNodePointer startUncompress = usecTimestampNow(); OctreePacketData packetData(packetIsCompressed); - packetData.loadFinalizedContent(reinterpret_cast(message.getPayload() + message.pos()), + packetData.loadFinalizedContent(reinterpret_cast(message.getRawMessage() + message.getPosition()), sectionLength); if (extraDebugging) { qCDebug(octree, "OctreeRenderer::processDatagram() ... Got Packet Section" " color:%s compressed:%s sequence: %u flight:%d usec size:%lld data:%lld" " subsection:%d sectionLength:%d uncompressed:%d", debug::valueOf(packetIsColored), debug::valueOf(packetIsCompressed), - sequence, flightTime, message.getDataSize(), message.getBytesLeftToRead(), subsection, sectionLength, + sequence, flightTime, message.getSize(), message.getBytesLeftToRead(), subsection, sectionLength, packetData.getUncompressedSize()); } @@ -148,7 +148,7 @@ void OctreeRenderer::processDatagram(ReceivedMessage& message, SharedNodePointer }); // seek forwards in packet - message.seek(message.pos() + sectionLength); + message.seek(message.getPosition() + sectionLength); elementsPerPacket += args.elementsPerPacket; entitiesPerPacket += args.entitiesPerPacket; diff --git a/libraries/octree/src/OctreeSceneStats.cpp b/libraries/octree/src/OctreeSceneStats.cpp index 716db7a2ed..7b45eacf5c 100644 --- a/libraries/octree/src/OctreeSceneStats.cpp +++ b/libraries/octree/src/OctreeSceneStats.cpp @@ -550,7 +550,7 @@ int OctreeSceneStats::unpackFromPacket(ReceivedMessage& packet) { float calculatedBPV = total == 0 ? 0 : (_bytes * 8) / total; _bitsPerOctreeAverage.updateAverage(calculatedBPV); - return packet.pos(); // excludes header! + return packet.getPosition(); // excludes header! } @@ -790,8 +790,8 @@ void OctreeSceneStats::trackIncomingOctreePacket(ReceivedMessage& message, bool // track packets here... _incomingPacket++; - _incomingBytes += message.getDataSize(); + _incomingBytes += message.getSize(); if (!wasStatsPacket) { - _incomingWastedBytes += (udt::MAX_PACKET_SIZE - message.getDataSize()); + _incomingWastedBytes += (udt::MAX_PACKET_SIZE - message.getSize()); } }