Switch project license from GPL-3.0-or-later to MIT

This commit is contained in:
Adrien Béraud committed 2026-01-17 22:25:43 -05:00
1 parent 4fd4745647
commit f9cba71d51
123 files changed
+5944 -7638

No files matched your search

+21 -28
View File
@@ -1,19 +1,5 @@
/*
* Copyright (c) 2014-2026 Savoir-faire Linux Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// Copyright (c) 2014-2026 Savoir-faire Linux Inc.
// SPDX-License-Identifier: MIT
#include "node_cache.h"
@@ -29,12 +15,14 @@ NodeCache::~NodeCache()
}
Sp<Node>
NodeCache::getNode(const InfoHash& id, sa_family_t family) {
NodeCache::getNode(const InfoHash& id, sa_family_t family)
{
return cache(family).getNode(id);
}
Sp<Node>
NodeCache::getNode(const InfoHash& id, const SockAddr& addr, time_point now, bool confirm, bool client) {
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, rd, client);
return cache(addr.getFamily()).getNode(id, addr, now, confirm, client, rd);
@@ -58,8 +46,7 @@ NodeCache::NodeMap::getCachedNodes(const InfoHash& id, size_t count) const
return ret;
};
auto it_p = lower_bound(id),
it_n = it_p;
auto it_p = lower_bound(id), it_n = it_p;
if (not empty())
dec_it(it_p); /* Create 2 separate iterator if we could */
@@ -67,12 +54,15 @@ NodeCache::NodeMap::getCachedNodes(const InfoHash& id, size_t count) const
/* If one of the iterator is at the end, then take the other one
If they are both in middle of somewhere comapre both and take
the closest to the id. */
if (it_p == cend()) it = it_n++;
else if (it_n == cend()) it = dec_it(it_p);
else it = id.xorCmp(it_p->first, it_n->first) < 0 ? dec_it(it_p) : it_n++;
if (it_p == cend())
it = it_n++;
else if (it_n == cend())
it = dec_it(it_p);
else
it = id.xorCmp(it_p->first, it_n->first) < 0 ? dec_it(it_p) : it_n++;
if (auto n = it->second.lock())
if ( not n->isExpired() and not n->isClient() )
if (not n->isExpired() and not n->isClient())
nodes.emplace_back(std::move(n));
}
@@ -103,7 +93,8 @@ NodeCache::NodeMap::getNode(const InfoHash& id)
}
Sp<Node>
NodeCache::NodeMap::getNode(const InfoHash& id, const SockAddr& addr, time_point now, bool confirm, bool client, std::mt19937_64& rd)
NodeCache::NodeMap::getNode(
const InfoHash& id, const SockAddr& addr, time_point now, bool confirm, bool client, std::mt19937_64& rd)
{
auto& nref = (*this)[id];
auto node = nref.lock();
@@ -121,7 +112,8 @@ NodeCache::NodeMap::getNode(const InfoHash& id, const SockAddr& addr, time_point
}
void
NodeCache::NodeMap::clearBadNodes() {
NodeCache::NodeMap::clearBadNodes()
{
for (auto it = cbegin(); it != cend();) {
if (auto n = it->second.lock()) {
n->reset();
@@ -134,7 +126,8 @@ NodeCache::NodeMap::clearBadNodes() {
}
void
NodeCache::NodeMap::setExpired() {
NodeCache::NodeMap::setExpired()
{
for (auto& wn : *this)
if (auto n = wn.second.lock())
n->setExpired();
@@ -156,4 +149,4 @@ NodeCache::NodeMap::cleanup()
}
}
}
} // namespace dht