Skip to content
Snippets Groups Projects
Commit 8c5c1c23 authored by Adrien Béraud's avatar Adrien Béraud Committed by François-Simon Fauteux-Chapleau
Browse files

TransferChannelHandler: run on io pool

GitLab: #1110
Change-Id: I36e090fcb6c44b2483b1765786d64be108d93d21
parent 8eb66bf8
Branches
Tags
No related merge requests found
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "jamidht/transfer_channel_handler.h" #include "jamidht/transfer_channel_handler.h"
#include <opendht/thread_pool.h>
#include <charconv> #include <charconv>
#include "fileutils.h" #include "fileutils.h"
...@@ -118,7 +119,7 @@ TransferChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>& ...@@ -118,7 +119,7 @@ TransferChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>&
sha3Sum = keyVal[1]; sha3Sum = keyVal[1];
} else if (keyVal[0] == "modified") { } else if (keyVal[0] == "modified") {
try { try {
lastModified = jami::to_int<uint64_t>(keyVal[1]); lastModified = to_int<uint64_t>(keyVal[1]);
} catch (const std::exception& e) { } catch (const std::exception& e) {
JAMI_WARNING("TransferChannel: Unable to parse modified date: {}: {}", JAMI_WARNING("TransferChannel: Unable to parse modified date: {}: {}",
keyVal[1], keyVal[1],
...@@ -130,6 +131,8 @@ TransferChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>& ...@@ -130,6 +131,8 @@ TransferChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>&
// Check if profile // Check if profile
if (idstr == "profile.vcf") { if (idstr == "profile.vcf") {
dht::ThreadPool::io().run([wacc = acc->weak(), path = idPath_ / "profile.vcf", channel, idstr, lastModified, sha3Sum] {
if (auto acc = wacc.lock()) {
if (!channel->isInitiator()) { if (!channel->isInitiator()) {
// Only accept newest profiles // Only accept newest profiles
if (lastModified == 0 if (lastModified == 0
...@@ -139,15 +142,16 @@ TransferChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>& ...@@ -139,15 +142,16 @@ TransferChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>&
channel->shutdown(); channel->shutdown();
} else { } else {
// If it's a profile from sync // If it's a profile from sync
auto path = idPath_ / "profile.vcf";
acc->dataTransfer()->transferFile(channel, idstr, "", path.string()); acc->dataTransfer()->transferFile(channel, idstr, "", path.string());
} }
}
});
return; return;
} }
auto splitted_id = split_string(idstr, '/'); auto splitted_id = split_string(idstr, '/');
if (splitted_id.size() < 3) { if (splitted_id.size() < 3) {
JAMI_ERR() << "Unsupported ID detected " << name; JAMI_ERROR("Unsupported ID detected {}", name);
channel->shutdown(); channel->shutdown();
return; return;
} }
...@@ -161,9 +165,10 @@ TransferChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>& ...@@ -161,9 +165,10 @@ TransferChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>&
return; return;
// Profile for a member in the conversation // Profile for a member in the conversation
dht::ThreadPool::io().run([wacc = acc->weak(), profilePath = idPath_ / "profile.vcf", channel, conversationId, fileId, isContactProfile, idstr, start, end, sha3Sum] {
if (auto acc = wacc.lock()) {
if (fileId == fmt::format("{}.vcf", acc->getUsername())) { if (fileId == fmt::format("{}.vcf", acc->getUsername())) {
auto path = idPath_ / "profile.vcf"; acc->dataTransfer()->transferFile(channel, fileId, "", profilePath.string());
acc->dataTransfer()->transferFile(channel, fileId, "", path.string());
return; return;
} else if (isContactProfile && fileId.find(".vcf") != std::string::npos) { } else if (isContactProfile && fileId.find(".vcf") != std::string::npos) {
auto path = acc->dataTransfer()->profilePath(fileId.substr(0, fileId.size() - 4)); auto path = acc->dataTransfer()->profilePath(fileId.substr(0, fileId.size() - 4));
...@@ -175,7 +180,7 @@ TransferChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>& ...@@ -175,7 +180,7 @@ TransferChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>&
} }
// Check if it's a file in a conversation // Check if it's a file in a conversation
auto dt = acc->dataTransfer(conversationId); auto dt = acc->dataTransfer(conversationId);
sep = fileId.find('_'); auto sep = fileId.find('_');
if (!dt or sep == std::string::npos) { if (!dt or sep == std::string::npos) {
channel->shutdown(); channel->shutdown();
return; return;
...@@ -184,5 +189,7 @@ TransferChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>& ...@@ -184,5 +189,7 @@ TransferChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>&
auto path = dt->path(fileId); auto path = dt->path(fileId);
dt->transferFile(channel, fileId, interactionId, path.string(), start, end); dt->transferFile(channel, fileId, interactionId, path.string(), start, end);
} }
});
}
} // namespace jami } // namespace jami
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment