mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 20:44:14 +02:00
Update AssetClient to handle disconnections from a node
This commit is contained in:
parent
3ae323cb2e
commit
42b4c7d423
2 changed files with 40 additions and 1 deletions
|
@ -31,10 +31,13 @@ AssetClient::AssetClient() {
|
|||
static_cast<AssetClient*>(dependency)->deleteLater();
|
||||
});
|
||||
|
||||
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
auto& packetReceiver = nodeList->getPacketReceiver();
|
||||
packetReceiver.registerListener(PacketType::AssetGetInfoReply, this, "handleAssetGetInfoReply");
|
||||
packetReceiver.registerMessageListener(PacketType::AssetGetReply, this, "handleAssetGetReply");
|
||||
packetReceiver.registerListener(PacketType::AssetUploadReply, this, "handleAssetUploadReply");
|
||||
|
||||
connect(nodeList.data(), &LimitedNodeList::nodeKilled, this, &AssetClient::handleNodeKilled);
|
||||
}
|
||||
|
||||
AssetRequest* AssetClient::createRequest(const QString& hash, const QString& extension) {
|
||||
|
@ -281,3 +284,36 @@ void AssetClient::handleAssetUploadReply(QSharedPointer<NLPacket> packet, Shared
|
|||
// it to avoid constantly creating/deleting the map on subsequent requests.
|
||||
}
|
||||
}
|
||||
|
||||
void AssetClient::handleNodeKilled(SharedNodePointer node) {
|
||||
{
|
||||
auto messageMapIt = _pendingRequests.find(node);
|
||||
if (messageMapIt != _pendingRequests.end()) {
|
||||
for (const auto& value : messageMapIt->second) {
|
||||
value.second(AssetServerError::NetworkError, QByteArray());
|
||||
}
|
||||
messageMapIt->second.clear();
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto messageMapIt = _pendingInfoRequests.find(node);
|
||||
if (messageMapIt != _pendingInfoRequests.end()) {
|
||||
AssetInfo info { "", 0 };
|
||||
for (const auto& value : messageMapIt->second) {
|
||||
value.second(AssetServerError::NetworkError, info);
|
||||
}
|
||||
messageMapIt->second.clear();
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto messageMapIt = _pendingUploads.find(node);
|
||||
if (messageMapIt != _pendingUploads.end()) {
|
||||
for (const auto& value : messageMapIt->second) {
|
||||
value.second(AssetServerError::NetworkError, "");
|
||||
}
|
||||
messageMapIt->second.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "AssetUtils.h"
|
||||
#include "LimitedNodeList.h"
|
||||
#include "NLPacket.h"
|
||||
#include "Node.h"
|
||||
|
||||
class AssetRequest;
|
||||
class AssetUpload;
|
||||
|
@ -46,6 +47,8 @@ private slots:
|
|||
void handleAssetGetReply(QSharedPointer<NLPacketList> packetList, SharedNodePointer senderNode);
|
||||
void handleAssetUploadReply(QSharedPointer<NLPacket> packet, SharedNodePointer senderNode);
|
||||
|
||||
void handleNodeKilled(SharedNodePointer node);
|
||||
|
||||
private:
|
||||
bool getAssetInfo(const QString& hash, const QString& extension, GetInfoCallback callback);
|
||||
bool getAsset(const QString& hash, const QString& extension, DataOffset start, DataOffset end, ReceivedAssetCallback callback);
|
||||
|
|
Loading…
Reference in a new issue