From 33f95c00a99eb0eac3d6dfa511616f6f0cf25e84 Mon Sep 17 00:00:00 2001 From: kaldoran Date: Tue, 2 Aug 2016 16:09:45 -0400 Subject: [PATCH] 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] --- include/opendht/node_cache.h | 4 ++-- src/network_engine.cpp | 10 +++++----- src/node_cache.cpp | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/opendht/node_cache.h b/include/opendht/node_cache.h index c7906938..cbddd0be 100644 --- a/include/opendht/node_cache.h +++ b/include/opendht/node_cache.h @@ -28,7 +28,7 @@ namespace dht { struct NodeCache { std::shared_ptr getNode(const InfoHash& id, sa_family_t family); - std::shared_ptr getNode(const InfoHash& id, const sockaddr* sa, socklen_t sa_len, time_point now, int confirmed); + std::shared_ptr 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> { public: std::shared_ptr getNode(const InfoHash& id); - std::shared_ptr getNode(const InfoHash& id, const sockaddr* sa, socklen_t sa_len, time_point now, int confirmed); + std::shared_ptr getNode(const InfoHash& id, const sockaddr* sa, socklen_t sa_len, time_point now, bool confirmed); void clearBadNodes(); }; diff --git a/src/network_engine.cpp b/src/network_engine.cpp index 56be1a69..75d05b06 100644 --- a/src/network_engine.cpp +++ b/src/network_engine.cpp @@ -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); } } diff --git a/src/node_cache.cpp b/src/node_cache.cpp index 24372d67..31ee1d64 100644 --- a/src/node_cache.cpp +++ b/src/node_cache.cpp @@ -27,7 +27,7 @@ NodeCache::getNode(const InfoHash& id, sa_family_t family) { } std::shared_ptr -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(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 -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{}); auto node = it.first->second.lock();