Skip to content
Snippets Groups Projects
Commit a39e2443 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

dht: reuse probe query, avoid leak

parent 57528e7a
Branches
Tags
No related merge requests found
...@@ -487,15 +487,16 @@ void Dht::searchSendAnnounceValue(const Sp<Search>& sr) { ...@@ -487,15 +487,16 @@ void Dht::searchSendAnnounceValue(const Sp<Search>& sr) {
} }
}; };
Sp<Query> probe_query {}; static const auto PROBE_QUERY = std::make_shared<Query>(Select {}.field(Value::Field::Id).field(Value::Field::SeqNum));
const auto& now = scheduler.time(); const auto& now = scheduler.time();
for (auto& np : sr->nodes) { for (auto& np : sr->nodes) {
auto& n = *np; auto& n = *np;
if (not n.isSynced(now)) if (not n.isSynced(now))
continue; continue;
const auto& gs = n.probe_query ? n.getStatus.find(n.probe_query) : n.getStatus.cend(); auto gs = n.probe_query ? n.getStatus.find(n.probe_query) : n.getStatus.end();
if (gs != n.getStatus.cend() and gs->second and gs->second->pending()) { if (gs != n.getStatus.end() and gs->second and gs->second->pending()) {
continue; continue;
} }
...@@ -517,18 +518,19 @@ void Dht::searchSendAnnounceValue(const Sp<Search>& sr) { ...@@ -517,18 +518,19 @@ void Dht::searchSendAnnounceValue(const Sp<Search>& sr) {
} }
if (sendQuery) { if (sendQuery) {
if (not probe_query) if (gs == n.getStatus.cend()) {
probe_query = std::make_shared<Query>(Select {}.field(Value::Field::Id).field(Value::Field::SeqNum)); n.probe_query = PROBE_QUERY;
gs = n.getStatus.emplace(n.probe_query, Sp<net::Request>()).first;
}
if (logger_) if (logger_)
logger_->d(sr->id, n.node->id, "[search %s] [node %s] sending %s", logger_->d(sr->id, n.node->id, "[search %s] [node %s] sending %s",
sr->id.toString().c_str(), n.node->toString().c_str(), probe_query->toString().c_str()); sr->id.toString().c_str(), n.node->toString().c_str(), n.probe_query->toString().c_str());
n.probe_query = probe_query; gs->second = network_engine.sendGetValues(n.node,
n.getStatus[probe_query] = network_engine.sendGetValues(n.node,
sr->id, sr->id,
*probe_query, *PROBE_QUERY,
-1, -1,
onSelectDone, onSelectDone,
std::bind(&Dht::searchNodeGetExpired, this, _1, _2, ws, probe_query)); std::bind(&Dht::searchNodeGetExpired, this, _1, _2, ws, PROBE_QUERY));
} }
if (not n.candidate and ++i == TARGET_NODES) if (not n.candidate and ++i == TARGET_NODES)
break; break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment