Skip to content
Snippets Groups Projects
Commit 97fccc44 authored by Simon Désaulniers's avatar Simon Désaulniers Committed by Adrien Béraud
Browse files

dht: fix drop due to ratelimit bug

parent ee318818
No related branches found
No related tags found
No related merge requests found
...@@ -539,7 +539,6 @@ private: ...@@ -539,7 +539,6 @@ private:
std::queue<time_point> rate_limit_time {}; std::queue<time_point> rate_limit_time {};
static std::mt19937 rd_device; static std::mt19937 rd_device;
time_point now;
// requests handling // requests handling
uint16_t transaction_id {1}; uint16_t transaction_id {1};
......
...@@ -78,13 +78,13 @@ bool ...@@ -78,13 +78,13 @@ bool
NetworkEngine::rateLimit() NetworkEngine::rateLimit()
{ {
using namespace std::chrono; using namespace std::chrono;
while (not rate_limit_time.empty() and duration_cast<seconds>(now - rate_limit_time.front()) > seconds(1)) while (not rate_limit_time.empty() and duration_cast<seconds>(scheduler.time() - rate_limit_time.front()) > seconds(1))
rate_limit_time.pop(); rate_limit_time.pop();
if (rate_limit_time.size() >= MAX_REQUESTS_PER_SEC) if (rate_limit_time.size() >= MAX_REQUESTS_PER_SEC)
return false; return false;
rate_limit_time.emplace(now); rate_limit_time.emplace(scheduler.time());
return true; return true;
} }
...@@ -631,11 +631,11 @@ NetworkEngine::sendAnnounceValue(std::shared_ptr<Node> n, const InfoHash& infoha ...@@ -631,11 +631,11 @@ NetworkEngine::sendAnnounceValue(std::shared_ptr<Node> n, const InfoHash& infoha
msgpack::packer<msgpack::sbuffer> pk(&buffer); msgpack::packer<msgpack::sbuffer> pk(&buffer);
pk.pack_map(5); 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("id")); pk.pack(myid);
pk.pack(std::string("h")); pk.pack(infohash); pk.pack(std::string("h")); pk.pack(infohash);
pk.pack(std::string("values")); pk.pack_array(1); pk.pack(value); 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(std::string("c"));
pk.pack(to_time_t(created)); pk.pack(to_time_t(created));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment