diff --git a/include/opendht/node.h b/include/opendht/node.h index dec8c75f7..5219226f1 100644 --- a/include/opendht/node.h +++ b/include/opendht/node.h @@ -89,6 +89,9 @@ struct Node { bool isRemovable(const time_point& now) const { return isExpired() and isOld(now); } + bool isUpgradeable(const time_point& now) const { + return time + NODE_UPDATE_TIME < now; + } NodeExport exportNode() const { NodeExport ne; @@ -151,6 +154,9 @@ struct Node { /* The time after which we consider a node to be expirable. */ static constexpr const std::chrono::minutes NODE_EXPIRE_TIME {10}; + /* The time after which we consider a node to be upgradeable. */ + static constexpr const std::chrono::minutes NODE_UPDATE_TIME {1}; + /* Time for a request to timeout */ static constexpr const std::chrono::seconds MAX_RESPONSE_TIME {1}; diff --git a/src/node.cpp b/src/node.cpp index ac2be22df..756beb4de 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -28,6 +28,7 @@ namespace dht { constexpr std::chrono::minutes Node::NODE_EXPIRE_TIME; constexpr std::chrono::minutes Node::NODE_GOOD_TIME; +constexpr std::chrono::minutes Node::NODE_UPDATE_TIME; constexpr std::chrono::seconds Node::MAX_RESPONSE_TIME; Node::Node(const InfoHash& id, const SockAddr& addr, std::mt19937_64& rd, bool client) diff --git a/src/node_cache.cpp b/src/node_cache.cpp index 58a7018a8..a1b8b0d32 100644 --- a/src/node_cache.cpp +++ b/src/node_cache.cpp @@ -115,7 +115,7 @@ NodeCache::NodeMap::getNode(const InfoHash& id, const SockAddr& addr, time_point cleanup(); cleanup_counter = 0; } - } else if (confirm or node->isOld(now)) { + } else if ((confirm and node->isUpgradeable(now)) or node->isOld(now)) { node->update(addr); } return node;