Skip to content
Snippets Groups Projects
Commit 6cdc242b authored by Adrien Béraud's avatar Adrien Béraud
Browse files

node: add pendingMesageCount

parent ac234640
Branches
Tags
No related merge requests found
...@@ -57,7 +57,9 @@ struct Node { ...@@ -57,7 +57,9 @@ struct Node {
} }
bool isExpired() const { return expired_; } bool isExpired() const { return expired_; }
bool isGood(time_point now) const; bool isGood(time_point now) const;
bool isMessagePending() const; bool isPendingMessage() const;
size_t getPendingMessageCount() const;
NodeExport exportNode() const { return NodeExport {id, ss, sslen}; } NodeExport exportNode() const { return NodeExport {id, ss, sslen}; }
sa_family_t getFamily() const { return ss.ss_family; } sa_family_t getFamily() const { return ss.ss_family; }
......
...@@ -503,7 +503,7 @@ Dht::newNode(const std::shared_ptr<Node>& node, int confirm) ...@@ -503,7 +503,7 @@ Dht::newNode(const std::shared_ptr<Node>& node, int confirm)
of bad nodes fast. */ of bad nodes fast. */
if (not n->isGood(now)) { if (not n->isGood(now)) {
dubious = true; dubious = true;
if (not n->isMessagePending()) { if (not n->isPendingMessage()) {
DHT_LOG.DEBUG("Sending ping to dubious node %s.", n->toString().c_str()); DHT_LOG.DEBUG("Sending ping to dubious node %s.", n->toString().c_str());
network_engine.sendPing(n, nullptr, nullptr); network_engine.sendPing(n, nullptr, nullptr);
break; break;
......
...@@ -40,7 +40,7 @@ Node::isGood(time_point now) const ...@@ -40,7 +40,7 @@ Node::isGood(time_point now) const
} }
bool bool
Node::isMessagePending() const Node::isPendingMessage() const
{ {
for (auto w : requests_) { for (auto w : requests_) {
if (auto r = w.lock()) { if (auto r = w.lock()) {
...@@ -51,6 +51,19 @@ Node::isMessagePending() const ...@@ -51,6 +51,19 @@ Node::isMessagePending() const
return false; return false;
} }
size_t
Node::getPendingMessageCount() const
{
size_t count {0};
for (auto w : requests_) {
if (auto r = w.lock()) {
if (r->pending())
count++;
}
}
return count;
}
void void
Node::update(const sockaddr* sa, socklen_t salen) Node::update(const sockaddr* sa, socklen_t salen)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment