From 0b4caeda73ccd5a7a139727a4f9478df8ea43470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= Date: Sat, 19 Dec 2020 20:06:50 -0500 Subject: [PATCH] dht: don't send unnecessary findNode --- src/dht.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/dht.cpp b/src/dht.cpp index ef174806..6de05a35 100644 --- a/src/dht.cpp +++ b/src/dht.cpp @@ -382,7 +382,7 @@ Dht::searchSendGetValues(Sp sr, SearchNode* pn, bool update) } if (sr->callbacks.empty()) { /* 'find_node' request */ - if (not n) + if (not n or n->isSynced(now)) return nullptr; /* if (logger_) @@ -491,9 +491,9 @@ void Dht::searchSendAnnounceValue(const Sp& sr) { sr->id.toString().c_str(), sn->node->toString().c_str(), a.value->id); sn->acked[a.value->id] = { network_engine.sendRefreshValue(sn->node, sr->id, a.value->id, sn->token, onDone, - [this, ws, node=sn->node, v=a.value, - onDone, - onExpired, + [this, ws, node=sn->node, v=a.value, + onDone, + onExpired, created = a.permanent ? time_point::max() : a.created, next_refresh_time ](const net::Request& /*req*/, net::DhtProtocolException&& e){ @@ -591,7 +591,7 @@ Dht::searchSynchedNodeListen(const Sp& sr, SearchNode& n) std::weak_ptr ws = sr; for (const auto& l : sr->listeners) { const auto& query = l.second.query; - + auto r = n.listenStatus.find(query); if (n.getListenTime(r, listenExp) > scheduler.time()) continue; @@ -725,7 +725,7 @@ Dht::searchStep(Sp sr) while (sr->currentlySolicitedNodeCount() < MAX_REQUESTED_SEARCH_NODES and searchSendGetValues(sr)); - + if (sr->getNumberOfConsecutiveBadNodes() >= std::min(sr->nodes.size(), SEARCH_MAX_BAD_NODES)) { if (logger_) @@ -2528,7 +2528,7 @@ Dht::saveState(const std::string& path) const state.nodes = exportNodes(); state.values = exportValues(); std::ofstream file(path); - msgpack::pack(file, state); + msgpack::pack(file, state); } void