diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp index 52b8d915125f321b08136b12f4da6f2d4be6230d..af59cee5b8f6fb2e9add77acbbb5d7baf92913c5 100644 --- a/src/jamidht/jamiaccount.cpp +++ b/src/jamidht/jamiaccount.cpp @@ -2241,18 +2241,21 @@ JamiAccount::convModule(bool noCreation) shared->connectionManager_->connectDevice( DeviceId(deviceId), - "git://" + deviceId + "/" + convId, - [shared, cb, convId](std::shared_ptr<dhtnet::ChannelSocket> socket, + fmt::format("git://{}/{}", deviceId, convId), + [w, cb = std::move(cb), convId](std::shared_ptr<dhtnet::ChannelSocket> socket, const DeviceId&) { - if (socket) { - socket->onShutdown([shared, deviceId = socket->deviceId(), convId] { - shared->convModule()->removeGitSocket(deviceId.toString(), - convId); - }); - if (!cb(socket)) - socket->shutdown(); - } else - cb({}); + dht::ThreadPool::io().run([w, cb = std::move(cb), socket=std::move(socket), convId] { + if (socket) { + socket->onShutdown([w, deviceId = socket->deviceId(), convId] { + if (auto shared = w.lock()) + shared->convModule()->removeGitSocket(deviceId.toString(), + convId); + }); + if (!cb(socket)) + socket->shutdown(); + } else + cb({}); + }); }, false, false, @@ -2260,7 +2263,7 @@ JamiAccount::convModule(bool noCreation) }); }, [this](const auto& convId, const auto& deviceId, auto&& cb, const auto& connectionType) { - dht::ThreadPool::io().run([w = weak(), convId, deviceId, cb, connectionType] { + dht::ThreadPool::io().run([w = weak(), convId, deviceId, cb=std::move(cb), connectionType] { auto shared = w.lock(); if (!shared) return; @@ -2276,23 +2279,25 @@ JamiAccount::convModule(bool noCreation) shared->connectionManager_->connectDevice( DeviceId(deviceId), fmt::format("swarm://{}", convId), - [w, cb](std::shared_ptr<dhtnet::ChannelSocket> socket, + [w, cb=std::move(cb)](std::shared_ptr<dhtnet::ChannelSocket> socket, const DeviceId& deviceId) { - if (socket) { - auto shared = w.lock(); - if (!shared) - return; - auto remoteCert = socket->peerCertificate(); - auto uri = remoteCert->issuer->getId().toString(); - if (shared->accountManager()->getCertificateStatus(uri) - == dhtnet::tls::TrustStore::PermissionStatus::BANNED) { - cb(nullptr); - return; + dht::ThreadPool::io().run([w, cb = std::move(cb), socket=std::move(socket), deviceId] { + if (socket) { + auto shared = w.lock(); + if (!shared) + return; + auto remoteCert = socket->peerCertificate(); + auto uri = remoteCert->issuer->getId().toString(); + if (shared->accountManager()->getCertificateStatus(uri) + == dhtnet::tls::TrustStore::PermissionStatus::BANNED) { + cb(nullptr); + return; + } + + shared->requestSIPConnection(uri, deviceId, ""); } - - shared->requestSIPConnection(uri, deviceId, ""); - } - cb(socket); + cb(socket); + }); }); } });