diff --git a/src/jamidht/swarm/swarm_manager.cpp b/src/jamidht/swarm/swarm_manager.cpp index 8d042ca3e2dc88f8e11cdfd1a3fa1e3fa35a8734..1127db3b6be4322eeac33a474dbd1a4c5c324088 100644 --- a/src/jamidht/swarm/swarm_manager.cpp +++ b/src/jamidht/swarm/swarm_manager.cpp @@ -55,15 +55,22 @@ SwarmManager::setKnownNodes(const std::vector<NodeId>& known_nodes) } } } - // If we detect a new node which already got a TCP link - // we can use it to speed-up the bootstrap (because opening - // a new channel will be easy) - std::set<NodeId> toConnect; - for (const auto& nodeId: newNodes) { - if (toConnectCb_ && toConnectCb_(nodeId)) - toConnect.emplace(nodeId); - } - maintainBuckets(toConnect); + + dht::ThreadPool::io().run([w=weak(), newNodes=std::move(newNodes)] { + auto shared = w.lock(); + if (!shared) + return; + // If we detect a new node which already got a TCP link + // we can use it to speed-up the bootstrap (because opening + // a new channel will be easy) + std::set<NodeId> toConnect; + for (const auto& nodeId: newNodes) { + if (shared->toConnectCb_ && shared->toConnectCb_(nodeId)) + toConnect.emplace(nodeId); + } + shared->maintainBuckets(toConnect); + }); + } void