From 97fccc445888d21a2a6d2272f3018d705ed5c2d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20D=C3=A9saulniers?= Date: Thu, 7 Apr 2016 21:00:35 -0400 Subject: [PATCH] dht: fix drop due to ratelimit bug --- include/opendht/network_engine.h | 1 - src/network_engine.cpp | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/include/opendht/network_engine.h b/include/opendht/network_engine.h index cf14c27a..5eeaab5c 100644 --- a/include/opendht/network_engine.h +++ b/include/opendht/network_engine.h @@ -539,7 +539,6 @@ private: std::queue rate_limit_time {}; static std::mt19937 rd_device; - time_point now; // requests handling uint16_t transaction_id {1}; diff --git a/src/network_engine.cpp b/src/network_engine.cpp index c89ca8ab..64f5a3c3 100644 --- a/src/network_engine.cpp +++ b/src/network_engine.cpp @@ -78,13 +78,13 @@ bool NetworkEngine::rateLimit() { using namespace std::chrono; - while (not rate_limit_time.empty() and duration_cast(now - rate_limit_time.front()) > seconds(1)) + while (not rate_limit_time.empty() and duration_cast(scheduler.time() - rate_limit_time.front()) > seconds(1)) rate_limit_time.pop(); if (rate_limit_time.size() >= MAX_REQUESTS_PER_SEC) return false; - rate_limit_time.emplace(now); + rate_limit_time.emplace(scheduler.time()); return true; } @@ -631,11 +631,11 @@ NetworkEngine::sendAnnounceValue(std::shared_ptr n, const InfoHash& infoha msgpack::packer pk(&buffer); pk.pack_map(5); - pk.pack(std::string("a")); pk.pack_map((created < now ? 5 : 4)); + pk.pack(std::string("a")); pk.pack_map((created < scheduler.time() ? 5 : 4)); pk.pack(std::string("id")); pk.pack(myid); pk.pack(std::string("h")); pk.pack(infohash); pk.pack(std::string("values")); pk.pack_array(1); pk.pack(value); - if (created < now) { + if (created < scheduler.time()) { pk.pack(std::string("c")); pk.pack(to_time_t(created)); }