From 995196ce08b099fbeb305689babc125afdd84413 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Sat, 23 Apr 2016 02:26:29 -0400
Subject: [PATCH] clear getStatus after token error

---
 src/dht.cpp            | 8 +++++---
 src/network_engine.cpp | 2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/dht.cpp b/src/dht.cpp
index bc6997f1..390d321c 100644
--- a/src/dht.cpp
+++ b/src/dht.cpp
@@ -805,7 +805,7 @@ Dht::searchSendGetValues(std::shared_ptr<Search> sr, SearchNode* pn, bool update
 void
 Dht::searchStep(std::shared_ptr<Search> sr)
 {
-    if (not sr) return;
+    if (not sr or sr->expired) return;
 
     const auto& now = scheduler.time();
     DHT_LOG.DEBUG("[search %s IPv%c] step", sr->id.toString().c_str(), sr->af == AF_INET ? '4' : '6');
@@ -2534,6 +2534,8 @@ Dht::onError(std::shared_ptr<NetworkEngine::Request> status, DhtProtocolExceptio
             auto& sr = srp.second;
             for (auto& n : sr->nodes) {
                 if (n.node != status->node) continue;
+                n.getStatus = {};
+                n.last_get_reply = time_point::min();
                 cleared++;
                 if (searchSendGetValues(sr))
                     sr->get_step_time = scheduler.time();
@@ -2694,7 +2696,6 @@ void
 Dht::onListenDone(std::shared_ptr<NetworkEngine::Request>& status, NetworkEngine::RequestAnswer& answer, std::shared_ptr<Search>& sr)
 {
     DHT_LOG.DEBUG("[search %s] Got reply to listen.", sr->id.toString().c_str());
-    const auto& now = scheduler.time();
     if (sr) {
         if (not answer.values.empty()) { /* got new values from listen request */
             DHT_LOG.DEBUG("[listen %s] Got new values.", sr->id.toString().c_str());
@@ -2702,9 +2703,10 @@ Dht::onListenDone(std::shared_ptr<NetworkEngine::Request>& status, NetworkEngine
         }
 
         if (not sr->done) {
+            const auto& now = scheduler.time();
             if (searchSendGetValues(sr))
                 sr->get_step_time = now;
-            scheduler.edit(sr->nextSearchStep, now);
+            scheduler.edit(sr->nextSearchStep, sr->getNextStepTime(types, now));
         }
     } else
         DHT_LOG.DEBUG("Unknown search or announce!");
diff --git a/src/network_engine.cpp b/src/network_engine.cpp
index c03093a3..123c2e1b 100644
--- a/src/network_engine.cpp
+++ b/src/network_engine.cpp
@@ -228,7 +228,7 @@ NetworkEngine::processMessage(const uint8_t *buf, size_t buflen, const sockaddr
         } catch (const std::overflow_error& e) {
             DHT_LOG.ERROR("Can't send value: buffer not large enough !");
         } catch (DhtProtocolException& e) {
-            sendError(from, fromlen, msg.tid, e.getCode(), e.getMsg().c_str());
+            sendError(from, fromlen, msg.tid, e.getCode(), e.getMsg().c_str(), true);
         }
     }
 }
-- 
GitLab