Skip to content

Commit

Permalink
conversation: fix download file transfer
Browse files Browse the repository at this point in the history
Change-Id: I4037895ce57758541e61a89b7efeaccd71e79c5a
  • Loading branch information
katekm committed Sep 22, 2023
1 parent 3bbac87 commit 8b3a5eb
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/jamidht/conversation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1574,19 +1574,30 @@ Conversation::downloadFile(const std::string& interactionId,
std::size_t end)
{
auto commit = getCommit(interactionId);
if (commit == std::nullopt || commit->find("type") == commit->end()
|| commit->find("sha3sum") == commit->end() || commit->find("tid") == commit->end()
|| commit->at("type") != "application/data-transfer+json") {
JAMI_ERR() << "Cannot download file without linked interaction " << fileId;
if (commit == std::nullopt || commit->at("type") != "application/data-transfer+json") {
JAMI_ERROR("Commit doesn't exists or is not a file transfer");
return false;
}
auto tid = commit->find("tid");
auto sha3sum = commit->find("sha3sum");
auto size_str = commit->find("totalSize");

if (tid == commit->end() || sha3sum == commit->end() || size_str == commit->end()) {
JAMI_ERROR("Invalid file transfer commit (missing tid, size or sha3)");
return false;
}

auto totalSize = to_int<ssize_t>(size_str->second, (ssize_t)-1);
if (totalSize < 0) {
JAMI_ERROR("Invalid file size {}", totalSize);
return false;
}
auto sha3sum = commit->at("sha3sum");
auto size_str = commit->at("totalSize");
auto totalSize = to_int<size_t>(size_str);

// Be sure to not lock conversation
dht::ThreadPool().io().run(
[w = weak(), deviceId, fileId, interactionId, sha3sum, path, totalSize, start, end] {
[w = weak(),
deviceId,
fileId, interactionId, sha3sum=sha3sum->second, path, totalSize, start, end] {
if (auto shared = w.lock()) {
auto acc = shared->pimpl_->account_.lock();
if (!acc)
Expand Down

0 comments on commit 8b3a5eb

Please sign in to comment.