From 3f85e8a2fed5b3c4ec5e211e1c0048cace4f9f36 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 28 Aug 2015 11:12:52 -0700 Subject: [PATCH 1/6] add an UploadAssetTask so uploading is on diff thread --- assignment-client/src/assets/AssetServer.cpp | 77 ++------------- assignment-client/src/assets/AssetServer.h | 2 - assignment-client/src/assets/SendAssetTask.h | 3 - .../src/assets/UploadAssetTask.cpp | 99 +++++++++++++++++++ .../src/assets/UploadAssetTask.h | 37 +++++++ libraries/networking/src/AssetUtils.h | 4 +- libraries/networking/src/udt/SendQueue.h | 2 + 7 files changed, 147 insertions(+), 77 deletions(-) create mode 100644 assignment-client/src/assets/UploadAssetTask.cpp create mode 100644 assignment-client/src/assets/UploadAssetTask.h diff --git a/assignment-client/src/assets/AssetServer.cpp b/assignment-client/src/assets/AssetServer.cpp index 8c4807f412..c046b39f66 100644 --- a/assignment-client/src/assets/AssetServer.cpp +++ b/assignment-client/src/assets/AssetServer.cpp @@ -25,6 +25,7 @@ #include "NetworkLogging.h" #include "NodeType.h" #include "SendAssetTask.h" +#include "UploadAssetTask.h" const QString ASSET_SERVER_LOGGING_TARGET_NAME = "asset-server"; @@ -35,7 +36,8 @@ AssetServer::AssetServer(NLPacket& packet) : // Most of the work will be I/O bound, reading from disk and constructing packet objects, // so the ideal is greater than the number of cores on the system. - _taskPool.setMaxThreadCount(20); + static const int TASK_POOL_THREAD_COUNT = 50; + _taskPool.setMaxThreadCount(TASK_POOL_THREAD_COUNT); auto& packetReceiver = DependencyManager::get()->getPacketReceiver(); packetReceiver.registerListener(PacketType::AssetGet, this, "handleAssetGet"); @@ -153,76 +155,9 @@ void AssetServer::handleAssetGet(QSharedPointer packet, SharedNodePoin } void AssetServer::handleAssetUpload(QSharedPointer packetList, SharedNodePointer senderNode) { + qDebug() << "Starting an UploadAssetTask for upload from" << uuidStringWithoutCurlyBraces(senderNode->getUUID()); - auto data = packetList->getMessage(); - QBuffer buffer { &data }; - buffer.open(QIODevice::ReadOnly); - - MessageID messageID; - buffer.read(reinterpret_cast(&messageID), sizeof(messageID)); - - if (!senderNode->getCanRez()) { - // this is a node the domain told us is not allowed to rez entities - // for now this also means it isn't allowed to add assets - // so return a packet with error that indicates that - - auto permissionErrorPacket = NLPacket::create(PacketType::AssetUploadReply, sizeof(MessageID) + sizeof(AssetServerError)); - - // write the message ID and a permission denied error - permissionErrorPacket->writePrimitive(messageID); - permissionErrorPacket->writePrimitive(AssetServerError::PERMISSION_DENIED); - - // send off the packet - auto nodeList = DependencyManager::get(); - nodeList->sendPacket(std::move(permissionErrorPacket), *senderNode); - - // return so we're not attempting to handle upload - return; - } - - uint8_t extensionLength; - buffer.read(reinterpret_cast(&extensionLength), sizeof(extensionLength)); - - QByteArray extension = buffer.read(extensionLength); - - qDebug() << "Got extension: " << extension; - - uint64_t fileSize; - buffer.read(reinterpret_cast(&fileSize), sizeof(fileSize)); - - qDebug() << "Receiving a file of size " << fileSize; - - auto replyPacket = NLPacket::create(PacketType::AssetUploadReply); - replyPacket->writePrimitive(messageID); - - if (fileSize > MAX_UPLOAD_SIZE) { - replyPacket->writePrimitive(AssetServerError::ASSET_TOO_LARGE); - } else { - QByteArray fileData = buffer.read(fileSize); - - auto hash = hashData(fileData); - auto hexHash = hash.toHex(); - - qDebug() << "Got data: (" << hexHash << ") "; - - QFile file { _resourcesDirectory.filePath(QString(hexHash)) + "." + QString(extension) }; - - if (file.exists()) { - qDebug() << "[WARNING] This file already exists: " << hexHash; - } else { - file.open(QIODevice::WriteOnly); - file.write(fileData); - file.close(); - } - replyPacket->writePrimitive(AssetServerError::NO_ERROR); - replyPacket->write(hash); - } - - auto nodeList = DependencyManager::get(); - nodeList->sendPacket(std::move(replyPacket), *senderNode); -} - -QByteArray AssetServer::hashData(const QByteArray& data) { - return QCryptographicHash::hash(data, QCryptographicHash::Sha256); + auto task = new UploadAssetTask(packetList, senderNode, _resourcesDirectory); + _taskPool.start(task); } diff --git a/assignment-client/src/assets/AssetServer.h b/assignment-client/src/assets/AssetServer.h index 99a31b3768..1975f746a9 100644 --- a/assignment-client/src/assets/AssetServer.h +++ b/assignment-client/src/assets/AssetServer.h @@ -24,8 +24,6 @@ class AssetServer : public ThreadedAssignment { public: AssetServer(NLPacket& packet); - static QByteArray hashData(const QByteArray& data); - public slots: void run(); diff --git a/assignment-client/src/assets/SendAssetTask.h b/assignment-client/src/assets/SendAssetTask.h index 6b6c555326..477f42c1a3 100644 --- a/assignment-client/src/assets/SendAssetTask.h +++ b/assignment-client/src/assets/SendAssetTask.h @@ -27,9 +27,6 @@ public: void run(); -signals: - void finished(); - private: MessageID _messageID; QByteArray _assetHash; diff --git a/assignment-client/src/assets/UploadAssetTask.cpp b/assignment-client/src/assets/UploadAssetTask.cpp new file mode 100644 index 0000000000..66fdc80e90 --- /dev/null +++ b/assignment-client/src/assets/UploadAssetTask.cpp @@ -0,0 +1,99 @@ +// +// UploadAssetTask.cpp +// assignment-client/src/assets +// +// Created by Stephen Birarda on 2015-08-28. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "UploadAssetTask.h" + +#include +#include + +#include +#include +#include + + +UploadAssetTask::UploadAssetTask(QSharedPointer packetList, SharedNodePointer senderNode, + const QDir& resourcesDir) : + _packetList(packetList), + _senderNode(senderNode), + _resourcesDir(resourcesDir) +{ + +} + +void UploadAssetTask::run() { + auto data = _packetList->getMessage(); + + QBuffer buffer { &data }; + buffer.open(QIODevice::ReadOnly); + + MessageID messageID; + buffer.read(reinterpret_cast(&messageID), sizeof(messageID)); + + if (!_senderNode->getCanRez()) { + // this is a node the domain told us is not allowed to rez entities + // for now this also means it isn't allowed to add assets + // so return a packet with error that indicates that + + auto permissionErrorPacket = NLPacket::create(PacketType::AssetUploadReply, sizeof(MessageID) + sizeof(AssetServerError)); + + // write the message ID and a permission denied error + permissionErrorPacket->writePrimitive(messageID); + permissionErrorPacket->writePrimitive(AssetServerError::PERMISSION_DENIED); + + // send off the packet + auto nodeList = DependencyManager::get(); + nodeList->sendPacket(std::move(permissionErrorPacket), *_senderNode); + + // return so we're not attempting to handle upload + return; + } + + uint8_t extensionLength; + buffer.read(reinterpret_cast(&extensionLength), sizeof(extensionLength)); + + QByteArray extension = buffer.read(extensionLength); + + uint64_t fileSize; + buffer.read(reinterpret_cast(&fileSize), sizeof(fileSize)); + + qDebug() << "UploadAssetTask reading a file of " << fileSize << "bytes and extension" << extension << "from" + << uuidStringWithoutCurlyBraces(_senderNode->getUUID()); + + auto replyPacket = NLPacket::create(PacketType::AssetUploadReply); + replyPacket->writePrimitive(messageID); + + if (fileSize > MAX_UPLOAD_SIZE) { + replyPacket->writePrimitive(AssetServerError::ASSET_TOO_LARGE); + } else { + QByteArray fileData = buffer.read(fileSize); + + auto hash = hashData(fileData); + auto hexHash = hash.toHex(); + + qDebug() << "Hash for uploaded file from" << uuidStringWithoutCurlyBraces(_senderNode->getUUID()) + << "is: (" << hexHash << ") "; + + QFile file { _resourcesDir.filePath(QString(hexHash)) + "." + QString(extension) }; + + if (file.exists()) { + qDebug() << "[WARNING] This file already exists: " << hexHash; + } else { + file.open(QIODevice::WriteOnly); + file.write(fileData); + file.close(); + } + replyPacket->writePrimitive(AssetServerError::NO_ERROR); + replyPacket->write(hash); + } + + auto nodeList = DependencyManager::get(); + nodeList->sendPacket(std::move(replyPacket), *_senderNode); +} diff --git a/assignment-client/src/assets/UploadAssetTask.h b/assignment-client/src/assets/UploadAssetTask.h new file mode 100644 index 0000000000..c310bfc948 --- /dev/null +++ b/assignment-client/src/assets/UploadAssetTask.h @@ -0,0 +1,37 @@ +// +// UploadAssetTask.h +// assignment-client/src/assets +// +// Created by Stephen Birarda on 2015-08-28. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#pragma once + +#ifndef hifi_UploadAssetTask_h +#define hifi_UploadAssetTask_h + +#include +#include +#include +#include + +class NLPacketList; +class Node; + +class UploadAssetTask : public QRunnable { +public: + UploadAssetTask(QSharedPointer packetList, QSharedPointer senderNode, const QDir& resourcesDir); + + void run(); + +private: + QSharedPointer _packetList; + QSharedPointer _senderNode; + QDir _resourcesDir; +}; + +#endif // hifi_UploadAssetTask_h diff --git a/libraries/networking/src/AssetUtils.h b/libraries/networking/src/AssetUtils.h index ce9f3f4354..ae6f51df64 100644 --- a/libraries/networking/src/AssetUtils.h +++ b/libraries/networking/src/AssetUtils.h @@ -12,7 +12,7 @@ #ifndef hifi_AssetUtils_h #define hifi_AssetUtils_h -#include "NLPacketList.h" +#include using MessageID = uint32_t; using DataOffset = int64_t; @@ -31,4 +31,6 @@ enum AssetServerError : uint8_t { const QString ATP_SCHEME = "atp"; +inline QByteArray hashData(const QByteArray& data) { return QCryptographicHash::hash(data, QCryptographicHash::Sha256); } + #endif diff --git a/libraries/networking/src/udt/SendQueue.h b/libraries/networking/src/udt/SendQueue.h index c6668f1d09..fe07495e55 100644 --- a/libraries/networking/src/udt/SendQueue.h +++ b/libraries/networking/src/udt/SendQueue.h @@ -111,6 +111,8 @@ private: std::atomic _flowWindowSize { 0 }; // Flow control window size (number of packets that can be on wire) - set from CC + time_point _flowWindowFullSince; + mutable std::mutex _naksLock; // Protects the naks list. LossList _naks; // Sequence numbers of packets to resend From f2cb85ab09bcd3e005d5b62e305fca1dffe5c276 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 28 Aug 2015 11:16:05 -0700 Subject: [PATCH 2/6] add missing break to switch for LightACK --- libraries/networking/src/udt/Connection.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/networking/src/udt/Connection.cpp b/libraries/networking/src/udt/Connection.cpp index 93c13874ea..a416991c7a 100644 --- a/libraries/networking/src/udt/Connection.cpp +++ b/libraries/networking/src/udt/Connection.cpp @@ -415,6 +415,7 @@ void Connection::processControl(std::unique_ptr controlPacket) { if (_hasReceivedHandshakeACK) { processLightACK(move(controlPacket)); } + break; case ControlPacket::ACK2: if (_hasReceivedHandshake) { processACK2(move(controlPacket)); From 058a3c422b547494441fef01f3e977fc3a0d7a8d Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 28 Aug 2015 11:32:17 -0700 Subject: [PATCH 3/6] re-remove the flow window full variable --- libraries/networking/src/udt/SendQueue.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/networking/src/udt/SendQueue.h b/libraries/networking/src/udt/SendQueue.h index fe07495e55..c6668f1d09 100644 --- a/libraries/networking/src/udt/SendQueue.h +++ b/libraries/networking/src/udt/SendQueue.h @@ -111,8 +111,6 @@ private: std::atomic _flowWindowSize { 0 }; // Flow control window size (number of packets that can be on wire) - set from CC - time_point _flowWindowFullSince; - mutable std::mutex _naksLock; // Protects the naks list. LossList _naks; // Sequence numbers of packets to resend From b9d1f39c652b0078b87b03ee74eb453828b12ee6 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 28 Aug 2015 12:36:44 -0700 Subject: [PATCH 4/6] remove include in SendQueue that is unneeded --- libraries/networking/src/udt/SendQueue.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/networking/src/udt/SendQueue.h b/libraries/networking/src/udt/SendQueue.h index c6668f1d09..c9a40a4a75 100644 --- a/libraries/networking/src/udt/SendQueue.h +++ b/libraries/networking/src/udt/SendQueue.h @@ -20,7 +20,6 @@ #include #include -#include #include "../HifiSockAddr.h" From dc7d7ef4442bc0a4ec1b14b56d5e10d88da577df Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 31 Aug 2015 15:17:40 -0600 Subject: [PATCH 5/6] make SendAssetTask be consistent with new UploadAssetTask --- assignment-client/src/assets/AssetServer.cpp | 48 ++++++++++--------- .../src/assets/SendAssetTask.cpp | 32 +++++++++---- assignment-client/src/assets/SendAssetTask.h | 18 ++++--- .../src/assets/UploadAssetTask.cpp | 19 -------- 4 files changed, 61 insertions(+), 56 deletions(-) diff --git a/assignment-client/src/assets/AssetServer.cpp b/assignment-client/src/assets/AssetServer.cpp index c046b39f66..62f1b877b5 100644 --- a/assignment-client/src/assets/AssetServer.cpp +++ b/assignment-client/src/assets/AssetServer.cpp @@ -125,39 +125,43 @@ void AssetServer::handleAssetGetInfo(QSharedPointer packet, SharedNode } void AssetServer::handleAssetGet(QSharedPointer packet, SharedNodePointer senderNode) { - MessageID messageID; - QByteArray assetHash; - uint8_t extensionLength; - DataOffset start; - DataOffset end; - auto minSize = qint64(sizeof(messageID) + SHA256_HASH_LENGTH + sizeof(extensionLength) + sizeof(start) + sizeof(end)); + auto minSize = qint64(sizeof(MessageID) + SHA256_HASH_LENGTH + sizeof(uint8_t) + sizeof(DataOffset) + sizeof(DataOffset)); + if (packet->getPayloadSize() < minSize) { qDebug() << "ERROR bad file request"; return; } - packet->readPrimitive(&messageID); - assetHash = packet->read(SHA256_HASH_LENGTH); - packet->readPrimitive(&extensionLength); - QByteArray extension = packet->read(extensionLength); - packet->readPrimitive(&start); - packet->readPrimitive(&end); - - QByteArray hexHash = assetHash.toHex(); - - qDebug() << "Received a request for the file (" << messageID << "): " << hexHash << " from " << start << " to " << end; - // Queue task - QString filePath = _resourcesDirectory.filePath(QString(hexHash) + "." + QString(extension)); - auto task = new SendAssetTask(messageID, assetHash, filePath, start, end, senderNode); + auto task = new SendAssetTask(packet, senderNode, _resourcesDirectory); _taskPool.start(task); } void AssetServer::handleAssetUpload(QSharedPointer packetList, SharedNodePointer senderNode) { - qDebug() << "Starting an UploadAssetTask for upload from" << uuidStringWithoutCurlyBraces(senderNode->getUUID()); - auto task = new UploadAssetTask(packetList, senderNode, _resourcesDirectory); - _taskPool.start(task); + if (senderNode->getCanRez()) { + qDebug() << "Starting an UploadAssetTask for upload from" << uuidStringWithoutCurlyBraces(senderNode->getUUID()); + + auto task = new UploadAssetTask(packetList, senderNode, _resourcesDirectory); + _taskPool.start(task); + } else { + // this is a node the domain told us is not allowed to rez entities + // for now this also means it isn't allowed to add assets + // so return a packet with error that indicates that + + auto permissionErrorPacket = NLPacket::create(PacketType::AssetUploadReply, sizeof(MessageID) + sizeof(AssetServerError)); + + MessageID messageID; + packetList->readPrimitive(&messageID); + + // write the message ID and a permission denied error + permissionErrorPacket->writePrimitive(messageID); + permissionErrorPacket->writePrimitive(AssetServerError::PERMISSION_DENIED); + + // send off the packet + auto nodeList = DependencyManager::get(); + nodeList->sendPacket(std::move(permissionErrorPacket), *senderNode); + } } diff --git a/assignment-client/src/assets/SendAssetTask.cpp b/assignment-client/src/assets/SendAssetTask.cpp index 91782b95ad..c4c7bf2503 100644 --- a/assignment-client/src/assets/SendAssetTask.cpp +++ b/assignment-client/src/assets/SendAssetTask.cpp @@ -18,23 +18,35 @@ #include #include #include +#include #include "AssetUtils.h" -SendAssetTask::SendAssetTask(MessageID messageID, const QByteArray& assetHash, QString filePath, DataOffset start, DataOffset end, - const SharedNodePointer& sendToNode) : +SendAssetTask::SendAssetTask(QSharedPointer packet, const SharedNodePointer& sendToNode, const QDir& resourcesDir) : QRunnable(), - _messageID(messageID), - _assetHash(assetHash), - _filePath(filePath), - _start(start), - _end(end), - _sendToNode(sendToNode) + _packet(packet), + _senderNode(sendToNode), + _resourcesDir(resourcesDir) { + } void SendAssetTask::run() { + MessageID messageID; + uint8_t extensionLength; + DataOffset start, end; + + _packet->readPrimitive(&messageID); + QByteArray assetHash = _packet->read(SHA256_HASH_LENGTH); + _packet->readPrimitive(&extensionLength); + QByteArray extension = _packet->read(extensionLength); + _packet->readPrimitive(&start); + _packet->readPrimitive(&end); + QString hexHash = _assetHash.toHex(); + + qDebug() << "Received a request for the file (" << messageID << "): " << hexHash << " from " << start << " to " << end; + qDebug() << "Starting task to send asset: " << hexHash << " for messageID " << _messageID; auto replyPacketList = std::unique_ptr(new NLPacketList(PacketType::AssetGetReply, QByteArray(), true, true)); @@ -45,6 +57,8 @@ void SendAssetTask::run() { if (_end <= _start) { writeError(replyPacketList.get(), AssetServerError::INVALID_BYTE_RANGE); } else { + QString filePath = _resourcesDir.filePath(QString(hexHash) + "." + QString(extension)); + QFile file { _filePath }; if (file.open(QIODevice::ReadOnly)) { @@ -67,5 +81,5 @@ void SendAssetTask::run() { } auto nodeList = DependencyManager::get(); - nodeList->sendPacketList(std::move(replyPacketList), *_sendToNode); + nodeList->sendPacketList(std::move(replyPacketList), *_senderNode); } diff --git a/assignment-client/src/assets/SendAssetTask.h b/assignment-client/src/assets/SendAssetTask.h index 477f42c1a3..1dc6c8dca2 100644 --- a/assignment-client/src/assets/SendAssetTask.h +++ b/assignment-client/src/assets/SendAssetTask.h @@ -12,28 +12,34 @@ #ifndef hifi_SendAssetTask_h #define hifi_SendAssetTask_h -#include -#include -#include +#include +#include +#include +#include #include "AssetUtils.h" #include "AssetServer.h" #include "Node.h" +namespace udt { + class Packet; +} + class SendAssetTask : public QRunnable { public: - SendAssetTask(MessageID messageID, const QByteArray& assetHash, QString filePath, DataOffset start, DataOffset end, - const SharedNodePointer& sendToNode); + SendAssetTask(QSharedPointer packet, const SharedNodePointer& sendToNode, const QDir& resourcesDir); void run(); private: + QSharedPointer _packet; MessageID _messageID; QByteArray _assetHash; QString _filePath; DataOffset _start; DataOffset _end; - SharedNodePointer _sendToNode; + SharedNodePointer _senderNode; + QDir _resourcesDir; }; #endif diff --git a/assignment-client/src/assets/UploadAssetTask.cpp b/assignment-client/src/assets/UploadAssetTask.cpp index 66fdc80e90..d4991f9554 100644 --- a/assignment-client/src/assets/UploadAssetTask.cpp +++ b/assignment-client/src/assets/UploadAssetTask.cpp @@ -37,25 +37,6 @@ void UploadAssetTask::run() { MessageID messageID; buffer.read(reinterpret_cast(&messageID), sizeof(messageID)); - if (!_senderNode->getCanRez()) { - // this is a node the domain told us is not allowed to rez entities - // for now this also means it isn't allowed to add assets - // so return a packet with error that indicates that - - auto permissionErrorPacket = NLPacket::create(PacketType::AssetUploadReply, sizeof(MessageID) + sizeof(AssetServerError)); - - // write the message ID and a permission denied error - permissionErrorPacket->writePrimitive(messageID); - permissionErrorPacket->writePrimitive(AssetServerError::PERMISSION_DENIED); - - // send off the packet - auto nodeList = DependencyManager::get(); - nodeList->sendPacket(std::move(permissionErrorPacket), *_senderNode); - - // return so we're not attempting to handle upload - return; - } - uint8_t extensionLength; buffer.read(reinterpret_cast(&extensionLength), sizeof(extensionLength)); From cb903a8d06471c9744ec0ed4076da65de657d0ef Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 31 Aug 2015 15:30:18 -0600 Subject: [PATCH 6/6] fix the new send asset task --- .../src/assets/SendAssetTask.cpp | 24 +++++++++---------- assignment-client/src/assets/SendAssetTask.h | 13 +++------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/assignment-client/src/assets/SendAssetTask.cpp b/assignment-client/src/assets/SendAssetTask.cpp index c4c7bf2503..8131bafaf3 100644 --- a/assignment-client/src/assets/SendAssetTask.cpp +++ b/assignment-client/src/assets/SendAssetTask.cpp @@ -22,7 +22,7 @@ #include "AssetUtils.h" -SendAssetTask::SendAssetTask(QSharedPointer packet, const SharedNodePointer& sendToNode, const QDir& resourcesDir) : +SendAssetTask::SendAssetTask(QSharedPointer packet, const SharedNodePointer& sendToNode, const QDir& resourcesDir) : QRunnable(), _packet(packet), _senderNode(sendToNode), @@ -43,31 +43,31 @@ void SendAssetTask::run() { _packet->readPrimitive(&start); _packet->readPrimitive(&end); - QString hexHash = _assetHash.toHex(); + QString hexHash = assetHash.toHex(); qDebug() << "Received a request for the file (" << messageID << "): " << hexHash << " from " << start << " to " << end; - qDebug() << "Starting task to send asset: " << hexHash << " for messageID " << _messageID; + qDebug() << "Starting task to send asset: " << hexHash << " for messageID " << messageID; auto replyPacketList = std::unique_ptr(new NLPacketList(PacketType::AssetGetReply, QByteArray(), true, true)); - replyPacketList->write(_assetHash); + replyPacketList->write(assetHash); - replyPacketList->writePrimitive(_messageID); + replyPacketList->writePrimitive(messageID); - if (_end <= _start) { + if (end <= start) { writeError(replyPacketList.get(), AssetServerError::INVALID_BYTE_RANGE); } else { QString filePath = _resourcesDir.filePath(QString(hexHash) + "." + QString(extension)); - QFile file { _filePath }; + QFile file { filePath }; if (file.open(QIODevice::ReadOnly)) { - if (file.size() < _end) { + if (file.size() < end) { writeError(replyPacketList.get(), AssetServerError::INVALID_BYTE_RANGE); - qCDebug(networking) << "Bad byte range: " << hexHash << " " << _start << ":" << _end; + qCDebug(networking) << "Bad byte range: " << hexHash << " " << start << ":" << end; } else { - auto size = _end - _start; - file.seek(_start); + auto size = end - start; + file.seek(start); replyPacketList->writePrimitive(AssetServerError::NO_ERROR); replyPacketList->writePrimitive(size); replyPacketList->write(file.read(size)); @@ -75,7 +75,7 @@ void SendAssetTask::run() { } file.close(); } else { - qCDebug(networking) << "Asset not found: " << _filePath << "(" << hexHash << ")"; + qCDebug(networking) << "Asset not found: " << filePath << "(" << hexHash << ")"; writeError(replyPacketList.get(), AssetServerError::ASSET_NOT_FOUND); } } diff --git a/assignment-client/src/assets/SendAssetTask.h b/assignment-client/src/assets/SendAssetTask.h index 1dc6c8dca2..4e1a35b3fe 100644 --- a/assignment-client/src/assets/SendAssetTask.h +++ b/assignment-client/src/assets/SendAssetTask.h @@ -21,23 +21,16 @@ #include "AssetServer.h" #include "Node.h" -namespace udt { - class Packet; -} +class NLPacket; class SendAssetTask : public QRunnable { public: - SendAssetTask(QSharedPointer packet, const SharedNodePointer& sendToNode, const QDir& resourcesDir); + SendAssetTask(QSharedPointer packet, const SharedNodePointer& sendToNode, const QDir& resourcesDir); void run(); private: - QSharedPointer _packet; - MessageID _messageID; - QByteArray _assetHash; - QString _filePath; - DataOffset _start; - DataOffset _end; + QSharedPointer _packet; SharedNodePointer _senderNode; QDir _resourcesDir; };