Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

difficult node spoofing #710

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/opendht/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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};

Expand Down
1 change: 1 addition & 0 deletions src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/node_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading