From 87041e301fd0f88360e993eceb4cbe8c1c146ac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Thu, 2 Jan 2020 12:06:38 -0500 Subject: [PATCH] proxyclient: refresh put on restartListeners There is no need to check if the put is ok or not before refreshing it. Indeed, the first successful put will make the ok flag to true. But, if an expiration is missed (when not connected for example), the put will not be refreshed when the connectivity will change (moreover, server and client can have different timeouts). --- src/dht_proxy_client.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/dht_proxy_client.cpp b/src/dht_proxy_client.cpp index ace9421d..881d6455 100644 --- a/src/dht_proxy_client.cpp +++ b/src/dht_proxy_client.cpp @@ -1062,17 +1062,15 @@ DhtProxyClient::restartListeners() for (auto& search : searches_) { auto key = search.first; for (auto& put : search.second.puts) { - if (!*put.second.ok) { - doPut(key, put.second.value, [ok = put.second.ok](bool result){ - *ok = result; - }, time_point::max(), true); - if (!put.second.refreshPutTimer){ - put.second.refreshPutTimer = std::make_unique<asio::steady_timer>(httpContext_); - } - put.second.refreshPutTimer->expires_at(std::chrono::steady_clock::now() + proxy::OP_TIMEOUT - proxy::OP_MARGIN); - put.second.refreshPutTimer->async_wait(std::bind(&DhtProxyClient::handleRefreshPut, this, - std::placeholders::_1, key, put.first)); + doPut(key, put.second.value, [ok = put.second.ok](bool result){ + *ok = result; + }, time_point::max(), true); + if (!put.second.refreshPutTimer) { + put.second.refreshPutTimer = std::make_unique<asio::steady_timer>(httpContext_); } + put.second.refreshPutTimer->expires_at(std::chrono::steady_clock::now() + proxy::OP_TIMEOUT - proxy::OP_MARGIN); + put.second.refreshPutTimer->async_wait(std::bind(&DhtProxyClient::handleRefreshPut, this, + std::placeholders::_1, key, put.first)); } } if (not deviceKey_.empty()) { -- GitLab