From 5277b8d23ea29b44e02cf78dafb6a2cf4afed607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Sun, 23 Oct 2016 03:23:17 -0400 Subject: [PATCH] dht: storage refresh returns bool --- src/dht.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/dht.cpp b/src/dht.cpp index e2e2d12b..765cc039 100644 --- a/src/dht.cpp +++ b/src/dht.cpp @@ -185,15 +185,17 @@ struct Dht::Storage { /** * Refreshes the time point of the value's lifetime begining. * - * @param now The reference to now; - * @param vid The value id; + * @param now The reference to now + * @param vid The value id + * @return true if a value storage was updated, false otherwise */ - void refresh(const time_point& now, const Value::Id& vid) { - auto vs = std::find_if(values.begin(), values.end(), [&vid](const ValueStorage& vs) { - return vs.data->id == vid; - }); - if (vs != values.end()) - vs->time = now; + bool refresh(const time_point& now, const Value::Id& vid) { + for (auto& vs : values) + if (vs.data->id == vid) { + vs.time = now; + return true; + } + return false; } std::pair<ssize_t, ssize_t> expire(const std::map<ValueType::Id, ValueType>& types, time_point now); @@ -3338,9 +3340,8 @@ Dht::onRefresh(std::shared_ptr<Node> node, const InfoHash& hash, const Blob& tok } auto s = store.find(hash); - if (s != store.end()) { - DHT_LOG.DEBUG("[Storage %s] refreshed value (vid: %d).", hash.toString().c_str(), vid); - s->second.refresh(now, vid); + if (s != store.end() and s->second.refresh(now, vid)) { + DHT_LOG.DEBUG("[store %s] refreshed value %s.", hash.toString().c_str(), std::to_string(vid).c_str()); } else { DHT_LOG.DEBUG("[node %s] got refresh value for unknown storage (id: %s).", node->id.toString().c_str(), -- GitLab