From 1ab615096c6c147aab79cc664f0e89b0c35b8215 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 44a50cce..e1e81063 100644 --- a/src/dht.cpp +++ b/src/dht.cpp @@ -571,9 +571,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; @@ -903,10 +900,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