dht: always use pseudo-RNG for non-critical random numbers

This commit is contained in:
Adrien Béraud committed 2020-02-07 00:36:42 -05:00
1 parent abede1e72a
commit 95028e3770
9 files changed
+42 -46

No files matched your search

+7 -7
View File
@@ -37,8 +37,8 @@ NodeCache::getNode(const InfoHash& id, sa_family_t family) {
Sp<Node>
NodeCache::getNode(const InfoHash& id, const SockAddr& addr, time_point now, bool confirm, bool client) {
if (not id)
return std::make_shared<Node>(id, addr);
return cache(addr.getFamily()).getNode(id, addr, now, confirm, client);
return std::make_shared<Node>(id, addr, rd, client);
return cache(addr.getFamily()).getNode(id, addr, now, confirm, client, rd);
}
std::vector<Sp<Node>>
@@ -104,13 +104,13 @@ NodeCache::NodeMap::getNode(const InfoHash& id)
}
Sp<Node>
NodeCache::NodeMap::getNode(const InfoHash& id, const SockAddr& addr, time_point now, bool confirm, bool client)
NodeCache::NodeMap::getNode(const InfoHash& id, const SockAddr& addr, time_point now, bool confirm, bool client, std::mt19937_64& rd)
{
auto it = emplace(id, std::weak_ptr<Node>{});
auto node = it.first->second.lock();
auto& nref = (*this)[id];
auto node = nref.lock();
if (not node) {
node = std::make_shared<Node>(id, addr, client);
it.first->second = node;
node = std::make_shared<Node>(id, addr, rd, client);
nref = node;
if (cleanup_counter++ == CLEANUP_FREQ) {
cleanup();
cleanup_counter = 0;