From 54a4327039e8f657494bf8ac2087cac1ff0cce0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20D=C3=A9saulniers?= <sim.desaulniers@gmail.com> Date: Thu, 2 Jun 2016 17:31:13 -0400 Subject: [PATCH] dht: handle search expired before permanent put --- src/dht.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/dht.cpp b/src/dht.cpp index 00b9b894..d9969fe3 100644 --- a/src/dht.cpp +++ b/src/dht.cpp @@ -580,9 +580,6 @@ Dht::Search::removeExpiredNode(time_point now) bool Dht::Search::insertNode(const std::shared_ptr<Node>& snode, time_point now, const Blob& token) { - if (expired and nodes.empty()) - return false; - auto& node = *snode; const auto& nid = node.id; @@ -912,10 +909,14 @@ Dht::searchStep(std::shared_ptr<Search> sr) { std::vector<DoneCallback> a_cbs; a_cbs.reserve(sr->announce.size()); - for (const auto& a : sr->announce) - if (a.callback) - a_cbs.emplace_back(std::move(a.callback)); - sr->announce.clear(); + for (auto ait = sr->announce.begin() ; ait != sr->announce.end(); ) { + if (ait->callback) + a_cbs.emplace_back(std::move(ait->callback)); + if (not ait->permanent) + ait = sr->announce.erase(ait); + else + ait++; + } for (const auto& a : a_cbs) a(false, {}); } -- GitLab