From d1c2b20b284b6f0b4332bd38262eacd4b5cccb9a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simon=20D=C3=A9saulniers?= <sim.desaulniers@gmail.com>
Date: Tue, 20 Sep 2016 18:57:21 -0400
Subject: [PATCH] dht: canGet must allow sending when no token

---
 src/dht.cpp | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/dht.cpp b/src/dht.cpp
index 9bcbbd6f..9abbf363 100644
--- a/src/dht.cpp
+++ b/src/dht.cpp
@@ -275,19 +275,25 @@ struct Dht::SearchNode {
      * @return true if we can send get, else false.
      */
     bool canGet(time_point now, time_point update, std::shared_ptr<Query> q = {}) const {
-        if (node->isExpired() or not (now > last_get_reply + Node::NODE_EXPIRE_TIME or update > last_get_reply))
+        if (node->isExpired())
             return false;
 
-        auto completed_sq_status {false}, pending_sq_status {false};
+        auto pending {false}, completed_sq_status {false}, pending_sq_status {false};
         for (const auto& s : getStatus) {
+            if (s.second and s.second->pending())
+                pending = true;
             if (s.first and q and q->isSatisfiedBy(*s.first) and s.second) {
                 if (s.second->pending() and not pending_sq_status)
                     pending_sq_status = true;
-                if (s.second->reply_time > update and not completed_sq_status)
+                if (s.second->completed() and not (update > s.second->reply_time) and not completed_sq_status)
                     completed_sq_status = true;
+                if (completed_sq_status and pending_sq_status)
+                    break;
             }
         }
-        return not (hasStartedPagination(q) or completed_sq_status or pending_sq_status);
+
+        return (not pending and now > last_get_reply + Node::NODE_EXPIRE_TIME) or
+                not (hasStartedPagination(q) or completed_sq_status or pending_sq_status);
     }
 
     /**
-- 
GitLab