mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 04:21:51 +00:00
NodeCache: getNode takes bool not int
Since this was old code which use int as bool I edit that for a bool [and change related code]
This commit is contained in:
1 parent
7383505dcc
commit
33f95c00a9
3 files changed
+9
-9
No files matched your search
@@ -28,7 +28,7 @@ namespace dht {
|
||||
|
||||
struct NodeCache {
|
||||
std::shared_ptr<Node> getNode(const InfoHash& id, sa_family_t family);
|
||||
std::shared_ptr<Node> getNode(const InfoHash& id, const sockaddr* sa, socklen_t sa_len, time_point now, int confirmed);
|
||||
std::shared_ptr<Node> getNode(const InfoHash& id, const sockaddr* sa, socklen_t sa_len, time_point now, bool confirmed);
|
||||
|
||||
/**
|
||||
* Reset the connectivity state of every node,
|
||||
@@ -41,7 +41,7 @@ private:
|
||||
class NodeMap : public std::map<InfoHash, std::weak_ptr<Node>> {
|
||||
public:
|
||||
std::shared_ptr<Node> getNode(const InfoHash& id);
|
||||
std::shared_ptr<Node> getNode(const InfoHash& id, const sockaddr* sa, socklen_t sa_len, time_point now, int confirmed);
|
||||
std::shared_ptr<Node> getNode(const InfoHash& id, const sockaddr* sa, socklen_t sa_len, time_point now, bool confirmed);
|
||||
void clearBadNodes();
|
||||
};
|
||||
|
||||
|
||||
@@ -323,7 +323,7 @@ NetworkEngine::processMessage(const uint8_t *buf, size_t buflen, const sockaddr*
|
||||
if (msg.tid.length != 4) {
|
||||
DHT_LOG.ERR("Broken node truncates transaction ids (len: %d): ", msg.tid.length);
|
||||
DHT_LOG.ERR.logPrintable(buf, buflen);
|
||||
blacklistNode(cache.getNode(msg.id, from, fromlen, now, 1));
|
||||
blacklistNode(cache.getNode(msg.id, from, fromlen, now, true));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -338,7 +338,7 @@ NetworkEngine::processMessage(const uint8_t *buf, size_t buflen, const sockaddr*
|
||||
auto node = req->node;
|
||||
if (node->id != msg.id) {
|
||||
bool unknown_node = node->id == zeroes;
|
||||
node = cache.getNode(msg.id, from, fromlen, now, 2);
|
||||
node = cache.getNode(msg.id, from, fromlen, now, true);
|
||||
if (unknown_node) {
|
||||
// received reply to a message sent when we didn't know the node ID.
|
||||
req->node = node;
|
||||
@@ -392,7 +392,7 @@ NetworkEngine::processMessage(const uint8_t *buf, size_t buflen, const sockaddr*
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
auto node = cache.getNode(msg.id, from, fromlen, now, 1);
|
||||
auto node = cache.getNode(msg.id, from, fromlen, now, true);
|
||||
node->received(now, {});
|
||||
onNewNode(node, 1);
|
||||
try {
|
||||
@@ -665,7 +665,7 @@ NetworkEngine::deserializeNodes(ParsedMessage& msg) {
|
||||
memcpy(&sin.sin_port, ni + ni_id.size() + 4, 2);
|
||||
if (isMartian((sockaddr*)&sin, sizeof(sin)) || isNodeBlacklisted((sockaddr*)&sin, sizeof(sin)))
|
||||
continue;
|
||||
msg.nodes4.emplace_back(cache.getNode(ni_id, (sockaddr*)&sin, sizeof(sin), now, 0));
|
||||
msg.nodes4.emplace_back(cache.getNode(ni_id, (sockaddr*)&sin, sizeof(sin), now, false));
|
||||
onNewNode(msg.nodes4.back(), 0);
|
||||
}
|
||||
for (unsigned i = 0; i < msg.nodes6_raw.size() / NODE6_INFO_BUF_LEN; i++) {
|
||||
@@ -680,7 +680,7 @@ NetworkEngine::deserializeNodes(ParsedMessage& msg) {
|
||||
memcpy(&sin6.sin6_port, ni + HASH_LEN + 16, 2);
|
||||
if (isMartian((sockaddr*)&sin6, sizeof(sin6)) || isNodeBlacklisted((sockaddr*)&sin6, sizeof(sin6)))
|
||||
continue;
|
||||
msg.nodes6.emplace_back(cache.getNode(ni_id, (sockaddr*)&sin6, sizeof(sin6), now, 0));
|
||||
msg.nodes6.emplace_back(cache.getNode(ni_id, (sockaddr*)&sin6, sizeof(sin6), now, false));
|
||||
onNewNode(msg.nodes6.back(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -27,7 +27,7 @@ NodeCache::getNode(const InfoHash& id, sa_family_t family) {
|
||||
}
|
||||
|
||||
std::shared_ptr<Node>
|
||||
NodeCache::getNode(const InfoHash& id, const sockaddr* sa, socklen_t sa_len, time_point now, int confirm) {
|
||||
NodeCache::getNode(const InfoHash& id, const sockaddr* sa, socklen_t sa_len, time_point now, bool confirm) {
|
||||
if (id == zeroes)
|
||||
return std::make_shared<Node>(id, sa, sa_len);
|
||||
return (sa->sa_family == AF_INET ? cache_4 : cache_6).getNode(id, sa, sa_len, now, confirm);
|
||||
@@ -57,7 +57,7 @@ NodeCache::NodeMap::getNode(const InfoHash& id)
|
||||
}
|
||||
|
||||
std::shared_ptr<Node>
|
||||
NodeCache::NodeMap::getNode(const InfoHash& id, const sockaddr* sa, socklen_t sa_len, time_point now, int confirm)
|
||||
NodeCache::NodeMap::getNode(const InfoHash& id, const sockaddr* sa, socklen_t sa_len, time_point now, bool confirm)
|
||||
{
|
||||
auto it = emplace(id, std::weak_ptr<Node>{});
|
||||
auto node = it.first->second.lock();
|
||||
|
||||
Reference in new issue
Block a user