diff --git a/src/jamidht/conversation.cpp b/src/jamidht/conversation.cpp index 93f082d13252ede3f60bece8b9b75d57798a02d9..cea344fe15e0a72bf57b2406cb4f4af13d88c720 100644 --- a/src/jamidht/conversation.cpp +++ b/src/jamidht/conversation.cpp @@ -1853,7 +1853,7 @@ Conversation::checkBootstrapMember(const asio::error_code& ec, } void -Conversation::bootstrap(std::function<void()> onBootstraped) +Conversation::bootstrap(std::function<void()> onBootstraped, const std::vector<DeviceId>& knownDevices) { if (!pimpl_ || !pimpl_->repository_ || !pimpl_->swarmManager_) return; @@ -1861,15 +1861,9 @@ Conversation::bootstrap(std::function<void()> onBootstraped) // If this doesn't work, it will try to fallback with checkBootstrapMember // If it works, the callback onConnectionChanged will be called with ok=true pimpl_->bootstrapCb_ = std::move(onBootstraped); - std::vector<DeviceId> devices; + std::vector<DeviceId> devices = knownDevices; for (const auto& m : pimpl_->repository_->devices()) devices.insert(devices.end(), m.second.begin(), m.second.end()); - // Add known devices - if (auto acc = pimpl_->account_.lock()) { - for (const auto& [id, _] : acc->getKnownDevices()) { - devices.emplace_back(id); - } - } JAMI_DEBUG("{}[SwarmManager {}] Bootstrap with {} devices", pimpl_->toString(), fmt::ptr(pimpl_->swarmManager_.get()), diff --git a/src/jamidht/conversation.h b/src/jamidht/conversation.h index 5b468745e8fc27a4dddbaece89d5b6baff6f6f19..46812fcb7ae23e23fbf0ca67fb87183017e8a202 100644 --- a/src/jamidht/conversation.h +++ b/src/jamidht/conversation.h @@ -154,8 +154,9 @@ public: /** * Bootstrap swarm manager to other peers * @param onBootstraped Callback called when connection is successfully established + * @param knownDevices List of account's known devices */ - void bootstrap(std::function<void()> onBootstraped); + void bootstrap(std::function<void()> onBootstraped, const std::vector<DeviceId>& knownDevices); /** * Refresh active calls. diff --git a/src/jamidht/conversation_module.cpp b/src/jamidht/conversation_module.cpp index 1125efd3600b174747fab9bc6920f310afbf6a15..62f5af68207b2684c82ac00a958cd5e11083c9f2 100644 --- a/src/jamidht/conversation_module.cpp +++ b/src/jamidht/conversation_module.cpp @@ -556,6 +556,9 @@ ConversationModule::Impl::handlePendingConversation(const std::string& conversat auto acc = account_.lock(); if (!acc) return; + std::vector<DeviceId> kd; + for (const auto& [id, _] : acc->getKnownDevices()) + kd.emplace_back(id); auto erasePending = [&] { std::string toRm; { @@ -589,7 +592,7 @@ ConversationModule::Impl::handlePendingConversation(const std::string& conversat conversation->onBootstrapStatus(bootstrapCbTest_); #endif // LIBJAMI_TESTABLE conversation->bootstrap( - std::bind(&ConversationModule::Impl::bootstrapCb, this, conversation->id())); + std::bind(&ConversationModule::Impl::bootstrapCb, this, conversation->id()), kd); auto removeRepo = false; { std::lock_guard<std::mutex> lk(conversationsMtx_); @@ -1244,13 +1247,17 @@ ConversationModule::loadConversations() void ConversationModule::bootstrap(const std::string& convId) { + std::vector<DeviceId> kd; + if (auto acc = pimpl_->account_.lock()) + for (const auto& [id, _] : acc->getKnownDevices()) + kd.emplace_back(id); auto bootstrap = [&](auto& conv) { if (conv) { #ifdef LIBJAMI_TESTABLE conv->onBootstrapStatus(pimpl_->bootstrapCbTest_); #endif // LIBJAMI_TESTABLE conv->bootstrap( - std::bind(&ConversationModule::Impl::bootstrapCb, pimpl_.get(), conv->id())); + std::bind(&ConversationModule::Impl::bootstrapCb, pimpl_.get(), conv->id()), kd); } }; std::unique_lock<std::mutex> lk(pimpl_->conversationsMtx_); @@ -1477,6 +1484,9 @@ ConversationModule::startConversation(ConversationMode mode, const std::string& auto acc = pimpl_->account_.lock(); if (!acc) return {}; + std::vector<DeviceId> kd; + for (const auto& [id, _] : acc->getKnownDevices()) + kd.emplace_back(id); // Create the conversation object std::shared_ptr<Conversation> conversation; try { @@ -1488,7 +1498,7 @@ ConversationModule::startConversation(ConversationMode mode, const std::string& conversation->onBootstrapStatus(pimpl_->bootstrapCbTest_); #endif // LIBJAMI_TESTABLE conversation->bootstrap( - std::bind(&ConversationModule::Impl::bootstrapCb, pimpl_.get(), conversation->id())); + std::bind(&ConversationModule::Impl::bootstrapCb, pimpl_.get(), conversation->id()), kd); } catch (const std::exception& e) { JAMI_ERR("[Account %s] Error while generating a conversation %s", pimpl_->accountId_.c_str(), diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp index d485d3a277532988fa64ecce2ee2572bcb66f280..2a40a7db3e9e339447153c28e064affef7b59756 100644 --- a/src/jamidht/jamiaccount.cpp +++ b/src/jamidht/jamiaccount.cpp @@ -1939,11 +1939,8 @@ JamiAccount::doRegister_() // Bootstrap at the end to avoid to be long to load. dht::ThreadPool::io().run([w = weak()] { - if (auto shared = w.lock()) { - std::lock_guard<std::recursive_mutex> lock( - shared->configurationMutex_); + if (auto shared = w.lock()) shared->convModule()->bootstrap(); - } }); emitSignal<libjami::ConfigurationSignal::VolatileDetailsChanged>( accountID_, getVolatileAccountDetails());